From ed5e51dbb2e23ca43ff91733bad3a68a9d2d0f00 Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Fri, 21 Sep 2018 16:37:53 -0700 Subject: [PATCH] Synchronize access to sNotificationBundle. 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) --- .../src/com/android/shell/BugreportProgressService.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/Shell/src/com/android/shell/BugreportProgressService.java b/packages/Shell/src/com/android/shell/BugreportProgressService.java index 4fc190d43056..329d72c3c137 100644 --- a/packages/Shell/src/com/android/shell/BugreportProgressService.java +++ b/packages/Shell/src/com/android/shell/BugreportProgressService.java @@ -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) -- 2.11.0