diff options
6 files changed, 138 insertions, 40 deletions
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 6202b912adc0..5b2e77937199 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -4118,7 +4118,8 @@ public class ActivityManagerService extends IActivityManager.Stub ri.activityInfo.packageName, ri.activityInfo.name)); mActivityStarter.startActivityLocked(null, intent, null /*ephemeralIntent*/, null, ri.activityInfo, null /*rInfo*/, null, null, null, null, 0, 0, 0, - null, 0, 0, 0, null, false, false, null, null, null); + null, 0, 0, 0, null, false, false, null, null, null, + "startSetupActivity"); } } } @@ -4457,8 +4458,9 @@ public class ActivityManagerService extends IActivityManager.Stub container.checkEmbeddedAllowedInner(userId, intent, mimeType); intent.addFlags(FORCE_NEW_TASK_FLAGS); - return mActivityStarter.startActivityMayWait(null, -1, null, intent, mimeType, null, null, null, - null, 0, 0, null, null, null, null, false, userId, container, null); + return mActivityStarter.startActivityMayWait(null, -1, null, intent, mimeType, null, null, + null, null, 0, 0, null, null, null, null, false, userId, container, null, + "startActivity"); } @Override @@ -4471,7 +4473,8 @@ public class ActivityManagerService extends IActivityManager.Stub // TODO: Switch to user app stacks here. return mActivityStarter.startActivityMayWait(caller, -1, callingPackage, intent, resolvedType, null, null, resultTo, resultWho, requestCode, startFlags, - profilerInfo, null, null, bOptions, false, userId, null, null); + profilerInfo, null, null, bOptions, false, userId, null, null, + "startActivityAsUser"); } @Override @@ -4534,7 +4537,8 @@ public class ActivityManagerService extends IActivityManager.Stub try { int ret = mActivityStarter.startActivityMayWait(null, targetUid, targetPackage, intent, resolvedType, null, null, resultTo, resultWho, requestCode, startFlags, null, - null, null, bOptions, ignoreTargetSecurity, userId, null, null); + null, null, bOptions, ignoreTargetSecurity, userId, null, null, + "startActivityAsCaller"); return ret; } catch (SecurityException e) { // XXX need to figure out how to propagate to original app. @@ -4563,7 +4567,7 @@ public class ActivityManagerService extends IActivityManager.Stub // TODO: Switch to user app stacks here. mActivityStarter.startActivityMayWait(caller, -1, callingPackage, intent, resolvedType, null, null, resultTo, resultWho, requestCode, startFlags, profilerInfo, res, null, - bOptions, false, userId, null, null); + bOptions, false, userId, null, null, "startActivityAndWait"); return res; } @@ -4577,7 +4581,7 @@ public class ActivityManagerService extends IActivityManager.Stub // TODO: Switch to user app stacks here. int ret = mActivityStarter.startActivityMayWait(caller, -1, callingPackage, intent, resolvedType, null, null, resultTo, resultWho, requestCode, startFlags, - null, null, config, bOptions, false, userId, null, null); + null, null, config, bOptions, false, userId, null, null, "startActivityWithConfig"); return ret; } @@ -4634,7 +4638,7 @@ public class ActivityManagerService extends IActivityManager.Stub // TODO: Switch to user app stacks here. return mActivityStarter.startActivityMayWait(null, callingUid, callingPackage, intent, resolvedType, session, interactor, null, null, 0, startFlags, profilerInfo, null, - null, bOptions, false, userId, null, null); + null, bOptions, false, userId, null, null, "startVoiceActivity"); } @Override @@ -4653,7 +4657,7 @@ public class ActivityManagerService extends IActivityManager.Stub ALLOW_FULL_ONLY, "startAssistantActivity", null); return mActivityStarter.startActivityMayWait(null, callingUid, callingPackage, intent, resolvedType, null, null, null, null, 0, 0, null, null, null, bOptions, false, - userId, null, null); + userId, null, null, "startAssistantActivity"); } @Override @@ -4826,7 +4830,7 @@ public class ActivityManagerService extends IActivityManager.Stub null /*ephemeralIntent*/, r.resolvedType, aInfo, null /*rInfo*/, null, null, resultTo != null ? resultTo.appToken : null, resultWho, requestCode, -1, r.launchedFromUid, r.launchedFromPackage, -1, r.launchedFromUid, 0, options, - false, false, null, null, null); + false, false, null, null, null, "startNextMatchingActivity"); Binder.restoreCallingIdentity(origId); r.finishing = wasFinishing; @@ -4858,7 +4862,7 @@ public class ActivityManagerService extends IActivityManager.Stub final int startActivityInPackage(int uid, String callingPackage, Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, int startFlags, Bundle bOptions, int userId, - IActivityContainer container, TaskRecord inTask) { + IActivityContainer container, TaskRecord inTask, String reason) { userId = mUserController.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, false, ALLOW_FULL_ONLY, "startActivityInPackage", null); @@ -4866,7 +4870,7 @@ public class ActivityManagerService extends IActivityManager.Stub // TODO: Switch to user app stacks here. int ret = mActivityStarter.startActivityMayWait(null, uid, callingPackage, intent, resolvedType, null, null, resultTo, resultWho, requestCode, startFlags, - null, null, null, bOptions, false, userId, container, inTask); + null, null, null, bOptions, false, userId, container, inTask, reason); return ret; } @@ -4874,12 +4878,13 @@ public class ActivityManagerService extends IActivityManager.Stub public final int startActivities(IApplicationThread caller, String callingPackage, Intent[] intents, String[] resolvedTypes, IBinder resultTo, Bundle bOptions, int userId) { - enforceNotIsolatedCaller("startActivities"); + final String reason = "startActivities"; + enforceNotIsolatedCaller(reason); userId = mUserController.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), - userId, false, ALLOW_FULL_ONLY, "startActivity", null); + userId, false, ALLOW_FULL_ONLY, reason, null); // TODO: Switch to user app stacks here. int ret = mActivityStarter.startActivities(caller, -1, callingPackage, intents, - resolvedTypes, resultTo, bOptions, userId); + resolvedTypes, resultTo, bOptions, userId, reason); return ret; } @@ -4887,11 +4892,12 @@ public class ActivityManagerService extends IActivityManager.Stub Intent[] intents, String[] resolvedTypes, IBinder resultTo, Bundle bOptions, int userId) { + final String reason = "startActivityInPackage"; userId = mUserController.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), - userId, false, ALLOW_FULL_ONLY, "startActivityInPackage", null); + userId, false, ALLOW_FULL_ONLY, reason, null); // TODO: Switch to user app stacks here. int ret = mActivityStarter.startActivities(null, uid, callingPackage, intents, resolvedTypes, - resultTo, bOptions, userId); + resultTo, bOptions, userId, reason); return ret; } @@ -15005,6 +15011,10 @@ public class ActivityManagerService extends IActivityManager.Stub synchronized (this) { dumpLastANRLocked(pw); } + } else if ("starter".equals(cmd)) { + synchronized (this) { + dumpActivityStarterLocked(pw); + } } else if ("recents".equals(cmd) || "r".equals(cmd)) { synchronized (this) { dumpRecentsLocked(fd, pw, args, opti, true, dumpPackage); @@ -15238,6 +15248,11 @@ public class ActivityManagerService extends IActivityManager.Stub if (dumpAll) { pw.println("-------------------------------------------------------------------------------"); } + dumpActivityStarterLocked(pw); + pw.println(); + if (dumpAll) { + pw.println("-------------------------------------------------------------------------------"); + } dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage); if (mAssociations.size() > 0) { pw.println(); @@ -15303,6 +15318,11 @@ public class ActivityManagerService extends IActivityManager.Stub if (dumpAll) { pw.println("-------------------------------------------------------------------------------"); } + dumpActivityStarterLocked(pw); + pw.println(); + if (dumpAll) { + pw.println("-------------------------------------------------------------------------------"); + } dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage); if (mAssociations.size() > 0) { pw.println(); @@ -15322,14 +15342,19 @@ public class ActivityManagerService extends IActivityManager.Stub } private void dumpLastANRLocked(PrintWriter pw) { + pw.println("ACTIVITY MANAGER ACTIVITIES (dumpsys activity lastanr)"); if (mLastANRState == null) { - pw.println("ACTIVITY MANAGER ACTIVITIES (dumpsys activity lastanr)"); pw.println(" <no ANR has occurred since boot>"); } else { pw.println(mLastANRState); } } + private void dumpActivityStarterLocked(PrintWriter pw) { + pw.println("ACTIVITY MANAGER ACTIVITIES (dumpsys activity starter)"); + mActivityStarter.dump(pw, ""); + } + void dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, String[] args, int opti, boolean dumpAll, boolean dumpClient, String dumpPackage) { dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage, @@ -15356,7 +15381,6 @@ public class ActivityManagerService extends IActivityManager.Stub if (needSep) { pw.println(); } - needSep = true; printedAnything = true; mStackSupervisor.dump(pw, " "); } @@ -24079,17 +24103,13 @@ public class ActivityManagerService extends IActivityManager.Stub if (reason != null) { pw.println(" Reason: " + reason); } - pw.println(" mLastHomeActivityStartResult: " - + mActivityStarter.mLastHomeActivityStartResult); - final ActivityRecord r = mActivityStarter.mLastHomeActivityStartRecord[0]; - if (r != null) { - pw.println(" mLastHomeActivityStartRecord:"); - r.dump(pw, " "); - } pw.println(); + mActivityStarter.dump(pw, " "); + pw.println(); + pw.println("-------------------------------------------------------------------------------"); dumpActivitiesLocked(null /* fd */, pw, null /* args */, 0 /* opti */, true /* dumpAll */, false /* dumpClient */, null /* dumpPackage */, - "ACTIVITY MANAGER ACTIVITIES (dumpsys activity lastanr)"); + "" /* header */); pw.println(); pw.close(); @@ -24331,7 +24351,7 @@ public class ActivityManagerService extends IActivityManager.Stub } return mActivityStarter.startActivityMayWait(appThread, -1, callingPackage, intent, resolvedType, null, null, null, null, 0, 0, null, null, - null, bOptions, false, callingUser, null, tr); + null, bOptions, false, callingUser, null, tr, "AppTaskImpl"); } @Override diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java index a45becdd1dda..9cde98598987 100644 --- a/services/core/java/com/android/server/am/ActivityStack.java +++ b/services/core/java/com/android/server/am/ActivityStack.java @@ -3920,7 +3920,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai destIntent, null /*ephemeralIntent*/, null, aInfo, null /*rInfo*/, null, null, parent.appToken, null, 0, -1, parent.launchedFromUid, parent.launchedFromPackage, -1, parent.launchedFromUid, 0, null, - false, true, null, null, null); + false, true, null, null, null, "navigateUpTo"); foundParentInTask = res == ActivityManager.START_SUCCESS; } catch (RemoteException e) { foundParentInTask = false; diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java index 957b406373d4..1ccac1b8dc8a 100644 --- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java @@ -5184,7 +5184,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY); userId = task.userId; int result = mService.startActivityInPackage(callingUid, callingPackage, intent, null, - null, null, 0, 0, bOptions, userId, null, task); + null, null, 0, 0, bOptions, userId, null, task, "startActivityFromRecents"); if (launchStackId == DOCKED_STACK_ID) { setResizingDuringAnimation(task); } diff --git a/services/core/java/com/android/server/am/ActivityStarter.java b/services/core/java/com/android/server/am/ActivityStarter.java index c7ee149a9727..be30d5aaeab9 100644 --- a/services/core/java/com/android/server/am/ActivityStarter.java +++ b/services/core/java/com/android/server/am/ActivityStarter.java @@ -115,6 +115,7 @@ import android.os.SystemClock; import android.os.UserHandle; import android.os.UserManager; import android.service.voice.IVoiceInteractionSession; +import android.text.TextUtils; import android.util.EventLog; import android.util.Slog; @@ -124,7 +125,10 @@ import com.android.server.am.ActivityStackSupervisor.PendingActivityLaunch; import com.android.server.pm.InstantAppResolver; import com.android.server.wm.WindowManagerService; +import java.io.PrintWriter; +import java.text.DateFormat; import java.util.ArrayList; +import java.util.Date; /** * Controller for interpreting how and then launching activities. @@ -189,9 +193,17 @@ class ActivityStarter { private boolean mUsingVr2dDisplay; // Last home activity record we attempted to start - final ActivityRecord[] mLastHomeActivityStartRecord = new ActivityRecord[1]; + private final ActivityRecord[] mLastHomeActivityStartRecord = new ActivityRecord[1]; // The result of the last home activity we attempted to start. - int mLastHomeActivityStartResult; + private int mLastHomeActivityStartResult; + // Last activity record we attempted to start + private final ActivityRecord[] mLastStartActivityRecord = new ActivityRecord[1]; + // The result of the last activity we attempted to start. + private int mLastStartActivityResult; + // Time in milli seconds we attempted to start the last activity. + private long mLastStartActivityTimeMs; + // The reason we were trying to start the last activity + private String mLastStartReason; private void reset() { mStartActivity = null; @@ -241,7 +253,37 @@ class ActivityStarter { mUsingVr2dDisplay = false; } - final int startActivityLocked(IApplicationThread caller, Intent intent, Intent ephemeralIntent, + int startActivityLocked(IApplicationThread caller, Intent intent, Intent ephemeralIntent, + String resolvedType, ActivityInfo aInfo, ResolveInfo rInfo, + IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, + IBinder resultTo, String resultWho, int requestCode, int callingPid, int callingUid, + String callingPackage, int realCallingPid, int realCallingUid, int startFlags, + ActivityOptions options, boolean ignoreTargetSecurity, boolean componentSpecified, + ActivityRecord[] outActivity, ActivityStackSupervisor.ActivityContainer container, + TaskRecord inTask, String reason) { + + if (TextUtils.isEmpty(reason)) { + throw new IllegalArgumentException("Need to specify a reason."); + } + mLastStartReason = reason; + mLastStartActivityTimeMs = System.currentTimeMillis(); + mLastStartActivityRecord[0] = null; + + mLastStartActivityResult = startActivity(caller, intent, ephemeralIntent, resolvedType, + aInfo, rInfo, voiceSession, voiceInteractor, resultTo, resultWho, requestCode, + callingPid, callingUid, callingPackage, realCallingPid, realCallingUid, startFlags, + options, ignoreTargetSecurity, componentSpecified, mLastStartActivityRecord, + container, inTask); + + if (outActivity != null) { + // mLastStartActivityRecord[0] is set in the call to startActivity above. + outActivity[0] = mLastStartActivityRecord[0]; + } + return mLastStartActivityResult; + } + + /** DO NOT call this method directly. Use {@link #startActivityLocked} instead. */ + private int startActivity(IApplicationThread caller, Intent intent, Intent ephemeralIntent, String resolvedType, ActivityInfo aInfo, ResolveInfo rInfo, IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, IBinder resultTo, String resultWho, int requestCode, int callingPid, int callingUid, @@ -604,7 +646,7 @@ class ActivityStarter { null /*callingPackage*/, 0 /*realCallingPid*/, 0 /*realCallingUid*/, 0 /*startFlags*/, null /*options*/, false /*ignoreTargetSecurity*/, false /*componentSpecified*/, mLastHomeActivityStartRecord /*outActivity*/, - null /*container*/, null /*inTask*/); + null /*container*/, null /*inTask*/, "startHomeActivity: " + reason); if (mSupervisor.inResumeTopActivity) { // If we are in resume section already, home activity will be initialized, but not // resumed (to avoid recursive resume) and will stay that way until something pokes it @@ -629,7 +671,7 @@ class ActivityStarter { IBinder resultTo, String resultWho, int requestCode, int startFlags, ProfilerInfo profilerInfo, WaitResult outResult, Configuration globalConfig, Bundle bOptions, boolean ignoreTargetSecurity, int userId, - IActivityContainer iContainer, TaskRecord inTask) { + IActivityContainer iContainer, TaskRecord inTask, String reason) { // Refuse possible leaked file descriptors if (intent != null && intent.hasFileDescriptors()) { throw new IllegalArgumentException("File descriptors passed in Intent"); @@ -784,7 +826,7 @@ class ActivityStarter { resultTo, resultWho, requestCode, callingPid, callingUid, callingPackage, realCallingPid, realCallingUid, startFlags, options, ignoreTargetSecurity, componentSpecified, outRecord, container, - inTask); + inTask, reason); Binder.restoreCallingIdentity(origId); @@ -847,7 +889,7 @@ class ActivityStarter { final int startActivities(IApplicationThread caller, int callingUid, String callingPackage, Intent[] intents, String[] resolvedTypes, IBinder resultTo, - Bundle bOptions, int userId) { + Bundle bOptions, int userId, String reason) { if (intents == null) { throw new NullPointerException("intents is null"); } @@ -909,7 +951,7 @@ class ActivityStarter { resolvedTypes[i], aInfo, null /*rInfo*/, null, null, resultTo, null, -1, callingPid, callingUid, callingPackage, realCallingPid, realCallingUid, 0, - options, false, componentSpecified, outActivity, null, null); + options, false, componentSpecified, outActivity, null, null, reason); if (res < 0) { return res; } @@ -2261,4 +2303,40 @@ class ActivityStarter { } return didSomething; } + + void dump(PrintWriter pw, String prefix) { + pw.println(prefix + "ActivityStarter:"); + prefix = prefix + " "; + + pw.println(prefix + "mLastStartReason=" + mLastStartReason); + pw.println(prefix + "mLastStartActivityTimeMs=" + + DateFormat.getDateTimeInstance().format(new Date(mLastStartActivityTimeMs))); + pw.println(prefix + "mLastStartActivityResult=" + mLastStartActivityResult); + ActivityRecord r = mLastStartActivityRecord[0]; + if (r != null) { + pw.println(prefix + "mLastStartActivityRecord:"); + r.dump(pw, prefix + " "); + } + pw.println(prefix + "mLastHomeActivityStartResult=" + mLastHomeActivityStartResult); + r = mLastHomeActivityStartRecord[0]; + if (r != null) { + pw.println(prefix + "mLastHomeActivityStartRecord:"); + r.dump(pw, prefix + " "); + } + if (mStartActivity != null) { + pw.println(prefix + "mStartActivity:"); + mStartActivity.dump(pw, prefix + " "); + } + if (mIntent != null) { + pw.println(prefix + "mIntent=" + mIntent); + } + if (mOptions != null) { + pw.println(prefix + "mOptions=" + mOptions); + } + pw.println(prefix + "mLaunchSingleTop=" + mLaunchSingleTop + + " mLaunchSingleInstance=" + mLaunchSingleInstance + + " mLaunchSingleTask=" + mLaunchSingleTask + + " mLaunchFlags=0x" + Integer.toHexString(mLaunchFlags) + + " mDoResume=" + mDoResume + " mAddingToTask=" + mAddingToTask); + } } diff --git a/services/core/java/com/android/server/am/AppErrors.java b/services/core/java/com/android/server/am/AppErrors.java index a83f989fbc5d..0d1c579f2b81 100644 --- a/services/core/java/com/android/server/am/AppErrors.java +++ b/services/core/java/com/android/server/am/AppErrors.java @@ -412,7 +412,7 @@ class AppErrors { task.mCallingPackage, task.intent, null, null, null, 0, 0, ActivityOptions.makeBasic().toBundle(), - task.userId, null, null); + task.userId, null, null, "AppErrors"); } } } diff --git a/services/core/java/com/android/server/am/PendingIntentRecord.java b/services/core/java/com/android/server/am/PendingIntentRecord.java index 6eca3fa7350a..cad5dcf6b565 100644 --- a/services/core/java/com/android/server/am/PendingIntentRecord.java +++ b/services/core/java/com/android/server/am/PendingIntentRecord.java @@ -346,7 +346,7 @@ final class PendingIntentRecord extends IIntentSender.Stub { } else { owner.startActivityInPackage(uid, key.packageName, finalIntent, resolvedType, resultTo, resultWho, requestCode, 0, - options, userId, container, null); + options, userId, container, null, "PendingIntentRecord"); } } catch (RuntimeException e) { Slog.w(TAG, "Unable to send startActivity intent", e); |