diff options
author | 2024-10-22 15:45:07 +0000 | |
---|---|---|
committer | 2024-10-22 15:57:29 +0000 | |
commit | 91580c0885060b9ba3091e7bd5628f7743952d45 (patch) | |
tree | 2cd0995898871826805da6b72c181eb39ced697c /packages/Shell/src | |
parent | f7ff135d84da6cfbab4c86de83e01eec8ce75b43 (diff) |
Fix ANR in Process com.android.shell after BR is finished
Linked to http://pa/2964369
Bug: 360800881
Fix: 360800881
Test: Watch: https://screenshot.googleplex.com/4hYd3RTfdUXU5mG https://screenshot.googleplex.com/6L4YkmCYey8sHL5, Phone: https://screenshot.googleplex.com/3GWMVACFivfukc7
Flag: EXEMPT minor bugfix
Change-Id: I99443f172cf43bde9c3637e91a3af51859eb6f35
Diffstat (limited to 'packages/Shell/src')
-rw-r--r-- | packages/Shell/src/com/android/shell/BugreportProgressService.java | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/packages/Shell/src/com/android/shell/BugreportProgressService.java b/packages/Shell/src/com/android/shell/BugreportProgressService.java index bcfd8f620f9c..5a205f2e3165 100644 --- a/packages/Shell/src/com/android/shell/BugreportProgressService.java +++ b/packages/Shell/src/com/android/shell/BugreportProgressService.java @@ -30,7 +30,6 @@ import android.accounts.AccountManager; import android.annotation.MainThread; import android.annotation.Nullable; import android.annotation.SuppressLint; -import android.app.ActivityThread; import android.app.AlertDialog; import android.app.Notification; import android.app.Notification.Action; @@ -117,7 +116,9 @@ import java.util.Enumeration; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; @@ -174,6 +175,18 @@ public class BugreportProgressService extends Service { static final String EXTRA_EXTRA_ATTACHMENT_URI = "android.intent.extra.EXTRA_ATTACHMENT_URI"; + private static final ThreadFactory sBugreportManagerCallbackThreadFactory = + new ThreadFactory() { + private static final ThreadFactory mFactory = Executors.defaultThreadFactory(); + + @Override + public Thread newThread(Runnable r) { + Thread thread = mFactory.newThread(r); + thread.setName("BRMgrCallbackThread"); + return thread; + } + }; + private static final int MSG_SERVICE_COMMAND = 1; private static final int MSG_DELAYED_SCREENSHOT = 2; private static final int MSG_SCREENSHOT_REQUEST = 3; @@ -277,6 +290,7 @@ public class BugreportProgressService extends Service { private boolean mIsWatch; private boolean mIsTv; + private ExecutorService mBugreportSingleThreadExecutor; @Override public void onCreate() { @@ -307,6 +321,8 @@ public class BugreportProgressService extends Service { isTv(this) ? NotificationManager.IMPORTANCE_DEFAULT : NotificationManager.IMPORTANCE_LOW)); mBugreportManager = mContext.getSystemService(BugreportManager.class); + mBugreportSingleThreadExecutor = Executors.newSingleThreadExecutor( + sBugreportManagerCallbackThreadFactory); } @Override @@ -337,6 +353,7 @@ public class BugreportProgressService extends Service { public void onDestroy() { mServiceHandler.getLooper().quit(); mScreenshotHandler.getLooper().quit(); + mBugreportSingleThreadExecutor.close(); super.onDestroy(); } @@ -713,8 +730,6 @@ public class BugreportProgressService extends Service { } } - final Executor executor = ActivityThread.currentActivityThread().getExecutor(); - Log.i(TAG, "bugreport type = " + bugreportType + " bugreport file fd: " + bugreportFd + " screenshot file fd: " + screenshotFd); @@ -723,7 +738,8 @@ public class BugreportProgressService extends Service { try { synchronized (mLock) { mBugreportManager.startBugreport(bugreportFd, screenshotFd, - new BugreportParams(bugreportType), executor, bugreportCallback); + new BugreportParams(bugreportType), mBugreportSingleThreadExecutor, + bugreportCallback); bugreportCallback.trackInfoWithIdLocked(); } } catch (RuntimeException e) { |