diff options
author | Po-Chien Hsueh <pchsueh@google.com> | 2020-03-05 13:43:42 +0800 |
---|---|---|
committer | Po-Chien Hsueh <pchsueh@google.com> | 2020-03-05 13:49:16 +0800 |
commit | 7ba4d3945a325a7cab88be79576d490ede87c1a1 (patch) | |
tree | 7650e62b3568ac4111d0580faaf5f844a751953b | |
parent | efbcd6752d9e9f980ae5044b9bbd35fe4b192c52 (diff) | |
download | base-7ba4d3945a325a7cab88be79576d490ede87c1a1.tar.gz |
Keep error message notification after stop
If the notification contains an error message, keep it even after the
service is stopped.
Bug: 149876966
Test: adb shell am start-activity \
-n com.android.dynsystem/com.android.dynsystem.VerificationActivity \
-a android.os.image.action.START_INSTALL \
-d file:///file_does_not_exist
Change-Id: I5fdbcaf5ed28343f53d66b3f02ccb66d3c7920ff
-rw-r--r-- | packages/DynamicSystemInstallationService/src/com/android/dynsystem/DynamicSystemInstallationService.java | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/packages/DynamicSystemInstallationService/src/com/android/dynsystem/DynamicSystemInstallationService.java b/packages/DynamicSystemInstallationService/src/com/android/dynsystem/DynamicSystemInstallationService.java index f36f97ddf610..f80e934cf37c 100644 --- a/packages/DynamicSystemInstallationService/src/com/android/dynsystem/DynamicSystemInstallationService.java +++ b/packages/DynamicSystemInstallationService/src/com/android/dynsystem/DynamicSystemInstallationService.java @@ -139,6 +139,7 @@ public class DynamicSystemInstallationService extends Service private long mCurrentPartitionInstalledSize; private boolean mJustCancelledByUser; + private boolean mKeepNotification; // This is for testing only now private boolean mEnableWhenCompleted; @@ -173,8 +174,11 @@ public class DynamicSystemInstallationService extends Service if (cache != null) { cache.flush(); } - // Cancel the persistent notification. - mNM.cancel(NOTIFICATION_ID); + + if (!mKeepNotification) { + // Cancel the persistent notification. + mNM.cancel(NOTIFICATION_ID); + } } @Override @@ -227,9 +231,6 @@ public class DynamicSystemInstallationService extends Service return; } - // if it's not successful, reset the task and stop self. - resetTaskAndStop(); - switch (result) { case RESULT_CANCELLED: postStatus(STATUS_NOT_STARTED, CAUSE_INSTALL_CANCELLED, null); @@ -248,6 +249,9 @@ public class DynamicSystemInstallationService extends Service postStatus(STATUS_NOT_STARTED, CAUSE_ERROR_EXCEPTION, detail); break; } + + // if it's not successful, reset the task and stop self. + resetTaskAndStop(); } private void executeInstallCommand(Intent intent) { @@ -392,10 +396,10 @@ public class DynamicSystemInstallationService extends Service private void resetTaskAndStop() { mInstallTask = null; - stopForeground(true); - - // stop self, but this service is not destroyed yet if it's still bound - stopSelf(); + new Handler().postDelayed(() -> { + stopForeground(STOP_FOREGROUND_DETACH); + stopSelf(); + }, 50); } private void prepareNotification() { @@ -503,6 +507,7 @@ public class DynamicSystemInstallationService extends Service private void postStatus(int status, int cause, Throwable detail) { String statusString; String causeString; + mKeepNotification = false; switch (status) { case STATUS_NOT_STARTED: @@ -531,12 +536,15 @@ public class DynamicSystemInstallationService extends Service break; case CAUSE_ERROR_IO: causeString = "ERROR_IO"; + mKeepNotification = true; break; case CAUSE_ERROR_INVALID_URL: causeString = "ERROR_INVALID_URL"; + mKeepNotification = true; break; case CAUSE_ERROR_EXCEPTION: causeString = "ERROR_EXCEPTION"; + mKeepNotification = true; break; default: causeString = "CAUSE_NOT_SPECIFIED"; |