From a3a10f3abc3455685aea8a9878ab0786accc0301 Mon Sep 17 00:00:00 2001 From: Zim Date: Fri, 2 Dec 2022 20:28:49 +0000 Subject: [PATCH] Finish attach appliation before creating app context Creating the app context involves getting app resources from the app's apk. This operation could be blocked on an incremental fs and trigger the proc start timeout. While fixing this, I noticed that apps could also run code and block in AppComponentFactory#instantiateClassLoader, so moved the call to finishAttachApplication even earlier. It's probably worth re-thinking the AnR timeouts around proc starts, because currently, if the app blocks in instantiateClassLoader for instance, neither AnR timeout nor proc start timeout will trigger. For now, this fixes the test and keeps the behavior as close to the old behavior as possible. Test: atest CtsPackageManagerStatsHostTestCases:com.android.cts.packagemanager.stats.host.IncrementalAppErrorStatsTests#testAppCrashOnIncremental Bug: 261009296 Change-Id: Ic75a4e9d38a7c21d4a0b948d6fb26389723a80f6 --- core/java/android/app/ActivityThread.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 897cd1f27e11c..70d93c730a7c9 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -6715,6 +6715,13 @@ public final class ActivityThread extends ClientTransactionHandler ii = null; } + final IActivityManager mgr = ActivityManager.getService(); + try { + mgr.finishAttachApplication(mStartSeq); + } catch (RemoteException ex) { + throw ex.rethrowFromSystemServer(); + } + final ContextImpl appContext = ContextImpl.createAppContext(this, data.info); mConfigurationController.updateLocaleListFromAppContext(appContext); @@ -6783,13 +6790,6 @@ public final class ActivityThread extends ClientTransactionHandler final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskWrites(); final StrictMode.ThreadPolicy writesAllowedPolicy = StrictMode.getThreadPolicy(); - final IActivityManager mgr = ActivityManager.getService(); - try { - mgr.finishAttachApplication(mStartSeq); - } catch (RemoteException ex) { - throw ex.rethrowFromSystemServer(); - } - // Wait for debugger after we have notified the system to finish attach application if (data.debugMode != ApplicationThreadConstants.DEBUG_OFF) { // XXX should have option to change the port.