Create task record with window container controller when adding task

- Call through the stack to create the task record completely instead of
  creating the record directly when adding a new task. If adding the task
  fails, also remove the task from the stack
- Remove unused caching members (they were never set) optimization when
  adding tasks

Bug: 73898704
Test: Manual, install APK from bug, and start up to ensure that SysUI
      does not crash

Change-Id: I5ef778e6e8ff90c225dadcf8494de5e09798bd8b
This commit is contained in:
Winson Chung
2018-03-14 11:36:42 -07:00
parent b8651f6fba
commit 4944ba252c

View File

@@ -187,6 +187,7 @@ import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_URI_PERMI
import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_VISIBILITY;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.am.ActivityStack.REMOVE_TASK_MODE_DESTROYING;
import static com.android.server.am.ActivityStackSupervisor.DEFER_RESUME;
import static com.android.server.am.ActivityStackSupervisor.MATCH_TASK_IN_STACKS_ONLY;
import static com.android.server.am.ActivityStackSupervisor.MATCH_TASK_IN_STACKS_OR_RECENT_TASKS;
@@ -754,21 +755,6 @@ public class ActivityManagerService extends IActivityManager.Stub
*/
private final RecentTasks mRecentTasks;
/**
* For addAppTask: cached of the last activity component that was added.
*/
ComponentName mLastAddedTaskComponent;
/**
* For addAppTask: cached of the last activity uid that was added.
*/
int mLastAddedTaskUid;
/**
* For addAppTask: cached of the last ActivityInfo that was added.
*/
ActivityInfo mLastAddedTaskActivity;
/**
* The package name of the DeviceOwner. This package is not permitted to have its data cleared.
*/
@@ -10611,27 +10597,24 @@ public class ActivityManagerService extends IActivityManager.Stub
intent.addFlags(Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS);
}
}
if (!comp.equals(mLastAddedTaskComponent) || callingUid != mLastAddedTaskUid) {
mLastAddedTaskActivity = null;
}
ActivityInfo ainfo = mLastAddedTaskActivity;
if (ainfo == null) {
ainfo = mLastAddedTaskActivity = AppGlobals.getPackageManager().getActivityInfo(
comp, 0, UserHandle.getUserId(callingUid));
if (ainfo.applicationInfo.uid != callingUid) {
throw new SecurityException(
"Can't add task for another application: target uid="
+ ainfo.applicationInfo.uid + ", calling uid=" + callingUid);
}
final ActivityInfo ainfo = AppGlobals.getPackageManager().getActivityInfo(comp, 0,
UserHandle.getUserId(callingUid));
if (ainfo.applicationInfo.uid != callingUid) {
throw new SecurityException(
"Can't add task for another application: target uid="
+ ainfo.applicationInfo.uid + ", calling uid=" + callingUid);
}
TaskRecord task = TaskRecord.create(this,
mStackSupervisor.getNextTaskIdForUserLocked(r.userId),
ainfo, intent, description);
final ActivityStack stack = r.getStack();
final TaskRecord task = stack.createTaskRecord(
mStackSupervisor.getNextTaskIdForUserLocked(r.userId), ainfo, intent,
null /* voiceSession */, null /* voiceInteractor */, !ON_TOP);
if (!mRecentTasks.addToBottom(task)) {
// The app has too many tasks already and we can't add any more
stack.removeTask(task, "addAppTask", REMOVE_TASK_MODE_DESTROYING);
return INVALID_TASK_ID;
}
r.getStack().addTask(task, !ON_TOP, "addAppTask");
task.lastTaskDescription.copyFrom(description);
// TODO: Send the thumbnail to WM to store it.