Loading services/java/com/android/server/am/ActiveServices.java +1 −1 Original line number Diff line number Diff line Loading @@ -439,7 +439,7 @@ public class ActiveServices { ActivityRecord activity = null; if (token != null) { activity = mAm.mMainStack.isInStackLocked(token); activity = ActivityRecord.isInStackLocked(token); if (activity == null) { Slog.w(TAG, "Binding with unknown activity: " + token); return 0; Loading services/java/com/android/server/am/ActivityManagerService.java +382 −237 File changed.Preview size limit exceeded, changes collapsed. Show changes services/java/com/android/server/am/ActivityRecord.java +40 −10 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ import com.android.internal.app.ResolverActivity; import com.android.server.AttributeCache; import com.android.server.am.ActivityStack.ActivityState; import android.app.Activity; import android.app.ActivityOptions; import android.app.ResultInfo; import android.content.ComponentName; Loading Loading @@ -56,7 +55,6 @@ import java.util.HashSet; */ final class ActivityRecord { final ActivityManagerService service; // owner final ActivityStack stack; // owner final IApplicationToken.Stub appToken; // window manager token final ActivityInfo info; // all about me final int launchedFromUid; // always the uid who started the activity. Loading Loading @@ -183,7 +181,7 @@ final class ActivityRecord { if (newIntents != null && newIntents.size() > 0) { pw.print(prefix); pw.println("Pending New Intents:"); for (int i=0; i<newIntents.size(); i++) { Intent intent = (Intent)newIntents.get(i); Intent intent = newIntents.get(i); pw.print(prefix); pw.print(" - "); if (intent == null) { pw.println("null"); Loading Loading @@ -327,13 +325,12 @@ final class ActivityRecord { } } ActivityRecord(ActivityManagerService _service, ActivityStack _stack, ProcessRecord _caller, ActivityRecord(ActivityManagerService _service, ProcessRecord _caller, int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType, ActivityInfo aInfo, Configuration _configuration, ActivityRecord _resultTo, String _resultWho, int _reqCode, boolean _componentSpecified) { service = _service; stack = _stack; appToken = new Token(this); info = aInfo; launchedFromUid = _launchedFromUid; Loading Loading @@ -565,7 +562,7 @@ final class ActivityRecord { void addNewIntentLocked(Intent intent) { if (newIntents == null) { newIntents = new ArrayList(); newIntents = new ArrayList<Intent>(); } newIntents.add(intent); } Loading @@ -585,7 +582,7 @@ final class ActivityRecord { // case we will deliver it if this is the current top activity on its // stack. if ((state == ActivityState.RESUMED || (service.mSleeping && stack.topRunningActivityLocked(null) == this)) && task.stack.topRunningActivityLocked(null) == this)) && app != null && app.thread != null) { try { ArrayList<Intent> ar = new ArrayList<Intent>(); Loading Loading @@ -729,6 +726,7 @@ final class ActivityRecord { boolean continueLaunchTickingLocked() { if (launchTickTime != 0) { final ActivityStack stack = task.stack; Message msg = stack.mHandler.obtainMessage(ActivityStack.LAUNCH_TICK_MSG); msg.obj = this; stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG); Loading @@ -740,7 +738,7 @@ final class ActivityRecord { void finishLaunchTickingLocked() { launchTickTime = 0; stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG); task.stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG); } // IApplicationToken Loading Loading @@ -769,6 +767,7 @@ final class ActivityRecord { public void windowsDrawn() { synchronized(service) { if (launchTime != 0) { final ActivityStack stack = task.stack; final long curTime = SystemClock.uptimeMillis(); final long thisTime = curTime - launchTime; final long totalTime = stack.mInitialStartTime != 0 Loading Loading @@ -804,6 +803,7 @@ final class ActivityRecord { public void windowsVisible() { synchronized(service) { final ActivityStack stack = task.stack; stack.reportActivityVisibleLocked(this); if (ActivityManagerService.DEBUG_SWITCH) Log.v( ActivityManagerService.TAG, "windowsVisible(): " + this); Loading @@ -824,8 +824,7 @@ final class ActivityRecord { final int N = stack.mWaitingVisibleActivities.size(); if (N > 0) { for (int i=0; i<N; i++) { ActivityRecord r = (ActivityRecord) stack.mWaitingVisibleActivities.get(i); ActivityRecord r = stack.mWaitingVisibleActivities.get(i); r.waitingVisible = false; if (ActivityManagerService.DEBUG_SWITCH) Log.v( ActivityManagerService.TAG, Loading Loading @@ -853,6 +852,7 @@ final class ActivityRecord { // for another app to start, then we have paused dispatching // for this activity. ActivityRecord r = this; final ActivityStack stack = task.stack; if (r.waitingVisible) { // Hmmm, who might we be waiting for? r = stack.mResumedActivity; Loading Loading @@ -902,6 +902,7 @@ final class ActivityRecord { if (app != null && app.thread != null) { try { app.thread.scheduleSleeping(appToken, _sleeping); final ActivityStack stack = task.stack; if (sleeping && !stack.mGoingToSleepActivities.contains(this)) { stack.mGoingToSleepActivities.add(this); } Loading @@ -913,6 +914,35 @@ final class ActivityRecord { } } static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) { final ActivityRecord r = ActivityRecord.forToken(token); if (r == null) { return -1; } final TaskRecord task = r.task; switch (task.mActivities.indexOf(r)) { case -1: return -1; case 0: return task.taskId; default: return onlyRoot ? -1 : task.taskId; } } static ActivityRecord isInStackLocked(IBinder token) { final ActivityRecord r = ActivityRecord.forToken(token); if (r != null) { return r.task.stack.isInStackLocked(token); } return null; } static final ActivityStack getStackLocked(IBinder token) { final ActivityRecord r = ActivityRecord.isInStackLocked(token); if (r != null) { return r.task.stack; } return null; } @Override public String toString() { if (stringName != null) { Loading services/java/com/android/server/am/ActivityStack.java +103 −147 Original line number Diff line number Diff line Loading @@ -163,11 +163,6 @@ final class ActivityStack { */ private ArrayList<TaskRecord> mTaskHistory = new ArrayList<TaskRecord>(); /** * Mapping from taskId to TaskRecord */ private SparseArray<TaskRecord> mTaskIdToTaskRecord = new SparseArray<TaskRecord>(); /** * Used for validating app tokens with window manager. */ Loading Loading @@ -368,9 +363,9 @@ final class ActivityStack { mService.logAppTooSlow(r.app, r.pauseTime, "pausing " + r); } } activityPaused(r != null ? r.appToken : null, true); activityPausedLocked(r != null ? r.appToken : null, true); } } break; case IDLE_TIMEOUT_MSG: { if (mService.mDidDexOpt) { Loading Loading @@ -400,7 +395,9 @@ final class ActivityStack { // We don't at this point know if the activity is fullscreen, // so we need to be conservative and assume it isn't. Slog.w(TAG, "Activity destroy timeout for " + r); activityDestroyed(r != null ? r.appToken : null); synchronized (mService) { activityDestroyedLocked(r != null ? r.appToken : null); } } break; case IDLE_NOW_MSG: { ActivityRecord r = (ActivityRecord)msg.obj; Loading Loading @@ -526,29 +523,28 @@ final class ActivityStack { return null; } final ActivityRecord isInStackLocked(IBinder token) { final ActivityRecord r = ActivityRecord.forToken(token); if (r != null) { final TaskRecord task = r.task; if (mTaskHistory.contains(task) && task.mActivities.contains(r)) { return r; TaskRecord taskForIdLocked(int id) { for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { final TaskRecord task = mTaskHistory.get(taskNdx); if (task.taskId == id) { return task; } } return null; } int getTaskForActivityLocked(IBinder token, boolean onlyRoot) { ActivityRecord isInStackLocked(IBinder token) { final ActivityRecord r = ActivityRecord.forToken(token); if (r == null) { return -1; } if (r != null) { final TaskRecord task = r.task; switch (task.mActivities.indexOf(r)) { case -1: return -1; case 0: return task.taskId; default: return onlyRoot ? -1 : task.taskId; if (task.mActivities.contains(r) && mTaskHistory.contains(task)) { if (task.stack != this) Slog.w(TAG, "Illegal state! task does not point to stack it is in."); return r; } } return null; } private final boolean updateLRUListLocked(ActivityRecord r) { final boolean hadit = mLRUActivities.remove(r); Loading Loading @@ -819,9 +815,7 @@ final class ActivityStack { r.stopped = false; mResumedActivity = r; r.task.touchActiveTime(); if (mMainStack) { mService.addRecentTaskLocked(r.task); } completeResumeLocked(r); checkReadyForSleepLocked(); if (DEBUG_SAVED_STATE) Slog.i(TAG, "Launch completed; removing icicle of " + r.icicle); Loading Loading @@ -1092,22 +1086,17 @@ final class ActivityStack { } } final void activityResumed(IBinder token) { synchronized (mService) { final ActivityRecord r = isInStackLocked(token); if (r != null) { final void activityResumedLocked(IBinder token) { final ActivityRecord r = ActivityRecord.forToken(token); if (DEBUG_SAVED_STATE) Slog.i(TAG, "Resumed activity; dropping state of: " + r); r.icicle = null; r.haveState = false; } } } final void activityPaused(IBinder token, boolean timeout) { final void activityPausedLocked(IBinder token, boolean timeout) { if (DEBUG_PAUSE) Slog.v( TAG, "Activity paused: token=" + token + ", timeout=" + timeout); synchronized (mService) { final ActivityRecord r = isInStackLocked(token); if (r != null) { mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); Loading @@ -1124,7 +1113,6 @@ final class ActivityStack { } } } } final void activityStoppedLocked(ActivityRecord r, Bundle icicle, Bitmap thumbnail, CharSequence description) { Loading Loading @@ -1706,9 +1694,7 @@ final class ActivityStack { next.state = ActivityState.RESUMED; mResumedActivity = next; next.task.touchActiveTime(); if (mMainStack) { mService.addRecentTaskLocked(next.task); } mService.updateLruProcessLocked(next.app, true); updateLRUListLocked(next); Loading Loading @@ -1843,16 +1829,16 @@ final class ActivityStack { private final void startActivityLocked(ActivityRecord r, boolean newTask, boolean doResume, boolean keepCurTransition, Bundle options) { TaskRecord task = null; final int taskId = r.task.taskId; if (mTaskIdToTaskRecord.indexOfKey(taskId) < 0 || newTask) { TaskRecord rTask = r.task; final int taskId = rTask.taskId; if (taskForIdLocked(taskId) == null || newTask) { // Last activity in task had been removed or ActivityManagerService is reusing task. // Insert or replace. mTaskIdToTaskRecord.put(taskId, r.task); // Might not even be in. mTaskHistory.remove(r.task); mTaskHistory.remove(rTask); // Now put task at top. mTaskHistory.add(r.task); mService.mWindowManager.moveTaskToTop(r.task.taskId); mTaskHistory.add(rTask); mService.mWindowManager.moveTaskToTop(taskId); } if (!newTask) { // If starting in an existing task, find where that is... Loading Loading @@ -2073,14 +2059,8 @@ final class ActivityStack { if (DEBUG_TASKS) Slog.v(TAG, "Start pushing activity " + target + " out to bottom task " + p.task); } else { do { mService.mCurTask++; if (mService.mCurTask <= 0) { mService.mCurTask = 1; } } while (mTaskIdToTaskRecord.get(mService.mCurTask) != null); setTask(target, createTaskRecord(mService.mCurTask, target.info, null, false), null, false); setTask(target, createTaskRecord(mService.getNextTaskId(), target.info, null, false), null, false); target.task.affinityIntent = target.intent; if (DEBUG_TASKS) Slog.v(TAG, "Start pushing activity " + target + " out to new task " + target.task); Loading Loading @@ -2594,7 +2574,7 @@ final class ActivityStack { } } ActivityRecord r = new ActivityRecord(mService, this, callerApp, callingUid, callingPackage, ActivityRecord r = new ActivityRecord(mService, callerApp, callingUid, callingPackage, intent, resolvedType, aInfo, mService.mConfiguration, resultRecord, resultWho, requestCode, componentSpecified); if (outActivity != null) { Loading Loading @@ -2935,12 +2915,8 @@ final class ActivityStack { if (r.resultTo == null && !addingToTask && (launchFlags&Intent.FLAG_ACTIVITY_NEW_TASK) != 0) { if (reuseTask == null) { // todo: should do better management of integers. mService.mCurTask++; if (mService.mCurTask <= 0) { mService.mCurTask = 1; } setTask(r, createTaskRecord(mService.mCurTask, r.info, intent, true), null, true); setTask(r, createTaskRecord(mService.getNextTaskId(), r.info, intent, true), null, true); if (DEBUG_TASKS) Slog.v(TAG, "Starting new activity " + r + " in new task " + r.task); } else { Loading Loading @@ -3010,7 +2986,8 @@ final class ActivityStack { } setTask(r, prev != null ? prev.task : createTaskRecord(mService.mCurTask, r.info, intent, true), null, true); : createTaskRecord(mService.getNextTaskId(), r.info, intent, true), null, true); if (DEBUG_TASKS) Slog.v(TAG, "Starting new activity " + r + " in new guessed " + r.task); } Loading Loading @@ -3654,12 +3631,7 @@ final class ActivityStack { return true; } final void finishSubActivityLocked(IBinder token, String resultWho, int requestCode) { ActivityRecord self = isInStackLocked(token); if (self == null) { return; } final void finishSubActivityLocked(ActivityRecord self, String resultWho, int requestCode) { for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { Loading @@ -3685,8 +3657,7 @@ final class ActivityStack { + r.intent.getComponent().flattenToShortString()); int taskNdx = mTaskHistory.indexOf(r.task); int activityNdx = r.task.mActivities.indexOf(r); r.stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "crashed", false); finishActivityLocked(r, Activity.RESULT_CANCELED, null, "crashed", false); // Also terminate any activities below it that aren't yet // stopped, to avoid a situation where one will get // re-start our crashing activity once it gets resumed again. Loading @@ -3708,22 +3679,14 @@ final class ActivityStack { if (!r.isHomeActivity || mService.mHomeProcess != r.app) { Slog.w(TAG, " Force finishing activity " + r.intent.getComponent().flattenToShortString()); r.stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "crashed", false); } finishActivityLocked(r, Activity.RESULT_CANCELED, null, "crashed", false); } } } } final boolean finishActivityAffinityLocked(IBinder token) { ActivityRecord r = isInStackLocked(token); if (DEBUG_RESULTS) Slog.v( TAG, "Finishing activity affinity token=" + token + " r=" + r); if (r == null) { return false; } final boolean finishActivityAffinityLocked(ActivityRecord r) { ArrayList<ActivityRecord> activities = r.task.mActivities; for (int index = activities.indexOf(r); index >= 0; --index) { ActivityRecord cur = activities.get(index); Loading Loading @@ -3913,8 +3876,9 @@ final class ActivityStack { return r; } final boolean navigateUpToLocked(ActivityRecord srec, Intent destIntent, int resultCode, final boolean navigateUpToLocked(IBinder token, Intent destIntent, int resultCode, Intent resultData) { final ActivityRecord srec = ActivityRecord.forToken(token); final TaskRecord task = srec.task; final ArrayList<ActivityRecord> activities = task.mActivities; final int start = activities.indexOf(srec); Loading Loading @@ -4165,10 +4129,7 @@ final class ActivityStack { if (hadApp) { if (removeFromApp) { int idx = r.app.activities.indexOf(r); if (idx >= 0) { r.app.activities.remove(idx); } r.app.activities.remove(r); if (mService.mHeavyWeightProcess == r.app && r.app.activities.size() <= 0) { mService.mHeavyWeightProcess = null; mService.mHandler.sendEmptyMessage( Loading Loading @@ -4244,8 +4205,7 @@ final class ActivityStack { return removedFromHistory; } final void activityDestroyed(IBinder token) { synchronized (mService) { final void activityDestroyedLocked(IBinder token) { final long origId = Binder.clearCallingIdentity(); try { ActivityRecord r = ActivityRecord.forToken(token); Loading @@ -4264,7 +4224,6 @@ final class ActivityStack { Binder.restoreCallingIdentity(origId); } } } private void removeHistoryRecordsForAppLocked(ArrayList<ActivityRecord> list, ProcessRecord app, String listName) { Loading Loading @@ -4358,7 +4317,7 @@ final class ActivityStack { } } r.stack.cleanUpActivityLocked(r, true, true); cleanUpActivityLocked(r, true, true); } } } Loading Loading @@ -4397,8 +4356,8 @@ final class ActivityStack { } final boolean findTaskToMoveToFrontLocked(int taskId, int flags, Bundle options) { final TaskRecord task = mTaskIdToTaskRecord.get(taskId); if (mTaskHistory.contains(task)) { final TaskRecord task = taskForIdLocked(taskId); if (task != null) { if ((flags & ActivityManager.MOVE_TASK_NO_USER_ACTION) == 0) { mUserLeaving = true; } Loading Loading @@ -4496,7 +4455,10 @@ final class ActivityStack { if (DEBUG_TRANSITION) Slog.v(TAG, "Prepare to back transition: task=" + task); final TaskRecord tr = mTaskIdToTaskRecord.get(task); final TaskRecord tr = taskForIdLocked(task); if (tr == null) { return false; } mTaskHistory.remove(tr); mTaskHistory.add(0, tr); Loading Loading @@ -4525,7 +4487,7 @@ final class ActivityStack { TaskAccessInfo info = getTaskAccessInfoLocked(tr, true); ActivityRecord resumed = mResumedActivity; if (resumed != null && resumed.thumbHolder == tr) { info.mainThumbnail = resumed.stack.screenshotActivities(resumed); info.mainThumbnail = screenshotActivities(resumed); } if (info.mainThumbnail == null) { info.mainThumbnail = tr.lastThumbnail; Loading @@ -4538,7 +4500,7 @@ final class ActivityStack { if (resumed != null && resumed.task == tr) { // This task is the current resumed task, we just need to take // a screenshot of it and return that. return resumed.stack.screenshotActivities(resumed); return screenshotActivities(resumed); } // Return the information about the task, to figure out the top // thumbnail to return. Loading @@ -4551,7 +4513,10 @@ final class ActivityStack { public ActivityRecord removeTaskActivitiesLocked(int taskId, int subTaskIndex, boolean taskRequired) { final TaskRecord task = mTaskIdToTaskRecord.get(taskId); final TaskRecord task = taskForIdLocked(taskId); if (task == null) { return null; } TaskAccessInfo info = getTaskAccessInfoLocked(task, false); if (info.root == null) { if (taskRequired) { Loading Loading @@ -4633,7 +4598,7 @@ final class ActivityStack { TaskAccessInfo.SubTask sub = thumbs.subtasks.get(index); ActivityRecord resumed = mResumedActivity; if (resumed != null && resumed.thumbHolder == sub.holder) { return resumed.stack.screenshotActivities(resumed); return screenshotActivities(resumed); } return sub.holder.lastThumbnail; } Loading Loading @@ -4847,8 +4812,7 @@ final class ActivityStack { for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { final ActivityRecord r = activities.get(activityNdx); if ((r.info.flags&ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS) != 0) { r.stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "close-sys", true); finishActivityLocked(r, Activity.RESULT_CANCELED, null, "close-sys", true); } } } Loading Loading @@ -4884,8 +4848,7 @@ final class ActivityStack { r.app = null; } lastTask = r.task; r.stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "force-stop", true); finishActivityLocked(r, Activity.RESULT_CANCELED, null, "force-stop", true); } } } Loading Loading @@ -4975,8 +4938,7 @@ final class ActivityStack { if (r.app == app) { Slog.w(TAG, " Force finishing activity " + r.intent.getComponent().flattenToShortString()); r.stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "crashed", false); finishActivityLocked(r, Activity.RESULT_CANCELED, null, "crashed", false); } } } Loading Loading @@ -5048,11 +5010,11 @@ final class ActivityStack { private void removeActivity(ActivityRecord r) { final TaskRecord task = r.task; // TODO: use ActivityManagerService.removeTask to do this. if (task.removeActivity(r)) { if (DEBUG_ADD_REMOVE) Slog.i(TAG, "removeActivity: Removing from history, task=" + task); mTaskHistory.remove(task); mTaskIdToTaskRecord.delete(task.taskId); } } Loading @@ -5066,13 +5028,7 @@ final class ActivityStack { private TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent, boolean toTop) { TaskRecord oldTask = mTaskIdToTaskRecord.get(taskId); if (oldTask != null) { Slog.w(TAG, "createTaskRecord: Reusing taskId=" + taskId + " without removing"); mTaskHistory.remove(oldTask); } TaskRecord task = new TaskRecord(taskId, info, intent); mTaskIdToTaskRecord.put(taskId, task); TaskRecord task = new TaskRecord(taskId, info, intent, this); if (toTop) { mTaskHistory.add(task); } else { Loading services/java/com/android/server/am/CompatModePackages.java +7 −7 Original line number Diff line number Diff line Loading @@ -166,7 +166,7 @@ public class CompatModePackages { } public boolean getFrontActivityAskCompatModeLocked() { ActivityRecord r = mService.mMainStack.topRunningActivityLocked(null); ActivityRecord r = mService.mFocusedStack.topRunningActivityLocked(null); if (r == null) { return false; } Loading @@ -178,7 +178,7 @@ public class CompatModePackages { } public void setFrontActivityAskCompatModeLocked(boolean ask) { ActivityRecord r = mService.mMainStack.topRunningActivityLocked(null); ActivityRecord r = mService.mFocusedStack.topRunningActivityLocked(null); if (r != null) { setPackageAskCompatModeLocked(r.packageName, ask); } Loading @@ -200,7 +200,7 @@ public class CompatModePackages { } public int getFrontActivityScreenCompatModeLocked() { ActivityRecord r = mService.mMainStack.topRunningActivityLocked(null); ActivityRecord r = mService.mFocusedStack.topRunningActivityLocked(null); if (r == null) { return ActivityManager.COMPAT_MODE_UNKNOWN; } Loading @@ -208,7 +208,7 @@ public class CompatModePackages { } public void setFrontActivityScreenCompatModeLocked(int mode) { ActivityRecord r = mService.mMainStack.topRunningActivityLocked(null); ActivityRecord r = mService.mFocusedStack.topRunningActivityLocked(null); if (r == null) { Slog.w(TAG, "setFrontActivityScreenCompatMode failed: no top activity"); return; Loading Loading @@ -296,7 +296,7 @@ public class CompatModePackages { mHandler.sendMessageDelayed(msg, 10000); ActivityRecord starting = mService.mMainStack.restartPackage(packageName); ActivityRecord starting = mService.mFocusedStack.restartPackage(packageName); // Tell all processes that loaded this package about the change. for (int i=mService.mLruProcesses.size()-1; i>=0; i--) { Loading @@ -315,10 +315,10 @@ public class CompatModePackages { } if (starting != null) { mService.mMainStack.ensureActivityConfigurationLocked(starting, 0); mService.mFocusedStack.ensureActivityConfigurationLocked(starting, 0); // And we need to make sure at this point that all other activities // are made visible with the correct configuration. mService.mMainStack.ensureActivitiesVisibleLocked(starting, 0); mService.mFocusedStack.ensureActivitiesVisibleLocked(starting, 0); } } } Loading Loading
services/java/com/android/server/am/ActiveServices.java +1 −1 Original line number Diff line number Diff line Loading @@ -439,7 +439,7 @@ public class ActiveServices { ActivityRecord activity = null; if (token != null) { activity = mAm.mMainStack.isInStackLocked(token); activity = ActivityRecord.isInStackLocked(token); if (activity == null) { Slog.w(TAG, "Binding with unknown activity: " + token); return 0; Loading
services/java/com/android/server/am/ActivityManagerService.java +382 −237 File changed.Preview size limit exceeded, changes collapsed. Show changes
services/java/com/android/server/am/ActivityRecord.java +40 −10 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ import com.android.internal.app.ResolverActivity; import com.android.server.AttributeCache; import com.android.server.am.ActivityStack.ActivityState; import android.app.Activity; import android.app.ActivityOptions; import android.app.ResultInfo; import android.content.ComponentName; Loading Loading @@ -56,7 +55,6 @@ import java.util.HashSet; */ final class ActivityRecord { final ActivityManagerService service; // owner final ActivityStack stack; // owner final IApplicationToken.Stub appToken; // window manager token final ActivityInfo info; // all about me final int launchedFromUid; // always the uid who started the activity. Loading Loading @@ -183,7 +181,7 @@ final class ActivityRecord { if (newIntents != null && newIntents.size() > 0) { pw.print(prefix); pw.println("Pending New Intents:"); for (int i=0; i<newIntents.size(); i++) { Intent intent = (Intent)newIntents.get(i); Intent intent = newIntents.get(i); pw.print(prefix); pw.print(" - "); if (intent == null) { pw.println("null"); Loading Loading @@ -327,13 +325,12 @@ final class ActivityRecord { } } ActivityRecord(ActivityManagerService _service, ActivityStack _stack, ProcessRecord _caller, ActivityRecord(ActivityManagerService _service, ProcessRecord _caller, int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType, ActivityInfo aInfo, Configuration _configuration, ActivityRecord _resultTo, String _resultWho, int _reqCode, boolean _componentSpecified) { service = _service; stack = _stack; appToken = new Token(this); info = aInfo; launchedFromUid = _launchedFromUid; Loading Loading @@ -565,7 +562,7 @@ final class ActivityRecord { void addNewIntentLocked(Intent intent) { if (newIntents == null) { newIntents = new ArrayList(); newIntents = new ArrayList<Intent>(); } newIntents.add(intent); } Loading @@ -585,7 +582,7 @@ final class ActivityRecord { // case we will deliver it if this is the current top activity on its // stack. if ((state == ActivityState.RESUMED || (service.mSleeping && stack.topRunningActivityLocked(null) == this)) && task.stack.topRunningActivityLocked(null) == this)) && app != null && app.thread != null) { try { ArrayList<Intent> ar = new ArrayList<Intent>(); Loading Loading @@ -729,6 +726,7 @@ final class ActivityRecord { boolean continueLaunchTickingLocked() { if (launchTickTime != 0) { final ActivityStack stack = task.stack; Message msg = stack.mHandler.obtainMessage(ActivityStack.LAUNCH_TICK_MSG); msg.obj = this; stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG); Loading @@ -740,7 +738,7 @@ final class ActivityRecord { void finishLaunchTickingLocked() { launchTickTime = 0; stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG); task.stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG); } // IApplicationToken Loading Loading @@ -769,6 +767,7 @@ final class ActivityRecord { public void windowsDrawn() { synchronized(service) { if (launchTime != 0) { final ActivityStack stack = task.stack; final long curTime = SystemClock.uptimeMillis(); final long thisTime = curTime - launchTime; final long totalTime = stack.mInitialStartTime != 0 Loading Loading @@ -804,6 +803,7 @@ final class ActivityRecord { public void windowsVisible() { synchronized(service) { final ActivityStack stack = task.stack; stack.reportActivityVisibleLocked(this); if (ActivityManagerService.DEBUG_SWITCH) Log.v( ActivityManagerService.TAG, "windowsVisible(): " + this); Loading @@ -824,8 +824,7 @@ final class ActivityRecord { final int N = stack.mWaitingVisibleActivities.size(); if (N > 0) { for (int i=0; i<N; i++) { ActivityRecord r = (ActivityRecord) stack.mWaitingVisibleActivities.get(i); ActivityRecord r = stack.mWaitingVisibleActivities.get(i); r.waitingVisible = false; if (ActivityManagerService.DEBUG_SWITCH) Log.v( ActivityManagerService.TAG, Loading Loading @@ -853,6 +852,7 @@ final class ActivityRecord { // for another app to start, then we have paused dispatching // for this activity. ActivityRecord r = this; final ActivityStack stack = task.stack; if (r.waitingVisible) { // Hmmm, who might we be waiting for? r = stack.mResumedActivity; Loading Loading @@ -902,6 +902,7 @@ final class ActivityRecord { if (app != null && app.thread != null) { try { app.thread.scheduleSleeping(appToken, _sleeping); final ActivityStack stack = task.stack; if (sleeping && !stack.mGoingToSleepActivities.contains(this)) { stack.mGoingToSleepActivities.add(this); } Loading @@ -913,6 +914,35 @@ final class ActivityRecord { } } static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) { final ActivityRecord r = ActivityRecord.forToken(token); if (r == null) { return -1; } final TaskRecord task = r.task; switch (task.mActivities.indexOf(r)) { case -1: return -1; case 0: return task.taskId; default: return onlyRoot ? -1 : task.taskId; } } static ActivityRecord isInStackLocked(IBinder token) { final ActivityRecord r = ActivityRecord.forToken(token); if (r != null) { return r.task.stack.isInStackLocked(token); } return null; } static final ActivityStack getStackLocked(IBinder token) { final ActivityRecord r = ActivityRecord.isInStackLocked(token); if (r != null) { return r.task.stack; } return null; } @Override public String toString() { if (stringName != null) { Loading
services/java/com/android/server/am/ActivityStack.java +103 −147 Original line number Diff line number Diff line Loading @@ -163,11 +163,6 @@ final class ActivityStack { */ private ArrayList<TaskRecord> mTaskHistory = new ArrayList<TaskRecord>(); /** * Mapping from taskId to TaskRecord */ private SparseArray<TaskRecord> mTaskIdToTaskRecord = new SparseArray<TaskRecord>(); /** * Used for validating app tokens with window manager. */ Loading Loading @@ -368,9 +363,9 @@ final class ActivityStack { mService.logAppTooSlow(r.app, r.pauseTime, "pausing " + r); } } activityPaused(r != null ? r.appToken : null, true); activityPausedLocked(r != null ? r.appToken : null, true); } } break; case IDLE_TIMEOUT_MSG: { if (mService.mDidDexOpt) { Loading Loading @@ -400,7 +395,9 @@ final class ActivityStack { // We don't at this point know if the activity is fullscreen, // so we need to be conservative and assume it isn't. Slog.w(TAG, "Activity destroy timeout for " + r); activityDestroyed(r != null ? r.appToken : null); synchronized (mService) { activityDestroyedLocked(r != null ? r.appToken : null); } } break; case IDLE_NOW_MSG: { ActivityRecord r = (ActivityRecord)msg.obj; Loading Loading @@ -526,29 +523,28 @@ final class ActivityStack { return null; } final ActivityRecord isInStackLocked(IBinder token) { final ActivityRecord r = ActivityRecord.forToken(token); if (r != null) { final TaskRecord task = r.task; if (mTaskHistory.contains(task) && task.mActivities.contains(r)) { return r; TaskRecord taskForIdLocked(int id) { for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { final TaskRecord task = mTaskHistory.get(taskNdx); if (task.taskId == id) { return task; } } return null; } int getTaskForActivityLocked(IBinder token, boolean onlyRoot) { ActivityRecord isInStackLocked(IBinder token) { final ActivityRecord r = ActivityRecord.forToken(token); if (r == null) { return -1; } if (r != null) { final TaskRecord task = r.task; switch (task.mActivities.indexOf(r)) { case -1: return -1; case 0: return task.taskId; default: return onlyRoot ? -1 : task.taskId; if (task.mActivities.contains(r) && mTaskHistory.contains(task)) { if (task.stack != this) Slog.w(TAG, "Illegal state! task does not point to stack it is in."); return r; } } return null; } private final boolean updateLRUListLocked(ActivityRecord r) { final boolean hadit = mLRUActivities.remove(r); Loading Loading @@ -819,9 +815,7 @@ final class ActivityStack { r.stopped = false; mResumedActivity = r; r.task.touchActiveTime(); if (mMainStack) { mService.addRecentTaskLocked(r.task); } completeResumeLocked(r); checkReadyForSleepLocked(); if (DEBUG_SAVED_STATE) Slog.i(TAG, "Launch completed; removing icicle of " + r.icicle); Loading Loading @@ -1092,22 +1086,17 @@ final class ActivityStack { } } final void activityResumed(IBinder token) { synchronized (mService) { final ActivityRecord r = isInStackLocked(token); if (r != null) { final void activityResumedLocked(IBinder token) { final ActivityRecord r = ActivityRecord.forToken(token); if (DEBUG_SAVED_STATE) Slog.i(TAG, "Resumed activity; dropping state of: " + r); r.icicle = null; r.haveState = false; } } } final void activityPaused(IBinder token, boolean timeout) { final void activityPausedLocked(IBinder token, boolean timeout) { if (DEBUG_PAUSE) Slog.v( TAG, "Activity paused: token=" + token + ", timeout=" + timeout); synchronized (mService) { final ActivityRecord r = isInStackLocked(token); if (r != null) { mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); Loading @@ -1124,7 +1113,6 @@ final class ActivityStack { } } } } final void activityStoppedLocked(ActivityRecord r, Bundle icicle, Bitmap thumbnail, CharSequence description) { Loading Loading @@ -1706,9 +1694,7 @@ final class ActivityStack { next.state = ActivityState.RESUMED; mResumedActivity = next; next.task.touchActiveTime(); if (mMainStack) { mService.addRecentTaskLocked(next.task); } mService.updateLruProcessLocked(next.app, true); updateLRUListLocked(next); Loading Loading @@ -1843,16 +1829,16 @@ final class ActivityStack { private final void startActivityLocked(ActivityRecord r, boolean newTask, boolean doResume, boolean keepCurTransition, Bundle options) { TaskRecord task = null; final int taskId = r.task.taskId; if (mTaskIdToTaskRecord.indexOfKey(taskId) < 0 || newTask) { TaskRecord rTask = r.task; final int taskId = rTask.taskId; if (taskForIdLocked(taskId) == null || newTask) { // Last activity in task had been removed or ActivityManagerService is reusing task. // Insert or replace. mTaskIdToTaskRecord.put(taskId, r.task); // Might not even be in. mTaskHistory.remove(r.task); mTaskHistory.remove(rTask); // Now put task at top. mTaskHistory.add(r.task); mService.mWindowManager.moveTaskToTop(r.task.taskId); mTaskHistory.add(rTask); mService.mWindowManager.moveTaskToTop(taskId); } if (!newTask) { // If starting in an existing task, find where that is... Loading Loading @@ -2073,14 +2059,8 @@ final class ActivityStack { if (DEBUG_TASKS) Slog.v(TAG, "Start pushing activity " + target + " out to bottom task " + p.task); } else { do { mService.mCurTask++; if (mService.mCurTask <= 0) { mService.mCurTask = 1; } } while (mTaskIdToTaskRecord.get(mService.mCurTask) != null); setTask(target, createTaskRecord(mService.mCurTask, target.info, null, false), null, false); setTask(target, createTaskRecord(mService.getNextTaskId(), target.info, null, false), null, false); target.task.affinityIntent = target.intent; if (DEBUG_TASKS) Slog.v(TAG, "Start pushing activity " + target + " out to new task " + target.task); Loading Loading @@ -2594,7 +2574,7 @@ final class ActivityStack { } } ActivityRecord r = new ActivityRecord(mService, this, callerApp, callingUid, callingPackage, ActivityRecord r = new ActivityRecord(mService, callerApp, callingUid, callingPackage, intent, resolvedType, aInfo, mService.mConfiguration, resultRecord, resultWho, requestCode, componentSpecified); if (outActivity != null) { Loading Loading @@ -2935,12 +2915,8 @@ final class ActivityStack { if (r.resultTo == null && !addingToTask && (launchFlags&Intent.FLAG_ACTIVITY_NEW_TASK) != 0) { if (reuseTask == null) { // todo: should do better management of integers. mService.mCurTask++; if (mService.mCurTask <= 0) { mService.mCurTask = 1; } setTask(r, createTaskRecord(mService.mCurTask, r.info, intent, true), null, true); setTask(r, createTaskRecord(mService.getNextTaskId(), r.info, intent, true), null, true); if (DEBUG_TASKS) Slog.v(TAG, "Starting new activity " + r + " in new task " + r.task); } else { Loading Loading @@ -3010,7 +2986,8 @@ final class ActivityStack { } setTask(r, prev != null ? prev.task : createTaskRecord(mService.mCurTask, r.info, intent, true), null, true); : createTaskRecord(mService.getNextTaskId(), r.info, intent, true), null, true); if (DEBUG_TASKS) Slog.v(TAG, "Starting new activity " + r + " in new guessed " + r.task); } Loading Loading @@ -3654,12 +3631,7 @@ final class ActivityStack { return true; } final void finishSubActivityLocked(IBinder token, String resultWho, int requestCode) { ActivityRecord self = isInStackLocked(token); if (self == null) { return; } final void finishSubActivityLocked(ActivityRecord self, String resultWho, int requestCode) { for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { Loading @@ -3685,8 +3657,7 @@ final class ActivityStack { + r.intent.getComponent().flattenToShortString()); int taskNdx = mTaskHistory.indexOf(r.task); int activityNdx = r.task.mActivities.indexOf(r); r.stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "crashed", false); finishActivityLocked(r, Activity.RESULT_CANCELED, null, "crashed", false); // Also terminate any activities below it that aren't yet // stopped, to avoid a situation where one will get // re-start our crashing activity once it gets resumed again. Loading @@ -3708,22 +3679,14 @@ final class ActivityStack { if (!r.isHomeActivity || mService.mHomeProcess != r.app) { Slog.w(TAG, " Force finishing activity " + r.intent.getComponent().flattenToShortString()); r.stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "crashed", false); } finishActivityLocked(r, Activity.RESULT_CANCELED, null, "crashed", false); } } } } final boolean finishActivityAffinityLocked(IBinder token) { ActivityRecord r = isInStackLocked(token); if (DEBUG_RESULTS) Slog.v( TAG, "Finishing activity affinity token=" + token + " r=" + r); if (r == null) { return false; } final boolean finishActivityAffinityLocked(ActivityRecord r) { ArrayList<ActivityRecord> activities = r.task.mActivities; for (int index = activities.indexOf(r); index >= 0; --index) { ActivityRecord cur = activities.get(index); Loading Loading @@ -3913,8 +3876,9 @@ final class ActivityStack { return r; } final boolean navigateUpToLocked(ActivityRecord srec, Intent destIntent, int resultCode, final boolean navigateUpToLocked(IBinder token, Intent destIntent, int resultCode, Intent resultData) { final ActivityRecord srec = ActivityRecord.forToken(token); final TaskRecord task = srec.task; final ArrayList<ActivityRecord> activities = task.mActivities; final int start = activities.indexOf(srec); Loading Loading @@ -4165,10 +4129,7 @@ final class ActivityStack { if (hadApp) { if (removeFromApp) { int idx = r.app.activities.indexOf(r); if (idx >= 0) { r.app.activities.remove(idx); } r.app.activities.remove(r); if (mService.mHeavyWeightProcess == r.app && r.app.activities.size() <= 0) { mService.mHeavyWeightProcess = null; mService.mHandler.sendEmptyMessage( Loading Loading @@ -4244,8 +4205,7 @@ final class ActivityStack { return removedFromHistory; } final void activityDestroyed(IBinder token) { synchronized (mService) { final void activityDestroyedLocked(IBinder token) { final long origId = Binder.clearCallingIdentity(); try { ActivityRecord r = ActivityRecord.forToken(token); Loading @@ -4264,7 +4224,6 @@ final class ActivityStack { Binder.restoreCallingIdentity(origId); } } } private void removeHistoryRecordsForAppLocked(ArrayList<ActivityRecord> list, ProcessRecord app, String listName) { Loading Loading @@ -4358,7 +4317,7 @@ final class ActivityStack { } } r.stack.cleanUpActivityLocked(r, true, true); cleanUpActivityLocked(r, true, true); } } } Loading Loading @@ -4397,8 +4356,8 @@ final class ActivityStack { } final boolean findTaskToMoveToFrontLocked(int taskId, int flags, Bundle options) { final TaskRecord task = mTaskIdToTaskRecord.get(taskId); if (mTaskHistory.contains(task)) { final TaskRecord task = taskForIdLocked(taskId); if (task != null) { if ((flags & ActivityManager.MOVE_TASK_NO_USER_ACTION) == 0) { mUserLeaving = true; } Loading Loading @@ -4496,7 +4455,10 @@ final class ActivityStack { if (DEBUG_TRANSITION) Slog.v(TAG, "Prepare to back transition: task=" + task); final TaskRecord tr = mTaskIdToTaskRecord.get(task); final TaskRecord tr = taskForIdLocked(task); if (tr == null) { return false; } mTaskHistory.remove(tr); mTaskHistory.add(0, tr); Loading Loading @@ -4525,7 +4487,7 @@ final class ActivityStack { TaskAccessInfo info = getTaskAccessInfoLocked(tr, true); ActivityRecord resumed = mResumedActivity; if (resumed != null && resumed.thumbHolder == tr) { info.mainThumbnail = resumed.stack.screenshotActivities(resumed); info.mainThumbnail = screenshotActivities(resumed); } if (info.mainThumbnail == null) { info.mainThumbnail = tr.lastThumbnail; Loading @@ -4538,7 +4500,7 @@ final class ActivityStack { if (resumed != null && resumed.task == tr) { // This task is the current resumed task, we just need to take // a screenshot of it and return that. return resumed.stack.screenshotActivities(resumed); return screenshotActivities(resumed); } // Return the information about the task, to figure out the top // thumbnail to return. Loading @@ -4551,7 +4513,10 @@ final class ActivityStack { public ActivityRecord removeTaskActivitiesLocked(int taskId, int subTaskIndex, boolean taskRequired) { final TaskRecord task = mTaskIdToTaskRecord.get(taskId); final TaskRecord task = taskForIdLocked(taskId); if (task == null) { return null; } TaskAccessInfo info = getTaskAccessInfoLocked(task, false); if (info.root == null) { if (taskRequired) { Loading Loading @@ -4633,7 +4598,7 @@ final class ActivityStack { TaskAccessInfo.SubTask sub = thumbs.subtasks.get(index); ActivityRecord resumed = mResumedActivity; if (resumed != null && resumed.thumbHolder == sub.holder) { return resumed.stack.screenshotActivities(resumed); return screenshotActivities(resumed); } return sub.holder.lastThumbnail; } Loading Loading @@ -4847,8 +4812,7 @@ final class ActivityStack { for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { final ActivityRecord r = activities.get(activityNdx); if ((r.info.flags&ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS) != 0) { r.stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "close-sys", true); finishActivityLocked(r, Activity.RESULT_CANCELED, null, "close-sys", true); } } } Loading Loading @@ -4884,8 +4848,7 @@ final class ActivityStack { r.app = null; } lastTask = r.task; r.stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "force-stop", true); finishActivityLocked(r, Activity.RESULT_CANCELED, null, "force-stop", true); } } } Loading Loading @@ -4975,8 +4938,7 @@ final class ActivityStack { if (r.app == app) { Slog.w(TAG, " Force finishing activity " + r.intent.getComponent().flattenToShortString()); r.stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "crashed", false); finishActivityLocked(r, Activity.RESULT_CANCELED, null, "crashed", false); } } } Loading Loading @@ -5048,11 +5010,11 @@ final class ActivityStack { private void removeActivity(ActivityRecord r) { final TaskRecord task = r.task; // TODO: use ActivityManagerService.removeTask to do this. if (task.removeActivity(r)) { if (DEBUG_ADD_REMOVE) Slog.i(TAG, "removeActivity: Removing from history, task=" + task); mTaskHistory.remove(task); mTaskIdToTaskRecord.delete(task.taskId); } } Loading @@ -5066,13 +5028,7 @@ final class ActivityStack { private TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent, boolean toTop) { TaskRecord oldTask = mTaskIdToTaskRecord.get(taskId); if (oldTask != null) { Slog.w(TAG, "createTaskRecord: Reusing taskId=" + taskId + " without removing"); mTaskHistory.remove(oldTask); } TaskRecord task = new TaskRecord(taskId, info, intent); mTaskIdToTaskRecord.put(taskId, task); TaskRecord task = new TaskRecord(taskId, info, intent, this); if (toTop) { mTaskHistory.add(task); } else { Loading
services/java/com/android/server/am/CompatModePackages.java +7 −7 Original line number Diff line number Diff line Loading @@ -166,7 +166,7 @@ public class CompatModePackages { } public boolean getFrontActivityAskCompatModeLocked() { ActivityRecord r = mService.mMainStack.topRunningActivityLocked(null); ActivityRecord r = mService.mFocusedStack.topRunningActivityLocked(null); if (r == null) { return false; } Loading @@ -178,7 +178,7 @@ public class CompatModePackages { } public void setFrontActivityAskCompatModeLocked(boolean ask) { ActivityRecord r = mService.mMainStack.topRunningActivityLocked(null); ActivityRecord r = mService.mFocusedStack.topRunningActivityLocked(null); if (r != null) { setPackageAskCompatModeLocked(r.packageName, ask); } Loading @@ -200,7 +200,7 @@ public class CompatModePackages { } public int getFrontActivityScreenCompatModeLocked() { ActivityRecord r = mService.mMainStack.topRunningActivityLocked(null); ActivityRecord r = mService.mFocusedStack.topRunningActivityLocked(null); if (r == null) { return ActivityManager.COMPAT_MODE_UNKNOWN; } Loading @@ -208,7 +208,7 @@ public class CompatModePackages { } public void setFrontActivityScreenCompatModeLocked(int mode) { ActivityRecord r = mService.mMainStack.topRunningActivityLocked(null); ActivityRecord r = mService.mFocusedStack.topRunningActivityLocked(null); if (r == null) { Slog.w(TAG, "setFrontActivityScreenCompatMode failed: no top activity"); return; Loading Loading @@ -296,7 +296,7 @@ public class CompatModePackages { mHandler.sendMessageDelayed(msg, 10000); ActivityRecord starting = mService.mMainStack.restartPackage(packageName); ActivityRecord starting = mService.mFocusedStack.restartPackage(packageName); // Tell all processes that loaded this package about the change. for (int i=mService.mLruProcesses.size()-1; i>=0; i--) { Loading @@ -315,10 +315,10 @@ public class CompatModePackages { } if (starting != null) { mService.mMainStack.ensureActivityConfigurationLocked(starting, 0); mService.mFocusedStack.ensureActivityConfigurationLocked(starting, 0); // And we need to make sure at this point that all other activities // are made visible with the correct configuration. mService.mMainStack.ensureActivitiesVisibleLocked(starting, 0); mService.mFocusedStack.ensureActivitiesVisibleLocked(starting, 0); } } } Loading