OSDN Git Service

Synchronize access to sNotificationBundle.
authorFelipe Leme <felipeal@google.com>
Fri, 21 Sep 2018 23:37:53 +0000 (16:37 -0700)
committerNandana Dutt <nandana@google.com>
Tue, 2 Oct 2018 10:39:42 +0000 (11:39 +0100)
Otherwise Shell can crash due to ConcurrentModificationException

Test: atest BugreportReceiverTest
Test: manual verification

Fixes:116280360

Change-Id: I138acd43b313d2a7a9d945fb44a9d63e1ad798eb
Merged-In: I138acd43b313d2a7a9d945fb44a9d63e1ad798eb
(cherry picked from commit ee72fa19a97f2b0677a130204e3527bc3233e4d9)

packages/Shell/src/com/android/shell/BugreportProgressService.java

index 4fc190d..329d72c 100644 (file)
@@ -42,6 +42,7 @@ import java.util.zip.ZipOutputStream;
 
 import libcore.io.Streams;
 
+import com.android.internal.annotations.GuardedBy;
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.app.ChooserActivity;
 import com.android.internal.logging.MetricsLogger;
@@ -232,6 +233,7 @@ public class BugreportProgressService extends Service {
      */
     private boolean mTakingScreenshot;
 
+    @GuardedBy("sNotificationBundle")
     private static final Bundle sNotificationBundle = new Bundle();
 
     private boolean mIsWatch;
@@ -1053,10 +1055,12 @@ public class BugreportProgressService extends Service {
     }
 
     private static Notification.Builder newBaseNotification(Context context) {
-        if (sNotificationBundle.isEmpty()) {
-            // Rename notifcations from "Shell" to "Android System"
-            sNotificationBundle.putString(Notification.EXTRA_SUBSTITUTE_APP_NAME,
-                    context.getString(com.android.internal.R.string.android_system_label));
+        synchronized (sNotificationBundle) {
+            if (sNotificationBundle.isEmpty()) {
+                // Rename notifcations from "Shell" to "Android System"
+                sNotificationBundle.putString(Notification.EXTRA_SUBSTITUTE_APP_NAME,
+                        context.getString(com.android.internal.R.string.android_system_label));
+            }
         }
         return new Notification.Builder(context, NOTIFICATION_CHANNEL_ID)
                 .addExtras(sNotificationBundle)