summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Zimuzo Ezeozue <zezeozue@google.com> 2024-05-24 17:05:26 +0100
committer Zimuzo Ezeozue <zezeozue@google.com> 2024-12-09 19:39:37 +0000
commit752c49b6e444d6fb78bd9c1df5b33c408e406f1a (patch)
tree1d8dab5fefd776b6101b9ef4eadbe2f083e53690
parent5054fff0ca9fade624543369be3fae1f4a7a0a62 (diff)
Fix bindApplication starting activities late
With the attachApplication split introduced in I659f2083f460701d858ebb7a8af9fa748ff4bfe9 apps send a finishAttachApplication back to the system after their initialization (Application#onCreate). The system then dispatches Broadcast, Service and Activity starts to the app. The delayed dispatch of Activity has 2 side effects: 1. Apps could post messages on their main thread that will run before activity start message which could slow down their ttff. 2. The setFocusedApplication call is delayed and the system doesn't know the focused application until after app init. To mitigate this, we dispatch Activity start early before app init. Test: atest ActivityManagerTest Bug: 319519089 Bug: 333663697 Bug: 382378705 Bug: 366147979 Bug: 358102320 Flag: com.android.server.am.expedite_activity_launch_on_cold_start Change-Id: I762d6e943530133f8031a16f40eda97b4f476cd0
-rw-r--r--services/core/java/com/android/server/am/ActivityManagerService.java31
-rw-r--r--services/core/java/com/android/server/am/flags.aconfig10
2 files changed, 30 insertions, 11 deletions
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index cd929c1883d0..a184e905d0fa 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -4799,9 +4799,6 @@ public class ActivityManagerService extends IActivityManager.Stub
updateLruProcessLocked(app, false, null);
checkTime(startTime, "attachApplicationLocked: after updateLruProcessLocked");
- updateOomAdjLocked(app, OOM_ADJ_REASON_PROCESS_BEGIN);
- checkTime(startTime, "attachApplicationLocked: after updateOomAdjLocked");
-
final long now = SystemClock.uptimeMillis();
synchronized (mAppProfiler.mProfilerLock) {
app.mProfile.setLastRequestedGc(now);
@@ -4815,6 +4812,15 @@ public class ActivityManagerService extends IActivityManager.Stub
}
mProcessesOnHold.remove(app);
+ // See if the top visible activity is waiting to run in this process...
+ if (com.android.server.am.Flags.expediteActivityLaunchOnColdStart()) {
+ if (normalMode) {
+ mAtmInternal.attachApplication(app.getWindowProcessController());
+ }
+ }
+ updateOomAdjLocked(app, OOM_ADJ_REASON_PROCESS_BEGIN);
+ checkTime(startTime, "attachApplicationLocked: after updateOomAdjLocked");
+
if (!mConstants.mEnableWaitForFinishAttachApplication) {
finishAttachApplicationInner(startSeq, callingUid, pid);
}
@@ -4880,18 +4886,21 @@ public class ActivityManagerService extends IActivityManager.Stub
// Mark the finish attach application phase as completed
mProcessStateController.setPendingFinishAttach(app, false);
- final boolean normalMode = mProcessesReady || isAllowedWhileBooting(app.info);
final String processName = app.processName;
boolean badApp = false;
boolean didSomething = false;
- // See if the top visible activity is waiting to run in this process...
- if (normalMode) {
- try {
- didSomething = mAtmInternal.attachApplication(app.getWindowProcessController());
- } catch (Exception e) {
- Slog.wtf(TAG, "Exception thrown launching activities in " + app, e);
- badApp = true;
+ if (!com.android.server.am.Flags.expediteActivityLaunchOnColdStart()) {
+ final boolean normalMode = mProcessesReady || isAllowedWhileBooting(app.info);
+
+ if (normalMode) {
+ try {
+ didSomething |= mAtmInternal.attachApplication(
+ app.getWindowProcessController());
+ } catch (Exception e) {
+ Slog.wtf(TAG, "Exception thrown launching activities in " + app, e);
+ badApp = true;
+ }
}
}
diff --git a/services/core/java/com/android/server/am/flags.aconfig b/services/core/java/com/android/server/am/flags.aconfig
index 89e4a8d82676..cfcede8ee40d 100644
--- a/services/core/java/com/android/server/am/flags.aconfig
+++ b/services/core/java/com/android/server/am/flags.aconfig
@@ -288,3 +288,13 @@ flag {
purpose: PURPOSE_BUGFIX
}
}
+
+flag {
+ name: "expedite_activity_launch_on_cold_start"
+ namespace: "system_performance"
+ description: "Notify ActivityTaskManager of cold starts early to fix app launch behavior."
+ bug: "319519089"
+ metadata {
+ purpose: PURPOSE_BUGFIX
+ }
+}