Switched ActivityStack.mService to ActivityTaskManagerService (7/n)

Objects that contain or represent activities like ActivityStack can
no longer rely on ActivityManagerService as it is going to be in a
different package.

Test: Existing tests pass
Test: go/wm-smoke-auto
Bug: 80414790
Change-Id: I7ea20169245bee91f1be254ac30e88d2382c62a3
diff --git a/services/core/java/com/android/server/am/ActivityTaskManagerService.java b/services/core/java/com/android/server/am/ActivityTaskManagerService.java
index a49e20d..b27c480 100644
--- a/services/core/java/com/android/server/am/ActivityTaskManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityTaskManagerService.java
@@ -224,6 +224,7 @@
     private TaskChangeNotificationController mTaskChangeNotificationController;
     /** The controller for all operations related to locktask. */
     private LockTaskController mLockTaskController;
+    private ActivityStartController mActivityStartController;
 
     boolean mSuppressResizeConfigChanges;
 
@@ -262,6 +263,7 @@
         mTaskChangeNotificationController =
                 new TaskChangeNotificationController(mAm, mStackSupervisor, mH);
         mLockTaskController = new LockTaskController(mContext, mStackSupervisor, mH);
+        mActivityStartController = new ActivityStartController(mAm);
         mRecentTasks = createRecentTasks();
         mStackSupervisor.setRecentTasks(mRecentTasks);
         mVrController = new VrController(mAm);
@@ -285,6 +287,10 @@
         return mLifecycleManager;
     }
 
+    ActivityStartController getActivityStartController() {
+        return mActivityStartController;
+    }
+
     TaskChangeNotificationController getTaskChangeNotificationController() {
         return mTaskChangeNotificationController;
     }
@@ -334,7 +340,7 @@
         userId = mAm.mUserController.handleIncomingUser(Binder.getCallingPid(),
                 Binder.getCallingUid(), userId, false, ALLOW_FULL_ONLY, reason, null);
         // TODO: Switch to user app stacks here.
-        return mAm.getActivityStartController().startActivities(caller, -1, callingPackage, intents,
+        return getActivityStartController().startActivities(caller, -1, callingPackage, intents,
                 resolvedTypes, resultTo, SafeActivityOptions.fromBundle(bOptions), userId, reason);
     }
 
@@ -353,11 +359,11 @@
             boolean validateIncomingUser) {
         mAm.enforceNotIsolatedCaller("startActivityAsUser");
 
-        userId = mAm.getActivityStartController().checkTargetUser(userId, validateIncomingUser,
+        userId = getActivityStartController().checkTargetUser(userId, validateIncomingUser,
                 Binder.getCallingPid(), Binder.getCallingUid(), "startActivityAsUser");
 
         // TODO: Switch to user app stacks here.
-        return mAm.getActivityStartController().obtainStarter(intent, "startActivityAsUser")
+        return getActivityStartController().obtainStarter(intent, "startActivityAsUser")
                 .setCaller(caller)
                 .setCallingPackage(callingPackage)
                 .setResolvedType(resolvedType)
@@ -496,7 +502,7 @@
 
             final long origId = Binder.clearCallingIdentity();
             // TODO(b/64750076): Check if calling pid should really be -1.
-            final int res = mAm.getActivityStartController()
+            final int res = getActivityStartController()
                     .obtainStarter(intent, "startNextMatchingActivity")
                     .setCaller(r.app.thread)
                     .setResolvedType(r.resolvedType)
@@ -532,7 +538,7 @@
                     Binder.getCallingUid(), userId, false, ALLOW_FULL_ONLY,
                     "startActivityAndWait", null);
             // TODO: Switch to user app stacks here.
-            mAm.getActivityStartController().obtainStarter(intent, "startActivityAndWait")
+            getActivityStartController().obtainStarter(intent, "startActivityAndWait")
                     .setCaller(caller)
                     .setCallingPackage(callingPackage)
                     .setResolvedType(resolvedType)
@@ -559,7 +565,7 @@
                     Binder.getCallingUid(), userId, false, ALLOW_FULL_ONLY,
                     "startActivityWithConfig", null);
             // TODO: Switch to user app stacks here.
-            return mAm.getActivityStartController().obtainStarter(intent, "startActivityWithConfig")
+            return getActivityStartController().obtainStarter(intent, "startActivityWithConfig")
                     .setCaller(caller)
                     .setCallingPackage(callingPackage)
                     .setResolvedType(resolvedType)
@@ -634,7 +640,7 @@
 
         // TODO: Switch to user app stacks here.
         try {
-            return mAm.getActivityStartController().obtainStarter(intent, "startActivityAsCaller")
+            return getActivityStartController().obtainStarter(intent, "startActivityAsCaller")
                     .setCallingUid(targetUid)
                     .setCallingPackage(targetPackage)
                     .setResolvedType(resolvedType)
@@ -675,7 +681,7 @@
         userId = mAm.mUserController.handleIncomingUser(callingPid, callingUid, userId, false,
                 ALLOW_FULL_ONLY, "startVoiceActivity", null);
         // TODO: Switch to user app stacks here.
-        return mAm.getActivityStartController().obtainStarter(intent, "startVoiceActivity")
+        return getActivityStartController().obtainStarter(intent, "startVoiceActivity")
                 .setCallingUid(callingUid)
                 .setCallingPackage(callingPackage)
                 .setResolvedType(resolvedType)
@@ -695,7 +701,7 @@
         userId = mAm.mUserController.handleIncomingUser(callingPid, callingUid, userId, false,
                 ALLOW_FULL_ONLY, "startAssistantActivity", null);
 
-        return mAm.getActivityStartController().obtainStarter(intent, "startAssistantActivity")
+        return getActivityStartController().obtainStarter(intent, "startAssistantActivity")
                 .setCallingUid(callingUid)
                 .setCallingPackage(callingPackage)
                 .setResolvedType(resolvedType)
@@ -717,7 +723,7 @@
 
                 // Start a new recents animation
                 final RecentsAnimation anim = new RecentsAnimation(mAm, mStackSupervisor,
-                        mAm.getActivityStartController(), mAm.mWindowManager, mAm.mUserController,
+                        getActivityStartController(), mAm.mWindowManager, mAm.mUserController,
                         callingPid);
                 anim.startRecentsActivity(intent, recentsAnimationRunner, recentsComponent,
                         recentsUid, assistDataReceiver);
@@ -3391,7 +3397,7 @@
         synchronized (mGlobalLock) {
             final long origId = Binder.clearCallingIdentity();
             try {
-                mAm.getActivityStartController().registerRemoteAnimationForNextActivityStart(
+                getActivityStartController().registerRemoteAnimationForNextActivityStart(
                         packageName, adapter);
             } finally {
                 Binder.restoreCallingIdentity(origId);
@@ -3603,7 +3609,7 @@
             }
 
             synchronized (mGlobalLock) {
-                return mAm.getActivityStartController().startActivitiesInPackage(
+                return getActivityStartController().startActivitiesInPackage(
                         packageUid, packageName,
                         intents, resolvedTypes, null /* resultTo */,
                         SafeActivityOptions.fromBundle(bOptions), userId,