diff options
author | 2018-04-30 13:55:07 -0700 | |
---|---|---|
committer | 2018-06-12 13:38:39 -0700 | |
commit | 04d9cb5f401e74ad2e34baa4e7b20e280590fe02 (patch) | |
tree | 45c3178cb34ca0901e9ff36d02211686203fa5ac | |
parent | 8bb0cc2f5dd814fbed6ea19870bf0cb9e0fe5c3d (diff) |
Moved some activities implementation to ActivityTaskManagerService (2/n)
Second step in unifying the window hierarchy that is currently split
within AM and WM packages. We move some of the API implementation for
activities from ActivityManagerService.java to
ActivityTaskManagerService.java.
Test: Existing tests pass
Test: go/wm-smoke-auto
Bug: 80414790
Change-Id: I23dcd924493d8ad1e0b6e3a55386fd72b0146605
79 files changed, 3749 insertions, 3243 deletions
diff --git a/core/java/android/accounts/ChooseAccountActivity.java b/core/java/android/accounts/ChooseAccountActivity.java index 6a436869a0ec..4af22bfac92d 100644 --- a/core/java/android/accounts/ChooseAccountActivity.java +++ b/core/java/android/accounts/ChooseAccountActivity.java @@ -17,6 +17,7 @@ package android.accounts; import android.app.Activity; import android.app.ActivityManager; +import android.app.ActivityTaskManager; import android.content.Context; import android.content.pm.PackageManager; import android.content.res.Resources; @@ -72,8 +73,8 @@ public class ChooseAccountActivity extends Activity { try { IBinder activityToken = getActivityToken(); - mCallingUid = ActivityManager.getService().getLaunchedFromUid(activityToken); - mCallingPackage = ActivityManager.getService().getLaunchedFromPackage( + mCallingUid = ActivityTaskManager.getService().getLaunchedFromUid(activityToken); + mCallingPackage = ActivityTaskManager.getService().getLaunchedFromPackage( activityToken); } catch (RemoteException re) { // Couldn't figure out caller details diff --git a/core/java/android/accounts/ChooseTypeAndAccountActivity.java b/core/java/android/accounts/ChooseTypeAndAccountActivity.java index 6680ce6acb04..57c108326706 100644 --- a/core/java/android/accounts/ChooseTypeAndAccountActivity.java +++ b/core/java/android/accounts/ChooseTypeAndAccountActivity.java @@ -15,6 +15,7 @@ */ package android.accounts; +import android.app.ActivityTaskManager; import com.google.android.collect.Sets; import android.app.Activity; @@ -147,8 +148,8 @@ public class ChooseTypeAndAccountActivity extends Activity try { IBinder activityToken = getActivityToken(); - mCallingUid = ActivityManager.getService().getLaunchedFromUid(activityToken); - mCallingPackage = ActivityManager.getService().getLaunchedFromPackage( + mCallingUid = ActivityTaskManager.getService().getLaunchedFromUid(activityToken); + mCallingPackage = ActivityTaskManager.getService().getLaunchedFromPackage( activityToken); if (mCallingUid != 0 && mCallingPackage != null) { Bundle restrictions = UserManager.get(this) diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index a6d2be0842a7..8e0fa1395ed1 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -1442,7 +1442,7 @@ public class Activity extends ContextThemeWrapper public boolean isVoiceInteractionRoot() { try { return mVoiceInteractor != null - && ActivityManager.getService().isRootVoiceInteraction(mToken); + && ActivityTaskManager.getService().isRootVoiceInteraction(mToken); } catch (RemoteException e) { } return false; @@ -1465,7 +1465,7 @@ public class Activity extends ContextThemeWrapper */ public boolean isLocalVoiceInteractionSupported() { try { - return ActivityManager.getService().supportsLocalVoiceInteraction(); + return ActivityTaskManager.getService().supportsLocalVoiceInteraction(); } catch (RemoteException re) { } return false; @@ -1479,7 +1479,7 @@ public class Activity extends ContextThemeWrapper */ public void startLocalVoiceInteraction(Bundle privateOptions) { try { - ActivityManager.getService().startLocalVoiceInteraction(mToken, privateOptions); + ActivityTaskManager.getService().startLocalVoiceInteraction(mToken, privateOptions); } catch (RemoteException re) { } } @@ -1508,7 +1508,7 @@ public class Activity extends ContextThemeWrapper */ public void stopLocalVoiceInteraction() { try { - ActivityManager.getService().stopLocalVoiceInteraction(mToken); + ActivityTaskManager.getService().stopLocalVoiceInteraction(mToken); } catch (RemoteException re) { } } @@ -1886,7 +1886,7 @@ public class Activity extends ContextThemeWrapper */ public boolean showAssist(Bundle args) { try { - return ActivityManager.getService().showAssistFromActivity(mToken, args); + return ActivityTaskManager.getService().showAssistFromActivity(mToken, args); } catch (RemoteException e) { } return false; @@ -2019,7 +2019,8 @@ public class Activity extends ContextThemeWrapper if (mDoReportFullyDrawn) { mDoReportFullyDrawn = false; try { - ActivityManager.getService().reportActivityFullyDrawn(mToken, mRestoredFromBundle); + ActivityTaskManager.getService().reportActivityFullyDrawn( + mToken, mRestoredFromBundle); } catch (RemoteException e) { } } @@ -2066,7 +2067,7 @@ public class Activity extends ContextThemeWrapper */ public boolean isInMultiWindowMode() { try { - return ActivityManager.getService().isInMultiWindowMode(mToken); + return ActivityTaskManager.getService().isInMultiWindowMode(mToken); } catch (RemoteException e) { } return false; @@ -2113,7 +2114,7 @@ public class Activity extends ContextThemeWrapper */ public boolean isInPictureInPictureMode() { try { - return ActivityManager.getService().isInPictureInPictureMode(mToken); + return ActivityTaskManager.getService().isInPictureInPictureMode(mToken); } catch (RemoteException e) { } return false; @@ -2168,7 +2169,7 @@ public class Activity extends ContextThemeWrapper throw new IllegalStateException("Activity must be resumed to enter" + " picture-in-picture"); } - return ActivityManagerNative.getDefault().enterPictureInPictureMode(mToken, params); + return ActivityTaskManager.getService().enterPictureInPictureMode(mToken, params); } catch (RemoteException e) { return false; } @@ -2194,7 +2195,7 @@ public class Activity extends ContextThemeWrapper if (params == null) { throw new IllegalArgumentException("Expected non-null picture-in-picture params"); } - ActivityManagerNative.getDefault().setPictureInPictureParams(mToken, params); + ActivityTaskManager.getService().setPictureInPictureParams(mToken, params); } catch (RemoteException e) { } } @@ -2207,7 +2208,7 @@ public class Activity extends ContextThemeWrapper */ public int getMaxNumPictureInPictureActions() { try { - return ActivityManagerNative.getDefault().getMaxNumPictureInPictureActions(mToken); + return ActivityTaskManager.getService().getMaxNumPictureInPictureActions(mToken); } catch (RemoteException e) { return 0; } @@ -3321,7 +3322,7 @@ public class Activity extends ContextThemeWrapper */ @Override public void exitFreeformMode() throws RemoteException { - ActivityManager.getService().exitFreeformMode(mToken); + ActivityTaskManager.getService().exitFreeformMode(mToken); } /** @@ -4833,7 +4834,7 @@ public class Activity extends ContextThemeWrapper fillInIntent.prepareToLeaveProcess(this); resolvedType = fillInIntent.resolveTypeIfNeeded(getContentResolver()); } - int result = ActivityManager.getService() + int result = ActivityTaskManager.getService() .startActivityIntentSender(mMainThread.getApplicationThread(), intent != null ? intent.getTarget() : null, intent != null ? intent.getWhitelistToken() : null, @@ -5065,7 +5066,7 @@ public class Activity extends ContextThemeWrapper } intent.migrateExtraStreamToClipData(); intent.prepareToLeaveProcess(this); - result = ActivityManager.getService() + result = ActivityTaskManager.getService() .startActivity(mMainThread.getApplicationThread(), getBasePackageName(), intent, intent.resolveTypeIfNeeded(getContentResolver()), mToken, mEmbeddedID, requestCode, ActivityManager.START_FLAG_ONLY_IF_NEEDED, @@ -5136,7 +5137,7 @@ public class Activity extends ContextThemeWrapper try { intent.migrateExtraStreamToClipData(); intent.prepareToLeaveProcess(this); - return ActivityManager.getService() + return ActivityTaskManager.getService() .startNextMatchingActivity(mToken, intent, options); } catch (RemoteException e) { // Empty @@ -5351,7 +5352,7 @@ public class Activity extends ContextThemeWrapper */ public void overridePendingTransition(int enterAnim, int exitAnim) { try { - ActivityManager.getService().overridePendingTransition( + ActivityTaskManager.getService().overridePendingTransition( mToken, getPackageName(), enterAnim, exitAnim); } catch (RemoteException e) { } @@ -5476,7 +5477,7 @@ public class Activity extends ContextThemeWrapper @Nullable public String getCallingPackage() { try { - return ActivityManager.getService().getCallingPackage(mToken); + return ActivityTaskManager.getService().getCallingPackage(mToken); } catch (RemoteException e) { return null; } @@ -5499,7 +5500,7 @@ public class Activity extends ContextThemeWrapper @Nullable public ComponentName getCallingActivity() { try { - return ActivityManager.getService().getCallingActivity(mToken); + return ActivityTaskManager.getService().getCallingActivity(mToken); } catch (RemoteException e) { return null; } @@ -5603,7 +5604,7 @@ public class Activity extends ContextThemeWrapper if (resultData != null) { resultData.prepareToLeaveProcess(this); } - if (ActivityManager.getService() + if (ActivityTaskManager.getService() .finishActivity(mToken, resultCode, resultData, finishTask)) { mFinished = true; } @@ -5653,7 +5654,7 @@ public class Activity extends ContextThemeWrapper throw new IllegalStateException("Can not be called to deliver a result"); } try { - if (ActivityManager.getService().finishActivityAffinity(mToken)) { + if (ActivityTaskManager.getService().finishActivityAffinity(mToken)) { mFinished = true; } } catch (RemoteException e) { @@ -5699,7 +5700,7 @@ public class Activity extends ContextThemeWrapper public void finishActivity(int requestCode) { if (mParent == null) { try { - ActivityManager.getService() + ActivityTaskManager.getService() .finishSubActivity(mToken, mEmbeddedID, requestCode); } catch (RemoteException e) { // Empty @@ -5719,7 +5720,7 @@ public class Activity extends ContextThemeWrapper */ public void finishActivityFromChild(@NonNull Activity child, int requestCode) { try { - ActivityManager.getService() + ActivityTaskManager.getService() .finishSubActivity(mToken, child.mEmbeddedID, requestCode); } catch (RemoteException e) { // Empty @@ -5747,7 +5748,7 @@ public class Activity extends ContextThemeWrapper */ public boolean releaseInstance() { try { - return ActivityManager.getService().releaseActivityInstance(mToken); + return ActivityTaskManager.getService().releaseActivityInstance(mToken); } catch (RemoteException e) { // Empty } @@ -5862,7 +5863,7 @@ public class Activity extends ContextThemeWrapper public void setRequestedOrientation(@ActivityInfo.ScreenOrientation int requestedOrientation) { if (mParent == null) { try { - ActivityManager.getService().setRequestedOrientation( + ActivityTaskManager.getService().setRequestedOrientation( mToken, requestedOrientation); } catch (RemoteException e) { // Empty @@ -5885,7 +5886,7 @@ public class Activity extends ContextThemeWrapper public int getRequestedOrientation() { if (mParent == null) { try { - return ActivityManager.getService() + return ActivityTaskManager.getService() .getRequestedOrientation(mToken); } catch (RemoteException e) { // Empty @@ -5904,8 +5905,7 @@ public class Activity extends ContextThemeWrapper */ public int getTaskId() { try { - return ActivityManager.getService() - .getTaskForActivity(mToken, false); + return ActivityTaskManager.getService().getTaskForActivity(mToken, false); } catch (RemoteException e) { return -1; } @@ -5920,7 +5920,7 @@ public class Activity extends ContextThemeWrapper @Override public boolean isTaskRoot() { try { - return ActivityManager.getService().getTaskForActivity(mToken, true) >= 0; + return ActivityTaskManager.getService().getTaskForActivity(mToken, true) >= 0; } catch (RemoteException e) { return false; } @@ -5939,8 +5939,7 @@ public class Activity extends ContextThemeWrapper */ public boolean moveTaskToBack(boolean nonRoot) { try { - return ActivityManager.getService().moveActivityTaskToBack( - mToken, nonRoot); + return ActivityTaskManager.getService().moveActivityTaskToBack(mToken, nonRoot); } catch (RemoteException e) { // Empty } @@ -6115,7 +6114,7 @@ public class Activity extends ContextThemeWrapper } } try { - ActivityManager.getService().setTaskDescription(mToken, mTaskDescription); + ActivityTaskManager.getService().setTaskDescription(mToken, mTaskDescription); } catch (RemoteException e) { } } @@ -6390,7 +6389,7 @@ public class Activity extends ContextThemeWrapper */ public boolean isImmersive() { try { - return ActivityManager.getService().isImmersive(mToken); + return ActivityTaskManager.getService().isImmersive(mToken); } catch (RemoteException e) { return false; } @@ -6408,7 +6407,7 @@ public class Activity extends ContextThemeWrapper return false; } try { - return ActivityManager.getService().isTopOfTask(getActivityToken()); + return ActivityTaskManager.getService().isTopOfTask(getActivityToken()); } catch (RemoteException e) { return false; } @@ -6434,7 +6433,7 @@ public class Activity extends ContextThemeWrapper public void convertFromTranslucent() { try { mTranslucentCallback = null; - if (ActivityManager.getService().convertFromTranslucent(mToken)) { + if (ActivityTaskManager.getService().convertFromTranslucent(mToken)) { WindowManagerGlobal.getInstance().changeCanvasOpacity(mToken, true); } } catch (RemoteException e) { @@ -6473,7 +6472,7 @@ public class Activity extends ContextThemeWrapper boolean drawComplete; try { mTranslucentCallback = callback; - mChangeCanvasToTranslucent = ActivityManager.getService().convertToTranslucent( + mChangeCanvasToTranslucent = ActivityTaskManager.getService().convertToTranslucent( mToken, options == null ? null : options.toBundle()); WindowManagerGlobal.getInstance().changeCanvasOpacity(mToken, false); drawComplete = true; @@ -6519,7 +6518,7 @@ public class Activity extends ContextThemeWrapper ActivityOptions getActivityOptions() { try { return ActivityOptions.fromBundle( - ActivityManager.getService().getActivityOptions(mToken)); + ActivityTaskManager.getService().getActivityOptions(mToken)); } catch (RemoteException e) { } return null; @@ -6664,7 +6663,7 @@ public class Activity extends ContextThemeWrapper */ public void setImmersive(boolean i) { try { - ActivityManager.getService().setImmersive(mToken, i); + ActivityTaskManager.getService().setImmersive(mToken, i); } catch (RemoteException e) { // pass } @@ -6727,7 +6726,7 @@ public class Activity extends ContextThemeWrapper public void setVrModeEnabled(boolean enabled, @NonNull ComponentName requestedComponent) throws PackageManager.NameNotFoundException { try { - if (ActivityManager.getService().setVrMode(mToken, enabled, requestedComponent) + if (ActivityTaskManager.getService().setVrMode(mToken, enabled, requestedComponent) != 0) { throw new PackageManager.NameNotFoundException( requestedComponent.flattenToString()); @@ -6848,8 +6847,7 @@ public class Activity extends ContextThemeWrapper if (info.taskAffinity == null) { return false; } - return ActivityManager.getService() - .shouldUpRecreateTask(mToken, info.taskAffinity); + return ActivityTaskManager.getService().shouldUpRecreateTask(mToken, info.taskAffinity); } catch (RemoteException e) { return false; } catch (NameNotFoundException e) { @@ -6901,7 +6899,7 @@ public class Activity extends ContextThemeWrapper } try { upIntent.prepareToLeaveProcess(this); - return ActivityManager.getService().navigateUpTo(mToken, upIntent, + return ActivityTaskManager.getService().navigateUpTo(mToken, upIntent, resultCode, resultData); } catch (RemoteException e) { return false; @@ -7508,7 +7506,7 @@ public class Activity extends ContextThemeWrapper */ public void startLockTask() { try { - ActivityManager.getService().startLockTaskModeByToken(mToken); + ActivityTaskManager.getService().startLockTaskModeByToken(mToken); } catch (RemoteException e) { } } @@ -7531,7 +7529,7 @@ public class Activity extends ContextThemeWrapper */ public void stopLockTask() { try { - ActivityManager.getService().stopLockTaskModeByToken(mToken); + ActivityTaskManager.getService().stopLockTaskModeByToken(mToken); } catch (RemoteException e) { } } @@ -7543,7 +7541,7 @@ public class Activity extends ContextThemeWrapper */ public void showLockTaskEscapeMessage() { try { - ActivityManager.getService().showLockTaskEscapeMessage(mToken); + ActivityTaskManager.getService().showLockTaskEscapeMessage(mToken); } catch (RemoteException e) { } } @@ -7813,7 +7811,7 @@ public class Activity extends ContextThemeWrapper */ public void setDisablePreviewScreenshots(boolean disable) { try { - ActivityManager.getService().setDisablePreviewScreenshots(mToken, disable); + ActivityTaskManager.getService().setDisablePreviewScreenshots(mToken, disable); } catch (RemoteException e) { Log.e(TAG, "Failed to call setDisablePreviewScreenshots", e); } @@ -7834,7 +7832,7 @@ public class Activity extends ContextThemeWrapper */ public void setShowWhenLocked(boolean showWhenLocked) { try { - ActivityManager.getService().setShowWhenLocked(mToken, showWhenLocked); + ActivityTaskManager.getService().setShowWhenLocked(mToken, showWhenLocked); } catch (RemoteException e) { Log.e(TAG, "Failed to call setShowWhenLocked", e); } @@ -7860,7 +7858,7 @@ public class Activity extends ContextThemeWrapper */ public void setTurnScreenOn(boolean turnScreenOn) { try { - ActivityManager.getService().setTurnScreenOn(mToken, turnScreenOn); + ActivityTaskManager.getService().setTurnScreenOn(mToken, turnScreenOn); } catch (RemoteException e) { Log.e(TAG, "Failed to call setTurnScreenOn", e); } @@ -7876,7 +7874,7 @@ public class Activity extends ContextThemeWrapper @RequiresPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS) public void registerRemoteAnimations(RemoteAnimationDefinition definition) { try { - ActivityManager.getService().registerRemoteAnimations(mToken, definition); + ActivityTaskManager.getService().registerRemoteAnimations(mToken, definition); } catch (RemoteException e) { Log.e(TAG, "Failed to call registerRemoteAnimations", e); } diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java index 9ff8223474d4..e08b54f3eb5c 100644 --- a/core/java/android/app/ActivityManager.java +++ b/core/java/android/app/ActivityManager.java @@ -746,7 +746,7 @@ public class ActivityManager { /** @hide */ public int getFrontActivityScreenCompatMode() { try { - return getService().getFrontActivityScreenCompatMode(); + return getTaskService().getFrontActivityScreenCompatMode(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -755,7 +755,7 @@ public class ActivityManager { /** @hide */ public void setFrontActivityScreenCompatMode(int mode) { try { - getService().setFrontActivityScreenCompatMode(mode); + getTaskService().setFrontActivityScreenCompatMode(mode); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -1182,7 +1182,7 @@ public class ActivityManager { public static Bitmap loadTaskDescriptionIcon(String iconFilename, int userId) { if (iconFilename != null) { try { - return getService().getTaskDescriptionIcon(iconFilename, + return getTaskService().getTaskDescriptionIcon(iconFilename, userId); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); @@ -1582,7 +1582,7 @@ public class ActivityManager { if (maxNum < 0) { throw new IllegalArgumentException("The requested number of tasks should be >= 0"); } - return getService().getRecentTasks(maxNum, flags, mContext.getUserId()).getList(); + return getTaskService().getRecentTasks(maxNum, flags, mContext.getUserId()).getList(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -1735,7 +1735,7 @@ public class ActivityManager { ArrayList<AppTask> tasks = new ArrayList<AppTask>(); List<IBinder> appTasks; try { - appTasks = getService().getAppTasks(mContext.getPackageName()); + appTasks = getTaskService().getAppTasks(mContext.getPackageName()); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -1760,7 +1760,7 @@ public class ActivityManager { private void ensureAppTaskThumbnailSizeLocked() { if (mAppTaskThumbnailSize == null) { try { - mAppTaskThumbnailSize = getService().getAppTaskThumbnailSize(); + mAppTaskThumbnailSize = getTaskService().getAppTaskThumbnailSize(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -1825,7 +1825,7 @@ public class ActivityManager { description = new TaskDescription(); } try { - return getService().addAppTask(activity.getActivityToken(), + return getTaskService().addAppTask(activity.getActivityToken(), intent, description, thumbnail); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); @@ -1868,7 +1868,7 @@ public class ActivityManager { public List<RunningTaskInfo> getRunningTasks(int maxNum) throws SecurityException { try { - return getService().getTasks(maxNum); + return getTaskService().getTasks(maxNum); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -2077,7 +2077,7 @@ public class ActivityManager { @RequiresPermission(android.Manifest.permission.REORDER_TASKS) public void moveTaskToFront(int taskId, @MoveTaskFlags int flags, Bundle options) { try { - getService().moveTaskToFront(taskId, flags, options); + getTaskService().moveTaskToFront(taskId, flags, options); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -3584,7 +3584,7 @@ public class ActivityManager { @TestApi public void alwaysShowUnsupportedCompileSdkWarning(ComponentName activity) { try { - getService().alwaysShowUnsupportedCompileSdkWarning(activity); + getTaskService().alwaysShowUnsupportedCompileSdkWarning(activity); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -3907,6 +3907,10 @@ public class ActivityManager { return IActivityManagerSingleton.get(); } + private static IActivityTaskManager getTaskService() { + return ActivityTaskManager.getService(); + } + private static final Singleton<IActivityManager> IActivityManagerSingleton = new Singleton<IActivityManager>() { @Override @@ -4022,7 +4026,7 @@ public class ActivityManager { */ public int getLockTaskModeState() { try { - return getService().getLockTaskModeState(); + return getTaskService().getLockTaskModeState(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 369691973416..f3c67310c05d 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -1840,7 +1840,7 @@ public final class ActivityThread extends ClientTransactionHandler { } if (a != null) { mNewActivities = null; - IActivityManager am = ActivityManager.getService(); + IActivityTaskManager am = ActivityTaskManager.getService(); ActivityClientRecord prev; do { if (localLOGV) Slog.v( @@ -2993,7 +2993,7 @@ public final class ActivityThread extends ClientTransactionHandler { private ContextImpl createBaseContextForActivity(ActivityClientRecord r) { final int displayId; try { - displayId = ActivityManager.getService().getActivityDisplayId(r.token); + displayId = ActivityTaskManager.getService().getActivityDisplayId(r.token); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -3061,7 +3061,7 @@ public final class ActivityThread extends ClientTransactionHandler { } else { // If there was an error, for any reason, tell the activity manager to stop us. try { - ActivityManager.getService() + ActivityTaskManager.getService() .finishActivity(r.token, Activity.RESULT_CANCELED, null, Activity.DONT_FINISH_TASK_WITH_ACTIVITY); } catch (RemoteException ex) { @@ -3093,7 +3093,7 @@ public final class ActivityThread extends ClientTransactionHandler { } } try { - ActivityManager.getService().reportSizeConfigurations(r.token, + ActivityTaskManager.getService().reportSizeConfigurations(r.token, horizontal.copyKeys(), vertical.copyKeys(), smallest.copyKeys()); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); @@ -3210,7 +3210,7 @@ public final class ActivityThread extends ClientTransactionHandler { structure.setAcquisitionEndTime(SystemClock.uptimeMillis()); mLastAssistStructures.add(new WeakReference<>(structure)); - IActivityManager mgr = ActivityManager.getService(); + IActivityTaskManager mgr = ActivityTaskManager.getService(); try { mgr.reportAssistContextExtras(cmd.requestToken, data, structure, content, referrer); } catch (RemoteException e) { @@ -3838,7 +3838,7 @@ public final class ActivityThread extends ClientTransactionHandler { boolean willBeVisible = !a.mStartedActivity; if (!willBeVisible) { try { - willBeVisible = ActivityManager.getService().willActivityBeVisible( + willBeVisible = ActivityTaskManager.getService().willActivityBeVisible( a.getActivityToken()); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); @@ -4290,7 +4290,7 @@ public final class ActivityThread extends ClientTransactionHandler { // Tell activity manager we slept. try { - ActivityManager.getService().activitySlept(r.token); + ActivityTaskManager.getService().activitySlept(r.token); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } @@ -4537,7 +4537,7 @@ public final class ActivityThread extends ClientTransactionHandler { } if (finishing) { try { - ActivityManager.getService().activityDestroyed(token); + ActivityTaskManager.getService().activityDestroyed(token); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } @@ -4790,7 +4790,7 @@ public final class ActivityThread extends ClientTransactionHandler { @Override public void reportRelaunch(IBinder token, PendingTransactionActions pendingActions) { try { - ActivityManager.getService().activityRelaunched(token); + ActivityTaskManager.getService().activityRelaunched(token); final ActivityClientRecord r = mActivities.get(token); if (pendingActions.shouldReportRelaunchToWindowManager() && r != null && r.window != null) { @@ -6515,7 +6515,7 @@ public final class ActivityThread extends ClientTransactionHandler { + " used=" + (dalvikUsed/1024)); mSomeActivitiesChanged = false; try { - mgr.releaseSomeActivities(mAppThread); + ActivityTaskManager.getService().releaseSomeActivities(mAppThread); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } diff --git a/core/java/android/app/ActivityView.java b/core/java/android/app/ActivityView.java index e469098e22d5..c7fa33d1745d 100644 --- a/core/java/android/app/ActivityView.java +++ b/core/java/android/app/ActivityView.java @@ -64,6 +64,7 @@ public class ActivityView extends ViewGroup { private StateCallback mActivityViewCallback; private IActivityManager mActivityManager; + private IActivityTaskManager mActivityTaskManager; private IInputForwarder mInputForwarder; // Temp container to store view coordinates on screen. private final int[] mLocationOnScreen = new int[2]; @@ -85,6 +86,7 @@ public class ActivityView extends ViewGroup { super(context, attrs, defStyle); mActivityManager = ActivityManager.getService(); + mActivityTaskManager = ActivityTaskManager.getService(); mSurfaceView = new SurfaceView(context); mSurfaceCallback = new SurfaceCallback(); mSurfaceView.getHolder().addCallback(mSurfaceCallback); @@ -349,7 +351,7 @@ public class ActivityView extends ViewGroup { mInputForwarder = InputManager.getInstance().createInputForwarder(displayId); mTaskStackListener = new TaskStackListenerImpl(); try { - mActivityManager.registerTaskStackListener(mTaskStackListener); + mActivityTaskManager.registerTaskStackListener(mTaskStackListener); } catch (RemoteException e) { Log.e(TAG, "Failed to register task stack listener", e); } @@ -369,7 +371,7 @@ public class ActivityView extends ViewGroup { if (mTaskStackListener != null) { try { - mActivityManager.unregisterTaskStackListener(mTaskStackListener); + mActivityTaskManager.unregisterTaskStackListener(mTaskStackListener); } catch (RemoteException e) { Log.e(TAG, "Failed to unregister task stack listener", e); } @@ -474,7 +476,7 @@ public class ActivityView extends ViewGroup { // Find the topmost task on our virtual display - it will define the background // color of the surface view during resizing. final int displayId = mVirtualDisplay.getDisplay().getDisplayId(); - final List<StackInfo> stackInfoList = mActivityManager.getAllStackInfos(); + final List<StackInfo> stackInfoList = mActivityTaskManager.getAllStackInfos(); // Iterate through stacks from top to bottom. final int stackCount = stackInfoList.size(); diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java index 95117862a8da..82088dc569e7 100644 --- a/core/java/android/app/ContextImpl.java +++ b/core/java/android/app/ContextImpl.java @@ -923,7 +923,7 @@ class ContextImpl extends Context { @Override public void startActivityAsUser(Intent intent, Bundle options, UserHandle user) { try { - ActivityManager.getService().startActivityAsUser( + ActivityTaskManager.getService().startActivityAsUser( mMainThread.getApplicationThread(), getBasePackageName(), intent, intent.resolveTypeIfNeeded(getContentResolver()), null, null, 0, Intent.FLAG_ACTIVITY_NEW_TASK, null, options, @@ -985,7 +985,7 @@ class ContextImpl extends Context { fillInIntent.prepareToLeaveProcess(this); resolvedType = fillInIntent.resolveTypeIfNeeded(getContentResolver()); } - int result = ActivityManager.getService() + int result = ActivityTaskManager.getService() .startActivityIntentSender(mMainThread.getApplicationThread(), intent != null ? intent.getTarget() : null, intent != null ? intent.getWhitelistToken() : null, diff --git a/core/java/android/app/IActivityManager.aidl b/core/java/android/app/IActivityManager.aidl index d99084f74f8d..8aae4063ae19 100644 --- a/core/java/android/app/IActivityManager.aidl +++ b/core/java/android/app/IActivityManager.aidl @@ -105,7 +105,6 @@ interface IActivityManager { in String resolvedType, in IBinder resultTo, in String resultWho, int requestCode, int flags, in ProfilerInfo profilerInfo, in Bundle options); void unhandledBack(); - boolean finishActivity(in IBinder token, int code, in Intent data, int finishTask); Intent registerReceiver(in IApplicationThread caller, in String callerPackage, in IIntentReceiver receiver, in IntentFilter filter, @@ -119,25 +118,16 @@ interface IActivityManager { oneway void finishReceiver(in IBinder who, int resultCode, in String resultData, in Bundle map, boolean abortBroadcast, int flags); void attachApplication(in IApplicationThread app, long startSeq); - oneway void activityIdle(in IBinder token, in Configuration config, - in boolean stopProfiling); - void activityPaused(in IBinder token); - oneway void activityStopped(in IBinder token, in Bundle state, - in PersistableBundle persistentState, in CharSequence description); - String getCallingPackage(in IBinder token); - ComponentName getCallingActivity(in IBinder token); List<ActivityManager.RunningTaskInfo> getTasks(int maxNum); List<ActivityManager.RunningTaskInfo> getFilteredTasks(int maxNum, int ignoreActivityType, int ignoreWindowingMode); void moveTaskToFront(int task, int flags, in Bundle options); - void moveTaskBackwards(int task); int getTaskForActivity(in IBinder token, in boolean onlyRoot); ContentProviderHolder getContentProvider(in IApplicationThread caller, in String name, int userId, boolean stable); void publishContentProviders(in IApplicationThread caller, in List<ContentProviderHolder> providers); boolean refContentProvider(in IBinder connection, int stableDelta, int unstableDelta); - void finishSubActivity(in IBinder token, in String resultWho, int requestCode); PendingIntent getRunningServiceControlPanel(in ComponentName service); ComponentName startService(in IApplicationThread caller, in Intent service, in String resolvedType, boolean requireForeground, in String callingPackage, int userId); @@ -148,7 +138,6 @@ interface IActivityManager { in String callingPackage, int userId); boolean unbindService(in IServiceConnection connection); void publishService(in IBinder token, in Intent intent, in IBinder service); - void activityResumed(in IBinder token); void setDebugApp(in String packageName, boolean waitForDebugger, boolean persistent); void setAgentApp(in String packageName, @nullable String agent); void setAlwaysFinish(boolean enabled); @@ -174,8 +163,6 @@ interface IActivityManager { */ boolean updateConfiguration(in Configuration values); boolean stopServiceToken(in ComponentName className, in IBinder token, int startId); - ComponentName getActivityClassForToken(in IBinder token); - String getPackageForToken(in IBinder token); void setProcessLimit(int max); int getProcessLimit(); int checkPermission(in String permission, int pid, int uid); @@ -195,7 +182,6 @@ interface IActivityManager { ParceledListSlice getRecentTasks(int maxNum, int flags, int userId); oneway void serviceDoneExecuting(in IBinder token, int type, int startId, int res); - oneway void activityDestroyed(in IBinder token); IIntentSender getIntentSender(int type, in String packageName, in IBinder token, in String resultWho, int requestCode, in Intent[] intents, in String[] resolvedTypes, int flags, in Bundle options, int userId); @@ -204,13 +190,10 @@ interface IActivityManager { void registerIntentSenderCancelListener(in IIntentSender sender, in IResultReceiver receiver); void unregisterIntentSenderCancelListener(in IIntentSender sender, in IResultReceiver receiver); void enterSafeMode(); - boolean startNextMatchingActivity(in IBinder callingActivity, - in Intent intent, in Bundle options); void noteWakeupAlarm(in IIntentSender sender, in WorkSource workSource, int sourceUid, in String sourcePkg, in String tag); void removeContentProvider(in IBinder connection, boolean stable); void setRequestedOrientation(in IBinder token, int requestedOrientation); - int getRequestedOrientation(in IBinder token); void unbindFinished(in IBinder token, in Intent service, boolean doRebind); void setProcessImportant(in IBinder token, int pid, boolean isForeground, String reason); void setServiceForeground(in ComponentName className, in IBinder token, @@ -223,7 +206,6 @@ interface IActivityManager { void forceStopPackage(in String packageName, int userId); boolean killPids(in int[] pids, in String reason, boolean secure); List<ActivityManager.RunningServiceInfo> getServices(int maxNum, int flags); - ActivityManager.TaskDescription getTaskDescription(int taskId); // Retrieve running application processes in the system List<ActivityManager.RunningAppProcessInfo> getRunningAppProcesses(); // Get device configuration @@ -246,26 +228,11 @@ interface IActivityManager { void closeSystemDialogs(in String reason); Debug.MemoryInfo[] getProcessMemoryInfo(in int[] pids); void killApplicationProcess(in String processName, int uid); - int startActivityIntentSender(in IApplicationThread caller, - in IIntentSender target, in IBinder whitelistToken, in Intent fillInIntent, - in String resolvedType, in IBinder resultTo, in String resultWho, int requestCode, - int flagsMask, int flagsValues, in Bundle options); - void overridePendingTransition(in IBinder token, in String packageName, - int enterAnim, int exitAnim); // Special low-level communication with activity manager. boolean handleApplicationWtf(in IBinder app, in String tag, boolean system, in ApplicationErrorReport.ParcelableCrashInfo crashInfo); void killBackgroundProcesses(in String packageName, int userId); boolean isUserAMonkey(); - WaitResult startActivityAndWait(in IApplicationThread caller, in String callingPackage, - in Intent intent, in String resolvedType, in IBinder resultTo, in String resultWho, - int requestCode, int flags, in ProfilerInfo profilerInfo, in Bundle options, - int userId); - boolean willActivityBeVisible(in IBinder token); - int startActivityWithConfig(in IApplicationThread caller, in String callingPackage, - in Intent intent, in String resolvedType, in IBinder resultTo, in String resultWho, - int requestCode, int startFlags, in Configuration newConfig, - in Bundle options, int userId); // Retrieve info of applications installed on external media that are currently // running. List<ApplicationInfo> getRunningExternalApplications(); @@ -276,8 +243,6 @@ interface IActivityManager { // ActivityManagerService remaining set. void handleApplicationStrictModeViolation(in IBinder app, int violationMask, in StrictMode.ViolationInfo crashInfo); - boolean isImmersive(in IBinder token); - void setImmersive(in IBinder token, boolean immersive); boolean isTopActivityImmersive(); void crashApplication(int uid, int initialPid, in String packageName, int userId, in String message); String getProviderMimeType(in Uri uri, int userId); @@ -291,19 +256,12 @@ interface IActivityManager { boolean dumpHeap(in String process, int userId, boolean managed, boolean mallocInfo, boolean runGc, in String path, in ParcelFileDescriptor fd, in RemoteCallback finishCallback); - int startActivities(in IApplicationThread caller, in String callingPackage, - in Intent[] intents, in String[] resolvedTypes, in IBinder resultTo, - in Bundle options, int userId); boolean isUserRunning(int userid, int flags); - oneway void activitySlept(in IBinder token); - int getFrontActivityScreenCompatMode(); - void setFrontActivityScreenCompatMode(int mode); int getPackageScreenCompatMode(in String packageName); void setPackageScreenCompatMode(in String packageName, int mode); boolean getPackageAskScreenCompat(in String packageName); void setPackageAskScreenCompat(in String packageName, boolean ask); boolean switchUser(int userid); - void setFocusedTask(int taskId); boolean removeTask(int taskId); void registerProcessObserver(in IProcessObserver observer); void unregisterProcessObserver(in IProcessObserver observer); @@ -319,9 +277,6 @@ interface IActivityManager { void getMyMemoryState(out ActivityManager.RunningAppProcessInfo outInfo); boolean killProcessesBelowForeground(in String reason); UserInfo getCurrentUser(); - boolean shouldUpRecreateTask(in IBinder token, in String destAffinity); - boolean navigateUpTo(in IBinder token, in Intent target, int resultCode, - in Intent resultData); /** * Informs ActivityManagerService that the keyguard is showing. * @@ -333,7 +288,6 @@ interface IActivityManager { */ void setLockScreenShown(boolean showingKeyguard, boolean showingAod, int secondaryDisplayShowing); - boolean finishActivityAffinity(in IBinder token); // This is not public because you need to be very careful in how you // manage your activity to make sure it is always the uid you expect. int getLaunchedFromUid(in IBinder activityToken); @@ -383,9 +337,6 @@ interface IActivityManager { long inputDispatchingTimedOut(int pid, boolean aboveSystem, in String reason); void clearPendingBackup(); Intent getIntentForIntentSender(in IIntentSender sender); - Bundle getAssistContextExtras(int requestType); - void reportAssistContextExtras(in IBinder token, in Bundle extras, - in AssistStructure structure, in AssistContent content, in Uri referrer); // This is not public because you need to be very careful in how you // manage your activity to make sure it is always the uid you expect. String getLaunchedFromPackage(in IBinder activityToken); @@ -393,6 +344,7 @@ interface IActivityManager { void setUserIsMonkey(boolean monkey); void hang(in IBinder who, boolean allowRestart); + List<ActivityManager.StackInfo> getAllStackInfos(); void moveTaskToStack(int taskId, int stackId, boolean toTop); /** * Resizes the input stack id to the given bounds. @@ -410,14 +362,8 @@ interface IActivityManager { */ void resizeStack(int stackId, in Rect bounds, boolean allowResizeInDockedMode, boolean preserveWindows, boolean animate, int animationDuration); - List<ActivityManager.StackInfo> getAllStackInfos(); void setFocusedStack(int stackId); ActivityManager.StackInfo getFocusedStackInfo(); - ActivityManager.StackInfo getStackInfo(int windowingMode, int activityType); - boolean convertFromTranslucent(in IBinder token); - boolean convertToTranslucent(in IBinder token, in Bundle options); - void notifyActivityDrawn(in IBinder token); - void reportActivityFullyDrawn(in IBinder token, boolean restoredFromBundle); void restart(); void performIdleMaintenance(); void takePersistableUriPermission(in Uri uri, int modeFlags, String toPackage, int userId); @@ -425,60 +371,26 @@ interface IActivityManager { ParceledListSlice getPersistedUriPermissions(in String packageName, boolean incoming); void appNotRespondingViaProvider(in IBinder connection); Rect getTaskBounds(int taskId); - int getActivityDisplayId(in IBinder activityToken); boolean setProcessMemoryTrimLevel(in String process, int uid, int level); // Start of L transactions String getTagForIntentSender(in IIntentSender sender, in String prefix); boolean startUserInBackground(int userid); - void startLockTaskModeByToken(in IBinder token); - void stopLockTaskModeByToken(in IBinder token); boolean isInLockTaskMode(); - void setTaskDescription(in IBinder token, in ActivityManager.TaskDescription values); - int startVoiceActivity(in String callingPackage, int callingPid, int callingUid, - in Intent intent, in String resolvedType, in IVoiceInteractionSession session, - in IVoiceInteractor interactor, int flags, in ProfilerInfo profilerInfo, - in Bundle options, int userId); - int startAssistantActivity(in String callingPackage, int callingPid, int callingUid, - in Intent intent, in String resolvedType, in Bundle options, int userId); void startRecentsActivity(in Intent intent, in IAssistDataReceiver assistDataReceiver, in IRecentsAnimationRunner recentsAnimationRunner); void cancelRecentsAnimation(boolean restoreHomeStackPosition); int startActivityFromRecents(int taskId, in Bundle options); - Bundle getActivityOptions(in IBinder token); - List<IBinder> getAppTasks(in String callingPackage); void startSystemLockTaskMode(int taskId); - void stopSystemLockTaskMode(); - void finishVoiceTask(in IVoiceInteractionSession session); boolean isTopOfTask(in IBinder token); - void notifyLaunchTaskBehindComplete(in IBinder token); - void notifyEnterAnimationComplete(in IBinder token); - int startActivityAsCaller(in IApplicationThread caller, in String callingPackage, - in Intent intent, in String resolvedType, in IBinder resultTo, in String resultWho, - int requestCode, int flags, in ProfilerInfo profilerInfo, in Bundle options, - boolean ignoreTargetSecurity, int userId); - int addAppTask(in IBinder activityToken, in Intent intent, - in ActivityManager.TaskDescription description, in Bitmap thumbnail); - Point getAppTaskThumbnailSize(); - boolean releaseActivityInstance(in IBinder token); - void releaseSomeActivities(in IApplicationThread app); void bootAnimationComplete(); - Bitmap getTaskDescriptionIcon(in String filename, int userId); - boolean launchAssistIntent(in Intent intent, int requestType, in String hint, int userHandle, - in Bundle args); - void startInPlaceAnimationOnFrontMostApplication(in Bundle opts); int checkPermissionWithToken(in String permission, int pid, int uid, in IBinder callerToken); void registerTaskStackListener(in ITaskStackListener listener); void unregisterTaskStackListener(in ITaskStackListener listener); - void notifyCleartextNetwork(int uid, in byte[] firstPacket); - int createStackOnDisplay(int displayId); void setTaskResizeable(int taskId, int resizeableMode); - boolean requestAssistContextExtras(int requestType, in IAssistDataReceiver receiver, - in Bundle receiverExtras, in IBinder activityToken, - boolean focused, boolean newSessionId); void resizeTask(int taskId, in Rect bounds, int resizeMode); int getLockTaskModeState(); void setDumpHeapDebugLimit(in String processName, int uid, long maxMemSize, @@ -489,19 +401,8 @@ interface IActivityManager { void noteAlarmStart(in IIntentSender sender, in WorkSource workSource, int sourceUid, in String tag); void noteAlarmFinish(in IIntentSender sender, in WorkSource workSource, int sourceUid, in String tag); int getPackageProcessState(in String packageName, in String callingPackage); - oneway void showLockTaskEscapeMessage(in IBinder token); void updateDeviceOwner(in String packageName); - /** - * Notify the system that the keyguard is going away. - * - * @param flags See {@link android.view.WindowManagerPolicyConstants#KEYGUARD_GOING_AWAY_FLAG_TO_SHADE} - * etc. - */ - void keyguardGoingAway(int flags); int getUidProcessState(int uid, in String callingPackage); - boolean isAssistDataAllowedOnCurrentActivity(); - boolean showAssistFromActivity(in IBinder token, in Bundle args); - boolean isRootVoiceInteraction(in IBinder token); // Start of N transactions @@ -516,35 +417,12 @@ interface IActivityManager { * different stack. */ void positionTaskInStack(int taskId, int stackId, int position); - void exitFreeformMode(in IBinder token); - void reportSizeConfigurations(in IBinder token, in int[] horizontalSizeConfiguration, - in int[] verticalSizeConfigurations, in int[] smallestWidthConfigurations); - /** - * Dismisses split-screen multi-window mode. - * {@param toTop} If true the current primary split-screen stack will be placed or left on top. - */ - void dismissSplitScreenMode(boolean toTop); - /** - * Dismisses PiP - * @param animate True if the dismissal should be animated. - * @param animationDuration The duration of the resize animation in milliseconds or -1 if the - * default animation duration should be used. - */ - void dismissPip(boolean animate, int animationDuration); void suppressResizeConfigChanges(boolean suppress); - void moveTasksToFullscreenStack(int fromStackId, boolean onTop); boolean moveTopActivityToPinnedStack(int stackId, in Rect bounds); boolean isAppStartModeDisabled(int uid, in String packageName); boolean unlockUser(int userid, in byte[] token, in byte[] secret, in IProgressListener listener); - boolean isInMultiWindowMode(in IBinder token); - boolean isInPictureInPictureMode(in IBinder token); void killPackageDependents(in String packageName, int userId); - boolean enterPictureInPictureMode(in IBinder token, in PictureInPictureParams params); - void setPictureInPictureParams(in IBinder token, in PictureInPictureParams params); - int getMaxNumPictureInPictureActions(in IBinder token); - void activityRelaunched(in IBinder token); - IBinder getUriPermissionOwnerForActivity(in IBinder activityToken); /** * Resizes the docked stack, and all other stacks as the result of the dock stack bounds change. * @@ -567,12 +445,6 @@ interface IActivityManager { void resizeDockedStack(in Rect dockedBounds, in Rect tempDockedTaskBounds, in Rect tempDockedTaskInsetBounds, in Rect tempOtherTaskBounds, in Rect tempOtherTaskInsetBounds); - /** - * Sets whether we are currently in an interactive split screen resize operation where we - * are changing the docked stack size. - */ - void setSplitScreenResizing(boolean resizing); - int setVrMode(in IBinder token, boolean enabled, in ComponentName packageName); // Gets the URI permissions granted to an arbitrary package (or all packages if null) // NOTE: this is different from getPersistedUriPermissions(), which returns the URIs the package // granted to another packages (instead of those granted to it). @@ -580,24 +452,9 @@ interface IActivityManager { // Clears the URI permissions granted to an arbitrary package. void clearGrantedUriPermissions(in String packageName, int userId); boolean isAppForeground(int uid); - void startLocalVoiceInteraction(in IBinder token, in Bundle options); - void stopLocalVoiceInteraction(in IBinder token); - boolean supportsLocalVoiceInteraction(); - void notifyPinnedStackAnimationStarted(); - void notifyPinnedStackAnimationEnded(); void removeStack(int stackId); void makePackageIdle(String packageName, int userId); int getMemoryTrimLevel(); - /** - * Resizes the pinned stack. - * - * @param pinnedBounds The bounds for the pinned stack. - * @param tempPinnedTaskBounds The temporary bounds for the tasks in the pinned stack, which - * might be different from the stack bounds to allow more - * flexibility while resizing, or {@code null} if they should be the - * same as the stack bounds. - */ - void resizePinnedStack(in Rect pinnedBounds, in Rect tempPinnedTaskBounds); boolean isVrModePackageEnabled(in ComponentName packageName); void notifyLockedProfile(int userId); void startConfirmDeviceCredentialIntent(in Intent intent, in Bundle options); @@ -621,25 +478,9 @@ interface IActivityManager { void setHasTopUi(boolean hasTopUi); // Start of O transactions - /** - * Updates override configuration applied to specific display. - * @param values Update values for display configuration. If null is passed it will request the - * Window Manager to compute new config for the specified display. - * @param displayId Id of the display to apply the config to. - * @throws RemoteException - * @return Returns true if the configuration was updated. - */ - boolean updateDisplayOverrideConfiguration(in Configuration values, int displayId); - void moveStackToDisplay(int stackId, int displayId); - boolean requestAutofillData(in IAssistDataReceiver receiver, in Bundle receiverExtras, - in IBinder activityToken, int flags); - void dismissKeyguard(in IBinder token, in IKeyguardDismissCallback callback, - in CharSequence message); int restartUserInBackground(int userId); - /** Cancels the window transitions for the given task. */ void cancelTaskWindowTransition(int taskId); - /** * @param taskId the id of the task to retrieve the sAutoapshots for * @param reducedResolution if set, if the snapshot needs to be loaded from disk, this will load @@ -647,56 +488,19 @@ interface IActivityManager { * @return a graphic buffer representing a screenshot of a task */ ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean reducedResolution); - void scheduleApplicationInfoChanged(in List<String> packageNames, int userId); void setPersistentVrThread(int tid); void waitForNetworkStateUpdate(long procStateSeq); - - /** - * See {@link android.app.Activity#setDisablePreviewScreenshots} - */ - void setDisablePreviewScreenshots(IBinder token, boolean disable); - - /** - * Return the user id of last resumed activity. - */ - int getLastResumedActivityUserId(); - /** * Add a bare uid to the background restrictions whitelist. Only the system uid may call this. */ void backgroundWhitelistUid(int uid); // Start of P transactions - void updateLockTaskFeatures(int userId, int flags); - - // WARNING: when these transactions are updated, check if they are any callers on the native - // side. If so, make sure they are using the correct transaction ids and arguments. - // If a transaction which will also be used on the native side is being inserted, add it - // alongside with other transactions of this kind at the top of this file. - - void setShowWhenLocked(in IBinder token, boolean showWhenLocked); - void setTurnScreenOn(in IBinder token, boolean turnScreenOn); - /** * Similar to {@link #startUserInBackground(int userId), but with a listener to report * user unlock progress. */ boolean startUserInBackgroundWithListener(int userid, IProgressListener unlockProgressListener); - - /** - * Registers remote animations for a specific activity. - */ - void registerRemoteAnimations(in IBinder token, in RemoteAnimationDefinition definition); - - /** - * Registers a remote animation to be run for all activity starts from a certain package during - * a short predefined amount of time. - */ - void registerRemoteAnimationForNextActivityStart(in String packageName, - in RemoteAnimationAdapter adapter); - - /** @see android.app.ActivityManager#alwaysShowUnsupportedCompileSdkWarning */ - void alwaysShowUnsupportedCompileSdkWarning(in ComponentName activity); } diff --git a/core/java/android/app/IActivityTaskManager.aidl b/core/java/android/app/IActivityTaskManager.aidl index 8dfd6ab75b10..d2c6402d64b3 100644 --- a/core/java/android/app/IActivityTaskManager.aidl +++ b/core/java/android/app/IActivityTaskManager.aidl @@ -82,9 +82,127 @@ import java.util.List; * {@hide} */ interface IActivityTaskManager { + int startActivity(in IApplicationThread caller, in String callingPackage, in Intent intent, + in String resolvedType, in IBinder resultTo, in String resultWho, int requestCode, + int flags, in ProfilerInfo profilerInfo, in Bundle options); + int startActivities(in IApplicationThread caller, in String callingPackage, + in Intent[] intents, in String[] resolvedTypes, in IBinder resultTo, + in Bundle options, int userId); + int startActivityAsUser(in IApplicationThread caller, in String callingPackage, + in Intent intent, in String resolvedType, in IBinder resultTo, in String resultWho, + int requestCode, int flags, in ProfilerInfo profilerInfo, + in Bundle options, int userId); + boolean startNextMatchingActivity(in IBinder callingActivity, + in Intent intent, in Bundle options); + int startActivityIntentSender(in IApplicationThread caller, + in IIntentSender target, in IBinder whitelistToken, in Intent fillInIntent, + in String resolvedType, in IBinder resultTo, in String resultWho, int requestCode, + int flagsMask, int flagsValues, in Bundle options); + WaitResult startActivityAndWait(in IApplicationThread caller, in String callingPackage, + in Intent intent, in String resolvedType, in IBinder resultTo, in String resultWho, + int requestCode, int flags, in ProfilerInfo profilerInfo, in Bundle options, + int userId); + int startActivityWithConfig(in IApplicationThread caller, in String callingPackage, + in Intent intent, in String resolvedType, in IBinder resultTo, in String resultWho, + int requestCode, int startFlags, in Configuration newConfig, + in Bundle options, int userId); + int startVoiceActivity(in String callingPackage, int callingPid, int callingUid, + in Intent intent, in String resolvedType, in IVoiceInteractionSession session, + in IVoiceInteractor interactor, int flags, in ProfilerInfo profilerInfo, + in Bundle options, int userId); + int startAssistantActivity(in String callingPackage, int callingPid, int callingUid, + in Intent intent, in String resolvedType, in Bundle options, int userId); + void startRecentsActivity(in Intent intent, in IAssistDataReceiver assistDataReceiver, + in IRecentsAnimationRunner recentsAnimationRunner); + int startActivityFromRecents(int taskId, in Bundle options); + int startActivityAsCaller(in IApplicationThread caller, in String callingPackage, + in Intent intent, in String resolvedType, in IBinder resultTo, in String resultWho, + int requestCode, int flags, in ProfilerInfo profilerInfo, in Bundle options, + boolean ignoreTargetSecurity, int userId); + + void unhandledBack(); + boolean finishActivity(in IBinder token, int code, in Intent data, int finishTask); + boolean finishActivityAffinity(in IBinder token); + + oneway void activityIdle(in IBinder token, in Configuration config, + in boolean stopProfiling); + void activityResumed(in IBinder token); + void activityPaused(in IBinder token); + oneway void activityStopped(in IBinder token, in Bundle state, + in PersistableBundle persistentState, in CharSequence description); + oneway void activityDestroyed(in IBinder token); + void activityRelaunched(in IBinder token); + oneway void activitySlept(in IBinder token); + int getFrontActivityScreenCompatMode(); + void setFrontActivityScreenCompatMode(int mode); + String getCallingPackage(in IBinder token); + ComponentName getCallingActivity(in IBinder token); + void setFocusedTask(int taskId); + boolean removeTask(int taskId); List<ActivityManager.RunningTaskInfo> getTasks(int maxNum); List<ActivityManager.RunningTaskInfo> getFilteredTasks(int maxNum, int ignoreActivityType, int ignoreWindowingMode); + boolean shouldUpRecreateTask(in IBinder token, in String destAffinity); + boolean navigateUpTo(in IBinder token, in Intent target, int resultCode, + in Intent resultData); + void moveTaskToFront(int task, int flags, in Bundle options); + int getTaskForActivity(in IBinder token, in boolean onlyRoot); + void finishSubActivity(in IBinder token, in String resultWho, int requestCode); + ParceledListSlice getRecentTasks(int maxNum, int flags, int userId); + boolean willActivityBeVisible(in IBinder token); + void setRequestedOrientation(in IBinder token, int requestedOrientation); + int getRequestedOrientation(in IBinder token); + boolean convertFromTranslucent(in IBinder token); + boolean convertToTranslucent(in IBinder token, in Bundle options); + void notifyActivityDrawn(in IBinder token); + void reportActivityFullyDrawn(in IBinder token, boolean restoredFromBundle); + int getActivityDisplayId(in IBinder activityToken); + boolean isImmersive(in IBinder token); + void setImmersive(in IBinder token, boolean immersive); + boolean isTopActivityImmersive(); + boolean moveActivityTaskToBack(in IBinder token, boolean nonRoot); + ActivityManager.TaskDescription getTaskDescription(int taskId); + void overridePendingTransition(in IBinder token, in String packageName, + int enterAnim, int exitAnim); + int getLaunchedFromUid(in IBinder activityToken); + String getLaunchedFromPackage(in IBinder activityToken); + void reportAssistContextExtras(in IBinder token, in Bundle extras, + in AssistStructure structure, in AssistContent content, in Uri referrer); + + void setFocusedStack(int stackId); + ActivityManager.StackInfo getFocusedStackInfo(); + Rect getTaskBounds(int taskId); + + void cancelRecentsAnimation(boolean restoreHomeStackPosition); + void startLockTaskModeByToken(in IBinder token); + void stopLockTaskModeByToken(in IBinder token); + boolean isInLockTaskMode(); + int getLockTaskModeState(); + void setTaskDescription(in IBinder token, in ActivityManager.TaskDescription values); + Bundle getActivityOptions(in IBinder token); + List<IBinder> getAppTasks(in String callingPackage); + void startSystemLockTaskMode(int taskId); + void stopSystemLockTaskMode(); + void finishVoiceTask(in IVoiceInteractionSession session); + boolean isTopOfTask(in IBinder token); + void notifyLaunchTaskBehindComplete(in IBinder token); + void notifyEnterAnimationComplete(in IBinder token); + int addAppTask(in IBinder activityToken, in Intent intent, + in ActivityManager.TaskDescription description, in Bitmap thumbnail); + Point getAppTaskThumbnailSize(); + boolean releaseActivityInstance(in IBinder token); + void releaseSomeActivities(in IApplicationThread app); + Bitmap getTaskDescriptionIcon(in String filename, int userId); + void startInPlaceAnimationOnFrontMostApplication(in Bundle opts); + void registerTaskStackListener(in ITaskStackListener listener); + void unregisterTaskStackListener(in ITaskStackListener listener); + int createStackOnDisplay(int displayId); + void setTaskResizeable(int taskId, int resizeableMode); + void exitFreeformMode(in IBinder token); + void resizeTask(int taskId, in Rect bounds, int resizeMode); + void moveStackToDisplay(int stackId, int displayId); + void removeStack(int stackId); + /** * Sets the windowing mode for a specific task. Only works on tasks of type * {@link WindowConfiguration#ACTIVITY_TYPE_STANDARD} @@ -121,4 +239,180 @@ interface IActivityTaskManager { void removeStacksInWindowingModes(in int[] windowingModes); /** Removes stack of the activity types from the system. */ void removeStacksWithActivityTypes(in int[] activityTypes); + + List<ActivityManager.StackInfo> getAllStackInfos(); + ActivityManager.StackInfo getStackInfo(int windowingMode, int activityType); + + /** + * Informs ActivityManagerService that the keyguard is showing. + * + * @param showingKeyguard True if the keyguard is showing, false otherwise. + * @param showingAod True if AOD is showing, false otherwise. + * @param secondaryDisplayShowing The displayId of the secondary display on which the keyguard + * is showing, or INVALID_DISPLAY if there is no such display. Only meaningful if + * showing is true. + */ + void setLockScreenShown(boolean showingKeyguard, boolean showingAod, + int secondaryDisplayShowing); + Bundle getAssistContextExtras(int requestType); + boolean launchAssistIntent(in Intent intent, int requestType, in String hint, int userHandle, + in Bundle args); + boolean requestAssistContextExtras(int requestType, in IAssistDataReceiver receiver, + in Bundle receiverExtras, in IBinder activityToken, + boolean focused, boolean newSessionId); + boolean requestAutofillData(in IAssistDataReceiver receiver, in Bundle receiverExtras, + in IBinder activityToken, int flags); + boolean isAssistDataAllowedOnCurrentActivity(); + boolean showAssistFromActivity(in IBinder token, in Bundle args); + boolean isRootVoiceInteraction(in IBinder token); + oneway void showLockTaskEscapeMessage(in IBinder token); + + /** + * Notify the system that the keyguard is going away. + * + * @param flags See + * {@link android.view.WindowManagerPolicyConstants#KEYGUARD_GOING_AWAY_FLAG_TO_SHADE} + * etc. + */ + void keyguardGoingAway(int flags); + ComponentName getActivityClassForToken(in IBinder token); + String getPackageForToken(in IBinder token); + + /** + * Try to place task to provided position. The final position might be different depending on + * current user and stacks state. The task will be moved to target stack if it's currently in + * different stack. + */ + void positionTaskInStack(int taskId, int stackId, int position); + void reportSizeConfigurations(in IBinder token, in int[] horizontalSizeConfiguration, + in int[] verticalSizeConfigurations, in int[] smallestWidthConfigurations); + /** + * Dismisses split-screen multi-window mode. + * {@param toTop} If true the current primary split-screen stack will be placed or left on top. + */ + void dismissSplitScreenMode(boolean toTop); + + /** + * Dismisses PiP + * @param animate True if the dismissal should be animated. + * @param animationDuration The duration of the resize animation in milliseconds or -1 if the + * default animation duration should be used. + */ + void dismissPip(boolean animate, int animationDuration); + void suppressResizeConfigChanges(boolean suppress); + void moveTasksToFullscreenStack(int fromStackId, boolean onTop); + boolean moveTopActivityToPinnedStack(int stackId, in Rect bounds); + boolean isInMultiWindowMode(in IBinder token); + boolean isInPictureInPictureMode(in IBinder token); + boolean enterPictureInPictureMode(in IBinder token, in PictureInPictureParams params); + void setPictureInPictureParams(in IBinder token, in PictureInPictureParams params); + int getMaxNumPictureInPictureActions(in IBinder token); + IBinder getUriPermissionOwnerForActivity(in IBinder activityToken); + + /** + * Resizes the docked stack, and all other stacks as the result of the dock stack bounds change. + * + * @param dockedBounds The bounds for the docked stack. + * @param tempDockedTaskBounds The temporary bounds for the tasks in the docked stack, which + * might be different from the stack bounds to allow more + * flexibility while resizing, or {@code null} if they should be the + * same as the stack bounds. + * @param tempDockedTaskInsetBounds The temporary bounds for the tasks to calculate the insets. + * When resizing, we usually "freeze" the layout of a task. To + * achieve that, we also need to "freeze" the insets, which + * gets achieved by changing task bounds but not bounds used + * to calculate the insets in this transient state + * @param tempOtherTaskBounds The temporary bounds for the tasks in all other stacks, or + * {@code null} if they should be the same as the stack bounds. + * @param tempOtherTaskInsetBounds Like {@code tempDockedTaskInsetBounds}, but for the other + * stacks. + * @throws RemoteException + */ + void resizeDockedStack(in Rect dockedBounds, in Rect tempDockedTaskBounds, + in Rect tempDockedTaskInsetBounds, + in Rect tempOtherTaskBounds, in Rect tempOtherTaskInsetBounds); + + /** + * Sets whether we are currently in an interactive split screen resize operation where we + * are changing the docked stack size. + */ + void setSplitScreenResizing(boolean resizing); + int setVrMode(in IBinder token, boolean enabled, in ComponentName packageName); + void startLocalVoiceInteraction(in IBinder token, in Bundle options); + void stopLocalVoiceInteraction(in IBinder token); + boolean supportsLocalVoiceInteraction(); + void notifyPinnedStackAnimationStarted(); + void notifyPinnedStackAnimationEnded(); + + /** + * Resizes the pinned stack. + * + * @param pinnedBounds The bounds for the pinned stack. + * @param tempPinnedTaskBounds The temporary bounds for the tasks in the pinned stack, which + * might be different from the stack bounds to allow more + * flexibility while resizing, or {@code null} if they should be the + * same as the stack bounds. + */ + void resizePinnedStack(in Rect pinnedBounds, in Rect tempPinnedTaskBounds); + + /** + * Updates override configuration applied to specific display. + * @param values Update values for display configuration. If null is passed it will request the + * Window Manager to compute new config for the specified display. + * @param displayId Id of the display to apply the config to. + * @throws RemoteException + * @return Returns true if the configuration was updated. + */ + boolean updateDisplayOverrideConfiguration(in Configuration values, int displayId); + void dismissKeyguard(in IBinder token, in IKeyguardDismissCallback callback, + in CharSequence message); + + /** Cancels the window transitions for the given task. */ + void cancelTaskWindowTransition(int taskId); + + /** + * @param taskId the id of the task to retrieve the sAutoapshots for + * @param reducedResolution if set, if the snapshot needs to be loaded from disk, this will load + * a reduced resolution of it, which is much faster + * @return a graphic buffer representing a screenshot of a task + */ + ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean reducedResolution); + + /** + * See {@link android.app.Activity#setDisablePreviewScreenshots} + */ + void setDisablePreviewScreenshots(IBinder token, boolean disable); + + /** + * Return the user id of last resumed activity. + */ + int getLastResumedActivityUserId(); + + /** + * Updates global configuration and applies changes to the entire system. + * @param values Update values for global configuration. If null is passed it will request the + * Window Manager to compute new config for the default display. + * @throws RemoteException + * @return Returns true if the configuration was updated. + */ + boolean updateConfiguration(in Configuration values); + void updateLockTaskFeatures(int userId, int flags); + + void setShowWhenLocked(in IBinder token, boolean showWhenLocked); + void setTurnScreenOn(in IBinder token, boolean turnScreenOn); + + /** + * Registers remote animations for a specific activity. + */ + void registerRemoteAnimations(in IBinder token, in RemoteAnimationDefinition definition); + + /** + * Registers a remote animation to be run for all activity starts from a certain package during + * a short predefined amount of time. + */ + void registerRemoteAnimationForNextActivityStart(in String packageName, + in RemoteAnimationAdapter adapter); + + /** @see android.app.ActivityManager#alwaysShowUnsupportedCompileSdkWarning */ + void alwaysShowUnsupportedCompileSdkWarning(in ComponentName activity); } diff --git a/core/java/android/app/Instrumentation.java b/core/java/android/app/Instrumentation.java index c7618fe62c87..34be41b63233 100644 --- a/core/java/android/app/Instrumentation.java +++ b/core/java/android/app/Instrumentation.java @@ -1665,7 +1665,7 @@ public class Instrumentation { try { intent.migrateExtraStreamToClipData(); intent.prepareToLeaveProcess(who); - int result = ActivityManager.getService() + int result = ActivityTaskManager.getService() .startActivity(whoThread, who.getBasePackageName(), intent, intent.resolveTypeIfNeeded(who.getContentResolver()), token, target != null ? target.mEmbeddedID : null, @@ -1736,7 +1736,7 @@ public class Instrumentation { intents[i].prepareToLeaveProcess(who); resolvedTypes[i] = intents[i].resolveTypeIfNeeded(who.getContentResolver()); } - int result = ActivityManager.getService() + int result = ActivityTaskManager.getService() .startActivities(whoThread, who.getBasePackageName(), intents, resolvedTypes, token, options, userId); checkStartActivityResult(result, intents[0]); @@ -1803,7 +1803,7 @@ public class Instrumentation { try { intent.migrateExtraStreamToClipData(); intent.prepareToLeaveProcess(who); - int result = ActivityManager.getService() + int result = ActivityTaskManager.getService() .startActivity(whoThread, who.getBasePackageName(), intent, intent.resolveTypeIfNeeded(who.getContentResolver()), token, target, requestCode, 0, null, options); @@ -1870,7 +1870,7 @@ public class Instrumentation { try { intent.migrateExtraStreamToClipData(); intent.prepareToLeaveProcess(who); - int result = ActivityManager.getService() + int result = ActivityTaskManager.getService() .startActivityAsUser(whoThread, who.getBasePackageName(), intent, intent.resolveTypeIfNeeded(who.getContentResolver()), token, resultWho, @@ -1916,7 +1916,7 @@ public class Instrumentation { try { intent.migrateExtraStreamToClipData(); intent.prepareToLeaveProcess(who); - int result = ActivityManager.getService() + int result = ActivityTaskManager.getService() .startActivityAsCaller(whoThread, who.getBasePackageName(), intent, intent.resolveTypeIfNeeded(who.getContentResolver()), token, target != null ? target.mEmbeddedID : null, diff --git a/core/java/android/app/KeyguardManager.java b/core/java/android/app/KeyguardManager.java index b512e5ce8417..9ceecd96363f 100644 --- a/core/java/android/app/KeyguardManager.java +++ b/core/java/android/app/KeyguardManager.java @@ -513,7 +513,8 @@ public class KeyguardManager { public void requestDismissKeyguard(@NonNull Activity activity, @Nullable CharSequence message, @Nullable KeyguardDismissCallback callback) { try { - mAm.dismissKeyguard(activity.getActivityToken(), new IKeyguardDismissCallback.Stub() { + ActivityTaskManager.getService().dismissKeyguard( + activity.getActivityToken(), new IKeyguardDismissCallback.Stub() { @Override public void onDismissError() throws RemoteException { if (callback != null && !activity.isDestroyed()) { diff --git a/core/java/android/app/SearchManager.java b/core/java/android/app/SearchManager.java index 49faf4029157..ed6d2f57ba48 100644 --- a/core/java/android/app/SearchManager.java +++ b/core/java/android/app/SearchManager.java @@ -951,7 +951,7 @@ public class SearchManager try { Intent intent = new Intent(Intent.ACTION_ASSIST); if (inclContext) { - IActivityManager am = ActivityManager.getService(); + IActivityTaskManager am = ActivityTaskManager.getService(); Bundle extras = am.getAssistContextExtras(ActivityManager.ASSIST_CONTEXT_BASIC); if (extras != null) { intent.replaceExtras(extras); diff --git a/core/java/android/app/servertransaction/PauseActivityItem.java b/core/java/android/app/servertransaction/PauseActivityItem.java index 0c1eab56ec30..cae93b305a1a 100644 --- a/core/java/android/app/servertransaction/PauseActivityItem.java +++ b/core/java/android/app/servertransaction/PauseActivityItem.java @@ -19,6 +19,7 @@ package android.app.servertransaction; import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER; import android.app.ActivityManager; +import android.app.ActivityTaskManager; import android.app.ClientTransactionHandler; import android.os.IBinder; import android.os.Parcel; @@ -60,7 +61,7 @@ public class PauseActivityItem extends ActivityLifecycleItem { } try { // TODO(lifecycler): Use interface callback instead of AMS. - ActivityManager.getService().activityPaused(token); + ActivityTaskManager.getService().activityPaused(token); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } diff --git a/core/java/android/app/servertransaction/PendingTransactionActions.java b/core/java/android/app/servertransaction/PendingTransactionActions.java index af7b7a21a582..52ba8fb73f5f 100644 --- a/core/java/android/app/servertransaction/PendingTransactionActions.java +++ b/core/java/android/app/servertransaction/PendingTransactionActions.java @@ -19,6 +19,7 @@ package android.app.servertransaction; import static android.app.ActivityThread.DEBUG_MEMORY_TRIM; import android.app.ActivityManager; +import android.app.ActivityTaskManager; import android.app.ActivityThread.ActivityClientRecord; import android.os.Build; import android.os.Bundle; @@ -141,7 +142,7 @@ public class PendingTransactionActions { try { if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Reporting activity stopped: " + mActivity); // TODO(lifecycler): Use interface callback instead of AMS. - ActivityManager.getService().activityStopped( + ActivityTaskManager.getService().activityStopped( mActivity.token, mState, mPersistentState, mDescription); } catch (RemoteException ex) { // Dump statistics about bundle to help developers debug diff --git a/core/java/android/app/servertransaction/ResumeActivityItem.java b/core/java/android/app/servertransaction/ResumeActivityItem.java index 909eec751d65..a5b6f7c74e18 100644 --- a/core/java/android/app/servertransaction/ResumeActivityItem.java +++ b/core/java/android/app/servertransaction/ResumeActivityItem.java @@ -19,6 +19,7 @@ package android.app.servertransaction; import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER; import android.app.ActivityManager; +import android.app.ActivityTaskManager; import android.app.ClientTransactionHandler; import android.os.IBinder; import android.os.Parcel; @@ -58,7 +59,7 @@ public class ResumeActivityItem extends ActivityLifecycleItem { PendingTransactionActions pendingActions) { try { // TODO(lifecycler): Use interface callback instead of AMS. - ActivityManager.getService().activityResumed(token); + ActivityTaskManager.getService().activityResumed(token); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } diff --git a/core/java/com/android/internal/app/HeavyWeightSwitcherActivity.java b/core/java/com/android/internal/app/HeavyWeightSwitcherActivity.java index 4f41875d0deb..7735d84ab751 100644 --- a/core/java/com/android/internal/app/HeavyWeightSwitcherActivity.java +++ b/core/java/com/android/internal/app/HeavyWeightSwitcherActivity.java @@ -20,6 +20,7 @@ import com.android.internal.R; import android.app.Activity; import android.app.ActivityManager; +import android.app.ActivityTaskManager; import android.content.Intent; import android.content.IntentSender; import android.content.pm.ApplicationInfo; @@ -126,7 +127,7 @@ public class HeavyWeightSwitcherActivity extends Activity { private OnClickListener mSwitchOldListener = new OnClickListener() { public void onClick(View v) { try { - ActivityManager.getService().moveTaskToFront(mCurTask, 0, null); + ActivityTaskManager.getService().moveTaskToFront(mCurTask, 0, null); } catch (RemoteException e) { } finish(); diff --git a/core/java/com/android/internal/app/IntentForwarderActivity.java b/core/java/com/android/internal/app/IntentForwarderActivity.java index 398d08791b5c..abb9321a50a8 100644 --- a/core/java/com/android/internal/app/IntentForwarderActivity.java +++ b/core/java/com/android/internal/app/IntentForwarderActivity.java @@ -18,6 +18,7 @@ package com.android.internal.app; import android.app.Activity; import android.app.ActivityManager; +import android.app.ActivityTaskManager; import android.app.ActivityThread; import android.app.AppGlobals; import android.app.admin.DevicePolicyManager; @@ -112,9 +113,9 @@ public class IntentForwarderActivity extends Activity { int launchedFromUid = -1; String launchedFromPackage = "?"; try { - launchedFromUid = ActivityManager.getService().getLaunchedFromUid( + launchedFromUid = ActivityTaskManager.getService().getLaunchedFromUid( getActivityToken()); - launchedFromPackage = ActivityManager.getService().getLaunchedFromPackage( + launchedFromPackage = ActivityTaskManager.getService().getLaunchedFromPackage( getActivityToken()); } catch (RemoteException ignored) { } diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java index ceb06f511108..0a812c68854f 100644 --- a/core/java/com/android/internal/app/ResolverActivity.java +++ b/core/java/com/android/internal/app/ResolverActivity.java @@ -21,6 +21,7 @@ import android.annotation.StringRes; import android.annotation.UiThread; import android.app.Activity; import android.app.ActivityManager; +import android.app.ActivityTaskManager; import android.app.ActivityThread; import android.app.VoiceInteractor.PickOptionRequest; import android.app.VoiceInteractor.PickOptionRequest.Option; @@ -260,7 +261,7 @@ public class ResolverActivity extends Activity { setProfileSwitchMessageId(intent.getContentUserHint()); try { - mLaunchedFromUid = ActivityManager.getService().getLaunchedFromUid( + mLaunchedFromUid = ActivityTaskManager.getService().getLaunchedFromUid( getActivityToken()); } catch (RemoteException e) { mLaunchedFromUid = -1; @@ -846,7 +847,7 @@ public class ResolverActivity extends Activity { } catch (RuntimeException e) { String launchedFromPackage; try { - launchedFromPackage = ActivityManager.getService().getLaunchedFromPackage( + launchedFromPackage = ActivityTaskManager.getService().getLaunchedFromPackage( getActivityToken()); } catch (RemoteException e2) { launchedFromPackage = "??"; diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityManagerWrapper.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityManagerWrapper.java index 63a4cd497bc1..dce72b440f58 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityManagerWrapper.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityManagerWrapper.java @@ -30,6 +30,7 @@ import android.annotation.NonNull; import android.app.ActivityManager; import android.app.ActivityManager.RecentTaskInfo; import android.app.ActivityOptions; +import android.app.ActivityTaskManager; import android.app.AppGlobals; import android.app.IAssistDataReceiver; import android.app.WindowConfiguration.ActivityType; @@ -113,7 +114,7 @@ public class ActivityManagerWrapper { // Note: The set of running tasks from the system is ordered by recency try { List<ActivityManager.RunningTaskInfo> tasks = - ActivityManager.getService().getFilteredTasks(1, ignoreActivityType, + ActivityTaskManager.getService().getFilteredTasks(1, ignoreActivityType, WINDOWING_MODE_PINNED /* ignoreWindowingMode */); if (tasks.isEmpty()) { return null; @@ -129,7 +130,7 @@ public class ActivityManagerWrapper { */ public List<RecentTaskInfo> getRecentTasks(int numTasks, int userId) { try { - return ActivityManager.getService().getRecentTasks(numTasks, + return ActivityTaskManager.getService().getRecentTasks(numTasks, RECENT_IGNORE_UNAVAILABLE, userId).getList(); } catch (RemoteException e) { Log.e(TAG, "Failed to get recent tasks", e); @@ -143,7 +144,7 @@ public class ActivityManagerWrapper { public @NonNull ThumbnailData getTaskThumbnail(int taskId, boolean reducedResolution) { ActivityManager.TaskSnapshot snapshot = null; try { - snapshot = ActivityManager.getService().getTaskSnapshot(taskId, reducedResolution); + snapshot = ActivityTaskManager.getService().getTaskSnapshot(taskId, reducedResolution); } catch (RemoteException e) { Log.w(TAG, "Failed to retrieve task snapshot", e); } @@ -234,7 +235,7 @@ public class ActivityManagerWrapper { } }; } - ActivityManager.getService().startRecentsActivity(intent, receiver, runner); + ActivityTaskManager.getService().startRecentsActivity(intent, receiver, runner); if (resultCallback != null) { resultCallbackHandler.post(new Runnable() { @Override @@ -260,7 +261,7 @@ public class ActivityManagerWrapper { */ public void cancelRecentsAnimation(boolean restoreHomeStackPosition) { try { - ActivityManager.getService().cancelRecentsAnimation(restoreHomeStackPosition); + ActivityTaskManager.getService().cancelRecentsAnimation(restoreHomeStackPosition); } catch (RemoteException e) { Log.e(TAG, "Failed to cancel recents animation", e); } @@ -333,7 +334,7 @@ public class ActivityManagerWrapper { public boolean startActivityFromRecents(int taskId, ActivityOptions options) { try { Bundle optsBundle = options == null ? null : options.toBundle(); - ActivityManager.getService().startActivityFromRecents(taskId, optsBundle); + ActivityTaskManager.getService().startActivityFromRecents(taskId, optsBundle); return true; } catch (Exception e) { return false; @@ -384,7 +385,7 @@ public class ActivityManagerWrapper { @Override public void run() { try { - ActivityManager.getService().removeTask(taskId); + ActivityTaskManager.getService().removeTask(taskId); } catch (RemoteException e) { Log.w(TAG, "Failed to remove task=" + taskId, e); } @@ -397,7 +398,7 @@ public class ActivityManagerWrapper { */ public void cancelWindowTransition(int taskId) { try { - ActivityManager.getService().cancelTaskWindowTransition(taskId); + ActivityTaskManager.getService().cancelTaskWindowTransition(taskId); } catch (RemoteException e) { Log.w(TAG, "Failed to cancel window transition for task=" + taskId, e); } @@ -408,7 +409,7 @@ public class ActivityManagerWrapper { */ public boolean isScreenPinningActive() { try { - return ActivityManager.getService().getLockTaskModeState() == LOCK_TASK_MODE_PINNED; + return ActivityTaskManager.getService().getLockTaskModeState() == LOCK_TASK_MODE_PINNED; } catch (RemoteException e) { return false; } @@ -427,7 +428,7 @@ public class ActivityManagerWrapper { */ public boolean isLockToAppActive() { try { - return ActivityManager.getService().getLockTaskModeState() != LOCK_TASK_MODE_NONE; + return ActivityTaskManager.getService().getLockTaskModeState() != LOCK_TASK_MODE_NONE; } catch (RemoteException e) { return false; } diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/TaskStackChangeListeners.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/TaskStackChangeListeners.java index 5e293c61c35a..628b3c6e21dc 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/TaskStackChangeListeners.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/TaskStackChangeListeners.java @@ -16,6 +16,7 @@ package com.android.systemui.shared.system; +import android.app.ActivityTaskManager; import android.app.ActivityManager.TaskSnapshot; import android.app.IActivityManager; import android.app.TaskStackListener; @@ -57,7 +58,7 @@ public class TaskStackChangeListeners extends TaskStackListener { if (!mRegistered) { // Register mTaskStackListener to IActivityManager only once if needed. try { - am.registerTaskStackListener(this); + ActivityTaskManager.getService().registerTaskStackListener(this); mRegistered = true; } catch (Exception e) { Log.w(TAG, "Failed to call registerTaskStackListener", e); diff --git a/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java b/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java index 943558943821..5605b7a4babe 100644 --- a/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java +++ b/packages/SystemUI/src/com/android/keyguard/EmergencyButton.java @@ -18,6 +18,7 @@ package com.android.keyguard; import android.app.ActivityManager; import android.app.ActivityOptions; +import android.app.ActivityTaskManager; import android.content.Context; import android.content.Intent; import android.content.res.Configuration; @@ -171,7 +172,7 @@ public class EmergencyButton extends Button { // should be the equivalent to the old userActivity(EMERGENCY_CALL_TIMEOUT) mPowerManager.userActivity(SystemClock.uptimeMillis(), true); try { - ActivityManager.getService().stopSystemLockTaskMode(); + ActivityTaskManager.getService().stopSystemLockTaskMode(); } catch (RemoteException e) { Slog.w(LOG_TAG, "Failed to stop app pinning"); } diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java index 62cd13b7dc17..d9a1b111345a 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java @@ -32,6 +32,7 @@ import static android.os.BatteryManager.EXTRA_STATUS; import android.annotation.AnyThread; import android.annotation.MainThread; import android.app.ActivityManager; +import android.app.ActivityTaskManager; import android.app.AlarmManager; import android.app.Instrumentation; import android.app.PendingIntent; @@ -1843,7 +1844,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { @Override public void onTaskStackChangedBackground() { try { - ActivityManager.StackInfo info = ActivityManager.getService().getStackInfo( + ActivityManager.StackInfo info = ActivityTaskManager.getService().getStackInfo( WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_ASSISTANT); if (info == null) { return; diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java index 5e94dd7a564c..cf6f16a0e154 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java @@ -26,6 +26,7 @@ import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STR import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_TIMEOUT; import android.app.ActivityManager; +import android.app.ActivityTaskManager; import android.app.AlarmManager; import android.app.PendingIntent; import android.app.StatusBarManager; @@ -1750,7 +1751,7 @@ public class KeyguardViewMediator extends SystemUI { int secondaryDisplayShowing) { mUiOffloadThread.submit(() -> { try { - ActivityManager.getService().setLockScreenShown(showing, aodShowing, + ActivityTaskManager.getService().setLockScreenShown(showing, aodShowing, secondaryDisplayShowing); } catch (RemoteException e) { } @@ -1813,7 +1814,7 @@ public class KeyguardViewMediator extends SystemUI { // Don't actually hide the Keyguard at the moment, wait for window // manager until it tells us it's safe to do so with // startKeyguardExitAnimation. - ActivityManager.getService().keyguardGoingAway(flags); + ActivityTaskManager.getService().keyguardGoingAway(flags); } catch (RemoteException e) { Log.e(TAG, "Error while calling WindowManager", e); } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/WorkLockActivityController.java b/packages/SystemUI/src/com/android/systemui/keyguard/WorkLockActivityController.java index b9e9e0a7f529..0cedf9825990 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/WorkLockActivityController.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/WorkLockActivityController.java @@ -18,7 +18,9 @@ package com.android.systemui.keyguard; import android.app.ActivityManager; import android.app.ActivityOptions; +import android.app.ActivityTaskManager; import android.app.IActivityManager; +import android.app.IActivityTaskManager; import android.app.KeyguardManager; import android.content.ComponentName; import android.content.Context; @@ -37,16 +39,17 @@ public class WorkLockActivityController { private static final String TAG = WorkLockActivityController.class.getSimpleName(); private final Context mContext; - private final IActivityManager mIam; + private final IActivityTaskManager mIatm; public WorkLockActivityController(Context context) { - this(context, ActivityManagerWrapper.getInstance(), ActivityManager.getService()); + this(context, ActivityManagerWrapper.getInstance(), ActivityTaskManager.getService()); } @VisibleForTesting - WorkLockActivityController(Context context, ActivityManagerWrapper am, IActivityManager iAm) { + WorkLockActivityController( + Context context, ActivityManagerWrapper am, IActivityTaskManager iAtm) { mContext = context; - mIam = iAm; + mIatm = iAtm; am.registerTaskStackListener(mLockListener); } @@ -54,7 +57,7 @@ public class WorkLockActivityController { private void startWorkChallengeInTask(int taskId, int userId) { ActivityManager.TaskDescription taskDescription = null; try { - taskDescription = mIam.getTaskDescription(taskId); + taskDescription = mIatm.getTaskDescription(taskId); } catch (RemoteException e) { Log.w(TAG, "Failed to get description for task=" + taskId); } @@ -76,7 +79,7 @@ public class WorkLockActivityController { // Starting the activity inside the task failed. We can't be sure why, so to be // safe just remove the whole task if it still exists. try { - mIam.removeTask(taskId); + mIatm.removeTask(taskId); } catch (RemoteException e) { Log.w(TAG, "Failed to get description for task=" + taskId); } @@ -89,7 +92,7 @@ public class WorkLockActivityController { */ private int startActivityAsUser(Intent intent, Bundle options, int userId) { try { - return mIam.startActivityAsUser( + return mIatm.startActivityAsUser( mContext.getIApplicationThread() /*caller*/, mContext.getBasePackageName() /*callingPackage*/, intent /*intent*/, diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivityController.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivityController.java index 26fced307bac..360fe73be95a 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivityController.java +++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivityController.java @@ -19,6 +19,7 @@ package com.android.systemui.pip.phone; import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; +import android.app.ActivityTaskManager; import android.app.ActivityManager.StackInfo; import android.app.ActivityOptions; import android.app.IActivityManager; @@ -384,7 +385,7 @@ public class PipMenuActivityController { private void startMenuActivity(int menuState, Rect stackBounds, Rect movementBounds, boolean allowMenuTimeout, boolean willResizeMenu) { try { - StackInfo pinnedStackInfo = mActivityManager.getStackInfo( + StackInfo pinnedStackInfo = ActivityTaskManager.getService().getStackInfo( WINDOWING_MODE_PINNED, ACTIVITY_TYPE_UNDEFINED); if (pinnedStackInfo != null && pinnedStackInfo.taskIds != null && pinnedStackInfo.taskIds.length > 0) { @@ -423,7 +424,7 @@ public class PipMenuActivityController { // Fetch the pinned stack bounds Rect stackBounds = null; try { - StackInfo pinnedStackInfo = mActivityManager.getStackInfo( + StackInfo pinnedStackInfo = ActivityTaskManager.getService().getStackInfo( WINDOWING_MODE_PINNED, ACTIVITY_TYPE_UNDEFINED); if (pinnedStackInfo != null) { stackBounds = pinnedStackInfo.bounds; diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java index 2ec566247d52..f0ab046f7dbe 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java +++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java @@ -30,6 +30,7 @@ import android.animation.RectEvaluator; import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.app.ActivityManager.StackInfo; +import android.app.ActivityTaskManager; import android.app.IActivityManager; import android.app.IActivityTaskManager; import android.content.Context; @@ -124,8 +125,8 @@ public class PipMotionHelper implements Handler.Callback { void synchronizePinnedStackBounds() { cancelAnimations(); try { - StackInfo stackInfo = - mActivityManager.getStackInfo(WINDOWING_MODE_PINNED, ACTIVITY_TYPE_UNDEFINED); + StackInfo stackInfo = mActivityTaskManager.getStackInfo( + WINDOWING_MODE_PINNED, ACTIVITY_TYPE_UNDEFINED); if (stackInfo != null) { mBounds.set(stackInfo.bounds); } @@ -162,7 +163,7 @@ public class PipMotionHelper implements Handler.Callback { mMenuController.hideMenuWithoutResize(); mHandler.post(() -> { try { - mActivityManager.dismissPip(!skipAnimation, EXPAND_STACK_TO_FULLSCREEN_DURATION); + mActivityTaskManager.dismissPip(!skipAnimation, EXPAND_STACK_TO_FULLSCREEN_DURATION); } catch (RemoteException e) { Log.e(TAG, "Error expanding PiP activity", e); } @@ -516,7 +517,8 @@ public class PipMotionHelper implements Handler.Callback { SomeArgs args = (SomeArgs) msg.obj; Rect toBounds = (Rect) args.arg1; try { - mActivityManager.resizePinnedStack(toBounds, null /* tempPinnedTaskBounds */); + mActivityTaskManager.resizePinnedStack( + toBounds, null /* tempPinnedTaskBounds */); mBounds.set(toBounds); } catch (RemoteException e) { Log.e(TAG, "Could not resize pinned stack to bounds: " + toBounds, e); @@ -529,7 +531,7 @@ public class PipMotionHelper implements Handler.Callback { Rect toBounds = (Rect) args.arg1; int duration = args.argi1; try { - StackInfo stackInfo = mActivityManager.getStackInfo( + StackInfo stackInfo = mActivityTaskManager.getStackInfo( WINDOWING_MODE_PINNED, ACTIVITY_TYPE_UNDEFINED); if (stackInfo == null) { // In the case where we've already re-expanded or dismissed the PiP, then diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipUtils.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipUtils.java index 2f53de96db2d..1ed1904d30fb 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipUtils.java +++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipUtils.java @@ -20,6 +20,7 @@ import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; import android.app.ActivityManager.StackInfo; +import android.app.ActivityTaskManager; import android.app.IActivityManager; import android.content.ComponentName; import android.content.Context; @@ -39,8 +40,8 @@ public class PipUtils { IActivityManager activityManager) { try { final String sysUiPackageName = context.getPackageName(); - final StackInfo pinnedStackInfo = - activityManager.getStackInfo(WINDOWING_MODE_PINNED, ACTIVITY_TYPE_UNDEFINED); + final StackInfo pinnedStackInfo = ActivityTaskManager.getService().getStackInfo( + WINDOWING_MODE_PINNED, ACTIVITY_TYPE_UNDEFINED); if (pinnedStackInfo != null && pinnedStackInfo.taskIds != null && pinnedStackInfo.taskIds.length > 0) { for (int i = pinnedStackInfo.taskNames.length - 1; i >= 0; i--) { diff --git a/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java b/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java index 1dcdc5fe8275..d9f923f2b4e3 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java +++ b/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java @@ -347,7 +347,7 @@ public class PipManager implements BasePipManager { mMediaSessionManager.removeOnActiveSessionsChangedListener(mActiveMediaSessionListener); if (removePipStack) { try { - mActivityManager.removeStack(mPinnedStackId); + mActivityTaskManager.removeStack(mPinnedStackId); } catch (RemoteException e) { Log.e(TAG, "removeStack failed", e); } finally { @@ -515,7 +515,7 @@ public class PipManager implements BasePipManager { private StackInfo getPinnedStackInfo() { StackInfo stackInfo = null; try { - stackInfo = mActivityManager.getStackInfo( + stackInfo = ActivityTaskManager.getService().getStackInfo( WINDOWING_MODE_PINNED, ACTIVITY_TYPE_UNDEFINED); } catch (RemoteException e) { Log.e(TAG, "getStackInfo failed", e); @@ -608,7 +608,7 @@ public class PipManager implements BasePipManager { private boolean isSettingsShown() { List<RunningTaskInfo> runningTasks; try { - runningTasks = mActivityManager.getTasks(1); + runningTasks = mActivityTaskManager.getTasks(1); if (runningTasks.isEmpty()) { return false; } diff --git a/packages/SystemUI/src/com/android/systemui/recents/ScreenPinningRequest.java b/packages/SystemUI/src/com/android/systemui/recents/ScreenPinningRequest.java index 481d54f3bbb6..91512dd53f96 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/ScreenPinningRequest.java +++ b/packages/SystemUI/src/com/android/systemui/recents/ScreenPinningRequest.java @@ -19,6 +19,7 @@ package com.android.systemui.recents; import android.animation.ArgbEvaluator; import android.animation.ValueAnimator; import android.app.ActivityManager; +import android.app.ActivityTaskManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -124,7 +125,7 @@ public class ScreenPinningRequest implements View.OnClickListener { public void onClick(View v) { if (v.getId() == R.id.screen_pinning_ok_button || mRequestWindow == v) { try { - ActivityManager.getService().startSystemLockTaskMode(taskId); + ActivityTaskManager.getService().startSystemLockTaskMode(taskId); } catch (RemoteException e) {} } clearPrompt(); diff --git a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java index 7321507cefc9..350fe7848d9d 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java +++ b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java @@ -207,7 +207,7 @@ public class SystemServicesProxy { if (mIam == null) return false; try { - List<StackInfo> stackInfos = mIam.getAllStackInfos(); + List<StackInfo> stackInfos = mIatm.getAllStackInfos(); ActivityManager.StackInfo homeStackInfo = null; ActivityManager.StackInfo fullscreenStackInfo = null; ActivityManager.StackInfo recentsStackInfo = null; @@ -280,7 +280,7 @@ public class SystemServicesProxy { public ActivityManager.StackInfo getSplitScreenPrimaryStack() { try { - return mIam.getStackInfo(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_UNDEFINED); + return mIatm.getStackInfo(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_UNDEFINED); } catch (RemoteException e) { return null; } @@ -376,7 +376,7 @@ public class SystemServicesProxy { if (mIam == null) return false; try { - return mIam.getLockTaskModeState() == ActivityManager.LOCK_TASK_MODE_PINNED; + return mIatm.getLockTaskModeState() == ActivityManager.LOCK_TASK_MODE_PINNED; } catch (RemoteException e) { return false; } @@ -417,9 +417,9 @@ public class SystemServicesProxy { try { // Use the recents stack bounds, fallback to fullscreen stack if it is null ActivityManager.StackInfo stackInfo = - mIam.getStackInfo(WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_RECENTS); + mIatm.getStackInfo(WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_RECENTS); if (stackInfo == null) { - stackInfo = mIam.getStackInfo(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); + stackInfo = mIatm.getStackInfo(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); } if (stackInfo != null) { windowRect.set(stackInfo.bounds); @@ -441,7 +441,7 @@ public class SystemServicesProxy { if (mIam == null) return; try { - mIam.startInPlaceAnimationOnFrontMostApplication( + mIatm.startInPlaceAnimationOnFrontMostApplication( opts == null ? null : opts.toBundle()); } catch (Exception e) { e.printStackTrace(); diff --git a/packages/SystemUI/src/com/android/systemui/stackdivider/WindowManagerProxy.java b/packages/SystemUI/src/com/android/systemui/stackdivider/WindowManagerProxy.java index 1e5b37c9af50..600964e98b84 100644 --- a/packages/SystemUI/src/com/android/systemui/stackdivider/WindowManagerProxy.java +++ b/packages/SystemUI/src/com/android/systemui/stackdivider/WindowManagerProxy.java @@ -19,6 +19,7 @@ package com.android.systemui.stackdivider; import static android.view.WindowManager.DOCKED_INVALID; import android.app.ActivityManager; +import android.app.ActivityTaskManager; import android.graphics.Rect; import android.os.RemoteException; import android.util.Log; @@ -71,7 +72,7 @@ public class WindowManagerProxy { mTmpRect5.set(mTempOtherInsetRect); } try { - ActivityManager.getService() + ActivityTaskManager.getService() .resizeDockedStack(mTmpRect1, mTmpRect2.isEmpty() ? null : mTmpRect2, mTmpRect3.isEmpty() ? null : mTmpRect3, @@ -87,7 +88,7 @@ public class WindowManagerProxy { @Override public void run() { try { - ActivityManager.getService().dismissSplitScreenMode(false /* onTop */); + ActivityTaskManager.getService().dismissSplitScreenMode(false /* onTop */); } catch (RemoteException e) { Log.w(TAG, "Failed to remove stack: " + e); } @@ -98,7 +99,7 @@ public class WindowManagerProxy { @Override public void run() { try { - ActivityManager.getService().dismissSplitScreenMode(true /* onTop */); + ActivityTaskManager.getService().dismissSplitScreenMode(true /* onTop */); } catch (RemoteException e) { Log.w(TAG, "Failed to resize stack: " + e); } @@ -180,7 +181,7 @@ public class WindowManagerProxy { @Override public void run() { try { - ActivityManager.getService().setSplitScreenResizing(resizing); + ActivityTaskManager.getService().setSplitScreenResizing(resizing); } catch (RemoteException e) { Log.w(TAG, "Error calling setDockedStackResizing: " + e); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManager.java index 1287ced8594c..7e397e8bdd35 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManager.java @@ -16,6 +16,7 @@ package com.android.systemui.statusbar; import android.app.ActivityManager; +import android.app.ActivityTaskManager; import android.app.Notification; import android.app.admin.DevicePolicyManager; import android.content.BroadcastReceiver; @@ -111,7 +112,7 @@ public class NotificationLockscreenUserManager implements Dumpable { } else if (Intent.ACTION_USER_PRESENT.equals(action)) { try { final int lastResumedActivityUserId = - ActivityManager.getService().getLastResumedActivityUserId(); + ActivityTaskManager.getService().getLastResumedActivityUserId(); if (mUserManager.isManagedProfile(lastResumedActivityUserId)) { showForegroundManagedProfileActivityToast(); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java index 83021ca51a55..288b473461e0 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java @@ -17,6 +17,7 @@ package com.android.systemui.statusbar.car; import android.app.ActivityManager; +import android.app.ActivityTaskManager; import android.graphics.PixelFormat; import android.graphics.drawable.Drawable; import android.os.SystemProperties; @@ -452,7 +453,7 @@ public class CarStatusBar extends StatusBar implements public void onTaskStackChanged() { try { mCarFacetButtonController.taskChanged( - ActivityManager.getService().getAllStackInfos()); + ActivityTaskManager.getService().getAllStackInfos()); } catch (Exception e) { Log.e(TAG, "Getting StackInfo from activity manager failed", e); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java index 0716b37ff8d9..3b120511ea1e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java @@ -26,6 +26,7 @@ import static com.android.systemui.tuner.LockscreenFragment.LOCKSCREEN_RIGHT_UNL import android.app.ActivityManager; import android.app.ActivityOptions; +import android.app.ActivityTaskManager; import android.app.admin.DevicePolicyManager; import android.content.BroadcastReceiver; import android.content.ComponentName; @@ -523,7 +524,7 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL o.setRotationAnimationHint( WindowManager.LayoutParams.ROTATION_ANIMATION_SEAMLESS); try { - result = ActivityManager.getService().startActivityAsUser( + result = ActivityTaskManager.getService().startActivityAsUser( null, getContext().getBasePackageName(), intent, intent.resolveTypeIfNeeded(getContext().getContentResolver()), diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java index faf9d525385d..1003833f003a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java @@ -38,6 +38,7 @@ import android.app.ActivityManagerNative; import android.app.ActivityTaskManager; import android.app.Fragment; import android.app.IActivityManager; +import android.app.IActivityTaskManager; import android.app.StatusBarManager; import android.content.BroadcastReceiver; import android.content.ContentResolver; @@ -880,7 +881,7 @@ public class NavigationBarFragment extends Fragment implements Callbacks { private boolean onLongPressNavigationButtons(View v, @IdRes int btnId1, @IdRes int btnId2) { try { boolean sendBackLongPress = false; - IActivityManager activityManager = ActivityManagerNative.getDefault(); + IActivityTaskManager activityManager = ActivityTaskManager.getService(); boolean touchExplorationEnabled = mAccessibilityManager.isTouchExplorationEnabled(); boolean inLockTaskMode = activityManager.isInLockTaskMode(); if (inLockTaskMode && !touchExplorationEnabled) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java index e0c734281092..57e01e7cd4f6 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java @@ -23,6 +23,7 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECOND import android.app.ActivityManager; import android.app.ActivityManager.StackInfo; +import android.app.ActivityTaskManager; import android.app.AlarmManager; import android.app.AlarmManager.AlarmClockInfo; import android.app.AppGlobals; @@ -505,7 +506,7 @@ public class PhoneStatusBarPolicy implements Callback, Callbacks, mUiOffloadThread.submit(() -> { final int userId; try { - userId = ActivityManager.getService().getLastResumedActivityUserId(); + userId = ActivityTaskManager.getService().getLastResumedActivityUserId(); boolean isManagedProfile = mUserManager.isManagedProfile(userId); mHandler.post(() -> { final boolean showIcon; @@ -536,7 +537,8 @@ public class PhoneStatusBarPolicy implements Callback, Callbacks, mCurrentNotifs.clear(); mUiOffloadThread.submit(() -> { try { - final StackInfo focusedStack = ActivityManager.getService().getFocusedStackInfo(); + final StackInfo focusedStack = + ActivityTaskManager.getService().getFocusedStackInfo(); if (focusedStack != null) { final int windowingMode = focusedStack.configuration.windowConfiguration.getWindowingMode(); @@ -562,7 +564,7 @@ public class PhoneStatusBarPolicy implements Callback, Callbacks, ArraySet<Pair<String, Integer>> notifs, NotificationManager noMan, IPackageManager pm) { try { final StackInfo info = - ActivityManager.getService().getStackInfo(windowingMode, activityType); + ActivityTaskManager.getService().getStackInfo(windowingMode, activityType); checkStack(info, notifs, noMan, pm); } catch (RemoteException e) { e.rethrowFromSystemServer(); @@ -651,7 +653,7 @@ public class PhoneStatusBarPolicy implements Callback, Callbacks, private Intent getTaskIntent(int taskId, int userId) { try { final List<ActivityManager.RecentTaskInfo> tasks = - ActivityManager.getService().getRecentTasks( + ActivityTaskManager.getService().getRecentTasks( NUM_TASKS_FOR_INSTANT_APP_INFO, 0, userId).getList(); for (int i = 0; i < tasks.size(); i++) { if (tasks.get(i).id == taskId) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index 252f776f8fca..5d366a0805a5 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -46,6 +46,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.app.ActivityManager; import android.app.ActivityOptions; +import android.app.ActivityTaskManager; import android.app.AlarmManager; import android.app.IWallpaperManager; import android.app.KeyguardManager; @@ -2959,7 +2960,7 @@ public class StatusBar extends SystemUI implements DemoMode, WindowManager.LayoutParams.ROTATION_ANIMATION_SEAMLESS); } try { - result = ActivityManager.getService().startActivityAsUser( + result = ActivityTaskManager.getService().startActivityAsUser( null, mContext.getBasePackageName(), intent, intent.resolveTypeIfNeeded(mContext.getContentResolver()), @@ -5152,7 +5153,7 @@ public class StatusBar extends SystemUI implements DemoMode, row, wasOccluded); try { if (adapter != null) { - ActivityManager.getService() + ActivityTaskManager.getService() .registerRemoteAnimationForNextActivityStart( intent.getCreatorPackage(), adapter); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/WorkLockActivityControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/keyguard/WorkLockActivityControllerTest.java index cf32760dc803..f8aa28dbb945 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/WorkLockActivityControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/WorkLockActivityControllerTest.java @@ -27,7 +27,7 @@ import static org.mockito.Matchers.argThat; import android.app.Activity; import android.app.ActivityManager; import android.app.ActivityOptions; -import android.app.IActivityManager; +import android.app.IActivityTaskManager; import android.app.IApplicationThread; import android.app.ProfilerInfo; import android.content.ComponentName; @@ -62,7 +62,7 @@ public class WorkLockActivityControllerTest extends SysuiTestCase { private @Mock Context mContext; private @Mock ActivityManagerWrapper mActivityManager; - private @Mock IActivityManager mIActivityManager; + private @Mock IActivityTaskManager mIActivityTaskManager; private WorkLockActivityController mController; private SysUiTaskStackChangeListener mTaskStackListener; @@ -77,7 +77,8 @@ public class WorkLockActivityControllerTest extends SysuiTestCase { // Construct controller. Save the TaskStackListener for injecting events. final ArgumentCaptor<SysUiTaskStackChangeListener> listenerCaptor = ArgumentCaptor.forClass(SysUiTaskStackChangeListener.class); - mController = new WorkLockActivityController(mContext, mActivityManager, mIActivityManager); + mController = new WorkLockActivityController(mContext, mActivityManager, + mIActivityTaskManager); verify(mActivityManager).registerTaskStackListener(listenerCaptor.capture()); mTaskStackListener = listenerCaptor.getValue(); @@ -93,7 +94,7 @@ public class WorkLockActivityControllerTest extends SysuiTestCase { // The overlay should start and the task the activity started in should not be removed. verifyStartActivity(TASK_ID, true /*taskOverlay*/); - verify(mIActivityManager, never()).removeTask(anyInt() /*taskId*/); + verify(mIActivityTaskManager, never()).removeTask(anyInt() /*taskId*/); } @Test @@ -107,14 +108,14 @@ public class WorkLockActivityControllerTest extends SysuiTestCase { // The task the activity started in should be removed to prevent the locked task from // being shown. verifyStartActivity(TASK_ID, true /*taskOverlay*/); - verify(mIActivityManager).removeTask(TASK_ID); + verify(mIActivityTaskManager).removeTask(TASK_ID); } // End of tests, start of helpers // ------------------------------ private void setActivityStartCode(int taskId, boolean taskOverlay, int code) throws Exception { - doReturn(code).when(mIActivityManager).startActivityAsUser( + doReturn(code).when(mIActivityTaskManager).startActivityAsUser( eq((IApplicationThread) null), eq((String) null), any(Intent.class), @@ -129,7 +130,7 @@ public class WorkLockActivityControllerTest extends SysuiTestCase { } private void verifyStartActivity(int taskId, boolean taskOverlay) throws Exception { - verify(mIActivityManager).startActivityAsUser( + verify(mIActivityTaskManager).startActivityAsUser( eq((IApplicationThread) null), eq((String) null), any(Intent.class), diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java index 1ccce177bca8..6c359fe0df2e 100644 --- a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java +++ b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java @@ -26,9 +26,11 @@ import static com.android.server.autofill.Helper.sVerbose; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.ActivityManager; +import android.app.ActivityTaskManager; import android.app.ActivityManagerInternal; import android.app.AppGlobals; import android.app.IActivityManager; +import android.app.IActivityTaskManager; import android.content.ComponentName; import android.content.Context; import android.content.pm.ApplicationInfo; @@ -1296,13 +1298,13 @@ final class AutofillManagerServiceImpl { } } - IActivityManager am = ActivityManager.getService(); + final IActivityTaskManager atm = ActivityTaskManager.getService(); // Only remove sessions which's activities are not known to the activity manager anymore for (int i = 0; i < numSessionsToRemove; i++) { try { // The activity manager cannot resolve activities that have been removed - if (am.getActivityClassForToken(sessionsToRemove.valueAt(i)) != null) { + if (atm.getActivityClassForToken(sessionsToRemove.valueAt(i)) != null) { sessionsToRemove.removeAt(i); i--; numSessionsToRemove--; diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java index 1168f55d118c..767b2f798c12 100644 --- a/services/autofill/java/com/android/server/autofill/Session.java +++ b/services/autofill/java/com/android/server/autofill/Session.java @@ -38,6 +38,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.app.Activity; import android.app.ActivityManager; +import android.app.ActivityTaskManager; import android.app.IAssistDataReceiver; import android.app.assist.AssistStructure; import android.app.assist.AssistStructure.AutofillOverlay; @@ -515,7 +516,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState receiverExtras.putInt(EXTRA_REQUEST_ID, requestId); final long identity = Binder.clearCallingIdentity(); try { - if (!ActivityManager.getService().requestAutofillData(mAssistReceiver, + if (!ActivityTaskManager.getService().requestAutofillData(mAssistReceiver, receiverExtras, mActivityToken, flags)) { Slog.w(TAG, "failed to request autofill data for " + mActivityToken); } diff --git a/services/core/java/com/android/server/UiModeManagerService.java b/services/core/java/com/android/server/UiModeManagerService.java index 6b5366a39a43..c29fc7f753a1 100644 --- a/services/core/java/com/android/server/UiModeManagerService.java +++ b/services/core/java/com/android/server/UiModeManagerService.java @@ -19,6 +19,7 @@ package com.android.server; import android.annotation.Nullable; import android.app.Activity; import android.app.ActivityManager; +import android.app.ActivityTaskManager; import android.app.IUiModeManager; import android.app.Notification; import android.app.NotificationManager; @@ -475,7 +476,7 @@ final class UiModeManagerService extends SystemService { mSetUiMode = mConfiguration.uiMode; try { - ActivityManager.getService().updateConfiguration(mConfiguration); + ActivityTaskManager.getService().updateConfiguration(mConfiguration); } catch (RemoteException e) { Slog.w(TAG, "Failure communicating with activity manager", e); } @@ -637,7 +638,7 @@ final class UiModeManagerService extends SystemService { Intent homeIntent = buildHomeIntent(category); if (Sandman.shouldStartDockApp(getContext(), homeIntent)) { try { - int result = ActivityManager.getService().startActivityWithConfig( + int result = ActivityTaskManager.getService().startActivityWithConfig( null, null, homeIntent, null, null, null, 0, 0, mConfiguration, null, UserHandle.USER_CURRENT); if (ActivityManager.isStartResultSuccessful(result)) { diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 215670bd53bc..97c3fe4e48f4 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -601,17 +601,6 @@ public class ActivityManagerService extends IActivityManager.Stub // Must be kept in sync with Am. private static final int INSTRUMENTATION_FLAG_DISABLE_HIDDEN_API_CHECKS = 1 << 0; - // How long to wait in getAssistContextExtras for the activity and foreground services - // to respond with the result. - static final int PENDING_ASSIST_EXTRAS_TIMEOUT = 500; - - // How long top wait when going through the modern assist (which doesn't need to block - // on getting this result before starting to launch its UI). - static final int PENDING_ASSIST_EXTRAS_LONG_TIMEOUT = 2000; - - // How long to wait in getAutofillAssistStructure() for the activity to respond with the result. - static final int PENDING_AUTOFILL_ASSIST_STRUCTURE_TIMEOUT = 2000; - // Maximum number of persisted Uri grants a package is allowed static final int MAX_PERSISTED_URI_GRANTS = 128; @@ -679,9 +668,6 @@ public class ActivityManagerService extends IActivityManager.Stub /** All system services */ SystemServiceManager mSystemServiceManager; - // Wrapper around VoiceInteractionServiceManager - private AssistUtils mAssistUtils; - // Keeps track of the active voice interaction service component, notified from // VoiceInteractionManagerService ComponentName mActiveVoiceInteractionServiceComponent; @@ -690,7 +676,7 @@ public class ActivityManagerService extends IActivityManager.Stub /** Run all ActivityStacks through this */ final ActivityStackSupervisor mStackSupervisor; - private final KeyguardController mKeyguardController; + final KeyguardController mKeyguardController; private final ActivityStartController mActivityStartController; @@ -741,7 +727,7 @@ public class ActivityManagerService extends IActivityManager.Stub * of the time but could be different when we're pausing one activity before we resume * another activity. */ - private ActivityRecord mLastResumedActivity; + ActivityRecord mLastResumedActivity; /** * The activity that is currently being traced as the active resumed activity. @@ -844,45 +830,6 @@ public class ActivityManagerService extends IActivityManager.Stub sThreadPriorityBooster.reset(); } - public class PendingAssistExtras extends Binder implements Runnable { - public final ActivityRecord activity; - public boolean isHome; - public final Bundle extras; - public final Intent intent; - public final String hint; - public final IAssistDataReceiver receiver; - public final int userHandle; - public boolean haveResult = false; - public Bundle result = null; - public AssistStructure structure = null; - public AssistContent content = null; - public Bundle receiverExtras; - - public PendingAssistExtras(ActivityRecord _activity, Bundle _extras, Intent _intent, - String _hint, IAssistDataReceiver _receiver, Bundle _receiverExtras, - int _userHandle) { - activity = _activity; - extras = _extras; - intent = _intent; - hint = _hint; - receiver = _receiver; - receiverExtras = _receiverExtras; - userHandle = _userHandle; - } - - @Override - public void run() { - Slog.w(TAG, "getAssistContextExtras failed: timeout retrieving from " + activity); - synchronized (this) { - haveResult = true; - notifyAll(); - } - pendingAssistExtrasTimedOut(this); - } - } - - final ArrayList<PendingAssistExtras> mPendingAssistExtras = new ArrayList<>(); - /** * Process management. */ @@ -1427,22 +1374,6 @@ public class ActivityManagerService extends IActivityManager.Stub */ private Configuration mTempConfig = new Configuration(); - private final UpdateConfigurationResult mTmpUpdateConfigurationResult = - new UpdateConfigurationResult(); - private static final class UpdateConfigurationResult { - // Configuration changes that were updated. - int changes; - // If the activity was relaunched to match the new configuration. - boolean activityRelaunched; - - void reset() { - changes = 0; - activityRelaunched = false; - } - } - - boolean mSuppressResizeConfigChanges; - /** * Hardware-reported OpenGLES version. */ @@ -1548,11 +1479,6 @@ public class ActivityManagerService extends IActivityManager.Stub private int mWakefulness = PowerManagerInternal.WAKEFULNESS_AWAKE; /** - * State of external calls telling us if the device is awake or asleep. - */ - private boolean mKeyguardShown = false; - - /** * Set if we are shutting down the system, similar to sleeping. */ boolean mShuttingDown = false; @@ -1974,10 +1900,6 @@ public class ActivityManagerService extends IActivityManager.Stub PackageManagerInternal mPackageManagerInt; - // VoiceInteraction session ID that changes for each new request except when - // being called for multiwindow assist in a single session. - private int mViSessionId = 1000; - final boolean mPermissionReviewRequired; boolean mHasHeavyWeightFeature; @@ -3555,7 +3477,7 @@ public class ActivityManagerService extends IActivityManager.Stub // move to something different. Just finish the session, we can't // return to it and retain the proper state and synchronization with // the voice interaction service. - finishVoiceTask(session); + mActivityTaskManager.finishVoiceTask(session); } } } @@ -3595,74 +3517,21 @@ public class ActivityManagerService extends IActivityManager.Stub @Override public void setFocusedStack(int stackId) { - enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "setFocusedStack()"); - if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, "setFocusedStack: stackId=" + stackId); - final long callingId = Binder.clearCallingIdentity(); - try { - synchronized (this) { - final ActivityStack stack = mStackSupervisor.getStack(stackId); - if (stack == null) { - Slog.w(TAG, "setFocusedStack: No stack with id=" + stackId); - return; - } - final ActivityRecord r = stack.topRunningActivityLocked(); - if (mStackSupervisor.moveFocusableActivityStackToFrontLocked(r, "setFocusedStack")) { - mStackSupervisor.resumeFocusedStackTopActivityLocked(); - } - } - } finally { - Binder.restoreCallingIdentity(callingId); - } - } - - @Override - public void setFocusedTask(int taskId) { - enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "setFocusedTask()"); - if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, "setFocusedTask: taskId=" + taskId); - final long callingId = Binder.clearCallingIdentity(); - try { - synchronized (this) { - final TaskRecord task = mStackSupervisor.anyTaskForIdLocked(taskId); - if (task == null) { - return; - } - final ActivityRecord r = task.topRunningActivityLocked(); - if (mStackSupervisor.moveFocusableActivityStackToFrontLocked(r, "setFocusedTask")) { - mStackSupervisor.resumeFocusedStackTopActivityLocked(); - } - } - } finally { - Binder.restoreCallingIdentity(callingId); - } + mActivityTaskManager.setFocusedStack(stackId); } /** Sets the task stack listener that gets callbacks when a task stack changes. */ @Override - public void registerTaskStackListener(ITaskStackListener listener) throws RemoteException { - enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, - "registerTaskStackListener()"); - mTaskChangeNotificationController.registerTaskStackListener(listener); + public void registerTaskStackListener(ITaskStackListener listener) { + mActivityTaskManager.registerTaskStackListener(listener); } /** * Unregister a task stack listener so that it stops receiving callbacks. */ @Override - public void unregisterTaskStackListener(ITaskStackListener listener) throws RemoteException { - enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, - "unregisterTaskStackListener()"); - mTaskChangeNotificationController.unregisterTaskStackListener(listener); - } - - @Override - public void notifyActivityDrawn(IBinder token) { - if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY, "notifyActivityDrawn: token=" + token); - synchronized (this) { - ActivityRecord r = mStackSupervisor.isInAnyStackLocked(token); - if (r != null) { - r.getStack().notifyActivityDrawnLocked(r); - } - } + public void unregisterTaskStackListener(ITaskStackListener listener) { + mActivityTaskManager.unregisterTaskStackListener(listener); } final void applyUpdateLockStateLocked(ActivityRecord r) { @@ -4733,23 +4602,6 @@ public class ActivityManagerService extends IActivityManager.Stub } @Override - public int getFrontActivityScreenCompatMode() { - enforceNotIsolatedCaller("getFrontActivityScreenCompatMode"); - synchronized (this) { - return mCompatModePackages.getFrontActivityScreenCompatModeLocked(); - } - } - - @Override - public void setFrontActivityScreenCompatMode(int mode) { - enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, - "setFrontActivityScreenCompatMode"); - synchronized (this) { - mCompatModePackages.setFrontActivityScreenCompatModeLocked(mode); - } - } - - @Override public int getPackageScreenCompatMode(String packageName) { enforceNotIsolatedCaller("getPackageScreenCompatMode"); synchronized (this) { @@ -5086,329 +4938,37 @@ public class ActivityManagerService extends IActivityManager.Stub } @Override - public final int startActivity(IApplicationThread caller, String callingPackage, + public int startActivity(IApplicationThread caller, String callingPackage, Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, int startFlags, ProfilerInfo profilerInfo, Bundle bOptions) { - return startActivityAsUser(caller, callingPackage, intent, resolvedType, resultTo, - resultWho, requestCode, startFlags, profilerInfo, bOptions, - UserHandle.getCallingUserId()); + return mActivityTaskManager.startActivity(caller, callingPackage, intent, resolvedType, + resultTo, resultWho, requestCode, startFlags, profilerInfo, bOptions); } @Override public final int startActivityAsUser(IApplicationThread caller, String callingPackage, Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, int userId) { - return startActivityAsUser(caller, callingPackage, intent, resolvedType, resultTo, - resultWho, requestCode, startFlags, profilerInfo, bOptions, userId, - true /*validateIncomingUser*/); - } - - public final int startActivityAsUser(IApplicationThread caller, String callingPackage, - Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, - int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, int userId, - boolean validateIncomingUser) { - enforceNotIsolatedCaller("startActivity"); - - userId = mActivityStartController.checkTargetUser(userId, validateIncomingUser, - Binder.getCallingPid(), Binder.getCallingUid(), "startActivityAsUser"); - - // TODO: Switch to user app stacks here. - return mActivityStartController.obtainStarter(intent, "startActivityAsUser") - .setCaller(caller) - .setCallingPackage(callingPackage) - .setResolvedType(resolvedType) - .setResultTo(resultTo) - .setResultWho(resultWho) - .setRequestCode(requestCode) - .setStartFlags(startFlags) - .setProfilerInfo(profilerInfo) - .setActivityOptions(bOptions) - .setMayWait(userId) - .execute(); - - } - - @Override - public final int startActivityAsCaller(IApplicationThread caller, String callingPackage, - Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, - int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, boolean ignoreTargetSecurity, - int userId) { - - // This is very dangerous -- it allows you to perform a start activity (including - // permission grants) as any app that may launch one of your own activities. So - // we will only allow this to be done from activities that are part of the core framework, - // and then only when they are running as the system. - final ActivityRecord sourceRecord; - final int targetUid; - final String targetPackage; - final boolean isResolver; - synchronized (this) { - if (resultTo == null) { - throw new SecurityException("Must be called from an activity"); - } - sourceRecord = mStackSupervisor.isInAnyStackLocked(resultTo); - if (sourceRecord == null) { - throw new SecurityException("Called with bad activity token: " + resultTo); - } - if (!sourceRecord.info.packageName.equals("android")) { - throw new SecurityException( - "Must be called from an activity that is declared in the android package"); - } - if (sourceRecord.app == null) { - throw new SecurityException("Called without a process attached to activity"); - } - if (UserHandle.getAppId(sourceRecord.app.uid) != SYSTEM_UID) { - // This is still okay, as long as this activity is running under the - // uid of the original calling activity. - if (sourceRecord.app.uid != sourceRecord.launchedFromUid) { - throw new SecurityException( - "Calling activity in uid " + sourceRecord.app.uid - + " must be system uid or original calling uid " - + sourceRecord.launchedFromUid); - } - } - if (ignoreTargetSecurity) { - if (intent.getComponent() == null) { - throw new SecurityException( - "Component must be specified with ignoreTargetSecurity"); - } - if (intent.getSelector() != null) { - throw new SecurityException( - "Selector not allowed with ignoreTargetSecurity"); - } - } - targetUid = sourceRecord.launchedFromUid; - targetPackage = sourceRecord.launchedFromPackage; - isResolver = sourceRecord.isResolverOrChildActivity(); - } - - if (userId == UserHandle.USER_NULL) { - userId = UserHandle.getUserId(sourceRecord.app.uid); - } - - // TODO: Switch to user app stacks here. - try { - return mActivityStartController.obtainStarter(intent, "startActivityAsCaller") - .setCallingUid(targetUid) - .setCallingPackage(targetPackage) - .setResolvedType(resolvedType) - .setResultTo(resultTo) - .setResultWho(resultWho) - .setRequestCode(requestCode) - .setStartFlags(startFlags) - .setActivityOptions(bOptions) - .setMayWait(userId) - .setIgnoreTargetSecurity(ignoreTargetSecurity) - .setFilterCallingUid(isResolver ? 0 /* system */ : targetUid) - .execute(); - } catch (SecurityException e) { - // XXX need to figure out how to propagate to original app. - // A SecurityException here is generally actually a fault of the original - // calling activity (such as a fairly granting permissions), so propagate it - // back to them. - /* - StringBuilder msg = new StringBuilder(); - msg.append("While launching"); - msg.append(intent.toString()); - msg.append(": "); - msg.append(e.getMessage()); - */ - throw e; - } - } - - @Override - public final WaitResult startActivityAndWait(IApplicationThread caller, String callingPackage, - Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, - int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, int userId) { - enforceNotIsolatedCaller("startActivityAndWait"); - userId = mUserController.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), - userId, false, ALLOW_FULL_ONLY, "startActivityAndWait", null); - WaitResult res = new WaitResult(); - // TODO: Switch to user app stacks here. - mActivityStartController.obtainStarter(intent, "startActivityAndWait") - .setCaller(caller) - .setCallingPackage(callingPackage) - .setResolvedType(resolvedType) - .setResultTo(resultTo) - .setResultWho(resultWho) - .setRequestCode(requestCode) - .setStartFlags(startFlags) - .setActivityOptions(bOptions) - .setMayWait(userId) - .setProfilerInfo(profilerInfo) - .setWaitResult(res) - .execute(); - return res; + return mActivityTaskManager.startActivityAsUser(caller, callingPackage, intent, + resolvedType, resultTo, resultWho, requestCode, startFlags, profilerInfo, bOptions, + userId); } @Override - public final int startActivityWithConfig(IApplicationThread caller, String callingPackage, - Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, - int startFlags, Configuration config, Bundle bOptions, int userId) { - enforceNotIsolatedCaller("startActivityWithConfig"); - userId = mUserController.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), - userId, false, ALLOW_FULL_ONLY, "startActivityWithConfig", null); - // TODO: Switch to user app stacks here. - return mActivityStartController.obtainStarter(intent, "startActivityWithConfig") - .setCaller(caller) - .setCallingPackage(callingPackage) - .setResolvedType(resolvedType) - .setResultTo(resultTo) - .setResultWho(resultWho) - .setRequestCode(requestCode) - .setStartFlags(startFlags) - .setGlobalConfiguration(config) - .setActivityOptions(bOptions) - .setMayWait(userId) - .execute(); - } - - @Override - public int startActivityIntentSender(IApplicationThread caller, IIntentSender target, - IBinder whitelistToken, Intent fillInIntent, String resolvedType, IBinder resultTo, - String resultWho, int requestCode, int flagsMask, int flagsValues, Bundle bOptions) - throws TransactionTooLargeException { - enforceNotIsolatedCaller("startActivityIntentSender"); - // Refuse possible leaked file descriptors - if (fillInIntent != null && fillInIntent.hasFileDescriptors()) { - throw new IllegalArgumentException("File descriptors passed in Intent"); - } - - if (!(target instanceof PendingIntentRecord)) { - throw new IllegalArgumentException("Bad PendingIntent object"); - } - - PendingIntentRecord pir = (PendingIntentRecord)target; - - synchronized (this) { - // If this is coming from the currently resumed activity, it is - // effectively saying that app switches are allowed at this point. - final ActivityStack stack = getFocusedStack(); - if (stack.mResumedActivity != null && - stack.mResumedActivity.info.applicationInfo.uid == Binder.getCallingUid()) { - mAppSwitchesAllowedTime = 0; - } - } - int ret = pir.sendInner(0, fillInIntent, resolvedType, whitelistToken, null, null, - resultTo, resultWho, requestCode, flagsMask, flagsValues, bOptions); - return ret; - } - - @Override - public int startVoiceActivity(String callingPackage, int callingPid, int callingUid, - Intent intent, String resolvedType, IVoiceInteractionSession session, - IVoiceInteractor interactor, int startFlags, ProfilerInfo profilerInfo, - Bundle bOptions, int userId) { - enforceCallingPermission(BIND_VOICE_INTERACTION, "startVoiceActivity()"); - if (session == null || interactor == null) { - throw new NullPointerException("null session or interactor"); - } - userId = mUserController.handleIncomingUser(callingPid, callingUid, userId, false, - ALLOW_FULL_ONLY, "startVoiceActivity", null); - // TODO: Switch to user app stacks here. - return mActivityStartController.obtainStarter(intent, "startVoiceActivity") - .setCallingUid(callingUid) - .setCallingPackage(callingPackage) - .setResolvedType(resolvedType) - .setVoiceSession(session) - .setVoiceInteractor(interactor) - .setStartFlags(startFlags) - .setProfilerInfo(profilerInfo) - .setActivityOptions(bOptions) - .setMayWait(userId) - .execute(); - } - - @Override - public int startAssistantActivity(String callingPackage, int callingPid, int callingUid, - Intent intent, String resolvedType, Bundle bOptions, int userId) { - enforceCallingPermission(BIND_VOICE_INTERACTION, "startAssistantActivity()"); - userId = mUserController.handleIncomingUser(callingPid, callingUid, userId, false, - ALLOW_FULL_ONLY, "startAssistantActivity", null); - - return mActivityStartController.obtainStarter(intent, "startAssistantActivity") - .setCallingUid(callingUid) - .setCallingPackage(callingPackage) - .setResolvedType(resolvedType) - .setActivityOptions(bOptions) - .setMayWait(userId) - .execute(); + public final int startActivityFromRecents(int taskId, Bundle bOptions) { + return mActivityTaskManager.startActivityFromRecents(taskId, bOptions); } @Override public void startRecentsActivity(Intent intent, IAssistDataReceiver assistDataReceiver, - IRecentsAnimationRunner recentsAnimationRunner) { - enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "startRecentsActivity()"); - final int callingPid = Binder.getCallingPid(); - final long origId = Binder.clearCallingIdentity(); - try { - synchronized (this) { - final ComponentName recentsComponent = mRecentTasks.getRecentsComponent(); - final int recentsUid = mRecentTasks.getRecentsComponentUid(); - - // Start a new recents animation - final RecentsAnimation anim = new RecentsAnimation(this, mStackSupervisor, - mActivityStartController, mWindowManager, mUserController, callingPid); - anim.startRecentsActivity(intent, recentsAnimationRunner, recentsComponent, - recentsUid, assistDataReceiver); - } - } finally { - Binder.restoreCallingIdentity(origId); - } + IRecentsAnimationRunner recentsAnimationRunner) { + mActivityTaskManager.startRecentsActivity( + intent, assistDataReceiver, recentsAnimationRunner); } @Override public void cancelRecentsAnimation(boolean restoreHomeStackPosition) { - enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "cancelRecentsAnimation()"); - final long callingUid = Binder.getCallingUid(); - final long origId = Binder.clearCallingIdentity(); - try { - synchronized (this) { - // Cancel the recents animation synchronously (do not hold the WM lock) - mWindowManager.cancelRecentsAnimationSynchronously(restoreHomeStackPosition - ? REORDER_MOVE_TO_ORIGINAL_POSITION - : REORDER_KEEP_IN_PLACE, "cancelRecentsAnimation/uid=" + callingUid); - } - } finally { - Binder.restoreCallingIdentity(origId); - } - } - - @Override - public void startLocalVoiceInteraction(IBinder callingActivity, Bundle options) - throws RemoteException { - Slog.i(TAG, "Activity tried to startVoiceInteraction"); - synchronized (this) { - ActivityRecord activity = getFocusedStack().getTopActivity(); - if (ActivityRecord.forTokenLocked(callingActivity) != activity) { - throw new SecurityException("Only focused activity can call startVoiceInteraction"); - } - if (mRunningVoice != null || activity.getTask().voiceSession != null - || activity.voiceSession != null) { - Slog.w(TAG, "Already in a voice interaction, cannot start new voice interaction"); - return; - } - if (activity.pendingVoiceInteractionStart) { - Slog.w(TAG, "Pending start of voice interaction already."); - return; - } - activity.pendingVoiceInteractionStart = true; - } - LocalServices.getService(VoiceInteractionManagerInternal.class) - .startLocalVoiceInteraction(callingActivity, options); - } - - @Override - public void stopLocalVoiceInteraction(IBinder callingActivity) throws RemoteException { - LocalServices.getService(VoiceInteractionManagerInternal.class) - .stopLocalVoiceInteraction(callingActivity); - } - - @Override - public boolean supportsLocalVoiceInteraction() throws RemoteException { - return LocalServices.getService(VoiceInteractionManagerInternal.class) - .supportsLocalVoiceInteraction(); + mActivityTaskManager.cancelRecentsAnimation(restoreHomeStackPosition); } @GuardedBy("this") @@ -5449,197 +5009,6 @@ public class ActivityManagerService extends IActivityManager.Stub } } - @Override - public boolean startNextMatchingActivity(IBinder callingActivity, - Intent intent, Bundle bOptions) { - // Refuse possible leaked file descriptors - if (intent != null && intent.hasFileDescriptors() == true) { - throw new IllegalArgumentException("File descriptors passed in Intent"); - } - SafeActivityOptions options = SafeActivityOptions.fromBundle(bOptions); - - synchronized (this) { - final ActivityRecord r = ActivityRecord.isInStackLocked(callingActivity); - if (r == null) { - SafeActivityOptions.abort(options); - return false; - } - if (r.app == null || r.app.thread == null) { - // The caller is not running... d'oh! - SafeActivityOptions.abort(options); - return false; - } - intent = new Intent(intent); - // The caller is not allowed to change the data. - intent.setDataAndType(r.intent.getData(), r.intent.getType()); - // And we are resetting to find the next component... - intent.setComponent(null); - - final boolean debug = ((intent.getFlags() & Intent.FLAG_DEBUG_LOG_RESOLUTION) != 0); - - ActivityInfo aInfo = null; - try { - List<ResolveInfo> resolves = - AppGlobals.getPackageManager().queryIntentActivities( - intent, r.resolvedType, - PackageManager.MATCH_DEFAULT_ONLY | STOCK_PM_FLAGS, - UserHandle.getCallingUserId()).getList(); - - // Look for the original activity in the list... - final int N = resolves != null ? resolves.size() : 0; - for (int i=0; i<N; i++) { - ResolveInfo rInfo = resolves.get(i); - if (rInfo.activityInfo.packageName.equals(r.packageName) - && rInfo.activityInfo.name.equals(r.info.name)) { - // We found the current one... the next matching is - // after it. - i++; - if (i<N) { - aInfo = resolves.get(i).activityInfo; - } - if (debug) { - Slog.v(TAG, "Next matching activity: found current " + r.packageName - + "/" + r.info.name); - Slog.v(TAG, "Next matching activity: next is " + ((aInfo == null) - ? "null" : aInfo.packageName + "/" + aInfo.name)); - } - break; - } - } - } catch (RemoteException e) { - } - - if (aInfo == null) { - // Nobody who is next! - SafeActivityOptions.abort(options); - if (debug) Slog.d(TAG, "Next matching activity: nothing found"); - return false; - } - - intent.setComponent(new ComponentName( - aInfo.applicationInfo.packageName, aInfo.name)); - intent.setFlags(intent.getFlags()&~( - Intent.FLAG_ACTIVITY_FORWARD_RESULT| - Intent.FLAG_ACTIVITY_CLEAR_TOP| - Intent.FLAG_ACTIVITY_MULTIPLE_TASK| - FLAG_ACTIVITY_NEW_TASK)); - - // Okay now we need to start the new activity, replacing the - // currently running activity. This is a little tricky because - // we want to start the new one as if the current one is finished, - // but not finish the current one first so that there is no flicker. - // And thus... - final boolean wasFinishing = r.finishing; - r.finishing = true; - - // Propagate reply information over to the new activity. - final ActivityRecord resultTo = r.resultTo; - final String resultWho = r.resultWho; - final int requestCode = r.requestCode; - r.resultTo = null; - if (resultTo != null) { - resultTo.removeResultsLocked(r, resultWho, requestCode); - } - - final long origId = Binder.clearCallingIdentity(); - // TODO(b/64750076): Check if calling pid should really be -1. - final int res = mActivityStartController - .obtainStarter(intent, "startNextMatchingActivity") - .setCaller(r.app.thread) - .setResolvedType(r.resolvedType) - .setActivityInfo(aInfo) - .setResultTo(resultTo != null ? resultTo.appToken : null) - .setResultWho(resultWho) - .setRequestCode(requestCode) - .setCallingPid(-1) - .setCallingUid(r.launchedFromUid) - .setCallingPackage(r.launchedFromPackage) - .setRealCallingPid(-1) - .setRealCallingUid(r.launchedFromUid) - .setActivityOptions(options) - .execute(); - Binder.restoreCallingIdentity(origId); - - r.finishing = wasFinishing; - if (res != ActivityManager.START_SUCCESS) { - return false; - } - return true; - } - } - - @Override - public final int startActivityFromRecents(int taskId, Bundle bOptions) { - enforceCallerIsRecentsOrHasPermission(START_TASKS_FROM_RECENTS, - "startActivityFromRecents()"); - - final int callingPid = Binder.getCallingPid(); - final int callingUid = Binder.getCallingUid(); - final SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(bOptions); - final long origId = Binder.clearCallingIdentity(); - try { - synchronized (this) { - return mStackSupervisor.startActivityFromRecents(callingPid, callingUid, taskId, - safeOptions); - } - } finally { - Binder.restoreCallingIdentity(origId); - } - } - - @Override - public final int startActivities(IApplicationThread caller, String callingPackage, - Intent[] intents, String[] resolvedTypes, IBinder resultTo, Bundle bOptions, - int userId) { - final String reason = "startActivities"; - enforceNotIsolatedCaller(reason); - userId = mUserController.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), - userId, false, ALLOW_FULL_ONLY, reason, null); - // TODO: Switch to user app stacks here. - int ret = mActivityStartController.startActivities(caller, -1, callingPackage, - intents, resolvedTypes, resultTo, SafeActivityOptions.fromBundle(bOptions), userId, - reason); - return ret; - } - - @Override - public void reportActivityFullyDrawn(IBinder token, boolean restoredFromBundle) { - synchronized (this) { - ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r == null) { - return; - } - r.reportFullyDrawnLocked(restoredFromBundle); - } - } - - @Override - public void setRequestedOrientation(IBinder token, int requestedOrientation) { - synchronized (this) { - ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r == null) { - return; - } - final long origId = Binder.clearCallingIdentity(); - try { - r.setRequestedOrientation(requestedOrientation); - } finally { - Binder.restoreCallingIdentity(origId); - } - } - } - - @Override - public int getRequestedOrientation(IBinder token) { - synchronized (this) { - ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r == null) { - return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; - } - return r.getRequestedOrientation(); - } - } - /** * This is the internal entry point for handling Activity.finish(). * @@ -5653,76 +5022,12 @@ public class ActivityManagerService extends IActivityManager.Stub @Override public final boolean finishActivity(IBinder token, int resultCode, Intent resultData, int finishTask) { - // Refuse possible leaked file descriptors - if (resultData != null && resultData.hasFileDescriptors() == true) { - throw new IllegalArgumentException("File descriptors passed in Intent"); - } - - synchronized(this) { - ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r == null) { - return true; - } - // Keep track of the root activity of the task before we finish it - TaskRecord tr = r.getTask(); - ActivityRecord rootR = tr.getRootActivity(); - if (rootR == null) { - Slog.w(TAG, "Finishing task with all activities already finished"); - } - // Do not allow task to finish if last task in lockTask mode. Launchable priv-apps can - // finish. - if (mLockTaskController.activityBlockedFromFinish(r)) { - return false; - } - - if (mController != null) { - // Find the first activity that is not finishing. - ActivityRecord next = r.getStack().topRunningActivityLocked(token, 0); - if (next != null) { - // ask watcher if this is allowed - boolean resumeOK = true; - try { - resumeOK = mController.activityResuming(next.packageName); - } catch (RemoteException e) { - mController = null; - Watchdog.getInstance().setActivityController(null); - } + return mActivityTaskManager.finishActivity(token, resultCode, resultData, finishTask); + } - if (!resumeOK) { - Slog.i(TAG, "Not finishing activity because controller resumed"); - return false; - } - } - } - final long origId = Binder.clearCallingIdentity(); - try { - boolean res; - final boolean finishWithRootActivity = - finishTask == Activity.FINISH_TASK_WITH_ROOT_ACTIVITY; - if (finishTask == Activity.FINISH_TASK_WITH_ACTIVITY - || (finishWithRootActivity && r == rootR)) { - // If requested, remove the task that is associated to this activity only if it - // was the root activity in the task. The result code and data is ignored - // because we don't support returning them across task boundaries. Also, to - // keep backwards compatibility we remove the task from recents when finishing - // task with root activity. - res = mStackSupervisor.removeTaskByIdLocked(tr.taskId, false, - finishWithRootActivity, "finish-activity"); - if (!res) { - Slog.i(TAG, "Removing task failed to finish activity"); - } - } else { - res = tr.getStack().requestFinishActivityLocked(token, resultCode, - resultData, "app-request", true); - if (!res) { - Slog.i(TAG, "Failed to finish by app-request"); - } - } - return res; - } finally { - Binder.restoreCallingIdentity(origId); - } - } + @Override + public void setRequestedOrientation(IBinder token, int requestedOrientation) { + mActivityTaskManager.setRequestedOrientation(token, requestedOrientation); } @Override @@ -5776,117 +5081,6 @@ public class ActivityManagerService extends IActivityManager.Stub } } - @Override - public final void finishSubActivity(IBinder token, String resultWho, - int requestCode) { - synchronized(this) { - final long origId = Binder.clearCallingIdentity(); - ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r != null) { - r.getStack().finishSubActivityLocked(r, resultWho, requestCode); - } - Binder.restoreCallingIdentity(origId); - } - } - - @Override - public boolean finishActivityAffinity(IBinder token) { - synchronized(this) { - final long origId = Binder.clearCallingIdentity(); - try { - ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r == null) { - return false; - } - - // Do not allow task to finish if last task in lockTask mode. Launchable priv-apps - // can finish. - final TaskRecord task = r.getTask(); - if (mLockTaskController.activityBlockedFromFinish(r)) { - return false; - } - return task.getStack().finishActivityAffinityLocked(r); - } finally { - Binder.restoreCallingIdentity(origId); - } - } - } - - @Override - public void finishVoiceTask(IVoiceInteractionSession session) { - synchronized (this) { - final long origId = Binder.clearCallingIdentity(); - try { - // TODO: VI Consider treating local voice interactions and voice tasks - // differently here - mStackSupervisor.finishVoiceTask(session); - } finally { - Binder.restoreCallingIdentity(origId); - } - } - - } - - @Override - public boolean releaseActivityInstance(IBinder token) { - synchronized(this) { - final long origId = Binder.clearCallingIdentity(); - try { - ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r == null) { - return false; - } - return r.getStack().safelyDestroyActivityLocked(r, "app-req"); - } finally { - Binder.restoreCallingIdentity(origId); - } - } - } - - @Override - public void releaseSomeActivities(IApplicationThread appInt) { - synchronized(this) { - final long origId = Binder.clearCallingIdentity(); - try { - ProcessRecord app = getRecordForAppLocked(appInt); - mStackSupervisor.releaseSomeActivitiesLocked(app, "low-mem"); - } finally { - Binder.restoreCallingIdentity(origId); - } - } - } - - @Override - public boolean willActivityBeVisible(IBinder token) { - synchronized(this) { - ActivityStack stack = ActivityRecord.getStackLocked(token); - if (stack != null) { - return stack.willActivityBeVisibleLocked(token); - } - return false; - } - } - - @Override - public void overridePendingTransition(IBinder token, String packageName, - int enterAnim, int exitAnim) { - synchronized(this) { - ActivityRecord self = ActivityRecord.isInStackLocked(token); - if (self == null) { - return; - } - - final long origId = Binder.clearCallingIdentity(); - - if (self.isState(ActivityState.RESUMED, ActivityState.PAUSING)) { - mWindowManager.overridePendingAppTransition(packageName, - enterAnim, exitAnim, null); - } - - Binder.restoreCallingIdentity(origId); - } - } - /** * Main function for removing an existing process from the activity manager * as a result of that process going away. Clears out all connections @@ -7813,25 +7007,6 @@ public class ActivityManagerService extends IActivityManager.Stub } } - @Override - public final void activityIdle(IBinder token, Configuration config, boolean stopProfiling) { - final long origId = Binder.clearCallingIdentity(); - synchronized (this) { - ActivityStack stack = ActivityRecord.getStackLocked(token); - if (stack != null) { - ActivityRecord r = - mStackSupervisor.activityIdleInternalLocked(token, false /* fromTimeout */, - false /* processPausingActivities */, config); - if (stopProfiling) { - if ((mProfileProc == r.app) && mProfilerInfo != null) { - clearProfilerLocked(); - } - } - } - } - Binder.restoreCallingIdentity(origId); - } - void postFinishBooting(boolean finishBooting, boolean enableScreen) { mHandler.sendMessage(mHandler.obtainMessage(FINISH_BOOTING_MSG, finishBooting ? 1 : 0, enableScreen ? 1 : 0)); @@ -7855,19 +7030,6 @@ public class ActivityManagerService extends IActivityManager.Stub mWindowManager.showBootMessage(msg, always); } - @Override - public void keyguardGoingAway(int flags) { - enforceNotIsolatedCaller("keyguardGoingAway"); - final long token = Binder.clearCallingIdentity(); - try { - synchronized (this) { - mKeyguardController.keyguardGoingAway(flags); - } - } finally { - Binder.restoreCallingIdentity(token); - } - } - /** * @return whther the keyguard is currently locked. */ @@ -8019,155 +7181,6 @@ public class ActivityManagerService extends IActivityManager.Stub } @Override - public final void activityResumed(IBinder token) { - final long origId = Binder.clearCallingIdentity(); - synchronized(this) { - ActivityRecord.activityResumedLocked(token); - mWindowManager.notifyAppResumedFinished(token); - } - Binder.restoreCallingIdentity(origId); - } - - @Override - public final void activityPaused(IBinder token) { - final long origId = Binder.clearCallingIdentity(); - synchronized(this) { - ActivityStack stack = ActivityRecord.getStackLocked(token); - if (stack != null) { - stack.activityPausedLocked(token, false); - } - } - Binder.restoreCallingIdentity(origId); - } - - @Override - public final void activityStopped(IBinder token, Bundle icicle, - PersistableBundle persistentState, CharSequence description) { - if (DEBUG_ALL) Slog.v(TAG, "Activity stopped: token=" + token); - - // Refuse possible leaked file descriptors - if (icicle != null && icicle.hasFileDescriptors()) { - throw new IllegalArgumentException("File descriptors passed in Bundle"); - } - - final long origId = Binder.clearCallingIdentity(); - - synchronized (this) { - final ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r != null) { - r.activityStoppedLocked(icicle, persistentState, description); - } - } - - trimApplications(); - - Binder.restoreCallingIdentity(origId); - } - - @Override - public final void activityDestroyed(IBinder token) { - if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "ACTIVITY DESTROYED: " + token); - synchronized (this) { - ActivityStack stack = ActivityRecord.getStackLocked(token); - if (stack != null) { - stack.activityDestroyedLocked(token, "activityDestroyed"); - } - } - } - - @Override - public final void activityRelaunched(IBinder token) { - final long origId = Binder.clearCallingIdentity(); - synchronized (this) { - mStackSupervisor.activityRelaunchedLocked(token); - } - Binder.restoreCallingIdentity(origId); - } - - @Override - public void reportSizeConfigurations(IBinder token, int[] horizontalSizeConfiguration, - int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) { - if (DEBUG_CONFIGURATION) Slog.v(TAG, "Report configuration: " + token + " " - + horizontalSizeConfiguration + " " + verticalSizeConfigurations); - synchronized (this) { - ActivityRecord record = ActivityRecord.isInStackLocked(token); - if (record == null) { - throw new IllegalArgumentException("reportSizeConfigurations: ActivityRecord not " - + "found for: " + token); - } - record.setSizeConfigurations(horizontalSizeConfiguration, - verticalSizeConfigurations, smallestSizeConfigurations); - } - } - - @Override - public final void notifyLaunchTaskBehindComplete(IBinder token) { - mStackSupervisor.scheduleLaunchTaskBehindComplete(token); - } - - @Override - public final void notifyEnterAnimationComplete(IBinder token) { - mHandler.sendMessage(mHandler.obtainMessage(ENTER_ANIMATION_COMPLETE_MSG, token)); - } - - @Override - public String getCallingPackage(IBinder token) { - synchronized (this) { - ActivityRecord r = getCallingRecordLocked(token); - return r != null ? r.info.packageName : null; - } - } - - @Override - public ComponentName getCallingActivity(IBinder token) { - synchronized (this) { - ActivityRecord r = getCallingRecordLocked(token); - return r != null ? r.intent.getComponent() : null; - } - } - - private ActivityRecord getCallingRecordLocked(IBinder token) { - ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r == null) { - return null; - } - return r.resultTo; - } - - @Override - public ComponentName getActivityClassForToken(IBinder token) { - synchronized(this) { - ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r == null) { - return null; - } - return r.intent.getComponent(); - } - } - - @Override - public String getPackageForToken(IBinder token) { - synchronized(this) { - ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r == null) { - return null; - } - return r.packageName; - } - } - - @Override - public boolean isRootVoiceInteraction(IBinder token) { - synchronized(this) { - ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r == null) { - return false; - } - return r.rootVoiceInteraction; - } - } - - @Override public IIntentSender getIntentSender(int type, String packageName, IBinder token, String resultWho, int requestCode, Intent[] intents, String[] resolvedTypes, @@ -8659,199 +7672,6 @@ public class ActivityManagerService extends IActivityManager.Stub return uidRec == null ? ActivityManager.PROCESS_STATE_NONEXISTENT : uidRec.curProcState; } - @Override - public boolean isInMultiWindowMode(IBinder token) { - final long origId = Binder.clearCallingIdentity(); - try { - synchronized(this) { - final ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r == null) { - return false; - } - // An activity is consider to be in multi-window mode if its task isn't fullscreen. - return r.inMultiWindowMode(); - } - } finally { - Binder.restoreCallingIdentity(origId); - } - } - - @Override - public boolean isInPictureInPictureMode(IBinder token) { - final long origId = Binder.clearCallingIdentity(); - try { - synchronized(this) { - return isInPictureInPictureMode(ActivityRecord.forTokenLocked(token)); - } - } finally { - Binder.restoreCallingIdentity(origId); - } - } - - private boolean isInPictureInPictureMode(ActivityRecord r) { - if (r == null || r.getStack() == null || !r.inPinnedWindowingMode() - || r.getStack().isInStackLocked(r) == null) { - return false; - } - - // If we are animating to fullscreen then we have already dispatched the PIP mode - // changed, so we should reflect that check here as well. - final PinnedActivityStack stack = r.getStack(); - final PinnedStackWindowController windowController = stack.getWindowContainerController(); - return !windowController.isAnimatingBoundsToFullscreen(); - } - - @Override - public boolean enterPictureInPictureMode(IBinder token, final PictureInPictureParams params) { - final long origId = Binder.clearCallingIdentity(); - try { - synchronized(this) { - final ActivityRecord r = ensureValidPictureInPictureActivityParamsLocked( - "enterPictureInPictureMode", token, params); - - // If the activity is already in picture in picture mode, then just return early - if (isInPictureInPictureMode(r)) { - return true; - } - - // Activity supports picture-in-picture, now check that we can enter PiP at this - // point, if it is - if (!r.checkEnterPictureInPictureState("enterPictureInPictureMode", - false /* beforeStopping */)) { - return false; - } - - final Runnable enterPipRunnable = () -> { - // Only update the saved args from the args that are set - r.pictureInPictureArgs.copyOnlySet(params); - final float aspectRatio = r.pictureInPictureArgs.getAspectRatio(); - final List<RemoteAction> actions = r.pictureInPictureArgs.getActions(); - // Adjust the source bounds by the insets for the transition down - final Rect sourceBounds = new Rect(r.pictureInPictureArgs.getSourceRectHint()); - mStackSupervisor.moveActivityToPinnedStackLocked(r, sourceBounds, aspectRatio, - "enterPictureInPictureMode"); - final PinnedActivityStack stack = r.getStack(); - stack.setPictureInPictureAspectRatio(aspectRatio); - stack.setPictureInPictureActions(actions); - MetricsLoggerWrapper.logPictureInPictureEnter(mContext, r.appInfo.uid, - r.shortComponentName, r.supportsEnterPipOnTaskSwitch); - logPictureInPictureArgs(params); - }; - - if (isKeyguardLocked()) { - // If the keyguard is showing or occluded, then try and dismiss it before - // entering picture-in-picture (this will prompt the user to authenticate if the - // device is currently locked). - try { - dismissKeyguard(token, new KeyguardDismissCallback() { - @Override - public void onDismissSucceeded() throws RemoteException { - mHandler.post(enterPipRunnable); - } - }, null /* message */); - } catch (RemoteException e) { - // Local call - } - } else { - // Enter picture in picture immediately otherwise - enterPipRunnable.run(); - } - return true; - } - } finally { - Binder.restoreCallingIdentity(origId); - } - } - - @Override - public void setPictureInPictureParams(IBinder token, final PictureInPictureParams params) { - final long origId = Binder.clearCallingIdentity(); - try { - synchronized(this) { - final ActivityRecord r = ensureValidPictureInPictureActivityParamsLocked( - "setPictureInPictureParams", token, params); - - // Only update the saved args from the args that are set - r.pictureInPictureArgs.copyOnlySet(params); - if (r.inPinnedWindowingMode()) { - // If the activity is already in picture-in-picture, update the pinned stack now - // if it is not already expanding to fullscreen. Otherwise, the arguments will - // be used the next time the activity enters PiP - final PinnedActivityStack stack = r.getStack(); - if (!stack.isAnimatingBoundsToFullscreen()) { - stack.setPictureInPictureAspectRatio( - r.pictureInPictureArgs.getAspectRatio()); - stack.setPictureInPictureActions(r.pictureInPictureArgs.getActions()); - } - } - logPictureInPictureArgs(params); - } - } finally { - Binder.restoreCallingIdentity(origId); - } - } - - @Override - public int getMaxNumPictureInPictureActions(IBinder token) { - // Currently, this is a static constant, but later, we may change this to be dependent on - // the context of the activity - return 3; - } - - private void logPictureInPictureArgs(PictureInPictureParams params) { - if (params.hasSetActions()) { - MetricsLogger.histogram(mContext, "tron_varz_picture_in_picture_actions_count", - params.getActions().size()); - } - if (params.hasSetAspectRatio()) { - LogMaker lm = new LogMaker(MetricsEvent.ACTION_PICTURE_IN_PICTURE_ASPECT_RATIO_CHANGED); - lm.addTaggedData(MetricsEvent.PICTURE_IN_PICTURE_ASPECT_RATIO, params.getAspectRatio()); - MetricsLogger.action(lm); - } - } - - /** - * Checks the state of the system and the activity associated with the given {@param token} to - * verify that picture-in-picture is supported for that activity. - * - * @return the activity record for the given {@param token} if all the checks pass. - */ - private ActivityRecord ensureValidPictureInPictureActivityParamsLocked(String caller, - IBinder token, PictureInPictureParams params) { - if (!mSupportsPictureInPicture) { - throw new IllegalStateException(caller - + ": Device doesn't support picture-in-picture mode."); - } - - final ActivityRecord r = ActivityRecord.forTokenLocked(token); - if (r == null) { - throw new IllegalStateException(caller - + ": Can't find activity for token=" + token); - } - - if (!r.supportsPictureInPicture()) { - throw new IllegalStateException(caller - + ": Current activity does not support picture-in-picture."); - } - - if (params.hasSetAspectRatio() - && !mWindowManager.isValidPictureInPictureAspectRatio(r.getStack().mDisplayId, - params.getAspectRatio())) { - final float minAspectRatio = mContext.getResources().getFloat( - com.android.internal.R.dimen.config_pictureInPictureMinAspectRatio); - final float maxAspectRatio = mContext.getResources().getFloat( - com.android.internal.R.dimen.config_pictureInPictureMaxAspectRatio); - throw new IllegalArgumentException(String.format(caller - + ": Aspect ratio is too extreme (must be between %f and %f).", - minAspectRatio, maxAspectRatio)); - } - - // Truncate the number of actions if necessary - params.truncateActions(getMaxNumPictureInPictureActions(token)); - - return r; - } - // ========================================================= // PROCESS INFO // ========================================================= @@ -10066,18 +8886,6 @@ public class ActivityManagerService extends IActivityManager.Stub } } - @Override - public IBinder getUriPermissionOwnerForActivity(IBinder activityToken) { - enforceNotIsolatedCaller("getUriPermissionOwnerForActivity"); - synchronized(this) { - ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); - if (r == null) { - throw new IllegalArgumentException("Activity does not exist; token=" - + activityToken); - } - return r.getUriPermissionsLocked().getExternalTokenLocked(); - } - } /** * @param uri This uri must NOT contain an embedded userId. * @param sourceUserId The userId in which the uri is to be resolved. @@ -10527,21 +9335,8 @@ public class ActivityManagerService extends IActivityManager.Stub // ========================================================= @Override - public List<IBinder> getAppTasks(String callingPackage) { - int callingUid = Binder.getCallingUid(); - long ident = Binder.clearCallingIdentity(); - try { - synchronized(this) { - return mRecentTasks.getAppTasksList(callingUid, callingPackage); - } - } finally { - Binder.restoreCallingIdentity(ident); - } - } - - @Override public List<RunningTaskInfo> getTasks(int maxNum) { - return mActivityTaskManager.getTasks(maxNum); + return mActivityTaskManager.getTasks(maxNum); } @Override @@ -10551,6 +9346,11 @@ public class ActivityManagerService extends IActivityManager.Stub maxNum, ignoreActivityType, ignoreWindowingMode); } + @Override + public void cancelTaskWindowTransition(int taskId) { + mActivityTaskManager.cancelTaskWindowTransition(taskId); + } + boolean isGetTasksAllowed(String caller, int callingPid, int callingUid) { if (mRecentTasks.isCallerRecents(callingUid)) { // Always allow the recents component to get tasks @@ -10584,394 +9384,38 @@ public class ActivityManagerService extends IActivityManager.Stub } @Override - public ParceledListSlice<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum, int flags, - int userId) { - final int callingUid = Binder.getCallingUid(); - userId = mUserController.handleIncomingUser(Binder.getCallingPid(), callingUid, userId, - false, ALLOW_FULL_ONLY, "getRecentTasks", null); - final boolean allowed = isGetTasksAllowed("getRecentTasks", Binder.getCallingPid(), - callingUid); - final boolean detailed = checkCallingPermission( - android.Manifest.permission.GET_DETAILED_TASKS) - == PackageManager.PERMISSION_GRANTED; - - synchronized (this) { - return mRecentTasks.getRecentTasks(maxNum, flags, allowed, detailed, userId, - callingUid); - } - } - - @Override - public ActivityManager.TaskDescription getTaskDescription(int id) { - synchronized (this) { - enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getTaskDescription()"); - final TaskRecord tr = mStackSupervisor.anyTaskForIdLocked(id, - MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); - if (tr != null) { - return tr.lastTaskDescription; - } - } - return null; - } - - @Override - public int addAppTask(IBinder activityToken, Intent intent, - ActivityManager.TaskDescription description, Bitmap thumbnail) throws RemoteException { - final int callingUid = Binder.getCallingUid(); - final long callingIdent = Binder.clearCallingIdentity(); - - try { - synchronized (this) { - ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); - if (r == null) { - throw new IllegalArgumentException("Activity does not exist; token=" - + activityToken); - } - ComponentName comp = intent.getComponent(); - if (comp == null) { - throw new IllegalArgumentException("Intent " + intent - + " must specify explicit component"); - } - if (thumbnail.getWidth() != mThumbnailWidth - || thumbnail.getHeight() != mThumbnailHeight) { - throw new IllegalArgumentException("Bad thumbnail size: got " - + thumbnail.getWidth() + "x" + thumbnail.getHeight() + ", require " - + mThumbnailWidth + "x" + mThumbnailHeight); - } - if (intent.getSelector() != null) { - intent.setSelector(null); - } - if (intent.getSourceBounds() != null) { - intent.setSourceBounds(null); - } - if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0) { - if ((intent.getFlags()&Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS) == 0) { - // The caller has added this as an auto-remove task... that makes no - // sense, so turn off auto-remove. - intent.addFlags(Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS); - } - } - final ActivityInfo ainfo = AppGlobals.getPackageManager().getActivityInfo(comp, - STOCK_PM_FLAGS, 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 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; - } - task.lastTaskDescription.copyFrom(description); - - // TODO: Send the thumbnail to WM to store it. - - return task.taskId; - } - } finally { - Binder.restoreCallingIdentity(callingIdent); - } - } - - @Override - public Point getAppTaskThumbnailSize() { - synchronized (this) { - return new Point(mThumbnailWidth, mThumbnailHeight); - } - } - - @Override - public void setTaskDescription(IBinder token, ActivityManager.TaskDescription td) { - synchronized (this) { - ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r != null) { - r.setTaskDescription(td); - final TaskRecord task = r.getTask(); - task.updateTaskDescription(); - mTaskChangeNotificationController.notifyTaskDescriptionChanged(task.taskId, td); - } - } + public void setTaskResizeable(int taskId, int resizeableMode) { + mActivityTaskManager.setTaskResizeable(taskId, resizeableMode); } @Override - public void setTaskResizeable(int taskId, int resizeableMode) { - synchronized (this) { - final TaskRecord task = mStackSupervisor.anyTaskForIdLocked( - taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); - if (task == null) { - Slog.w(TAG, "setTaskResizeable: taskId=" + taskId + " not found"); - return; - } - task.setResizeMode(resizeableMode); - } + public ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean reducedResolution) { + return mActivityTaskManager.getTaskSnapshot(taskId, reducedResolution); } @Override public void resizeTask(int taskId, Rect bounds, int resizeMode) { - enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "resizeTask()"); - long ident = Binder.clearCallingIdentity(); - try { - synchronized (this) { - TaskRecord task = mStackSupervisor.anyTaskForIdLocked(taskId); - if (task == null) { - Slog.w(TAG, "resizeTask: taskId=" + taskId + " not found"); - return; - } - // Place the task in the right stack if it isn't there already based on - // the requested bounds. - // The stack transition logic is: - // - a null bounds on a freeform task moves that task to fullscreen - // - a non-null bounds on a non-freeform (fullscreen OR docked) task moves - // that task to freeform - // - otherwise the task is not moved - ActivityStack stack = task.getStack(); - if (!task.getWindowConfiguration().canResizeTask()) { - throw new IllegalArgumentException("resizeTask not allowed on task=" + task); - } - if (bounds == null && stack.getWindowingMode() == WINDOWING_MODE_FREEFORM) { - stack = stack.getDisplay().getOrCreateStack( - WINDOWING_MODE_FULLSCREEN, stack.getActivityType(), ON_TOP); - } else if (bounds != null && stack.getWindowingMode() != WINDOWING_MODE_FREEFORM) { - stack = stack.getDisplay().getOrCreateStack( - WINDOWING_MODE_FREEFORM, stack.getActivityType(), ON_TOP); - } - - // Reparent the task to the right stack if necessary - boolean preserveWindow = (resizeMode & RESIZE_MODE_PRESERVE_WINDOW) != 0; - if (stack != task.getStack()) { - // Defer resume until the task is resized below - task.reparent(stack, ON_TOP, REPARENT_KEEP_STACK_AT_FRONT, ANIMATE, - DEFER_RESUME, "resizeTask"); - preserveWindow = false; - } - - // After reparenting (which only resizes the task to the stack bounds), resize the - // task to the actual bounds provided - task.resize(bounds, resizeMode, preserveWindow, !DEFER_RESUME); - } - } finally { - Binder.restoreCallingIdentity(ident); - } + mActivityTaskManager.resizeTask(taskId, bounds, resizeMode); } @Override public Rect getTaskBounds(int taskId) { - enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "getTaskBounds()"); - long ident = Binder.clearCallingIdentity(); - Rect rect = new Rect(); - try { - synchronized (this) { - final TaskRecord task = mStackSupervisor.anyTaskForIdLocked(taskId, - MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); - if (task == null) { - Slog.w(TAG, "getTaskBounds: taskId=" + taskId + " not found"); - return rect; - } - if (task.getStack() != null) { - // Return the bounds from window manager since it will be adjusted for various - // things like the presense of a docked stack for tasks that aren't resizeable. - task.getWindowContainerBounds(rect); - } else { - // Task isn't in window manager yet since it isn't associated with a stack. - // Return the persist value from activity manager - if (!task.matchParentBounds()) { - rect.set(task.getBounds()); - } else if (task.mLastNonFullscreenBounds != null) { - rect.set(task.mLastNonFullscreenBounds); - } - } - } - } finally { - Binder.restoreCallingIdentity(ident); - } - return rect; - } - - @Override - public void cancelTaskWindowTransition(int taskId) { - enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, - "cancelTaskWindowTransition()"); - final long ident = Binder.clearCallingIdentity(); - try { - synchronized (this) { - final TaskRecord task = mStackSupervisor.anyTaskForIdLocked(taskId, - MATCH_TASK_IN_STACKS_ONLY); - if (task == null) { - Slog.w(TAG, "cancelTaskWindowTransition: taskId=" + taskId + " not found"); - return; - } - task.cancelWindowTransition(); - } - } finally { - Binder.restoreCallingIdentity(ident); - } - } - - @Override - public TaskSnapshot getTaskSnapshot(int taskId, boolean reducedResolution) { - enforceCallerIsRecentsOrHasPermission(READ_FRAME_BUFFER, "getTaskSnapshot()"); - final long ident = Binder.clearCallingIdentity(); - try { - final TaskRecord task; - synchronized (this) { - task = mStackSupervisor.anyTaskForIdLocked(taskId, - MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); - if (task == null) { - Slog.w(TAG, "getTaskSnapshot: taskId=" + taskId + " not found"); - return null; - } - } - // Don't call this while holding the lock as this operation might hit the disk. - return task.getSnapshot(reducedResolution); - } finally { - Binder.restoreCallingIdentity(ident); - } - } - - @Override - public Bitmap getTaskDescriptionIcon(String filePath, int userId) { - userId = mUserController.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), - userId, false, ALLOW_FULL_ONLY, "getTaskDescriptionIcon", null); - - final File passedIconFile = new File(filePath); - final File legitIconFile = new File(TaskPersister.getUserImagesDir(userId), - passedIconFile.getName()); - if (!legitIconFile.getPath().equals(filePath) - || !filePath.contains(ActivityRecord.ACTIVITY_ICON_SUFFIX)) { - throw new IllegalArgumentException("Bad file path: " + filePath - + " passed for userId " + userId); - } - return mRecentTasks.getTaskDescriptionIcon(filePath); - } - - @Override - public void startInPlaceAnimationOnFrontMostApplication(Bundle opts) - throws RemoteException { - final SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(opts); - final ActivityOptions activityOptions = safeOptions != null - ? safeOptions.getOptions(mStackSupervisor) - : null; - if (activityOptions == null - || activityOptions.getAnimationType() != ActivityOptions.ANIM_CUSTOM_IN_PLACE - || activityOptions.getCustomInPlaceResId() == 0) { - throw new IllegalArgumentException("Expected in-place ActivityOption " + - "with valid animation"); - } - mWindowManager.prepareAppTransition(TRANSIT_TASK_IN_PLACE, false); - mWindowManager.overridePendingAppTransitionInPlace(activityOptions.getPackageName(), - activityOptions.getCustomInPlaceResId()); - mWindowManager.executeAppTransition(); + return mActivityTaskManager.getTaskBounds(taskId); } @Override public void removeStack(int stackId) { - enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "removeStack()"); - synchronized (this) { - final long ident = Binder.clearCallingIdentity(); - try { - final ActivityStack stack = mStackSupervisor.getStack(stackId); - if (stack == null) { - Slog.w(TAG, "removeStack: No stack with id=" + stackId); - return; - } - if (!stack.isActivityTypeStandardOrUndefined()) { - throw new IllegalArgumentException( - "Removing non-standard stack is not allowed."); - } - mStackSupervisor.removeStack(stack); - } finally { - Binder.restoreCallingIdentity(ident); - } - } - } - - @Override - public void moveStackToDisplay(int stackId, int displayId) { - enforceCallingPermission(INTERNAL_SYSTEM_WINDOW, "moveStackToDisplay()"); - - synchronized (this) { - final long ident = Binder.clearCallingIdentity(); - try { - if (DEBUG_STACK) Slog.d(TAG_STACK, "moveStackToDisplay: moving stackId=" + stackId - + " to displayId=" + displayId); - mStackSupervisor.moveStackToDisplayLocked(stackId, displayId, ON_TOP); - } finally { - Binder.restoreCallingIdentity(ident); - } - } + mActivityTaskManager.removeStack(stackId); } @Override public boolean removeTask(int taskId) { - enforceCallerIsRecentsOrHasPermission(REMOVE_TASKS, "removeTask()"); - synchronized (this) { - final long ident = Binder.clearCallingIdentity(); - try { - return mStackSupervisor.removeTaskByIdLocked(taskId, true, REMOVE_FROM_RECENTS, - "remove-task"); - } finally { - Binder.restoreCallingIdentity(ident); - } - } + return mActivityTaskManager.removeTask(taskId); } - /** - * TODO: Add mController hook - */ @Override public void moveTaskToFront(int taskId, int flags, Bundle bOptions) { - enforceCallingPermission(android.Manifest.permission.REORDER_TASKS, "moveTaskToFront()"); - - if (DEBUG_STACK) Slog.d(TAG_STACK, "moveTaskToFront: moving taskId=" + taskId); - synchronized(this) { - moveTaskToFrontLocked(taskId, flags, SafeActivityOptions.fromBundle(bOptions), - false /* fromRecents */); - } - } - - void moveTaskToFrontLocked(int taskId, int flags, SafeActivityOptions options, - boolean fromRecents) { - - if (!checkAppSwitchAllowedLocked(Binder.getCallingPid(), - Binder.getCallingUid(), -1, -1, "Task to front")) { - SafeActivityOptions.abort(options); - return; - } - final long origId = Binder.clearCallingIdentity(); - try { - final TaskRecord task = mStackSupervisor.anyTaskForIdLocked(taskId); - if (task == null) { - Slog.d(TAG, "Could not find task for id: "+ taskId); - return; - } - if (mLockTaskController.isLockTaskModeViolation(task)) { - Slog.e(TAG, "moveTaskToFront: Attempt to violate Lock Task Mode"); - return; - } - ActivityOptions realOptions = options != null - ? options.getOptions(mStackSupervisor) - : null; - mStackSupervisor.findTaskToMoveToFront(task, flags, realOptions, "moveTaskToFront", - false /* forceNonResizable */); - - final ActivityRecord topActivity = task.getTopActivity(); - if (topActivity != null) { - - // We are reshowing a task, use a starting window to hide the initial draw delay - // so the transition can start earlier. - topActivity.showStartingWindow(null /* prev */, false /* newTask */, - true /* taskSwitch */, fromRecents); - } - } finally { - Binder.restoreCallingIdentity(origId); - } - SafeActivityOptions.abort(options); + mActivityTaskManager.moveTaskToFront(taskId, flags, bOptions); } /** @@ -10995,92 +9439,7 @@ public class ActivityManagerService extends IActivityManager.Stub */ @Override public boolean moveActivityTaskToBack(IBinder token, boolean nonRoot) { - enforceNotIsolatedCaller("moveActivityTaskToBack"); - synchronized(this) { - final long origId = Binder.clearCallingIdentity(); - try { - int taskId = ActivityRecord.getTaskForActivityLocked(token, !nonRoot); - final TaskRecord task = mStackSupervisor.anyTaskForIdLocked(taskId); - if (task != null) { - return ActivityRecord.getStackLocked(token).moveTaskToBackLocked(taskId); - } - } finally { - Binder.restoreCallingIdentity(origId); - } - } - return false; - } - - @Override - public void moveTaskBackwards(int task) { - enforceCallingPermission(android.Manifest.permission.REORDER_TASKS, - "moveTaskBackwards()"); - - synchronized(this) { - if (!checkAppSwitchAllowedLocked(Binder.getCallingPid(), - Binder.getCallingUid(), -1, -1, "Task backwards")) { - return; - } - final long origId = Binder.clearCallingIdentity(); - moveTaskBackwardsLocked(task); - Binder.restoreCallingIdentity(origId); - } - } - - private final void moveTaskBackwardsLocked(int task) { - Slog.e(TAG, "moveTaskBackwards not yet implemented!"); - } - - @Override - public int createStackOnDisplay(int displayId) throws RemoteException { - enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "createStackOnDisplay()"); - synchronized (this) { - final ActivityDisplay display = - mStackSupervisor.getActivityDisplayOrCreateLocked(displayId); - if (display == null) { - return INVALID_STACK_ID; - } - // TODO(multi-display): Have the caller pass in the windowing mode and activity type. - final ActivityStack stack = display.createStack( - WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_STANDARD, - ON_TOP); - return (stack != null) ? stack.mStackId : INVALID_STACK_ID; - } - } - - @Override - public int getActivityDisplayId(IBinder activityToken) throws RemoteException { - synchronized (this) { - final ActivityStack stack = ActivityRecord.getStackLocked(activityToken); - if (stack != null && stack.mDisplayId != INVALID_DISPLAY) { - return stack.mDisplayId; - } - return DEFAULT_DISPLAY; - } - } - - @Override - public void exitFreeformMode(IBinder token) throws RemoteException { - synchronized (this) { - long ident = Binder.clearCallingIdentity(); - try { - final ActivityRecord r = ActivityRecord.forTokenLocked(token); - if (r == null) { - throw new IllegalArgumentException( - "exitFreeformMode: No activity record matching token=" + token); - } - - final ActivityStack stack = r.getStack(); - if (stack == null || !stack.inFreeformWindowingMode()) { - throw new IllegalStateException( - "exitFreeformMode: You can only go fullscreen from freeform."); - } - - stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); - } finally { - Binder.restoreCallingIdentity(ident); - } - } + return mActivityTaskManager.moveActivityTaskToBack(token, nonRoot); } @Override @@ -11088,77 +9447,17 @@ public class ActivityManagerService extends IActivityManager.Stub mActivityTaskManager.moveTaskToStack(taskId, stackId, toTop); } - /** - * Dismisses split-screen multi-window mode. - * @param toTop If true the current primary split-screen stack will be placed or left on top. - */ @Override - public void dismissSplitScreenMode(boolean toTop) { - enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "dismissSplitScreenMode()"); - final long ident = Binder.clearCallingIdentity(); - try { - synchronized (this) { - final ActivityStack stack = - mStackSupervisor.getDefaultDisplay().getSplitScreenPrimaryStack(); - if (stack == null) { - Slog.w(TAG, "dismissSplitScreenMode: primary split-screen stack not found."); - return; - } - - if (toTop) { - // Caller wants the current split-screen primary stack to be the top stack after - // it goes fullscreen, so move it to the front. - stack.moveToFront("dismissSplitScreenMode"); - } else if (mStackSupervisor.isFocusedStack(stack)) { - // In this case the current split-screen primary stack shouldn't be the top - // stack after it goes fullscreen, but it current has focus, so we move the - // focus to the top-most split-screen secondary stack next to it. - final ActivityStack otherStack = stack.getDisplay().getTopStackInWindowingMode( - WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); - if (otherStack != null) { - otherStack.moveToFront("dismissSplitScreenMode_other"); - } - } - - stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); - } - } finally { - Binder.restoreCallingIdentity(ident); - } + public void resizeStack(int stackId, Rect destBounds, boolean allowResizeInDockedMode, + boolean preserveWindows, boolean animate, int animationDuration) { + mActivityTaskManager.resizeStack(stackId, destBounds, allowResizeInDockedMode, + preserveWindows, animate, animationDuration); } - /** - * Dismisses Pip - * @param animate True if the dismissal should be animated. - * @param animationDuration The duration of the resize animation in milliseconds or -1 if the - * default animation duration should be used. - */ @Override - public void dismissPip(boolean animate, int animationDuration) { - enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "dismissPip()"); - final long ident = Binder.clearCallingIdentity(); - try { - synchronized (this) { - final PinnedActivityStack stack = - mStackSupervisor.getDefaultDisplay().getPinnedStack(); - if (stack == null) { - Slog.w(TAG, "dismissPip: pinned stack not found."); - return; - } - if (stack.getWindowingMode() != WINDOWING_MODE_PINNED) { - throw new IllegalArgumentException("Stack: " + stack - + " doesn't support animated resize."); - } - if (animate) { - stack.animateResizePinnedStack(null /* sourceHintBounds */, - null /* destBounds */, animationDuration, false /* fromFullscreen */); - } else { - mStackSupervisor.moveTasksToFullscreenStackLocked(stack, true /* onTop */); - } - } - } finally { - Binder.restoreCallingIdentity(ident); - } + public ParceledListSlice<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum, int flags, + int userId) { + return mActivityTaskManager.getRecentTasks(maxNum, flags, userId); } /** @@ -11172,150 +9471,30 @@ public class ActivityManagerService extends IActivityManager.Stub */ @Override public boolean moveTopActivityToPinnedStack(int stackId, Rect bounds) { - enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, - "moveTopActivityToPinnedStack()"); - synchronized (this) { - if (!mSupportsPictureInPicture) { - throw new IllegalStateException("moveTopActivityToPinnedStack:" - + "Device doesn't support picture-in-picture mode"); - } - - long ident = Binder.clearCallingIdentity(); - try { - return mStackSupervisor.moveTopStackActivityToPinnedStackLocked(stackId, bounds); - } finally { - Binder.restoreCallingIdentity(ident); - } - } - } - - @Override - public void resizeStack(int stackId, Rect destBounds, boolean allowResizeInDockedMode, - boolean preserveWindows, boolean animate, int animationDuration) { - mActivityTaskManager.resizeStack(stackId, destBounds, allowResizeInDockedMode, - preserveWindows, animate, animationDuration); + return mActivityTaskManager.moveTopActivityToPinnedStack(stackId, bounds); } @Override public void resizeDockedStack(Rect dockedBounds, Rect tempDockedTaskBounds, Rect tempDockedTaskInsetBounds, Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds) { - enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizeDockedStack()"); - long ident = Binder.clearCallingIdentity(); - try { - synchronized (this) { - mStackSupervisor.resizeDockedStackLocked(dockedBounds, tempDockedTaskBounds, - tempDockedTaskInsetBounds, tempOtherTaskBounds, tempOtherTaskInsetBounds, - PRESERVE_WINDOWS); - } - } finally { - Binder.restoreCallingIdentity(ident); - } - } - - @Override - public void setSplitScreenResizing(boolean resizing) { - enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "setSplitScreenResizing()"); - final long ident = Binder.clearCallingIdentity(); - try { - synchronized (this) { - mStackSupervisor.setSplitScreenResizing(resizing); - } - } finally { - Binder.restoreCallingIdentity(ident); - } - } - - @Override - public void resizePinnedStack(Rect pinnedBounds, Rect tempPinnedTaskBounds) { - enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizePinnedStack()"); - final long ident = Binder.clearCallingIdentity(); - try { - synchronized (this) { - mStackSupervisor.resizePinnedStackLocked(pinnedBounds, tempPinnedTaskBounds); - } - } finally { - Binder.restoreCallingIdentity(ident); - } + mActivityTaskManager.resizeDockedStack(dockedBounds, tempDockedTaskBounds, + tempDockedTaskInsetBounds, tempOtherTaskBounds, tempOtherTaskInsetBounds); } - /** - * Try to place task to provided position. The final position might be different depending on - * current user and stacks state. The task will be moved to target stack if it's currently in - * different stack. - */ @Override public void positionTaskInStack(int taskId, int stackId, int position) { - enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "positionTaskInStack()"); - synchronized (this) { - long ident = Binder.clearCallingIdentity(); - try { - if (DEBUG_STACK) Slog.d(TAG_STACK, "positionTaskInStack: positioning task=" - + taskId + " in stackId=" + stackId + " at position=" + position); - final TaskRecord task = mStackSupervisor.anyTaskForIdLocked(taskId); - if (task == null) { - throw new IllegalArgumentException("positionTaskInStack: no task for id=" - + taskId); - } - - final ActivityStack stack = mStackSupervisor.getStack(stackId); - - if (stack == null) { - throw new IllegalArgumentException("positionTaskInStack: no stack for id=" - + stackId); - } - if (!stack.isActivityTypeStandardOrUndefined()) { - throw new IllegalArgumentException("positionTaskInStack: Attempt to change" - + " the position of task " + taskId + " in/to non-standard stack"); - } - - // TODO: Have the callers of this API call a separate reparent method if that is - // what they intended to do vs. having this method also do reparenting. - if (task.getStack() == stack) { - // Change position in current stack. - stack.positionChildAt(task, position); - } else { - // Reparent to new stack. - task.reparent(stack, position, REPARENT_LEAVE_STACK_IN_PLACE, !ANIMATE, - !DEFER_RESUME, "positionTaskInStack"); - } - } finally { - Binder.restoreCallingIdentity(ident); - } - } + mActivityTaskManager.positionTaskInStack(taskId, stackId, position); } @Override public List<StackInfo> getAllStackInfos() { - enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getAllStackInfos()"); - long ident = Binder.clearCallingIdentity(); - try { - synchronized (this) { - return mStackSupervisor.getAllStackInfosLocked(); - } - } finally { - Binder.restoreCallingIdentity(ident); - } - } - - @Override - public StackInfo getStackInfo(int windowingMode, int activityType) { - enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); - long ident = Binder.clearCallingIdentity(); - try { - synchronized (this) { - return mStackSupervisor.getStackInfo(windowingMode, activityType); - } - } finally { - Binder.restoreCallingIdentity(ident); - } + return mActivityTaskManager.getAllStackInfos(); } @Override public int getTaskForActivity(IBinder token, boolean onlyRoot) { - synchronized(this) { - return ActivityRecord.getTaskForActivityLocked(token, onlyRoot); - } + return mActivityTaskManager.getTaskForActivity(token, onlyRoot); } @Override @@ -11344,156 +9523,18 @@ public class ActivityManagerService extends IActivityManager.Stub } @Override - public void updateLockTaskFeatures(int userId, int flags) { - final int callingUid = Binder.getCallingUid(); - if (callingUid != 0 && callingUid != SYSTEM_UID) { - enforceCallingPermission(android.Manifest.permission.UPDATE_LOCK_TASK_PACKAGES, - "updateLockTaskFeatures()"); - } - synchronized (this) { - if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "Allowing features " + userId + ":0x" + - Integer.toHexString(flags)); - mLockTaskController.updateLockTaskFeatures(userId, flags); - } - } - - private void startLockTaskModeLocked(@Nullable TaskRecord task, boolean isSystemCaller) { - if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "startLockTaskModeLocked: " + task); - if (task == null || task.mLockTaskAuth == LOCK_TASK_AUTH_DONT_LOCK) { - return; - } - - final ActivityStack stack = mStackSupervisor.getFocusedStack(); - if (stack == null || task != stack.topTask()) { - throw new IllegalArgumentException("Invalid task, not in foreground"); - } - - // {@code isSystemCaller} is used to distinguish whether this request is initiated by the - // system or a specific app. - // * System-initiated requests will only start the pinned mode (screen pinning) - // * App-initiated requests - // - will put the device in fully locked mode (LockTask), if the app is whitelisted - // - will start the pinned mode, otherwise - final int callingUid = Binder.getCallingUid(); - long ident = Binder.clearCallingIdentity(); - try { - // When a task is locked, dismiss the pinned stack if it exists - mStackSupervisor.removeStacksInWindowingModes(WINDOWING_MODE_PINNED); - - mLockTaskController.startLockTaskMode(task, isSystemCaller, callingUid); - } finally { - Binder.restoreCallingIdentity(ident); - } - } - - @Override - public void startLockTaskModeByToken(IBinder token) { - synchronized (this) { - final ActivityRecord r = ActivityRecord.forTokenLocked(token); - if (r == null) { - return; - } - startLockTaskModeLocked(r.getTask(), false /* isSystemCaller */); - } - } - - @Override - public void startSystemLockTaskMode(int taskId) throws RemoteException { - enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "startSystemLockTaskMode"); - // This makes inner call to look as if it was initiated by system. - long ident = Binder.clearCallingIdentity(); - try { - synchronized (this) { - final TaskRecord task = mStackSupervisor.anyTaskForIdLocked(taskId); - - // When starting lock task mode the stack must be in front and focused - task.getStack().moveToFront("startSystemLockTaskMode"); - startLockTaskModeLocked(task, true /* isSystemCaller */); - } - } finally { - Binder.restoreCallingIdentity(ident); - } - } - - @Override - public void stopLockTaskModeByToken(IBinder token) { - synchronized (this) { - final ActivityRecord r = ActivityRecord.forTokenLocked(token); - if (r == null) { - return; - } - stopLockTaskModeInternal(r.getTask(), false /* isSystemCaller */); - } - } - - /** - * This API should be called by SystemUI only when user perform certain action to dismiss - * lock task mode. We should only dismiss pinned lock task mode in this case. - */ - @Override - public void stopSystemLockTaskMode() throws RemoteException { - enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "stopSystemLockTaskMode"); - stopLockTaskModeInternal(null, true /* isSystemCaller */); - } - - private void stopLockTaskModeInternal(@Nullable TaskRecord task, boolean isSystemCaller) { - final int callingUid = Binder.getCallingUid(); - long ident = Binder.clearCallingIdentity(); - try { - synchronized (this) { - mLockTaskController.stopLockTaskMode(task, isSystemCaller, callingUid); - } - // Launch in-call UI if a call is ongoing. This is necessary to allow stopping the lock - // task and jumping straight into a call in the case of emergency call back. - TelecomManager tm = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); - if (tm != null) { - tm.showInCallScreen(false); - } - } finally { - Binder.restoreCallingIdentity(ident); - } - } - - @Override public boolean isInLockTaskMode() { - return getLockTaskModeState() != LOCK_TASK_MODE_NONE; + return mActivityTaskManager.isInLockTaskMode(); } @Override public int getLockTaskModeState() { - synchronized (this) { - return mLockTaskController.getLockTaskModeState(); - } + return mActivityTaskManager.getLockTaskModeState(); } @Override - public void showLockTaskEscapeMessage(IBinder token) { - synchronized (this) { - final ActivityRecord r = ActivityRecord.forTokenLocked(token); - if (r == null) { - return; - } - mLockTaskController.showLockTaskToast(); - } - } - - @Override - public void setDisablePreviewScreenshots(IBinder token, boolean disable) - throws RemoteException { - synchronized (this) { - final ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r == null) { - Slog.w(TAG, "setDisablePreviewScreenshots: Unable to find activity for token=" - + token); - return; - } - final long origId = Binder.clearCallingIdentity(); - try { - r.setDisablePreviewScreenshots(disable); - } finally { - Binder.restoreCallingIdentity(origId); - } - } + public void startSystemLockTaskMode(int taskId) throws RemoteException { + mActivityTaskManager.startSystemLockTaskMode(taskId); } // ========================================================= @@ -12893,17 +10934,7 @@ public class ActivityManagerService extends IActivityManager.Stub } public void unhandledBack() { - enforceCallingPermission(android.Manifest.permission.FORCE_BACK, - "unhandledBack()"); - - synchronized(this) { - final long origId = Binder.clearCallingIdentity(); - try { - getFocusedStack().unhandledBackLocked(); - } finally { - Binder.restoreCallingIdentity(origId); - } - } + mActivityTaskManager.unhandledBack(); } public ParcelFileDescriptor openContentUri(String uriString) throws RemoteException { @@ -12970,12 +11001,6 @@ public class ActivityManagerService extends IActivityManager.Stub : UsageEvents.Event.SCREEN_NON_INTERACTIVE); } - void reportCurKeyguardUsageEventLocked() { - reportGlobalUsageEventLocked(mKeyguardShown - ? UsageEvents.Event.KEYGUARD_SHOWN - : UsageEvents.Event.KEYGUARD_HIDDEN); - } - void onWakefulnessChanged(int wakefulness) { synchronized(this) { boolean wasAwake = mWakefulness == PowerManagerInternal.WAKEFULNESS_AWAKE; @@ -13045,22 +11070,6 @@ public class ActivityManagerService extends IActivityManager.Stub mRecentTasks.notifyTaskPersisterLocked(task, flush); } - /** - * Notifies all listeners when the pinned stack animation starts. - */ - @Override - public void notifyPinnedStackAnimationStarted() { - mTaskChangeNotificationController.notifyPinnedStackAnimationStarted(); - } - - /** - * Notifies all listeners when the pinned stack animation ends. - */ - @Override - public void notifyPinnedStackAnimationEnded() { - mTaskChangeNotificationController.notifyPinnedStackAnimationEnded(); - } - @Override public void notifyCleartextNetwork(int uid, byte[] firstPacket) { mHandler.obtainMessage(NOTIFY_CLEARTEXT_NETWORK_MSG, uid, 0, firstPacket).sendToTarget(); @@ -13096,21 +11105,6 @@ public class ActivityManagerService extends IActivityManager.Stub return timedout; } - public final void activitySlept(IBinder token) { - if (DEBUG_ALL) Slog.v(TAG, "Activity slept: token=" + token); - - final long origId = Binder.clearCallingIdentity(); - - synchronized (this) { - final ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r != null) { - mStackSupervisor.activitySleptLocked(r); - } - } - - Binder.restoreCallingIdentity(origId); - } - @GuardedBy("this") void startRunningVoiceLocked(IVoiceInteractionSession session, int targetUid) { Slog.d(TAG, "<<< startRunningVoiceLocked()"); @@ -13132,28 +11126,8 @@ public class ActivityManagerService extends IActivityManager.Stub @Override public void setLockScreenShown(boolean keyguardShowing, boolean aodShowing, int secondaryDisplayShowing) { - if (checkCallingPermission(android.Manifest.permission.DEVICE_POWER) - != PackageManager.PERMISSION_GRANTED) { - throw new SecurityException("Requires permission " - + android.Manifest.permission.DEVICE_POWER); - } - - synchronized(this) { - long ident = Binder.clearCallingIdentity(); - if (mKeyguardShown != keyguardShowing) { - mKeyguardShown = keyguardShowing; - reportCurKeyguardUsageEventLocked(); - } - try { - mKeyguardController.setKeyguardShown(keyguardShowing, aodShowing, - secondaryDisplayShowing); - } finally { - Binder.restoreCallingIdentity(ident); - } - } - - mHandler.obtainMessage(DISPATCH_SCREEN_KEYGUARD_MSG, keyguardShowing ? 1 : 0, 0) - .sendToTarget(); + mActivityTaskManager.setLockScreenShown( + keyguardShowing, aodShowing, secondaryDisplayShowing); } @Override @@ -13644,266 +11618,6 @@ public class ActivityManagerService extends IActivityManager.Stub return true; } - @Override - public Bundle getAssistContextExtras(int requestType) { - PendingAssistExtras pae = enqueueAssistContext(requestType, null, null, null, - null, null, true /* focused */, true /* newSessionId */, - UserHandle.getCallingUserId(), null, PENDING_ASSIST_EXTRAS_TIMEOUT, 0); - if (pae == null) { - return null; - } - synchronized (pae) { - while (!pae.haveResult) { - try { - pae.wait(); - } catch (InterruptedException e) { - } - } - } - synchronized (this) { - buildAssistBundleLocked(pae, pae.result); - mPendingAssistExtras.remove(pae); - mUiHandler.removeCallbacks(pae); - } - return pae.extras; - } - - @Override - public boolean isAssistDataAllowedOnCurrentActivity() { - int userId; - synchronized (this) { - final ActivityStack focusedStack = getFocusedStack(); - if (focusedStack == null || focusedStack.isActivityTypeAssistant()) { - return false; - } - - final ActivityRecord activity = focusedStack.getTopActivity(); - if (activity == null) { - return false; - } - userId = activity.userId; - } - return !DevicePolicyCache.getInstance().getScreenCaptureDisabled(userId); - } - - @Override - public boolean showAssistFromActivity(IBinder token, Bundle args) { - long ident = Binder.clearCallingIdentity(); - try { - synchronized (this) { - ActivityRecord caller = ActivityRecord.forTokenLocked(token); - ActivityRecord top = getFocusedStack().getTopActivity(); - if (top != caller) { - Slog.w(TAG, "showAssistFromActivity failed: caller " + caller - + " is not current top " + top); - return false; - } - if (!top.nowVisible) { - Slog.w(TAG, "showAssistFromActivity failed: caller " + caller - + " is not visible"); - return false; - } - } - return mAssistUtils.showSessionForActiveService(args, SHOW_SOURCE_APPLICATION, null, - token); - } finally { - Binder.restoreCallingIdentity(ident); - } - } - - @Override - public boolean requestAssistContextExtras(int requestType, IAssistDataReceiver receiver, - Bundle receiverExtras, IBinder activityToken, boolean focused, boolean newSessionId) { - return enqueueAssistContext(requestType, null, null, receiver, receiverExtras, - activityToken, focused, newSessionId, UserHandle.getCallingUserId(), null, - PENDING_ASSIST_EXTRAS_LONG_TIMEOUT, 0) != null; - } - - @Override - public boolean requestAutofillData(IAssistDataReceiver receiver, Bundle receiverExtras, - IBinder activityToken, int flags) { - return enqueueAssistContext(ActivityManager.ASSIST_CONTEXT_AUTOFILL, null, null, - receiver, receiverExtras, activityToken, true, true, UserHandle.getCallingUserId(), - null, PENDING_AUTOFILL_ASSIST_STRUCTURE_TIMEOUT, flags) != null; - } - - private PendingAssistExtras enqueueAssistContext(int requestType, Intent intent, String hint, - IAssistDataReceiver receiver, Bundle receiverExtras, IBinder activityToken, - boolean focused, boolean newSessionId, int userHandle, Bundle args, long timeout, - int flags) { - enforceCallingPermission(android.Manifest.permission.GET_TOP_ACTIVITY_INFO, - "enqueueAssistContext()"); - - synchronized (this) { - ActivityRecord activity = getFocusedStack().getTopActivity(); - if (activity == null) { - Slog.w(TAG, "getAssistContextExtras failed: no top activity"); - return null; - } - if (activity.app == null || activity.app.thread == null) { - Slog.w(TAG, "getAssistContextExtras failed: no process for " + activity); - return null; - } - if (focused) { - if (activityToken != null) { - ActivityRecord caller = ActivityRecord.forTokenLocked(activityToken); - if (activity != caller) { - Slog.w(TAG, "enqueueAssistContext failed: caller " + caller - + " is not current top " + activity); - return null; - } - } - } else { - activity = ActivityRecord.forTokenLocked(activityToken); - if (activity == null) { - Slog.w(TAG, "enqueueAssistContext failed: activity for token=" + activityToken - + " couldn't be found"); - return null; - } - if (activity.app == null || activity.app.thread == null) { - Slog.w(TAG, "enqueueAssistContext failed: no process for " + activity); - return null; - } - } - - PendingAssistExtras pae; - Bundle extras = new Bundle(); - if (args != null) { - extras.putAll(args); - } - extras.putString(Intent.EXTRA_ASSIST_PACKAGE, activity.packageName); - extras.putInt(Intent.EXTRA_ASSIST_UID, activity.app.uid); - - pae = new PendingAssistExtras(activity, extras, intent, hint, receiver, receiverExtras, - userHandle); - pae.isHome = activity.isActivityTypeHome(); - - // Increment the sessionId if necessary - if (newSessionId) { - mViSessionId++; - } - try { - activity.app.thread.requestAssistContextExtras(activity.appToken, pae, requestType, - mViSessionId, flags); - mPendingAssistExtras.add(pae); - mUiHandler.postDelayed(pae, timeout); - } catch (RemoteException e) { - Slog.w(TAG, "getAssistContextExtras failed: crash calling " + activity); - return null; - } - return pae; - } - } - - void pendingAssistExtrasTimedOut(PendingAssistExtras pae) { - IAssistDataReceiver receiver; - synchronized (this) { - mPendingAssistExtras.remove(pae); - receiver = pae.receiver; - } - if (receiver != null) { - // Caller wants result sent back to them. - Bundle sendBundle = new Bundle(); - // At least return the receiver extras - sendBundle.putBundle(ASSIST_KEY_RECEIVER_EXTRAS, pae.receiverExtras); - try { - pae.receiver.onHandleAssistData(sendBundle); - } catch (RemoteException e) { - } - } - } - - private void buildAssistBundleLocked(PendingAssistExtras pae, Bundle result) { - if (result != null) { - pae.extras.putBundle(Intent.EXTRA_ASSIST_CONTEXT, result); - } - if (pae.hint != null) { - pae.extras.putBoolean(pae.hint, true); - } - } - - /** Called from an app when assist data is ready. */ - @Override - public void reportAssistContextExtras(IBinder token, Bundle extras, AssistStructure structure, - AssistContent content, Uri referrer) { - PendingAssistExtras pae = (PendingAssistExtras)token; - synchronized (pae) { - pae.result = extras; - pae.structure = structure; - pae.content = content; - if (referrer != null) { - pae.extras.putParcelable(Intent.EXTRA_REFERRER, referrer); - } - if (structure != null) { - structure.setHomeActivity(pae.isHome); - } - pae.haveResult = true; - pae.notifyAll(); - if (pae.intent == null && pae.receiver == null) { - // Caller is just waiting for the result. - return; - } - } - // We are now ready to launch the assist activity. - IAssistDataReceiver sendReceiver = null; - Bundle sendBundle = null; - synchronized (this) { - buildAssistBundleLocked(pae, extras); - boolean exists = mPendingAssistExtras.remove(pae); - mUiHandler.removeCallbacks(pae); - if (!exists) { - // Timed out. - return; - } - - if ((sendReceiver=pae.receiver) != null) { - // Caller wants result sent back to them. - sendBundle = new Bundle(); - sendBundle.putBundle(ASSIST_KEY_DATA, pae.extras); - sendBundle.putParcelable(ASSIST_KEY_STRUCTURE, pae.structure); - sendBundle.putParcelable(ASSIST_KEY_CONTENT, pae.content); - sendBundle.putBundle(ASSIST_KEY_RECEIVER_EXTRAS, pae.receiverExtras); - } - } - if (sendReceiver != null) { - try { - sendReceiver.onHandleAssistData(sendBundle); - } catch (RemoteException e) { - } - return; - } - - final long ident = Binder.clearCallingIdentity(); - try { - if (TextUtils.equals(pae.intent.getAction(), - android.service.voice.VoiceInteractionService.SERVICE_INTERFACE)) { - pae.intent.putExtras(pae.extras); - mContext.startServiceAsUser(pae.intent, new UserHandle(pae.userHandle)); - } else { - pae.intent.replaceExtras(pae.extras); - pae.intent.setFlags(FLAG_ACTIVITY_NEW_TASK - | Intent.FLAG_ACTIVITY_SINGLE_TOP - | Intent.FLAG_ACTIVITY_CLEAR_TOP); - closeSystemDialogs("assist"); - - try { - mContext.startActivityAsUser(pae.intent, new UserHandle(pae.userHandle)); - } catch (ActivityNotFoundException e) { - Slog.w(TAG, "No activity to handle assist action.", e); - } - } - } finally { - Binder.restoreCallingIdentity(ident); - } - } - - public boolean launchAssistIntent(Intent intent, int requestType, String hint, int userHandle, - Bundle args) { - return enqueueAssistContext(requestType, intent, hint, null, null, null, - true /* focused */, true /* newSessionId */, userHandle, args, - PENDING_ASSIST_EXTRAS_TIMEOUT, 0) != null; - } - public void registerProcessObserver(IProcessObserver observer) { enforceCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER, "registerProcessObserver()"); @@ -13969,101 +11683,6 @@ public class ActivityManagerService extends IActivityManager.Stub } @Override - public boolean convertFromTranslucent(IBinder token) { - final long origId = Binder.clearCallingIdentity(); - try { - synchronized (this) { - final ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r == null) { - return false; - } - final boolean translucentChanged = r.changeWindowTranslucency(true); - if (translucentChanged) { - mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); - } - mWindowManager.setAppFullscreen(token, true); - return translucentChanged; - } - } finally { - Binder.restoreCallingIdentity(origId); - } - } - - @Override - public boolean convertToTranslucent(IBinder token, Bundle options) { - SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(options); - final long origId = Binder.clearCallingIdentity(); - try { - synchronized (this) { - final ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r == null) { - return false; - } - final TaskRecord task = r.getTask(); - int index = task.mActivities.lastIndexOf(r); - if (index > 0) { - ActivityRecord under = task.mActivities.get(index - 1); - under.returningOptions = safeOptions != null ? safeOptions.getOptions(r) : null; - } - final boolean translucentChanged = r.changeWindowTranslucency(false); - if (translucentChanged) { - r.getStack().convertActivityToTranslucent(r); - } - mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); - mWindowManager.setAppFullscreen(token, false); - return translucentChanged; - } - } finally { - Binder.restoreCallingIdentity(origId); - } - } - - @Override - public Bundle getActivityOptions(IBinder token) { - final long origId = Binder.clearCallingIdentity(); - try { - synchronized (this) { - final ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r != null) { - final ActivityOptions activityOptions = r.takeOptionsLocked(); - return activityOptions == null ? null : activityOptions.toBundle(); - } - return null; - } - } finally { - Binder.restoreCallingIdentity(origId); - } - } - - @Override - public void setImmersive(IBinder token, boolean immersive) { - synchronized(this) { - final ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r == null) { - throw new IllegalArgumentException(); - } - r.immersive = immersive; - - // update associated state if we're frontmost - if (r == mStackSupervisor.getResumedActivityLocked()) { - if (DEBUG_IMMERSIVE) Slog.d(TAG_IMMERSIVE, "Frontmost changed immersion: "+ r); - applyUpdateLockStateLocked(r); - } - } - } - - @Override - public boolean isImmersive(IBinder token) { - synchronized (this) { - ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r == null) { - throw new IllegalArgumentException(); - } - return r.immersive; - } - } - - @Override public void setVrThread(int tid) { enforceSystemHasVrFeature(); synchronized (this) { @@ -14147,7 +11766,7 @@ public class ActivityManagerService extends IActivityManager.Stub * Check that we have the features required for VR-related API calls, and throw an exception if * not. */ - private void enforceSystemHasVrFeature() { + void enforceSystemHasVrFeature() { if (!mContext.getPackageManager().hasSystemFeature( PackageManager.FEATURE_VR_MODE_HIGH_PERFORMANCE)) { throw new UnsupportedOperationException("VR mode not supported on this device!"); @@ -14207,44 +11826,6 @@ public class ActivityManagerService extends IActivityManager.Stub } @Override - public int setVrMode(IBinder token, boolean enabled, ComponentName packageName) { - enforceSystemHasVrFeature(); - - final VrManagerInternal vrService = LocalServices.getService(VrManagerInternal.class); - - ActivityRecord r; - synchronized (this) { - r = ActivityRecord.isInStackLocked(token); - } - - if (r == null) { - throw new IllegalArgumentException(); - } - - int err; - if ((err = vrService.hasVrPackage(packageName, r.userId)) != - VrManagerInternal.NO_ERROR) { - return err; - } - - // Clear the binder calling uid since this path may call moveToTask(). - final long callingId = Binder.clearCallingIdentity(); - try { - synchronized(this) { - r.requestedVrComponent = (enabled) ? packageName : null; - - // Update associated state if this activity is currently focused - if (r == mStackSupervisor.getResumedActivityLocked()) { - applyUpdateVrModeLocked(r); - } - return 0; - } - } finally { - Binder.restoreCallingIdentity(callingId); - } - } - - @Override public boolean isVrModePackageEnabled(ComponentName packageName) { enforceSystemHasVrFeature(); @@ -14255,11 +11836,7 @@ public class ActivityManagerService extends IActivityManager.Stub } public boolean isTopActivityImmersive() { - enforceNotIsolatedCaller("startActivity"); - synchronized (this) { - ActivityRecord r = getFocusedStack().topRunningActivityLocked(); - return (r != null) ? r.immersive : false; - } + return mActivityTaskManager.isTopActivityImmersive(); } /** @@ -14271,13 +11848,7 @@ public class ActivityManagerService extends IActivityManager.Stub @Override public boolean isTopOfTask(IBinder token) { - synchronized (this) { - ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r == null) { - throw new IllegalArgumentException(); - } - return r.getTask().getTopActivity() == r; - } + return mActivityTaskManager.isTopOfTask(token); } @Override @@ -14843,7 +12414,7 @@ public class ActivityManagerService extends IActivityManager.Stub PackageManager.FEATURE_CANT_SAVE_STATE); mLocalDeviceIdleController = LocalServices.getService(DeviceIdleController.LocalService.class); - mAssistUtils = new AssistUtils(mContext); + mActivityTaskManager.onSystemReady(); mVrController.onSystemReady(); // Make sure we have the current profile info, since it is needed for security checks. mUserController.onSystemReady(); @@ -22006,19 +19577,7 @@ public class ActivityManagerService extends IActivityManager.Stub @Override public StackInfo getFocusedStackInfo() throws RemoteException { - enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); - long ident = Binder.clearCallingIdentity(); - try { - synchronized (this) { - ActivityStack focusedStack = getFocusedStack(); - if (focusedStack != null) { - return mStackSupervisor.getStackInfo(focusedStack.mStackId); - } - return null; - } - } finally { - Binder.restoreCallingIdentity(ident); - } + return mActivityTaskManager.getFocusedStackInfo(); } public Configuration getConfiguration() { @@ -22032,37 +19591,7 @@ public class ActivityManagerService extends IActivityManager.Stub @Override public void suppressResizeConfigChanges(boolean suppress) throws RemoteException { - enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "suppressResizeConfigChanges()"); - synchronized (this) { - mSuppressResizeConfigChanges = suppress; - } - } - - /** - * NOTE: For the pinned stack, this method is usually called after the bounds animation has - * animated the stack to the fullscreen, but can also be called if we are relaunching an - * activity and clearing the task at the same time. - */ - @Override - // TODO: API should just be about changing windowing modes... - public void moveTasksToFullscreenStack(int fromStackId, boolean onTop) { - enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, - "moveTasksToFullscreenStack()"); - synchronized (this) { - final long origId = Binder.clearCallingIdentity(); - try { - final ActivityStack stack = mStackSupervisor.getStack(fromStackId); - if (stack != null){ - if (!stack.isActivityTypeStandardOrUndefined()) { - throw new IllegalArgumentException( - "You can't move tasks from non-standard stacks."); - } - mStackSupervisor.moveTasksToFullscreenStackLocked(stack, onTop); - } - } finally { - Binder.restoreCallingIdentity(origId); - } - } + mActivityTaskManager.suppressResizeConfigChanges(suppress); } @Override @@ -22126,32 +19655,7 @@ public class ActivityManagerService extends IActivityManager.Stub @Override public boolean updateConfiguration(Configuration values) { - enforceCallingPermission(CHANGE_CONFIGURATION, "updateConfiguration()"); - - synchronized(this) { - if (values == null && mWindowManager != null) { - // sentinel: fetch the current configuration from the window manager - values = mWindowManager.computeNewConfiguration(DEFAULT_DISPLAY); - } - - if (mWindowManager != null) { - // Update OOM levels based on display size. - mProcessList.applyDisplaySize(mWindowManager); - } - - final long origId = Binder.clearCallingIdentity(); - try { - if (values != null) { - Settings.System.clearConfiguration(values); - } - updateConfigurationLocked(values, null, false, false /* persistent */, - UserHandle.USER_NULL, false /* deferResume */, - mTmpUpdateConfigurationResult); - return mTmpUpdateConfigurationResult.changes != 0; - } finally { - Binder.restoreCallingIdentity(origId); - } - } + return mActivityTaskManager.updateConfiguration(values); } void updateUserConfigurationLocked() { @@ -22194,9 +19698,9 @@ public class ActivityManagerService extends IActivityManager.Stub * @param userId is only used when persistent parameter is set to true to persist configuration * for that particular user */ - private boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, + boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, boolean initLocale, boolean persistent, int userId, boolean deferResume, - UpdateConfigurationResult result) { + ActivityTaskManagerService.UpdateConfigurationResult result) { int changes = 0; boolean kept = true; @@ -22375,45 +19879,6 @@ public class ActivityManagerService extends IActivityManager.Stub return changes; } - @Override - public boolean updateDisplayOverrideConfiguration(Configuration values, int displayId) { - enforceCallingPermission(CHANGE_CONFIGURATION, "updateDisplayOverrideConfiguration()"); - - synchronized (this) { - // Check if display is initialized in AM. - if (!mStackSupervisor.isDisplayAdded(displayId)) { - // Call might come when display is not yet added or has already been removed. - if (DEBUG_CONFIGURATION) { - Slog.w(TAG, "Trying to update display configuration for non-existing displayId=" - + displayId); - } - return false; - } - - if (values == null && mWindowManager != null) { - // sentinel: fetch the current configuration from the window manager - values = mWindowManager.computeNewConfiguration(displayId); - } - - if (mWindowManager != null) { - // Update OOM levels based on display size. - mProcessList.applyDisplaySize(mWindowManager); - } - - final long origId = Binder.clearCallingIdentity(); - try { - if (values != null) { - Settings.System.clearConfiguration(values); - } - updateDisplayOverrideConfigurationLocked(values, null /* starting */, - false /* deferResume */, displayId, mTmpUpdateConfigurationResult); - return mTmpUpdateConfigurationResult.changes != 0; - } finally { - Binder.restoreCallingIdentity(origId); - } - } - } - boolean updateDisplayOverrideConfigurationLocked(Configuration values, ActivityRecord starting, boolean deferResume, int displayId) { return updateDisplayOverrideConfigurationLocked(values, starting, deferResume /* deferResume */, @@ -22424,9 +19889,9 @@ public class ActivityManagerService extends IActivityManager.Stub * Updates override configuration specific for the selected display. If no config is provided, * new one will be computed in WM based on current display info. */ - private boolean updateDisplayOverrideConfigurationLocked(Configuration values, + boolean updateDisplayOverrideConfigurationLocked(Configuration values, ActivityRecord starting, boolean deferResume, int displayId, - UpdateConfigurationResult result) { + ActivityTaskManagerService.UpdateConfigurationResult result) { int changes = 0; boolean kept = true; @@ -22567,48 +20032,12 @@ public class ActivityManagerService extends IActivityManager.Stub } @Override - public boolean shouldUpRecreateTask(IBinder token, String destAffinity) { - synchronized (this) { - ActivityRecord srec = ActivityRecord.forTokenLocked(token); - if (srec != null) { - return srec.getStack().shouldUpRecreateTaskLocked(srec, destAffinity); - } - } - return false; - } - - public boolean navigateUpTo(IBinder token, Intent destIntent, int resultCode, - Intent resultData) { - - synchronized (this) { - final ActivityRecord r = ActivityRecord.forTokenLocked(token); - if (r != null) { - return r.getStack().navigateUpToLocked(r, destIntent, resultCode, resultData); - } - return false; - } - } - public int getLaunchedFromUid(IBinder activityToken) { - ActivityRecord srec; - synchronized (this) { - srec = ActivityRecord.forTokenLocked(activityToken); - } - if (srec == null) { - return -1; - } - return srec.launchedFromUid; + return mActivityTaskManager.getLaunchedFromUid(activityToken); } public String getLaunchedFromPackage(IBinder activityToken) { - ActivityRecord srec; - synchronized (this) { - srec = ActivityRecord.forTokenLocked(activityToken); - } - if (srec == null) { - return null; - } - return srec.launchedFromPackage; + return mActivityTaskManager.getLaunchedFromPackage(activityToken); } // ========================================================= @@ -25563,7 +22992,7 @@ public class ActivityManagerService extends IActivityManager.Stub } } - private void clearProfilerLocked() { + void clearProfilerLocked() { if (mProfilerInfo !=null && mProfilerInfo.profileFd != null) { try { mProfilerInfo.profileFd.close(); @@ -26210,7 +23639,7 @@ public class ActivityManagerService extends IActivityManager.Stub @Override public int startActivityAsUser(IApplicationThread caller, String callerPacakge, Intent intent, Bundle options, int userId) { - return ActivityManagerService.this.startActivityAsUser( + return ActivityManagerService.this.mActivityTaskManager.startActivityAsUser( caller, callerPacakge, intent, intent.resolveTypeIfNeeded(mContext.getContentResolver()), null, null, 0, Intent.FLAG_ACTIVITY_NEW_TASK, null, options, userId, @@ -26494,7 +23923,8 @@ public class ActivityManagerService extends IActivityManager.Stub @Override public void cancelRecentsAnimation(boolean restoreHomeStackPosition) { - ActivityManagerService.this.cancelRecentsAnimation(restoreHomeStackPosition); + ActivityManagerService.this.mActivityTaskManager.cancelRecentsAnimation( + restoreHomeStackPosition); } @Override @@ -26634,21 +24064,6 @@ public class ActivityManagerService extends IActivityManager.Stub } /** - * Return the user id of the last resumed activity. - */ - @Override - public @UserIdInt int getLastResumedActivityUserId() { - enforceCallingPermission( - permission.INTERACT_ACROSS_USERS_FULL, "getLastResumedActivityUserId()"); - synchronized (this) { - if (mLastResumedActivity == null) { - return mUserController.getCurrentUserId(); - } - return mLastResumedActivity.userId; - } - } - - /** * Kill processes for the user with id userId and that depend on the package named packageName */ @Override @@ -26682,21 +24097,6 @@ public class ActivityManagerService extends IActivityManager.Stub } @Override - public void dismissKeyguard(IBinder token, IKeyguardDismissCallback callback, - CharSequence message) throws RemoteException { - if (message != null) { - enforceCallingPermission(permission.SHOW_KEYGUARD_MESSAGE, - "dismissKeyguard()"); - } - final long callingId = Binder.clearCallingIdentity(); - try { - mKeyguardController.dismissKeyguard(token, callback, message); - } finally { - Binder.restoreCallingIdentity(callingId); - } - } - - @Override public int restartUserInBackground(final int userId) { return mUserController.restartUser(userId, /* foreground */ false); } @@ -26815,87 +24215,4 @@ public class ActivityManagerService extends IActivityManager.Stub return mNmi != null; } } - - @Override - public void setShowWhenLocked(IBinder token, boolean showWhenLocked) - throws RemoteException { - synchronized (this) { - final ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r == null) { - return; - } - final long origId = Binder.clearCallingIdentity(); - try { - r.setShowWhenLocked(showWhenLocked); - } finally { - Binder.restoreCallingIdentity(origId); - } - } - } - - @Override - public void setTurnScreenOn(IBinder token, boolean turnScreenOn) throws RemoteException { - synchronized (this) { - final ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r == null) { - return; - } - final long origId = Binder.clearCallingIdentity(); - try { - r.setTurnScreenOn(turnScreenOn); - } finally { - Binder.restoreCallingIdentity(origId); - } - } - } - - @Override - public void registerRemoteAnimations(IBinder token, RemoteAnimationDefinition definition) - throws RemoteException { - enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, - "registerRemoteAnimations"); - definition.setCallingPid(Binder.getCallingPid()); - synchronized (this) { - final ActivityRecord r = ActivityRecord.isInStackLocked(token); - if (r == null) { - return; - } - final long origId = Binder.clearCallingIdentity(); - try { - r.registerRemoteAnimations(definition); - } finally { - Binder.restoreCallingIdentity(origId); - } - } - } - - @Override - public void registerRemoteAnimationForNextActivityStart(String packageName, - RemoteAnimationAdapter adapter) throws RemoteException { - enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, - "registerRemoteAnimationForNextActivityStart"); - adapter.setCallingPid(Binder.getCallingPid()); - synchronized (this) { - final long origId = Binder.clearCallingIdentity(); - try { - mActivityStartController.registerRemoteAnimationForNextActivityStart(packageName, - adapter); - } finally { - Binder.restoreCallingIdentity(origId); - } - } - } - - /** @see android.app.ActivityManager#alwaysShowUnsupportedCompileSdkWarning */ - @Override - public void alwaysShowUnsupportedCompileSdkWarning(ComponentName activity) { - synchronized (this) { - final long origId = Binder.clearCallingIdentity(); - try { - mAppWarnings.alwaysShowUnsupportedCompileSdkWarning(activity); - } finally { - Binder.restoreCallingIdentity(origId); - } - } - } } diff --git a/services/core/java/com/android/server/am/ActivityManagerShellCommand.java b/services/core/java/com/android/server/am/ActivityManagerShellCommand.java index b443de8dddf8..0e78d06367d1 100644 --- a/services/core/java/com/android/server/am/ActivityManagerShellCommand.java +++ b/services/core/java/com/android/server/am/ActivityManagerShellCommand.java @@ -479,12 +479,12 @@ final class ActivityManagerShellCommand extends ShellCommand { options.setLockTaskEnabled(true); } if (mWaitOption) { - result = mInterface.startActivityAndWait(null, null, intent, mimeType, + result = mTaskInterface.startActivityAndWait(null, null, intent, mimeType, null, null, 0, mStartFlags, profilerInfo, options != null ? options.toBundle() : null, mUserId); res = result.result; } else { - res = mInterface.startActivityAsUser(null, null, intent, mimeType, + res = mTaskInterface.startActivityAsUser(null, null, intent, mimeType, null, null, 0, mStartFlags, profilerInfo, options != null ? options.toBundle() : null, mUserId); } @@ -578,7 +578,7 @@ final class ActivityManagerShellCommand extends ShellCommand { } mRepeat--; if (mRepeat > 0) { - mInterface.unhandledBack(); + mTaskInterface.unhandledBack(); } } while (mRepeat > 0); return 0; @@ -2186,7 +2186,7 @@ final class ActivityManagerShellCommand extends ShellCommand { int runSuppressResizeConfigChanges(PrintWriter pw) throws RemoteException { boolean suppress = Boolean.valueOf(getNextArgRequired()); - mInterface.suppressResizeConfigChanges(suppress); + mTaskInterface.suppressResizeConfigChanges(suppress); return 0; } @@ -2453,7 +2453,7 @@ final class ActivityManagerShellCommand extends ShellCommand { int stackId = Integer.parseInt(stackIdStr); String displayIdStr = getNextArgRequired(); int displayId = Integer.parseInt(displayIdStr); - mInterface.moveStackToDisplay(stackId, displayId); + mTaskInterface.moveStackToDisplay(stackId, displayId); return 0; } @@ -2467,7 +2467,7 @@ final class ActivityManagerShellCommand extends ShellCommand { throw new RuntimeException(e.getMessage(), e); } - final int stackId = mInterface.createStackOnDisplay(displayId); + final int stackId = mTaskInterface.createStackOnDisplay(displayId); if (stackId != INVALID_STACK_ID) { // TODO: Need proper support if this is used by test... // container.startActivity(intent); @@ -2546,7 +2546,7 @@ final class ActivityManagerShellCommand extends ShellCommand { getErrPrintWriter().println("Error: invalid input bounds"); return -1; } - mInterface.resizeDockedStack(bounds, taskBounds, null, null, null); + mTaskInterface.resizeDockedStack(bounds, taskBounds, null, null, null); return 0; } @@ -2566,12 +2566,12 @@ final class ActivityManagerShellCommand extends ShellCommand { String positionStr = getNextArgRequired(); int position = Integer.parseInt(positionStr); - mInterface.positionTaskInStack(taskId, stackId, position); + mTaskInterface.positionTaskInStack(taskId, stackId, position); return 0; } int runStackList(PrintWriter pw) throws RemoteException { - List<ActivityManager.StackInfo> stacks = mInterface.getAllStackInfos(); + List<ActivityManager.StackInfo> stacks = mTaskInterface.getAllStackInfos(); for (ActivityManager.StackInfo info : stacks) { pw.println(info); } @@ -2581,7 +2581,7 @@ final class ActivityManagerShellCommand extends ShellCommand { int runStackInfo(PrintWriter pw) throws RemoteException { int windowingMode = Integer.parseInt(getNextArgRequired()); int activityType = Integer.parseInt(getNextArgRequired()); - ActivityManager.StackInfo info = mInterface.getStackInfo(windowingMode, activityType); + ActivityManager.StackInfo info = mTaskInterface.getStackInfo(windowingMode, activityType); pw.println(info); return 0; } @@ -2589,7 +2589,7 @@ final class ActivityManagerShellCommand extends ShellCommand { int runStackRemove(PrintWriter pw) throws RemoteException { String stackIdStr = getNextArgRequired(); int stackId = Integer.parseInt(stackIdStr); - mInterface.removeStack(stackId); + mTaskInterface.removeStack(stackId); return 0; } @@ -2601,7 +2601,7 @@ final class ActivityManagerShellCommand extends ShellCommand { return -1; } - if (!mInterface.moveTopActivityToPinnedStack(stackId, bounds)) { + if (!mTaskInterface.moveTopActivityToPinnedStack(stackId, bounds)) { getErrPrintWriter().println("Didn't move top activity to pinned stack."); return -1; } @@ -2647,12 +2647,12 @@ final class ActivityManagerShellCommand extends ShellCommand { int runTaskLock(PrintWriter pw) throws RemoteException { String taskIdStr = getNextArgRequired(); if (taskIdStr.equals("stop")) { - mInterface.stopSystemLockTaskMode(); + mTaskInterface.stopSystemLockTaskMode(); } else { int taskId = Integer.parseInt(taskIdStr); - mInterface.startSystemLockTaskMode(taskId); + mTaskInterface.startSystemLockTaskMode(taskId); } - pw.println("Activity manager is " + (mInterface.isInLockTaskMode() ? "" : "not ") + + pw.println("Activity manager is " + (mTaskInterface.isInLockTaskMode() ? "" : "not ") + "in lockTaskMode"); return 0; } @@ -2662,7 +2662,7 @@ final class ActivityManagerShellCommand extends ShellCommand { final int taskId = Integer.parseInt(taskIdStr); final String resizeableStr = getNextArgRequired(); final int resizeableMode = Integer.parseInt(resizeableStr); - mInterface.setTaskResizeable(taskId, resizeableMode); + mTaskInterface.setTaskResizeable(taskId, resizeableMode); return 0; } @@ -2681,7 +2681,7 @@ final class ActivityManagerShellCommand extends ShellCommand { void taskResize(int taskId, Rect bounds, int delay_ms, boolean pretendUserResize) throws RemoteException { final int resizeMode = pretendUserResize ? RESIZE_MODE_USER : RESIZE_MODE_SYSTEM; - mInterface.resizeTask(taskId, bounds, resizeMode); + mTaskInterface.resizeTask(taskId, bounds, resizeMode); try { Thread.sleep(delay_ms); } catch (InterruptedException e) { @@ -2753,7 +2753,7 @@ final class ActivityManagerShellCommand extends ShellCommand { int runTaskFocus(PrintWriter pw) throws RemoteException { final int taskId = Integer.parseInt(getNextArgRequired()); pw.println("Setting focus to task " + taskId); - mInterface.setFocusedTask(taskId); + mTaskInterface.setFocusedTask(taskId); return 0; } diff --git a/services/core/java/com/android/server/am/ActivityRecord.java b/services/core/java/com/android/server/am/ActivityRecord.java index 696a184bbaab..35f3c0938579 100644 --- a/services/core/java/com/android/server/am/ActivityRecord.java +++ b/services/core/java/com/android/server/am/ActivityRecord.java @@ -1293,7 +1293,7 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo } boolean isKeyguardLocked = service.isKeyguardLocked(); - boolean isCurrentAppLocked = service.getLockTaskModeState() != LOCK_TASK_MODE_NONE; + boolean isCurrentAppLocked = service.mActivityTaskManager.getLockTaskModeState() != LOCK_TASK_MODE_NONE; final ActivityDisplay display = getDisplay(); boolean hasPinnedStack = display != null && display.hasPinnedStack(); // Don't return early if !isNotLocked, since we want to throw an exception if the activity @@ -2732,7 +2732,7 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo } void relaunchActivityLocked(boolean andResume, boolean preserveWindow) { - if (service.mSuppressResizeConfigChanges && preserveWindow) { + if (service.mActivityTaskManager.mSuppressResizeConfigChanges && preserveWindow) { configChangeFlags = 0; return; } diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java index 1486115aecc7..88589cc09143 100644 --- a/services/core/java/com/android/server/am/ActivityStack.java +++ b/services/core/java/com/android/server/am/ActivityStack.java @@ -2818,7 +2818,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai /** * Used from {@link ActivityStack#positionTask(TaskRecord, int)}. - * @see ActivityManagerService#positionTaskInStack(int, int, int). + * @see ActivityTaskManagerService#positionTaskInStack(int, int, int). */ private void insertTaskAtPosition(TaskRecord task, int position) { if (position >= mTaskHistory.size()) { diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java index 7a6f5707019a..615edd5424e4 100644 --- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java @@ -4831,7 +4831,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D sendPowerHintForLaunchStartIfNeeded(true /* forceSend */, targetActivity); mActivityMetricsLogger.notifyActivityLaunching(); try { - mService.moveTaskToFrontLocked(task.taskId, 0, options, + mService.mActivityTaskManager.moveTaskToFrontLocked(task.taskId, 0, options, true /* fromRecents */); } finally { mActivityMetricsLogger.notifyActivityLaunched(START_TASK_TO_FRONT, diff --git a/services/core/java/com/android/server/am/ActivityTaskManagerService.java b/services/core/java/com/android/server/am/ActivityTaskManagerService.java index d7caa1a7b795..c6edfe59cd3e 100644 --- a/services/core/java/com/android/server/am/ActivityTaskManagerService.java +++ b/services/core/java/com/android/server/am/ActivityTaskManagerService.java @@ -16,31 +16,140 @@ package com.android.server.am; +import static android.Manifest.permission.BIND_VOICE_INTERACTION; +import static android.Manifest.permission.CHANGE_CONFIGURATION; +import static android.Manifest.permission.CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS; +import static android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; import static android.Manifest.permission.MANAGE_ACTIVITY_STACKS; +import static android.Manifest.permission.READ_FRAME_BUFFER; +import static android.Manifest.permission.REMOVE_TASKS; +import static android.Manifest.permission.START_TASKS_FROM_RECENTS; +import static android.app.ActivityManager.LOCK_TASK_MODE_NONE; +import static android.app.ActivityManagerInternal.ASSIST_KEY_CONTENT; +import static android.app.ActivityManagerInternal.ASSIST_KEY_DATA; +import static android.app.ActivityManagerInternal.ASSIST_KEY_RECEIVER_EXTRAS; +import static android.app.ActivityManagerInternal.ASSIST_KEY_STRUCTURE; +import static android.app.ActivityTaskManager.INVALID_STACK_ID; +import static android.app.ActivityTaskManager.RESIZE_MODE_PRESERVE_WINDOW; import static android.app.ActivityTaskManager.SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT; +import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; +import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; +import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; +import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY; import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; +import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; +import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; +import static android.os.Process.SYSTEM_UID; +import static android.service.voice.VoiceInteractionSession.SHOW_SOURCE_APPLICATION; +import static android.view.Display.DEFAULT_DISPLAY; +import static android.view.Display.INVALID_DISPLAY; +import static android.view.WindowManager.TRANSIT_TASK_IN_PLACE; import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ALL; +import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONFIGURATION; +import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_FOCUS; +import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_IMMERSIVE; +import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKTASK; import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STACK; +import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH; +import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_VISIBILITY; +import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_FOCUS; +import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_IMMERSIVE; +import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_LOCKTASK; import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STACK; +import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH; +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.ActivityManagerService.ALLOW_FULL_ONLY; import static com.android.server.am.ActivityManagerService.ANIMATE; +import static com.android.server.am.ActivityManagerService.DISPATCH_SCREEN_KEYGUARD_MSG; +import static com.android.server.am.ActivityManagerService.ENTER_ANIMATION_COMPLETE_MSG; +import static com.android.server.am.ActivityManagerService.STOCK_PM_FLAGS; +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; +import static com.android.server.am.ActivityStackSupervisor.ON_TOP; +import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS; +import static com.android.server.am.ActivityStackSupervisor.REMOVE_FROM_RECENTS; +import static com.android.server.am.TaskRecord.INVALID_TASK_ID; +import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_DONT_LOCK; import static com.android.server.am.TaskRecord.REPARENT_KEEP_STACK_AT_FRONT; +import static com.android.server.am.TaskRecord.REPARENT_LEAVE_STACK_IN_PLACE; +import static com.android.server.wm.RecentsAnimationController.REORDER_KEEP_IN_PLACE; +import static com.android.server.wm.RecentsAnimationController.REORDER_MOVE_TO_ORIGINAL_POSITION; +import android.Manifest; +import android.annotation.Nullable; +import android.annotation.UserIdInt; +import android.app.Activity; import android.app.ActivityManager; +import android.app.ActivityOptions; +import android.app.ActivityTaskManager; +import android.app.AppGlobals; import android.app.IActivityTaskManager; +import android.app.IApplicationThread; +import android.app.IAssistDataReceiver; +import android.app.ITaskStackListener; +import android.app.PictureInPictureParams; +import android.app.ProfilerInfo; +import android.app.RemoteAction; +import android.app.WaitResult; import android.app.WindowConfiguration; +import android.app.admin.DevicePolicyCache; +import android.app.assist.AssistContent; +import android.app.assist.AssistStructure; +import android.app.usage.UsageEvents; +import android.content.ActivityNotFoundException; +import android.content.ComponentName; import android.content.Context; +import android.content.IIntentSender; +import android.content.Intent; +import android.content.pm.ActivityInfo; +import android.content.pm.PackageManager; +import android.content.pm.ParceledListSlice; +import android.content.pm.ResolveInfo; +import android.content.res.Configuration; +import android.graphics.Bitmap; +import android.graphics.Point; import android.graphics.Rect; +import android.metrics.LogMaker; +import android.net.Uri; import android.os.Binder; +import android.os.Bundle; +import android.os.IBinder; +import android.os.PersistableBundle; +import android.os.RemoteException; +import android.os.TransactionTooLargeException; +import android.os.UserHandle; +import android.provider.Settings; +import android.service.voice.IVoiceInteractionSession; +import android.service.voice.VoiceInteractionManagerInternal; +import android.telecom.TelecomManager; +import android.text.TextUtils; import android.util.Slog; +import android.view.IRecentsAnimationRunner; +import android.view.RemoteAnimationAdapter; +import android.view.RemoteAnimationDefinition; + +import com.android.internal.app.AssistUtils; +import com.android.internal.app.IVoiceInteractor; +import com.android.internal.logging.MetricsLogger; +import com.android.internal.os.logging.MetricsLoggerWrapper; +import com.android.internal.logging.nano.MetricsProto.MetricsEvent; +import com.android.internal.policy.IKeyguardDismissCallback; +import com.android.internal.policy.KeyguardDismissCallback; +import com.android.server.LocalServices; import com.android.server.SystemService; +import com.android.server.Watchdog; +import com.android.server.vr.VrManagerInternal; +import com.android.server.wm.PinnedStackWindowController; +import java.io.File; import java.util.ArrayList; import java.util.List; @@ -52,6 +161,11 @@ import java.util.List; public class ActivityTaskManagerService extends IActivityTaskManager.Stub { private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityTaskManagerService" : TAG_AM; private static final String TAG_STACK = TAG + POSTFIX_STACK; + private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; + private static final String TAG_IMMERSIVE = TAG + POSTFIX_IMMERSIVE; + private static final String TAG_FOCUS = TAG + POSTFIX_FOCUS; + private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; + private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK; private Context mContext; private ActivityManagerService mAm; @@ -59,10 +173,54 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { Object mGlobalLock; private ActivityStackSupervisor mStackSupervisor; + /** State of external calls telling us if the device is awake or asleep. */ + private boolean mKeyguardShown = false; + + // Wrapper around VoiceInteractionServiceManager + private AssistUtils mAssistUtils; + + // VoiceInteraction session ID that changes for each new request except when + // being called for multi-window assist in a single session. + private int mViSessionId = 1000; + + // How long to wait in getAssistContextExtras for the activity and foreground services + // to respond with the result. + private static final int PENDING_ASSIST_EXTRAS_TIMEOUT = 500; + + // How long top wait when going through the modern assist (which doesn't need to block + // on getting this result before starting to launch its UI). + private static final int PENDING_ASSIST_EXTRAS_LONG_TIMEOUT = 2000; + + // How long to wait in getAutofillAssistStructure() for the activity to respond with the result. + private static final int PENDING_AUTOFILL_ASSIST_STRUCTURE_TIMEOUT = 2000; + + private final ArrayList<PendingAssistExtras> mPendingAssistExtras = new ArrayList<>(); + + boolean mSuppressResizeConfigChanges; + + private final UpdateConfigurationResult mTmpUpdateConfigurationResult = + new UpdateConfigurationResult(); + + static final class UpdateConfigurationResult { + // Configuration changes that were updated. + int changes; + // If the activity was relaunched to match the new configuration. + boolean activityRelaunched; + + void reset() { + changes = 0; + activityRelaunched = false; + } + } + ActivityTaskManagerService(Context context) { mContext = context; } + void onSystemReady() { + mAssistUtils = new AssistUtils(mContext); + } + // TODO: Will be converted to WM lock once transition is complete. void setActivityManagerService(ActivityManagerService am) { mAm = am; @@ -89,6 +247,1036 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { } @Override + public final int startActivity(IApplicationThread caller, String callingPackage, + Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, + int startFlags, ProfilerInfo profilerInfo, Bundle bOptions) { + return startActivityAsUser(caller, callingPackage, intent, resolvedType, resultTo, + resultWho, requestCode, startFlags, profilerInfo, bOptions, + UserHandle.getCallingUserId()); + } + + @Override + public final int startActivities(IApplicationThread caller, String callingPackage, + Intent[] intents, String[] resolvedTypes, IBinder resultTo, Bundle bOptions, + int userId) { + final String reason = "startActivities"; + mAm.enforceNotIsolatedCaller(reason); + 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, + resolvedTypes, resultTo, SafeActivityOptions.fromBundle(bOptions), userId, reason); + } + + @Override + public int startActivityAsUser(IApplicationThread caller, String callingPackage, + Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, + int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, int userId) { + return startActivityAsUser(caller, callingPackage, intent, resolvedType, resultTo, + resultWho, requestCode, startFlags, profilerInfo, bOptions, userId, + true /*validateIncomingUser*/); + } + + int startActivityAsUser(IApplicationThread caller, String callingPackage, + Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, + int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, int userId, + boolean validateIncomingUser) { + mAm.enforceNotIsolatedCaller("startActivityAsUser"); + + userId = mAm.getActivityStartController().checkTargetUser(userId, validateIncomingUser, + Binder.getCallingPid(), Binder.getCallingUid(), "startActivityAsUser"); + + // TODO: Switch to user app stacks here. + return mAm.getActivityStartController().obtainStarter(intent, "startActivityAsUser") + .setCaller(caller) + .setCallingPackage(callingPackage) + .setResolvedType(resolvedType) + .setResultTo(resultTo) + .setResultWho(resultWho) + .setRequestCode(requestCode) + .setStartFlags(startFlags) + .setProfilerInfo(profilerInfo) + .setActivityOptions(bOptions) + .setMayWait(userId) + .execute(); + + } + + @Override + public int startActivityIntentSender(IApplicationThread caller, IIntentSender target, + IBinder whitelistToken, Intent fillInIntent, String resolvedType, IBinder resultTo, + String resultWho, int requestCode, int flagsMask, int flagsValues, Bundle bOptions) + throws TransactionTooLargeException { + mAm.enforceNotIsolatedCaller("startActivityIntentSender"); + // Refuse possible leaked file descriptors + if (fillInIntent != null && fillInIntent.hasFileDescriptors()) { + throw new IllegalArgumentException("File descriptors passed in Intent"); + } + + if (!(target instanceof PendingIntentRecord)) { + throw new IllegalArgumentException("Bad PendingIntent object"); + } + + PendingIntentRecord pir = (PendingIntentRecord)target; + + synchronized (mGlobalLock) { + // If this is coming from the currently resumed activity, it is + // effectively saying that app switches are allowed at this point. + final ActivityStack stack = mAm.getFocusedStack(); + if (stack.mResumedActivity != null && + stack.mResumedActivity.info.applicationInfo.uid == Binder.getCallingUid()) { + mAm.mAppSwitchesAllowedTime = 0; + } + } + int ret = pir.sendInner(0, fillInIntent, resolvedType, whitelistToken, null, null, + resultTo, resultWho, requestCode, flagsMask, flagsValues, bOptions); + return ret; + } + + @Override + public boolean startNextMatchingActivity(IBinder callingActivity, Intent intent, + Bundle bOptions) { + // Refuse possible leaked file descriptors + if (intent != null && intent.hasFileDescriptors()) { + throw new IllegalArgumentException("File descriptors passed in Intent"); + } + SafeActivityOptions options = SafeActivityOptions.fromBundle(bOptions); + + synchronized (mGlobalLock) { + final ActivityRecord r = ActivityRecord.isInStackLocked(callingActivity); + if (r == null) { + SafeActivityOptions.abort(options); + return false; + } + if (r.app == null || r.app.thread == null) { + // The caller is not running... d'oh! + SafeActivityOptions.abort(options); + return false; + } + intent = new Intent(intent); + // The caller is not allowed to change the data. + intent.setDataAndType(r.intent.getData(), r.intent.getType()); + // And we are resetting to find the next component... + intent.setComponent(null); + + final boolean debug = ((intent.getFlags() & Intent.FLAG_DEBUG_LOG_RESOLUTION) != 0); + + ActivityInfo aInfo = null; + try { + List<ResolveInfo> resolves = + AppGlobals.getPackageManager().queryIntentActivities( + intent, r.resolvedType, + PackageManager.MATCH_DEFAULT_ONLY | STOCK_PM_FLAGS, + UserHandle.getCallingUserId()).getList(); + + // Look for the original activity in the list... + final int N = resolves != null ? resolves.size() : 0; + for (int i=0; i<N; i++) { + ResolveInfo rInfo = resolves.get(i); + if (rInfo.activityInfo.packageName.equals(r.packageName) + && rInfo.activityInfo.name.equals(r.info.name)) { + // We found the current one... the next matching is + // after it. + i++; + if (i<N) { + aInfo = resolves.get(i).activityInfo; + } + if (debug) { + Slog.v(TAG, "Next matching activity: found current " + r.packageName + + "/" + r.info.name); + Slog.v(TAG, "Next matching activity: next is " + ((aInfo == null) + ? "null" : aInfo.packageName + "/" + aInfo.name)); + } + break; + } + } + } catch (RemoteException e) { + } + + if (aInfo == null) { + // Nobody who is next! + SafeActivityOptions.abort(options); + if (debug) Slog.d(TAG, "Next matching activity: nothing found"); + return false; + } + + intent.setComponent(new ComponentName( + aInfo.applicationInfo.packageName, aInfo.name)); + intent.setFlags(intent.getFlags()&~( + Intent.FLAG_ACTIVITY_FORWARD_RESULT| + Intent.FLAG_ACTIVITY_CLEAR_TOP| + Intent.FLAG_ACTIVITY_MULTIPLE_TASK| + FLAG_ACTIVITY_NEW_TASK)); + + // Okay now we need to start the new activity, replacing the currently running activity. + // This is a little tricky because we want to start the new one as if the current one is + // finished, but not finish the current one first so that there is no flicker. + // And thus... + final boolean wasFinishing = r.finishing; + r.finishing = true; + + // Propagate reply information over to the new activity. + final ActivityRecord resultTo = r.resultTo; + final String resultWho = r.resultWho; + final int requestCode = r.requestCode; + r.resultTo = null; + if (resultTo != null) { + resultTo.removeResultsLocked(r, resultWho, requestCode); + } + + final long origId = Binder.clearCallingIdentity(); + // TODO(b/64750076): Check if calling pid should really be -1. + final int res = mAm.getActivityStartController() + .obtainStarter(intent, "startNextMatchingActivity") + .setCaller(r.app.thread) + .setResolvedType(r.resolvedType) + .setActivityInfo(aInfo) + .setResultTo(resultTo != null ? resultTo.appToken : null) + .setResultWho(resultWho) + .setRequestCode(requestCode) + .setCallingPid(-1) + .setCallingUid(r.launchedFromUid) + .setCallingPackage(r.launchedFromPackage) + .setRealCallingPid(-1) + .setRealCallingUid(r.launchedFromUid) + .setActivityOptions(options) + .execute(); + Binder.restoreCallingIdentity(origId); + + r.finishing = wasFinishing; + if (res != ActivityManager.START_SUCCESS) { + return false; + } + return true; + } + } + + @Override + public final WaitResult startActivityAndWait(IApplicationThread caller, String callingPackage, + Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, + int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, int userId) { + final WaitResult res = new WaitResult(); + synchronized (mGlobalLock) { + mAm.enforceNotIsolatedCaller("startActivityAndWait"); + userId = mAm.mUserController.handleIncomingUser(Binder.getCallingPid(), + Binder.getCallingUid(), userId, false, ALLOW_FULL_ONLY, + "startActivityAndWait", null); + // TODO: Switch to user app stacks here. + mAm.getActivityStartController().obtainStarter(intent, "startActivityAndWait") + .setCaller(caller) + .setCallingPackage(callingPackage) + .setResolvedType(resolvedType) + .setResultTo(resultTo) + .setResultWho(resultWho) + .setRequestCode(requestCode) + .setStartFlags(startFlags) + .setActivityOptions(bOptions) + .setMayWait(userId) + .setProfilerInfo(profilerInfo) + .setWaitResult(res) + .execute(); + } + return res; + } + + @Override + public final int startActivityWithConfig(IApplicationThread caller, String callingPackage, + Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, + int startFlags, Configuration config, Bundle bOptions, int userId) { + synchronized (mGlobalLock) { + mAm.enforceNotIsolatedCaller("startActivityWithConfig"); + userId = mAm.mUserController.handleIncomingUser(Binder.getCallingPid(), + Binder.getCallingUid(), userId, false, ALLOW_FULL_ONLY, + "startActivityWithConfig", null); + // TODO: Switch to user app stacks here. + return mAm.getActivityStartController().obtainStarter(intent, "startActivityWithConfig") + .setCaller(caller) + .setCallingPackage(callingPackage) + .setResolvedType(resolvedType) + .setResultTo(resultTo) + .setResultWho(resultWho) + .setRequestCode(requestCode) + .setStartFlags(startFlags) + .setGlobalConfiguration(config) + .setActivityOptions(bOptions) + .setMayWait(userId) + .execute(); + } + } + + @Override + public final int startActivityAsCaller(IApplicationThread caller, String callingPackage, + Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, + int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, boolean ignoreTargetSecurity, + int userId) { + + // This is very dangerous -- it allows you to perform a start activity (including + // permission grants) as any app that may launch one of your own activities. So + // we will only allow this to be done from activities that are part of the core framework, + // and then only when they are running as the system. + final ActivityRecord sourceRecord; + final int targetUid; + final String targetPackage; + final boolean isResolver; + synchronized (mGlobalLock) { + if (resultTo == null) { + throw new SecurityException("Must be called from an activity"); + } + sourceRecord = mStackSupervisor.isInAnyStackLocked(resultTo); + if (sourceRecord == null) { + throw new SecurityException("Called with bad activity token: " + resultTo); + } + if (!sourceRecord.info.packageName.equals("android")) { + throw new SecurityException( + "Must be called from an activity that is declared in the android package"); + } + if (sourceRecord.app == null) { + throw new SecurityException("Called without a process attached to activity"); + } + if (UserHandle.getAppId(sourceRecord.app.uid) != SYSTEM_UID) { + // This is still okay, as long as this activity is running under the + // uid of the original calling activity. + if (sourceRecord.app.uid != sourceRecord.launchedFromUid) { + throw new SecurityException( + "Calling activity in uid " + sourceRecord.app.uid + + " must be system uid or original calling uid " + + sourceRecord.launchedFromUid); + } + } + if (ignoreTargetSecurity) { + if (intent.getComponent() == null) { + throw new SecurityException( + "Component must be specified with ignoreTargetSecurity"); + } + if (intent.getSelector() != null) { + throw new SecurityException( + "Selector not allowed with ignoreTargetSecurity"); + } + } + targetUid = sourceRecord.launchedFromUid; + targetPackage = sourceRecord.launchedFromPackage; + isResolver = sourceRecord.isResolverOrChildActivity(); + } + + if (userId == UserHandle.USER_NULL) { + userId = UserHandle.getUserId(sourceRecord.app.uid); + } + + // TODO: Switch to user app stacks here. + try { + return mAm.getActivityStartController().obtainStarter(intent, "startActivityAsCaller") + .setCallingUid(targetUid) + .setCallingPackage(targetPackage) + .setResolvedType(resolvedType) + .setResultTo(resultTo) + .setResultWho(resultWho) + .setRequestCode(requestCode) + .setStartFlags(startFlags) + .setActivityOptions(bOptions) + .setMayWait(userId) + .setIgnoreTargetSecurity(ignoreTargetSecurity) + .setFilterCallingUid(isResolver ? 0 /* system */ : targetUid) + .execute(); + } catch (SecurityException e) { + // XXX need to figure out how to propagate to original app. + // A SecurityException here is generally actually a fault of the original + // calling activity (such as a fairly granting permissions), so propagate it + // back to them. + /* + StringBuilder msg = new StringBuilder(); + msg.append("While launching"); + msg.append(intent.toString()); + msg.append(": "); + msg.append(e.getMessage()); + */ + throw e; + } + } + + @Override + public int startVoiceActivity(String callingPackage, int callingPid, int callingUid, + Intent intent, String resolvedType, IVoiceInteractionSession session, + IVoiceInteractor interactor, int startFlags, ProfilerInfo profilerInfo, + Bundle bOptions, int userId) { + mAm.enforceCallingPermission(BIND_VOICE_INTERACTION, "startVoiceActivity()"); + if (session == null || interactor == null) { + throw new NullPointerException("null session or interactor"); + } + 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") + .setCallingUid(callingUid) + .setCallingPackage(callingPackage) + .setResolvedType(resolvedType) + .setVoiceSession(session) + .setVoiceInteractor(interactor) + .setStartFlags(startFlags) + .setProfilerInfo(profilerInfo) + .setActivityOptions(bOptions) + .setMayWait(userId) + .execute(); + } + + @Override + public int startAssistantActivity(String callingPackage, int callingPid, int callingUid, + Intent intent, String resolvedType, Bundle bOptions, int userId) { + mAm.enforceCallingPermission(BIND_VOICE_INTERACTION, "startAssistantActivity()"); + userId = mAm.mUserController.handleIncomingUser(callingPid, callingUid, userId, false, + ALLOW_FULL_ONLY, "startAssistantActivity", null); + + return mAm.getActivityStartController().obtainStarter(intent, "startAssistantActivity") + .setCallingUid(callingUid) + .setCallingPackage(callingPackage) + .setResolvedType(resolvedType) + .setActivityOptions(bOptions) + .setMayWait(userId) + .execute(); + } + + @Override + public void startRecentsActivity(Intent intent, IAssistDataReceiver assistDataReceiver, + IRecentsAnimationRunner recentsAnimationRunner) { + mAm.enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "startRecentsActivity()"); + final int callingPid = Binder.getCallingPid(); + final long origId = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + final ComponentName recentsComponent = mAm.getRecentTasks().getRecentsComponent(); + final int recentsUid = mAm.getRecentTasks().getRecentsComponentUid(); + + // Start a new recents animation + final RecentsAnimation anim = new RecentsAnimation(mAm, mStackSupervisor, + mAm.getActivityStartController(), mAm.mWindowManager, mAm.mUserController, + callingPid); + anim.startRecentsActivity(intent, recentsAnimationRunner, recentsComponent, + recentsUid, assistDataReceiver); + } + } finally { + Binder.restoreCallingIdentity(origId); + } + } + + @Override + public final int startActivityFromRecents(int taskId, Bundle bOptions) { + mAm.enforceCallerIsRecentsOrHasPermission(START_TASKS_FROM_RECENTS, + "startActivityFromRecents()"); + + final int callingPid = Binder.getCallingPid(); + final int callingUid = Binder.getCallingUid(); + final SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(bOptions); + final long origId = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + return mStackSupervisor.startActivityFromRecents(callingPid, callingUid, taskId, + safeOptions); + } + } finally { + Binder.restoreCallingIdentity(origId); + } + } + + /** + * This is the internal entry point for handling Activity.finish(). + * + * @param token The Binder token referencing the Activity we want to finish. + * @param resultCode Result code, if any, from this Activity. + * @param resultData Result data (Intent), if any, from this Activity. + * @param finishTask Whether to finish the task associated with this Activity. + * + * @return Returns true if the activity successfully finished, or false if it is still running. + */ + @Override + public final boolean finishActivity(IBinder token, int resultCode, Intent resultData, + int finishTask) { + // Refuse possible leaked file descriptors + if (resultData != null && resultData.hasFileDescriptors()) { + throw new IllegalArgumentException("File descriptors passed in Intent"); + } + + synchronized (mGlobalLock) { + ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r == null) { + return true; + } + // Keep track of the root activity of the task before we finish it + TaskRecord tr = r.getTask(); + ActivityRecord rootR = tr.getRootActivity(); + if (rootR == null) { + Slog.w(TAG, "Finishing task with all activities already finished"); + } + // Do not allow task to finish if last task in lockTask mode. Launchable priv-apps can + // finish. + if (mAm.getLockTaskController().activityBlockedFromFinish(r)) { + return false; + } + + if (mAm.mController != null) { + // Find the first activity that is not finishing. + ActivityRecord next = r.getStack().topRunningActivityLocked(token, 0); + if (next != null) { + // ask watcher if this is allowed + boolean resumeOK = true; + try { + resumeOK = mAm.mController.activityResuming(next.packageName); + } catch (RemoteException e) { + mAm.mController = null; + Watchdog.getInstance().setActivityController(null); + } + + if (!resumeOK) { + Slog.i(TAG, "Not finishing activity because controller resumed"); + return false; + } + } + } + final long origId = Binder.clearCallingIdentity(); + try { + boolean res; + final boolean finishWithRootActivity = + finishTask == Activity.FINISH_TASK_WITH_ROOT_ACTIVITY; + if (finishTask == Activity.FINISH_TASK_WITH_ACTIVITY + || (finishWithRootActivity && r == rootR)) { + // If requested, remove the task that is associated to this activity only if it + // was the root activity in the task. The result code and data is ignored + // because we don't support returning them across task boundaries. Also, to + // keep backwards compatibility we remove the task from recents when finishing + // task with root activity. + res = mStackSupervisor.removeTaskByIdLocked(tr.taskId, false, + finishWithRootActivity, "finish-activity"); + if (!res) { + Slog.i(TAG, "Removing task failed to finish activity"); + } + } else { + res = tr.getStack().requestFinishActivityLocked(token, resultCode, + resultData, "app-request", true); + if (!res) { + Slog.i(TAG, "Failed to finish by app-request"); + } + } + return res; + } finally { + Binder.restoreCallingIdentity(origId); + } + } + } + + @Override + public boolean finishActivityAffinity(IBinder token) { + synchronized (mGlobalLock) { + final long origId = Binder.clearCallingIdentity(); + try { + ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r == null) { + return false; + } + + // Do not allow task to finish if last task in lockTask mode. Launchable priv-apps + // can finish. + final TaskRecord task = r.getTask(); + if (mAm.getLockTaskController().activityBlockedFromFinish(r)) { + return false; + } + return task.getStack().finishActivityAffinityLocked(r); + } finally { + Binder.restoreCallingIdentity(origId); + } + } + } + + @Override + public final void activityIdle(IBinder token, Configuration config, boolean stopProfiling) { + final long origId = Binder.clearCallingIdentity(); + synchronized (mGlobalLock) { + ActivityStack stack = ActivityRecord.getStackLocked(token); + if (stack != null) { + ActivityRecord r = + mStackSupervisor.activityIdleInternalLocked(token, false /* fromTimeout */, + false /* processPausingActivities */, config); + if (stopProfiling) { + if ((mAm.mProfileProc == r.app) && mAm.mProfilerInfo != null) { + mAm.clearProfilerLocked(); + } + } + } + } + Binder.restoreCallingIdentity(origId); + } + + @Override + public final void activityResumed(IBinder token) { + final long origId = Binder.clearCallingIdentity(); + synchronized (mGlobalLock) { + ActivityRecord.activityResumedLocked(token); + mAm.mWindowManager.notifyAppResumedFinished(token); + } + Binder.restoreCallingIdentity(origId); + } + + @Override + public final void activityPaused(IBinder token) { + final long origId = Binder.clearCallingIdentity(); + synchronized (mGlobalLock) { + ActivityStack stack = ActivityRecord.getStackLocked(token); + if (stack != null) { + stack.activityPausedLocked(token, false); + } + } + Binder.restoreCallingIdentity(origId); + } + + @Override + public final void activityStopped(IBinder token, Bundle icicle, + PersistableBundle persistentState, CharSequence description) { + if (DEBUG_ALL) Slog.v(TAG, "Activity stopped: token=" + token); + + // Refuse possible leaked file descriptors + if (icicle != null && icicle.hasFileDescriptors()) { + throw new IllegalArgumentException("File descriptors passed in Bundle"); + } + + final long origId = Binder.clearCallingIdentity(); + + synchronized (mGlobalLock) { + final ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r != null) { + r.activityStoppedLocked(icicle, persistentState, description); + } + } + + mAm.trimApplications(); + + Binder.restoreCallingIdentity(origId); + } + + @Override + public final void activityDestroyed(IBinder token) { + if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "ACTIVITY DESTROYED: " + token); + synchronized (mGlobalLock) { + ActivityStack stack = ActivityRecord.getStackLocked(token); + if (stack != null) { + stack.activityDestroyedLocked(token, "activityDestroyed"); + } + } + } + + @Override + public final void activityRelaunched(IBinder token) { + final long origId = Binder.clearCallingIdentity(); + synchronized (mGlobalLock) { + mStackSupervisor.activityRelaunchedLocked(token); + } + Binder.restoreCallingIdentity(origId); + } + + public final void activitySlept(IBinder token) { + if (DEBUG_ALL) Slog.v(TAG, "Activity slept: token=" + token); + + final long origId = Binder.clearCallingIdentity(); + + synchronized (mGlobalLock) { + final ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r != null) { + mStackSupervisor.activitySleptLocked(r); + } + } + + Binder.restoreCallingIdentity(origId); + } + + @Override + public void setRequestedOrientation(IBinder token, int requestedOrientation) { + synchronized (mGlobalLock) { + ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r == null) { + return; + } + final long origId = Binder.clearCallingIdentity(); + try { + r.setRequestedOrientation(requestedOrientation); + } finally { + Binder.restoreCallingIdentity(origId); + } + } + } + + @Override + public int getRequestedOrientation(IBinder token) { + synchronized (mGlobalLock) { + ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r == null) { + return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; + } + return r.getRequestedOrientation(); + } + } + + @Override + public void setImmersive(IBinder token, boolean immersive) { + synchronized (mGlobalLock) { + final ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r == null) { + throw new IllegalArgumentException(); + } + r.immersive = immersive; + + // update associated state if we're frontmost + if (r == mStackSupervisor.getResumedActivityLocked()) { + if (DEBUG_IMMERSIVE) Slog.d(TAG_IMMERSIVE, "Frontmost changed immersion: "+ r); + mAm.applyUpdateLockStateLocked(r); + } + } + } + + @Override + public boolean isImmersive(IBinder token) { + synchronized (mGlobalLock) { + final ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r == null) { + throw new IllegalArgumentException(); + } + return r.immersive; + } + } + + @Override + public boolean isTopActivityImmersive() { + mAm.enforceNotIsolatedCaller("isTopActivityImmersive"); + synchronized (mGlobalLock) { + final ActivityRecord r = mAm.getFocusedStack().topRunningActivityLocked(); + return (r != null) ? r.immersive : false; + } + } + + @Override + public void overridePendingTransition(IBinder token, String packageName, + int enterAnim, int exitAnim) { + synchronized (mGlobalLock) { + ActivityRecord self = ActivityRecord.isInStackLocked(token); + if (self == null) { + return; + } + + final long origId = Binder.clearCallingIdentity(); + + if (self.isState( + ActivityStack.ActivityState.RESUMED, ActivityStack.ActivityState.PAUSING)) { + mAm.mWindowManager.overridePendingAppTransition(packageName, + enterAnim, exitAnim, null); + } + + Binder.restoreCallingIdentity(origId); + } + } + + @Override + public int getFrontActivityScreenCompatMode() { + mAm.enforceNotIsolatedCaller("getFrontActivityScreenCompatMode"); + synchronized (mGlobalLock) { + return mAm.mCompatModePackages.getFrontActivityScreenCompatModeLocked(); + } + } + + @Override + public void setFrontActivityScreenCompatMode(int mode) { + mAm.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, + "setFrontActivityScreenCompatMode"); + synchronized (mGlobalLock) { + mAm.mCompatModePackages.setFrontActivityScreenCompatModeLocked(mode); + } + } + + @Override + public int getLaunchedFromUid(IBinder activityToken) { + ActivityRecord srec; + synchronized (mGlobalLock) { + srec = ActivityRecord.forTokenLocked(activityToken); + } + if (srec == null) { + return -1; + } + return srec.launchedFromUid; + } + + @Override + public String getLaunchedFromPackage(IBinder activityToken) { + ActivityRecord srec; + synchronized (mGlobalLock) { + srec = ActivityRecord.forTokenLocked(activityToken); + } + if (srec == null) { + return null; + } + return srec.launchedFromPackage; + } + + @Override + public boolean convertFromTranslucent(IBinder token) { + final long origId = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + final ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r == null) { + return false; + } + final boolean translucentChanged = r.changeWindowTranslucency(true); + if (translucentChanged) { + mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); + } + mAm.mWindowManager.setAppFullscreen(token, true); + return translucentChanged; + } + } finally { + Binder.restoreCallingIdentity(origId); + } + } + + @Override + public boolean convertToTranslucent(IBinder token, Bundle options) { + SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(options); + final long origId = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + final ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r == null) { + return false; + } + final TaskRecord task = r.getTask(); + int index = task.mActivities.lastIndexOf(r); + if (index > 0) { + ActivityRecord under = task.mActivities.get(index - 1); + under.returningOptions = safeOptions != null ? safeOptions.getOptions(r) : null; + } + final boolean translucentChanged = r.changeWindowTranslucency(false); + if (translucentChanged) { + r.getStack().convertActivityToTranslucent(r); + } + mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); + mAm.mWindowManager.setAppFullscreen(token, false); + return translucentChanged; + } + } finally { + Binder.restoreCallingIdentity(origId); + } + } + + @Override + public void notifyActivityDrawn(IBinder token) { + if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY, "notifyActivityDrawn: token=" + token); + synchronized (mGlobalLock) { + ActivityRecord r = mStackSupervisor.isInAnyStackLocked(token); + if (r != null) { + r.getStack().notifyActivityDrawnLocked(r); + } + } + } + + @Override + public void reportActivityFullyDrawn(IBinder token, boolean restoredFromBundle) { + synchronized (mGlobalLock) { + ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r == null) { + return; + } + r.reportFullyDrawnLocked(restoredFromBundle); + } + } + + @Override + public int getActivityDisplayId(IBinder activityToken) throws RemoteException { + synchronized (mGlobalLock) { + final ActivityStack stack = ActivityRecord.getStackLocked(activityToken); + if (stack != null && stack.mDisplayId != INVALID_DISPLAY) { + return stack.mDisplayId; + } + return DEFAULT_DISPLAY; + } + } + + @Override + public ActivityManager.StackInfo getFocusedStackInfo() throws RemoteException { + mAm.enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); + long ident = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + ActivityStack focusedStack = mAm.getFocusedStack(); + if (focusedStack != null) { + return mStackSupervisor.getStackInfo(focusedStack.mStackId); + } + return null; + } + } finally { + Binder.restoreCallingIdentity(ident); + } + } + + @Override + public void setFocusedStack(int stackId) { + mAm.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "setFocusedStack()"); + if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, "setFocusedStack: stackId=" + stackId); + final long callingId = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + final ActivityStack stack = mStackSupervisor.getStack(stackId); + if (stack == null) { + Slog.w(TAG, "setFocusedStack: No stack with id=" + stackId); + return; + } + final ActivityRecord r = stack.topRunningActivityLocked(); + if (mStackSupervisor.moveFocusableActivityStackToFrontLocked( + r, "setFocusedStack")) { + mStackSupervisor.resumeFocusedStackTopActivityLocked(); + } + } + } finally { + Binder.restoreCallingIdentity(callingId); + } + } + + @Override + public void setFocusedTask(int taskId) { + mAm.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "setFocusedTask()"); + if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, "setFocusedTask: taskId=" + taskId); + final long callingId = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + final TaskRecord task = mStackSupervisor.anyTaskForIdLocked(taskId); + if (task == null) { + return; + } + final ActivityRecord r = task.topRunningActivityLocked(); + if (mStackSupervisor.moveFocusableActivityStackToFrontLocked(r, "setFocusedTask")) { + mStackSupervisor.resumeFocusedStackTopActivityLocked(); + } + } + } finally { + Binder.restoreCallingIdentity(callingId); + } + } + + @Override + public boolean removeTask(int taskId) { + mAm.enforceCallerIsRecentsOrHasPermission(REMOVE_TASKS, "removeTask()"); + synchronized (mGlobalLock) { + final long ident = Binder.clearCallingIdentity(); + try { + return mStackSupervisor.removeTaskByIdLocked(taskId, true, REMOVE_FROM_RECENTS, + "remove-task"); + } finally { + Binder.restoreCallingIdentity(ident); + } + } + } + + @Override + public boolean shouldUpRecreateTask(IBinder token, String destAffinity) { + synchronized (mGlobalLock) { + final ActivityRecord srec = ActivityRecord.forTokenLocked(token); + if (srec != null) { + return srec.getStack().shouldUpRecreateTaskLocked(srec, destAffinity); + } + } + return false; + } + + @Override + public boolean navigateUpTo(IBinder token, Intent destIntent, int resultCode, + Intent resultData) { + + synchronized (mGlobalLock) { + final ActivityRecord r = ActivityRecord.forTokenLocked(token); + if (r != null) { + return r.getStack().navigateUpToLocked(r, destIntent, resultCode, resultData); + } + return false; + } + } + + /** + * Attempts to move a task backwards in z-order (the order of activities within the task is + * unchanged). + * + * There are several possible results of this call: + * - if the task is locked, then we will show the lock toast + * - if there is a task behind the provided task, then that task is made visible and resumed as + * this task is moved to the back + * - otherwise, if there are no other tasks in the stack: + * - if this task is in the pinned stack, then we remove the stack completely, which will + * have the effect of moving the task to the top or bottom of the fullscreen stack + * (depending on whether it is visible) + * - otherwise, we simply return home and hide this task + * + * @param token A reference to the activity we wish to move + * @param nonRoot If false then this only works if the activity is the root + * of a task; if true it will work for any activity in a task. + * @return Returns true if the move completed, false if not. + */ + @Override + public boolean moveActivityTaskToBack(IBinder token, boolean nonRoot) { + mAm.enforceNotIsolatedCaller("moveActivityTaskToBack"); + synchronized (mGlobalLock) { + final long origId = Binder.clearCallingIdentity(); + try { + int taskId = ActivityRecord.getTaskForActivityLocked(token, !nonRoot); + final TaskRecord task = mStackSupervisor.anyTaskForIdLocked(taskId); + if (task != null) { + return ActivityRecord.getStackLocked(token).moveTaskToBackLocked(taskId); + } + } finally { + Binder.restoreCallingIdentity(origId); + } + } + return false; + } + + @Override + public Rect getTaskBounds(int taskId) { + mAm.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "getTaskBounds()"); + long ident = Binder.clearCallingIdentity(); + Rect rect = new Rect(); + try { + synchronized (mGlobalLock) { + final TaskRecord task = mStackSupervisor.anyTaskForIdLocked(taskId, + MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); + if (task == null) { + Slog.w(TAG, "getTaskBounds: taskId=" + taskId + " not found"); + return rect; + } + if (task.getStack() != null) { + // Return the bounds from window manager since it will be adjusted for various + // things like the presense of a docked stack for tasks that aren't resizeable. + task.getWindowContainerBounds(rect); + } else { + // Task isn't in window manager yet since it isn't associated with a stack. + // Return the persist value from activity manager + if (!task.matchParentBounds()) { + rect.set(task.getBounds()); + } else if (task.mLastNonFullscreenBounds != null) { + rect.set(task.mLastNonFullscreenBounds); + } + } + } + } finally { + Binder.restoreCallingIdentity(ident); + } + return rect; + } + + @Override + public ActivityManager.TaskDescription getTaskDescription(int id) { + synchronized (mGlobalLock) { + mAm.enforceCallerIsRecentsOrHasPermission( + MANAGE_ACTIVITY_STACKS, "getTaskDescription()"); + final TaskRecord tr = mStackSupervisor.anyTaskForIdLocked(id, + MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); + if (tr != null) { + return tr.lastTaskDescription; + } + } + return null; + } + + @Override public void setTaskWindowingMode(int taskId, int windowingMode, boolean toTop) { if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { setTaskWindowingModeSplitScreenPrimary(taskId, SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, @@ -126,6 +1314,104 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { } @Override + public String getCallingPackage(IBinder token) { + synchronized (this) { + ActivityRecord r = getCallingRecordLocked(token); + return r != null ? r.info.packageName : null; + } + } + + @Override + public ComponentName getCallingActivity(IBinder token) { + synchronized (this) { + ActivityRecord r = getCallingRecordLocked(token); + return r != null ? r.intent.getComponent() : null; + } + } + + private ActivityRecord getCallingRecordLocked(IBinder token) { + ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r == null) { + return null; + } + return r.resultTo; + } + + @Override + public void unhandledBack() { + mAm.enforceCallingPermission(android.Manifest.permission.FORCE_BACK, "unhandledBack()"); + + synchronized (mGlobalLock) { + final long origId = Binder.clearCallingIdentity(); + try { + mAm.getFocusedStack().unhandledBackLocked(); + } finally { + Binder.restoreCallingIdentity(origId); + } + } + } + + /** + * TODO: Add mController hook + */ + @Override + public void moveTaskToFront(int taskId, int flags, Bundle bOptions) { + mAm.enforceCallingPermission(android.Manifest.permission.REORDER_TASKS, "moveTaskToFront()"); + + if (DEBUG_STACK) Slog.d(TAG_STACK, "moveTaskToFront: moving taskId=" + taskId); + synchronized (mGlobalLock) { + moveTaskToFrontLocked(taskId, flags, SafeActivityOptions.fromBundle(bOptions), + false /* fromRecents */); + } + } + + void moveTaskToFrontLocked(int taskId, int flags, SafeActivityOptions options, + boolean fromRecents) { + + if (!mAm.checkAppSwitchAllowedLocked(Binder.getCallingPid(), + Binder.getCallingUid(), -1, -1, "Task to front")) { + SafeActivityOptions.abort(options); + return; + } + final long origId = Binder.clearCallingIdentity(); + try { + final TaskRecord task = mStackSupervisor.anyTaskForIdLocked(taskId); + if (task == null) { + Slog.d(TAG, "Could not find task for id: "+ taskId); + return; + } + if (mAm.getLockTaskController().isLockTaskModeViolation(task)) { + Slog.e(TAG, "moveTaskToFront: Attempt to violate Lock Task Mode"); + return; + } + ActivityOptions realOptions = options != null + ? options.getOptions(mStackSupervisor) + : null; + mStackSupervisor.findTaskToMoveToFront(task, flags, realOptions, "moveTaskToFront", + false /* forceNonResizable */); + + final ActivityRecord topActivity = task.getTopActivity(); + if (topActivity != null) { + + // We are reshowing a task, use a starting window to hide the initial draw delay + // so the transition can start earlier. + topActivity.showStartingWindow(null /* prev */, false /* newTask */, + true /* taskSwitch */, fromRecents); + } + } finally { + Binder.restoreCallingIdentity(origId); + } + SafeActivityOptions.abort(options); + } + + @Override + public int getTaskForActivity(IBinder token, boolean onlyRoot) { + synchronized (mGlobalLock) { + return ActivityRecord.getTaskForActivityLocked(token, onlyRoot); + } + } + + @Override public List<ActivityManager.RunningTaskInfo> getTasks(int maxNum) { return getFilteredTasks(maxNum, ACTIVITY_TYPE_UNDEFINED, WINDOWING_MODE_UNDEFINED); } @@ -150,6 +1436,29 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { } @Override + public final void finishSubActivity(IBinder token, String resultWho, int requestCode) { + synchronized (mGlobalLock) { + final long origId = Binder.clearCallingIdentity(); + ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r != null) { + r.getStack().finishSubActivityLocked(r, resultWho, requestCode); + } + Binder.restoreCallingIdentity(origId); + } + } + + @Override + public boolean willActivityBeVisible(IBinder token) { + synchronized(this) { + ActivityStack stack = ActivityRecord.getStackLocked(token); + if (stack != null) { + return stack.willActivityBeVisibleLocked(token); + } + return false; + } + } + + @Override public void moveTaskToStack(int taskId, int stackId, boolean toTop) { mAm.enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "moveTaskToStack()"); synchronized (mGlobalLock) { @@ -306,4 +1615,1716 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { } } } + + @Override + public ParceledListSlice<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum, int flags, + int userId) { + final int callingUid = Binder.getCallingUid(); + userId = mAm.mUserController.handleIncomingUser(Binder.getCallingPid(), callingUid, userId, + false, ALLOW_FULL_ONLY, "getRecentTasks", null); + final boolean allowed = mAm.isGetTasksAllowed("getRecentTasks", Binder.getCallingPid(), + callingUid); + final boolean detailed = mAm.checkCallingPermission( + android.Manifest.permission.GET_DETAILED_TASKS) + == PackageManager.PERMISSION_GRANTED; + + synchronized (mGlobalLock) { + return mAm.getRecentTasks().getRecentTasks(maxNum, flags, allowed, detailed, userId, + callingUid); + } + } + + @Override + public List<ActivityManager.StackInfo> getAllStackInfos() { + mAm.enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getAllStackInfos()"); + long ident = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + return mStackSupervisor.getAllStackInfosLocked(); + } + } finally { + Binder.restoreCallingIdentity(ident); + } + } + + @Override + public ActivityManager.StackInfo getStackInfo(int windowingMode, int activityType) { + mAm.enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); + long ident = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + return mStackSupervisor.getStackInfo(windowingMode, activityType); + } + } finally { + Binder.restoreCallingIdentity(ident); + } + } + + @Override + public void cancelRecentsAnimation(boolean restoreHomeStackPosition) { + mAm.enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "cancelRecentsAnimation()"); + final long callingUid = Binder.getCallingUid(); + final long origId = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + // Cancel the recents animation synchronously (do not hold the WM lock) + mAm.mWindowManager.cancelRecentsAnimationSynchronously(restoreHomeStackPosition + ? REORDER_MOVE_TO_ORIGINAL_POSITION + : REORDER_KEEP_IN_PLACE, "cancelRecentsAnimation/uid=" + callingUid); + } + } finally { + Binder.restoreCallingIdentity(origId); + } + } + + @Override + public void startLockTaskModeByToken(IBinder token) { + synchronized (mGlobalLock) { + final ActivityRecord r = ActivityRecord.forTokenLocked(token); + if (r == null) { + return; + } + startLockTaskModeLocked(r.getTask(), false /* isSystemCaller */); + } + } + + @Override + public void startSystemLockTaskMode(int taskId) throws RemoteException { + mAm.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "startSystemLockTaskMode"); + // This makes inner call to look as if it was initiated by system. + long ident = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + final TaskRecord task = mStackSupervisor.anyTaskForIdLocked(taskId); + + // When starting lock task mode the stack must be in front and focused + task.getStack().moveToFront("startSystemLockTaskMode"); + startLockTaskModeLocked(task, true /* isSystemCaller */); + } + } finally { + Binder.restoreCallingIdentity(ident); + } + } + + @Override + public void stopLockTaskModeByToken(IBinder token) { + synchronized (mGlobalLock) { + final ActivityRecord r = ActivityRecord.forTokenLocked(token); + if (r == null) { + return; + } + stopLockTaskModeInternal(r.getTask(), false /* isSystemCaller */); + } + } + + /** + * This API should be called by SystemUI only when user perform certain action to dismiss + * lock task mode. We should only dismiss pinned lock task mode in this case. + */ + @Override + public void stopSystemLockTaskMode() throws RemoteException { + mAm.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "stopSystemLockTaskMode"); + stopLockTaskModeInternal(null, true /* isSystemCaller */); + } + + private void startLockTaskModeLocked(@Nullable TaskRecord task, boolean isSystemCaller) { + if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "startLockTaskModeLocked: " + task); + if (task == null || task.mLockTaskAuth == LOCK_TASK_AUTH_DONT_LOCK) { + return; + } + + final ActivityStack stack = mStackSupervisor.getFocusedStack(); + if (stack == null || task != stack.topTask()) { + throw new IllegalArgumentException("Invalid task, not in foreground"); + } + + // {@code isSystemCaller} is used to distinguish whether this request is initiated by the + // system or a specific app. + // * System-initiated requests will only start the pinned mode (screen pinning) + // * App-initiated requests + // - will put the device in fully locked mode (LockTask), if the app is whitelisted + // - will start the pinned mode, otherwise + final int callingUid = Binder.getCallingUid(); + long ident = Binder.clearCallingIdentity(); + try { + // When a task is locked, dismiss the pinned stack if it exists + mStackSupervisor.removeStacksInWindowingModes(WINDOWING_MODE_PINNED); + + mAm.getLockTaskController().startLockTaskMode(task, isSystemCaller, callingUid); + } finally { + Binder.restoreCallingIdentity(ident); + } + } + + private void stopLockTaskModeInternal(@Nullable TaskRecord task, boolean isSystemCaller) { + final int callingUid = Binder.getCallingUid(); + long ident = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + mAm.getLockTaskController().stopLockTaskMode(task, isSystemCaller, callingUid); + } + // Launch in-call UI if a call is ongoing. This is necessary to allow stopping the lock + // task and jumping straight into a call in the case of emergency call back. + TelecomManager tm = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); + if (tm != null) { + tm.showInCallScreen(false); + } + } finally { + Binder.restoreCallingIdentity(ident); + } + } + + @Override + public boolean isInLockTaskMode() { + return getLockTaskModeState() != LOCK_TASK_MODE_NONE; + } + + @Override + public int getLockTaskModeState() { + synchronized (mGlobalLock) { + return mAm.getLockTaskController().getLockTaskModeState(); + } + } + + @Override + public void setTaskDescription(IBinder token, ActivityManager.TaskDescription td) { + synchronized (mGlobalLock) { + ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r != null) { + r.setTaskDescription(td); + final TaskRecord task = r.getTask(); + task.updateTaskDescription(); + mAm.mTaskChangeNotificationController.notifyTaskDescriptionChanged(task.taskId, td); + } + } + } + + @Override + public Bundle getActivityOptions(IBinder token) { + final long origId = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + final ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r != null) { + final ActivityOptions activityOptions = r.takeOptionsLocked(); + return activityOptions == null ? null : activityOptions.toBundle(); + } + return null; + } + } finally { + Binder.restoreCallingIdentity(origId); + } + } + + @Override + public List<IBinder> getAppTasks(String callingPackage) { + int callingUid = Binder.getCallingUid(); + long ident = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + return mAm.getRecentTasks().getAppTasksList(callingUid, callingPackage); + } + } finally { + Binder.restoreCallingIdentity(ident); + } + } + + @Override + public void finishVoiceTask(IVoiceInteractionSession session) { + synchronized (mGlobalLock) { + final long origId = Binder.clearCallingIdentity(); + try { + // TODO: VI Consider treating local voice interactions and voice tasks + // differently here + mStackSupervisor.finishVoiceTask(session); + } finally { + Binder.restoreCallingIdentity(origId); + } + } + + } + + @Override + public boolean isTopOfTask(IBinder token) { + synchronized (mGlobalLock) { + ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r == null) { + throw new IllegalArgumentException(); + } + return r.getTask().getTopActivity() == r; + } + } + + @Override + public void notifyLaunchTaskBehindComplete(IBinder token) { + mStackSupervisor.scheduleLaunchTaskBehindComplete(token); + } + + @Override + public void notifyEnterAnimationComplete(IBinder token) { + mAm.mHandler.sendMessage(mAm.mHandler.obtainMessage(ENTER_ANIMATION_COMPLETE_MSG, token)); + } + + /** Called from an app when assist data is ready. */ + @Override + public void reportAssistContextExtras(IBinder token, Bundle extras, AssistStructure structure, + AssistContent content, Uri referrer) { + PendingAssistExtras pae = (PendingAssistExtras)token; + synchronized (pae) { + pae.result = extras; + pae.structure = structure; + pae.content = content; + if (referrer != null) { + pae.extras.putParcelable(Intent.EXTRA_REFERRER, referrer); + } + if (structure != null) { + structure.setHomeActivity(pae.isHome); + } + pae.haveResult = true; + pae.notifyAll(); + if (pae.intent == null && pae.receiver == null) { + // Caller is just waiting for the result. + return; + } + } + // We are now ready to launch the assist activity. + IAssistDataReceiver sendReceiver = null; + Bundle sendBundle = null; + synchronized (mGlobalLock) { + buildAssistBundleLocked(pae, extras); + boolean exists = mPendingAssistExtras.remove(pae); + mAm.mUiHandler.removeCallbacks(pae); + if (!exists) { + // Timed out. + return; + } + + if ((sendReceiver=pae.receiver) != null) { + // Caller wants result sent back to them. + sendBundle = new Bundle(); + sendBundle.putBundle(ASSIST_KEY_DATA, pae.extras); + sendBundle.putParcelable(ASSIST_KEY_STRUCTURE, pae.structure); + sendBundle.putParcelable(ASSIST_KEY_CONTENT, pae.content); + sendBundle.putBundle(ASSIST_KEY_RECEIVER_EXTRAS, pae.receiverExtras); + } + } + if (sendReceiver != null) { + try { + sendReceiver.onHandleAssistData(sendBundle); + } catch (RemoteException e) { + } + return; + } + + final long ident = Binder.clearCallingIdentity(); + try { + if (TextUtils.equals(pae.intent.getAction(), + android.service.voice.VoiceInteractionService.SERVICE_INTERFACE)) { + pae.intent.putExtras(pae.extras); + mContext.startServiceAsUser(pae.intent, new UserHandle(pae.userHandle)); + } else { + pae.intent.replaceExtras(pae.extras); + pae.intent.setFlags(FLAG_ACTIVITY_NEW_TASK + | Intent.FLAG_ACTIVITY_SINGLE_TOP + | Intent.FLAG_ACTIVITY_CLEAR_TOP); + mAm.closeSystemDialogs("assist"); + + try { + mContext.startActivityAsUser(pae.intent, new UserHandle(pae.userHandle)); + } catch (ActivityNotFoundException e) { + Slog.w(TAG, "No activity to handle assist action.", e); + } + } + } finally { + Binder.restoreCallingIdentity(ident); + } + } + + @Override + public int addAppTask(IBinder activityToken, Intent intent, + ActivityManager.TaskDescription description, Bitmap thumbnail) throws RemoteException { + final int callingUid = Binder.getCallingUid(); + final long callingIdent = Binder.clearCallingIdentity(); + + try { + synchronized (mGlobalLock) { + ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); + if (r == null) { + throw new IllegalArgumentException("Activity does not exist; token=" + + activityToken); + } + ComponentName comp = intent.getComponent(); + if (comp == null) { + throw new IllegalArgumentException("Intent " + intent + + " must specify explicit component"); + } + if (thumbnail.getWidth() != mAm.mThumbnailWidth + || thumbnail.getHeight() != mAm.mThumbnailHeight) { + throw new IllegalArgumentException("Bad thumbnail size: got " + + thumbnail.getWidth() + "x" + thumbnail.getHeight() + ", require " + + mAm.mThumbnailWidth + "x" + mAm.mThumbnailHeight); + } + if (intent.getSelector() != null) { + intent.setSelector(null); + } + if (intent.getSourceBounds() != null) { + intent.setSourceBounds(null); + } + if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0) { + if ((intent.getFlags()&Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS) == 0) { + // The caller has added this as an auto-remove task... that makes no + // sense, so turn off auto-remove. + intent.addFlags(Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS); + } + } + final ActivityInfo ainfo = AppGlobals.getPackageManager().getActivityInfo(comp, + STOCK_PM_FLAGS, 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 ActivityStack stack = r.getStack(); + final TaskRecord task = stack.createTaskRecord( + mStackSupervisor.getNextTaskIdForUserLocked(r.userId), ainfo, intent, + null /* voiceSession */, null /* voiceInteractor */, !ON_TOP); + if (!mAm.getRecentTasks().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; + } + task.lastTaskDescription.copyFrom(description); + + // TODO: Send the thumbnail to WM to store it. + + return task.taskId; + } + } finally { + Binder.restoreCallingIdentity(callingIdent); + } + } + + @Override + public Point getAppTaskThumbnailSize() { + synchronized (mGlobalLock) { + return new Point(mAm.mThumbnailWidth, mAm.mThumbnailHeight); + } + } + + @Override + public void setTaskResizeable(int taskId, int resizeableMode) { + synchronized (mGlobalLock) { + final TaskRecord task = mStackSupervisor.anyTaskForIdLocked( + taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); + if (task == null) { + Slog.w(TAG, "setTaskResizeable: taskId=" + taskId + " not found"); + return; + } + task.setResizeMode(resizeableMode); + } + } + + @Override + public void resizeTask(int taskId, Rect bounds, int resizeMode) { + mAm.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "resizeTask()"); + long ident = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + TaskRecord task = mStackSupervisor.anyTaskForIdLocked(taskId); + if (task == null) { + Slog.w(TAG, "resizeTask: taskId=" + taskId + " not found"); + return; + } + // Place the task in the right stack if it isn't there already based on + // the requested bounds. + // The stack transition logic is: + // - a null bounds on a freeform task moves that task to fullscreen + // - a non-null bounds on a non-freeform (fullscreen OR docked) task moves + // that task to freeform + // - otherwise the task is not moved + ActivityStack stack = task.getStack(); + if (!task.getWindowConfiguration().canResizeTask()) { + throw new IllegalArgumentException("resizeTask not allowed on task=" + task); + } + if (bounds == null && stack.getWindowingMode() == WINDOWING_MODE_FREEFORM) { + stack = stack.getDisplay().getOrCreateStack( + WINDOWING_MODE_FULLSCREEN, stack.getActivityType(), ON_TOP); + } else if (bounds != null && stack.getWindowingMode() != WINDOWING_MODE_FREEFORM) { + stack = stack.getDisplay().getOrCreateStack( + WINDOWING_MODE_FREEFORM, stack.getActivityType(), ON_TOP); + } + + // Reparent the task to the right stack if necessary + boolean preserveWindow = (resizeMode & RESIZE_MODE_PRESERVE_WINDOW) != 0; + if (stack != task.getStack()) { + // Defer resume until the task is resized below + task.reparent(stack, ON_TOP, REPARENT_KEEP_STACK_AT_FRONT, ANIMATE, + DEFER_RESUME, "resizeTask"); + preserveWindow = false; + } + + // After reparenting (which only resizes the task to the stack bounds), resize the + // task to the actual bounds provided + task.resize(bounds, resizeMode, preserveWindow, !DEFER_RESUME); + } + } finally { + Binder.restoreCallingIdentity(ident); + } + } + + @Override + public boolean releaseActivityInstance(IBinder token) { + synchronized (mGlobalLock) { + final long origId = Binder.clearCallingIdentity(); + try { + ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r == null) { + return false; + } + return r.getStack().safelyDestroyActivityLocked(r, "app-req"); + } finally { + Binder.restoreCallingIdentity(origId); + } + } + } + + @Override + public void releaseSomeActivities(IApplicationThread appInt) { + synchronized (mGlobalLock) { + final long origId = Binder.clearCallingIdentity(); + try { + ProcessRecord app = mAm.getRecordForAppLocked(appInt); + mStackSupervisor.releaseSomeActivitiesLocked(app, "low-mem"); + } finally { + Binder.restoreCallingIdentity(origId); + } + } + } + + @Override + public void setLockScreenShown(boolean keyguardShowing, boolean aodShowing, + int secondaryDisplayShowing) { + if (mAm.checkCallingPermission(android.Manifest.permission.DEVICE_POWER) + != PackageManager.PERMISSION_GRANTED) { + throw new SecurityException("Requires permission " + + android.Manifest.permission.DEVICE_POWER); + } + + synchronized (mGlobalLock) { + long ident = Binder.clearCallingIdentity(); + if (mKeyguardShown != keyguardShowing) { + mKeyguardShown = keyguardShowing; + reportCurKeyguardUsageEventLocked(keyguardShowing); + } + try { + mAm.mKeyguardController.setKeyguardShown(keyguardShowing, aodShowing, + secondaryDisplayShowing); + } finally { + Binder.restoreCallingIdentity(ident); + } + } + + mAm.mHandler.obtainMessage(DISPATCH_SCREEN_KEYGUARD_MSG, keyguardShowing ? 1 : 0, 0) + .sendToTarget(); + } + + @Override + public Bitmap getTaskDescriptionIcon(String filePath, int userId) { + userId = mAm.mUserController.handleIncomingUser(Binder.getCallingPid(), + Binder.getCallingUid(), userId, false, ALLOW_FULL_ONLY, "getTaskDescriptionIcon", null); + + final File passedIconFile = new File(filePath); + final File legitIconFile = new File(TaskPersister.getUserImagesDir(userId), + passedIconFile.getName()); + if (!legitIconFile.getPath().equals(filePath) + || !filePath.contains(ActivityRecord.ACTIVITY_ICON_SUFFIX)) { + throw new IllegalArgumentException("Bad file path: " + filePath + + " passed for userId " + userId); + } + return mAm.getRecentTasks().getTaskDescriptionIcon(filePath); + } + + @Override + public void startInPlaceAnimationOnFrontMostApplication(Bundle opts) + throws RemoteException { + final SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(opts); + final ActivityOptions activityOptions = safeOptions != null + ? safeOptions.getOptions(mStackSupervisor) + : null; + if (activityOptions == null + || activityOptions.getAnimationType() != ActivityOptions.ANIM_CUSTOM_IN_PLACE + || activityOptions.getCustomInPlaceResId() == 0) { + throw new IllegalArgumentException("Expected in-place ActivityOption " + + "with valid animation"); + } + mAm.mWindowManager.prepareAppTransition(TRANSIT_TASK_IN_PLACE, false); + mAm.mWindowManager.overridePendingAppTransitionInPlace(activityOptions.getPackageName(), + activityOptions.getCustomInPlaceResId()); + mAm.mWindowManager.executeAppTransition(); + } + + @Override + public void removeStack(int stackId) { + mAm.enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "removeStack()"); + synchronized (mGlobalLock) { + final long ident = Binder.clearCallingIdentity(); + try { + final ActivityStack stack = mStackSupervisor.getStack(stackId); + if (stack == null) { + Slog.w(TAG, "removeStack: No stack with id=" + stackId); + return; + } + if (!stack.isActivityTypeStandardOrUndefined()) { + throw new IllegalArgumentException( + "Removing non-standard stack is not allowed."); + } + mStackSupervisor.removeStack(stack); + } finally { + Binder.restoreCallingIdentity(ident); + } + } + } + + @Override + public void moveStackToDisplay(int stackId, int displayId) { + mAm.enforceCallingPermission(INTERNAL_SYSTEM_WINDOW, "moveStackToDisplay()"); + + synchronized (mGlobalLock) { + final long ident = Binder.clearCallingIdentity(); + try { + if (DEBUG_STACK) Slog.d(TAG_STACK, "moveStackToDisplay: moving stackId=" + stackId + + " to displayId=" + displayId); + mStackSupervisor.moveStackToDisplayLocked(stackId, displayId, ON_TOP); + } finally { + Binder.restoreCallingIdentity(ident); + } + } + } + + @Override + public int createStackOnDisplay(int displayId) { + mAm.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "createStackOnDisplay()"); + synchronized (mGlobalLock) { + final ActivityDisplay display = + mStackSupervisor.getActivityDisplayOrCreateLocked(displayId); + if (display == null) { + return INVALID_STACK_ID; + } + // TODO(multi-display): Have the caller pass in the windowing mode and activity type. + final ActivityStack stack = display.createStack( + WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_STANDARD, + ON_TOP); + return (stack != null) ? stack.mStackId : INVALID_STACK_ID; + } + } + + @Override + public void exitFreeformMode(IBinder token) { + synchronized (mGlobalLock) { + long ident = Binder.clearCallingIdentity(); + try { + final ActivityRecord r = ActivityRecord.forTokenLocked(token); + if (r == null) { + throw new IllegalArgumentException( + "exitFreeformMode: No activity record matching token=" + token); + } + + final ActivityStack stack = r.getStack(); + if (stack == null || !stack.inFreeformWindowingMode()) { + throw new IllegalStateException( + "exitFreeformMode: You can only go fullscreen from freeform."); + } + + stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); + } finally { + Binder.restoreCallingIdentity(ident); + } + } + } + + /** Sets the task stack listener that gets callbacks when a task stack changes. */ + @Override + public void registerTaskStackListener(ITaskStackListener listener) { + mAm.enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, + "registerTaskStackListener()"); + mAm.mTaskChangeNotificationController.registerTaskStackListener(listener); + } + + /** Unregister a task stack listener so that it stops receiving callbacks. */ + @Override + public void unregisterTaskStackListener(ITaskStackListener listener) { + mAm.enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, + "unregisterTaskStackListener()"); + mAm.mTaskChangeNotificationController.unregisterTaskStackListener(listener); + } + + private void reportCurKeyguardUsageEventLocked(boolean keyguardShowing) { + mAm.reportGlobalUsageEventLocked(keyguardShowing + ? UsageEvents.Event.KEYGUARD_SHOWN + : UsageEvents.Event.KEYGUARD_HIDDEN); + } + + @Override + public boolean requestAssistContextExtras(int requestType, IAssistDataReceiver receiver, + Bundle receiverExtras, IBinder activityToken, boolean focused, boolean newSessionId) { + return enqueueAssistContext(requestType, null, null, receiver, receiverExtras, + activityToken, focused, newSessionId, UserHandle.getCallingUserId(), null, + PENDING_ASSIST_EXTRAS_LONG_TIMEOUT, 0) != null; + } + + @Override + public boolean requestAutofillData(IAssistDataReceiver receiver, Bundle receiverExtras, + IBinder activityToken, int flags) { + return enqueueAssistContext(ActivityManager.ASSIST_CONTEXT_AUTOFILL, null, null, + receiver, receiverExtras, activityToken, true, true, UserHandle.getCallingUserId(), + null, PENDING_AUTOFILL_ASSIST_STRUCTURE_TIMEOUT, flags) != null; + } + + @Override + public boolean launchAssistIntent(Intent intent, int requestType, String hint, int userHandle, + Bundle args) { + return enqueueAssistContext(requestType, intent, hint, null, null, null, + true /* focused */, true /* newSessionId */, userHandle, args, + PENDING_ASSIST_EXTRAS_TIMEOUT, 0) != null; + } + + @Override + public Bundle getAssistContextExtras(int requestType) { + PendingAssistExtras pae = enqueueAssistContext(requestType, null, null, null, + null, null, true /* focused */, true /* newSessionId */, + UserHandle.getCallingUserId(), null, PENDING_ASSIST_EXTRAS_TIMEOUT, 0); + if (pae == null) { + return null; + } + synchronized (pae) { + while (!pae.haveResult) { + try { + pae.wait(); + } catch (InterruptedException e) { + } + } + } + synchronized (mGlobalLock) { + buildAssistBundleLocked(pae, pae.result); + mPendingAssistExtras.remove(pae); + mAm.mUiHandler.removeCallbacks(pae); + } + return pae.extras; + } + + private PendingAssistExtras enqueueAssistContext(int requestType, Intent intent, String hint, + IAssistDataReceiver receiver, Bundle receiverExtras, IBinder activityToken, + boolean focused, boolean newSessionId, int userHandle, Bundle args, long timeout, + int flags) { + mAm.enforceCallingPermission(android.Manifest.permission.GET_TOP_ACTIVITY_INFO, + "enqueueAssistContext()"); + + synchronized (mGlobalLock) { + ActivityRecord activity = mAm.getFocusedStack().getTopActivity(); + if (activity == null) { + Slog.w(TAG, "getAssistContextExtras failed: no top activity"); + return null; + } + if (activity.app == null || activity.app.thread == null) { + Slog.w(TAG, "getAssistContextExtras failed: no process for " + activity); + return null; + } + if (focused) { + if (activityToken != null) { + ActivityRecord caller = ActivityRecord.forTokenLocked(activityToken); + if (activity != caller) { + Slog.w(TAG, "enqueueAssistContext failed: caller " + caller + + " is not current top " + activity); + return null; + } + } + } else { + activity = ActivityRecord.forTokenLocked(activityToken); + if (activity == null) { + Slog.w(TAG, "enqueueAssistContext failed: activity for token=" + activityToken + + " couldn't be found"); + return null; + } + if (activity.app == null || activity.app.thread == null) { + Slog.w(TAG, "enqueueAssistContext failed: no process for " + activity); + return null; + } + } + + PendingAssistExtras pae; + Bundle extras = new Bundle(); + if (args != null) { + extras.putAll(args); + } + extras.putString(Intent.EXTRA_ASSIST_PACKAGE, activity.packageName); + extras.putInt(Intent.EXTRA_ASSIST_UID, activity.app.uid); + + pae = new PendingAssistExtras(activity, extras, intent, hint, receiver, receiverExtras, + userHandle); + pae.isHome = activity.isActivityTypeHome(); + + // Increment the sessionId if necessary + if (newSessionId) { + mViSessionId++; + } + try { + activity.app.thread.requestAssistContextExtras(activity.appToken, pae, requestType, + mViSessionId, flags); + mPendingAssistExtras.add(pae); + mAm.mUiHandler.postDelayed(pae, timeout); + } catch (RemoteException e) { + Slog.w(TAG, "getAssistContextExtras failed: crash calling " + activity); + return null; + } + return pae; + } + } + + private void buildAssistBundleLocked(PendingAssistExtras pae, Bundle result) { + if (result != null) { + pae.extras.putBundle(Intent.EXTRA_ASSIST_CONTEXT, result); + } + if (pae.hint != null) { + pae.extras.putBoolean(pae.hint, true); + } + } + + private void pendingAssistExtrasTimedOut(PendingAssistExtras pae) { + IAssistDataReceiver receiver; + synchronized (mGlobalLock) { + mPendingAssistExtras.remove(pae); + receiver = pae.receiver; + } + if (receiver != null) { + // Caller wants result sent back to them. + Bundle sendBundle = new Bundle(); + // At least return the receiver extras + sendBundle.putBundle(ASSIST_KEY_RECEIVER_EXTRAS, pae.receiverExtras); + try { + pae.receiver.onHandleAssistData(sendBundle); + } catch (RemoteException e) { + } + } + } + + public class PendingAssistExtras extends Binder implements Runnable { + public final ActivityRecord activity; + public boolean isHome; + public final Bundle extras; + public final Intent intent; + public final String hint; + public final IAssistDataReceiver receiver; + public final int userHandle; + public boolean haveResult = false; + public Bundle result = null; + public AssistStructure structure = null; + public AssistContent content = null; + public Bundle receiverExtras; + + public PendingAssistExtras(ActivityRecord _activity, Bundle _extras, Intent _intent, + String _hint, IAssistDataReceiver _receiver, Bundle _receiverExtras, + int _userHandle) { + activity = _activity; + extras = _extras; + intent = _intent; + hint = _hint; + receiver = _receiver; + receiverExtras = _receiverExtras; + userHandle = _userHandle; + } + + @Override + public void run() { + Slog.w(TAG, "getAssistContextExtras failed: timeout retrieving from " + activity); + synchronized (this) { + haveResult = true; + notifyAll(); + } + pendingAssistExtrasTimedOut(this); + } + } + + @Override + public boolean isAssistDataAllowedOnCurrentActivity() { + int userId; + synchronized (mGlobalLock) { + final ActivityStack focusedStack = mAm.getFocusedStack(); + if (focusedStack == null || focusedStack.isActivityTypeAssistant()) { + return false; + } + + final ActivityRecord activity = focusedStack.getTopActivity(); + if (activity == null) { + return false; + } + userId = activity.userId; + } + return !DevicePolicyCache.getInstance().getScreenCaptureDisabled(userId); + } + + @Override + public boolean showAssistFromActivity(IBinder token, Bundle args) { + long ident = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + ActivityRecord caller = ActivityRecord.forTokenLocked(token); + ActivityRecord top = mAm.getFocusedStack().getTopActivity(); + if (top != caller) { + Slog.w(TAG, "showAssistFromActivity failed: caller " + caller + + " is not current top " + top); + return false; + } + if (!top.nowVisible) { + Slog.w(TAG, "showAssistFromActivity failed: caller " + caller + + " is not visible"); + return false; + } + } + return mAssistUtils.showSessionForActiveService(args, SHOW_SOURCE_APPLICATION, null, + token); + } finally { + Binder.restoreCallingIdentity(ident); + } + } + + @Override + public boolean isRootVoiceInteraction(IBinder token) { + synchronized (mGlobalLock) { + ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r == null) { + return false; + } + return r.rootVoiceInteraction; + } + } + + @Override + public ComponentName getActivityClassForToken(IBinder token) { + synchronized (mGlobalLock) { + ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r == null) { + return null; + } + return r.intent.getComponent(); + } + } + + @Override + public String getPackageForToken(IBinder token) { + synchronized (mGlobalLock) { + ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r == null) { + return null; + } + return r.packageName; + } + } + + @Override + public void showLockTaskEscapeMessage(IBinder token) { + synchronized (mGlobalLock) { + final ActivityRecord r = ActivityRecord.forTokenLocked(token); + if (r == null) { + return; + } + mAm.getLockTaskController().showLockTaskToast(); + } + } + + @Override + public void keyguardGoingAway(int flags) { + mAm.enforceNotIsolatedCaller("keyguardGoingAway"); + final long token = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + mAm.mKeyguardController.keyguardGoingAway(flags); + } + } finally { + Binder.restoreCallingIdentity(token); + } + } + + /** + * Try to place task to provided position. The final position might be different depending on + * current user and stacks state. The task will be moved to target stack if it's currently in + * different stack. + */ + @Override + public void positionTaskInStack(int taskId, int stackId, int position) { + mAm.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "positionTaskInStack()"); + synchronized (mGlobalLock) { + long ident = Binder.clearCallingIdentity(); + try { + if (DEBUG_STACK) Slog.d(TAG_STACK, "positionTaskInStack: positioning task=" + + taskId + " in stackId=" + stackId + " at position=" + position); + final TaskRecord task = mStackSupervisor.anyTaskForIdLocked(taskId); + if (task == null) { + throw new IllegalArgumentException("positionTaskInStack: no task for id=" + + taskId); + } + + final ActivityStack stack = mStackSupervisor.getStack(stackId); + + if (stack == null) { + throw new IllegalArgumentException("positionTaskInStack: no stack for id=" + + stackId); + } + if (!stack.isActivityTypeStandardOrUndefined()) { + throw new IllegalArgumentException("positionTaskInStack: Attempt to change" + + " the position of task " + taskId + " in/to non-standard stack"); + } + + // TODO: Have the callers of this API call a separate reparent method if that is + // what they intended to do vs. having this method also do reparenting. + if (task.getStack() == stack) { + // Change position in current stack. + stack.positionChildAt(task, position); + } else { + // Reparent to new stack. + task.reparent(stack, position, REPARENT_LEAVE_STACK_IN_PLACE, !ANIMATE, + !DEFER_RESUME, "positionTaskInStack"); + } + } finally { + Binder.restoreCallingIdentity(ident); + } + } + } + + @Override + public void reportSizeConfigurations(IBinder token, int[] horizontalSizeConfiguration, + int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) { + if (DEBUG_CONFIGURATION) Slog.v(TAG, "Report configuration: " + token + " " + + horizontalSizeConfiguration + " " + verticalSizeConfigurations); + synchronized (mGlobalLock) { + ActivityRecord record = ActivityRecord.isInStackLocked(token); + if (record == null) { + throw new IllegalArgumentException("reportSizeConfigurations: ActivityRecord not " + + "found for: " + token); + } + record.setSizeConfigurations(horizontalSizeConfiguration, + verticalSizeConfigurations, smallestSizeConfigurations); + } + } + + /** + * Dismisses split-screen multi-window mode. + * @param toTop If true the current primary split-screen stack will be placed or left on top. + */ + @Override + public void dismissSplitScreenMode(boolean toTop) { + mAm.enforceCallerIsRecentsOrHasPermission( + MANAGE_ACTIVITY_STACKS, "dismissSplitScreenMode()"); + final long ident = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + final ActivityStack stack = + mStackSupervisor.getDefaultDisplay().getSplitScreenPrimaryStack(); + if (stack == null) { + Slog.w(TAG, "dismissSplitScreenMode: primary split-screen stack not found."); + return; + } + + if (toTop) { + // Caller wants the current split-screen primary stack to be the top stack after + // it goes fullscreen, so move it to the front. + stack.moveToFront("dismissSplitScreenMode"); + } else if (mStackSupervisor.isFocusedStack(stack)) { + // In this case the current split-screen primary stack shouldn't be the top + // stack after it goes fullscreen, but it current has focus, so we move the + // focus to the top-most split-screen secondary stack next to it. + final ActivityStack otherStack = stack.getDisplay().getTopStackInWindowingMode( + WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); + if (otherStack != null) { + otherStack.moveToFront("dismissSplitScreenMode_other"); + } + } + + stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); + } + } finally { + Binder.restoreCallingIdentity(ident); + } + } + + /** + * Dismisses Pip + * @param animate True if the dismissal should be animated. + * @param animationDuration The duration of the resize animation in milliseconds or -1 if the + * default animation duration should be used. + */ + @Override + public void dismissPip(boolean animate, int animationDuration) { + mAm.enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "dismissPip()"); + final long ident = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + final PinnedActivityStack stack = + mStackSupervisor.getDefaultDisplay().getPinnedStack(); + if (stack == null) { + Slog.w(TAG, "dismissPip: pinned stack not found."); + return; + } + if (stack.getWindowingMode() != WINDOWING_MODE_PINNED) { + throw new IllegalArgumentException("Stack: " + stack + + " doesn't support animated resize."); + } + if (animate) { + stack.animateResizePinnedStack(null /* sourceHintBounds */, + null /* destBounds */, animationDuration, false /* fromFullscreen */); + } else { + mStackSupervisor.moveTasksToFullscreenStackLocked(stack, true /* onTop */); + } + } + } finally { + Binder.restoreCallingIdentity(ident); + } + } + + @Override + public void suppressResizeConfigChanges(boolean suppress) throws RemoteException { + mAm.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "suppressResizeConfigChanges()"); + synchronized (mGlobalLock) { + mSuppressResizeConfigChanges = suppress; + } + } + + /** + * NOTE: For the pinned stack, this method is usually called after the bounds animation has + * animated the stack to the fullscreen, but can also be called if we are relaunching an + * activity and clearing the task at the same time. + */ + @Override + // TODO: API should just be about changing windowing modes... + public void moveTasksToFullscreenStack(int fromStackId, boolean onTop) { + mAm.enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, + "moveTasksToFullscreenStack()"); + synchronized (mGlobalLock) { + final long origId = Binder.clearCallingIdentity(); + try { + final ActivityStack stack = mStackSupervisor.getStack(fromStackId); + if (stack != null){ + if (!stack.isActivityTypeStandardOrUndefined()) { + throw new IllegalArgumentException( + "You can't move tasks from non-standard stacks."); + } + mStackSupervisor.moveTasksToFullscreenStackLocked(stack, onTop); + } + } finally { + Binder.restoreCallingIdentity(origId); + } + } + } + + /** + * Moves the top activity in the input stackId to the pinned stack. + * + * @param stackId Id of stack to move the top activity to pinned stack. + * @param bounds Bounds to use for pinned stack. + * + * @return True if the top activity of the input stack was successfully moved to the pinned + * stack. + */ + @Override + public boolean moveTopActivityToPinnedStack(int stackId, Rect bounds) { + mAm.enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, + "moveTopActivityToPinnedStack()"); + synchronized (mGlobalLock) { + if (!mAm.mSupportsPictureInPicture) { + throw new IllegalStateException("moveTopActivityToPinnedStack:" + + "Device doesn't support picture-in-picture mode"); + } + + long ident = Binder.clearCallingIdentity(); + try { + return mStackSupervisor.moveTopStackActivityToPinnedStackLocked(stackId, bounds); + } finally { + Binder.restoreCallingIdentity(ident); + } + } + } + + @Override + public boolean isInMultiWindowMode(IBinder token) { + final long origId = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + final ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r == null) { + return false; + } + // An activity is consider to be in multi-window mode if its task isn't fullscreen. + return r.inMultiWindowMode(); + } + } finally { + Binder.restoreCallingIdentity(origId); + } + } + + @Override + public boolean isInPictureInPictureMode(IBinder token) { + final long origId = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + return isInPictureInPictureMode(ActivityRecord.forTokenLocked(token)); + } + } finally { + Binder.restoreCallingIdentity(origId); + } + } + + private boolean isInPictureInPictureMode(ActivityRecord r) { + if (r == null || r.getStack() == null || !r.inPinnedWindowingMode() + || r.getStack().isInStackLocked(r) == null) { + return false; + } + + // If we are animating to fullscreen then we have already dispatched the PIP mode + // changed, so we should reflect that check here as well. + final PinnedActivityStack stack = r.getStack(); + final PinnedStackWindowController windowController = stack.getWindowContainerController(); + return !windowController.isAnimatingBoundsToFullscreen(); + } + + @Override + public boolean enterPictureInPictureMode(IBinder token, final PictureInPictureParams params) { + final long origId = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + final ActivityRecord r = ensureValidPictureInPictureActivityParamsLocked( + "enterPictureInPictureMode", token, params); + + // If the activity is already in picture in picture mode, then just return early + if (isInPictureInPictureMode(r)) { + return true; + } + + // Activity supports picture-in-picture, now check that we can enter PiP at this + // point, if it is + if (!r.checkEnterPictureInPictureState("enterPictureInPictureMode", + false /* beforeStopping */)) { + return false; + } + + final Runnable enterPipRunnable = () -> { + // Only update the saved args from the args that are set + r.pictureInPictureArgs.copyOnlySet(params); + final float aspectRatio = r.pictureInPictureArgs.getAspectRatio(); + final List<RemoteAction> actions = r.pictureInPictureArgs.getActions(); + // Adjust the source bounds by the insets for the transition down + final Rect sourceBounds = new Rect(r.pictureInPictureArgs.getSourceRectHint()); + mStackSupervisor.moveActivityToPinnedStackLocked(r, sourceBounds, aspectRatio, + "enterPictureInPictureMode"); + final PinnedActivityStack stack = r.getStack(); + stack.setPictureInPictureAspectRatio(aspectRatio); + stack.setPictureInPictureActions(actions); + MetricsLoggerWrapper.logPictureInPictureEnter(mContext, r.appInfo.uid, + r.shortComponentName, r.supportsEnterPipOnTaskSwitch); + logPictureInPictureArgs(params); + }; + + if (mAm.isKeyguardLocked()) { + // If the keyguard is showing or occluded, then try and dismiss it before + // entering picture-in-picture (this will prompt the user to authenticate if the + // device is currently locked). + dismissKeyguard(token, new KeyguardDismissCallback() { + @Override + public void onDismissSucceeded() throws RemoteException { + mAm.mHandler.post(enterPipRunnable); + } + }, null /* message */); + } else { + // Enter picture in picture immediately otherwise + enterPipRunnable.run(); + } + return true; + } + } finally { + Binder.restoreCallingIdentity(origId); + } + } + + @Override + public void setPictureInPictureParams(IBinder token, final PictureInPictureParams params) { + final long origId = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + final ActivityRecord r = ensureValidPictureInPictureActivityParamsLocked( + "setPictureInPictureParams", token, params); + + // Only update the saved args from the args that are set + r.pictureInPictureArgs.copyOnlySet(params); + if (r.inPinnedWindowingMode()) { + // If the activity is already in picture-in-picture, update the pinned stack now + // if it is not already expanding to fullscreen. Otherwise, the arguments will + // be used the next time the activity enters PiP + final PinnedActivityStack stack = r.getStack(); + if (!stack.isAnimatingBoundsToFullscreen()) { + stack.setPictureInPictureAspectRatio( + r.pictureInPictureArgs.getAspectRatio()); + stack.setPictureInPictureActions(r.pictureInPictureArgs.getActions()); + } + } + logPictureInPictureArgs(params); + } + } finally { + Binder.restoreCallingIdentity(origId); + } + } + + @Override + public int getMaxNumPictureInPictureActions(IBinder token) { + // Currently, this is a static constant, but later, we may change this to be dependent on + // the context of the activity + return 3; + } + + private void logPictureInPictureArgs(PictureInPictureParams params) { + if (params.hasSetActions()) { + MetricsLogger.histogram(mContext, "tron_varz_picture_in_picture_actions_count", + params.getActions().size()); + } + if (params.hasSetAspectRatio()) { + LogMaker lm = new LogMaker(MetricsEvent.ACTION_PICTURE_IN_PICTURE_ASPECT_RATIO_CHANGED); + lm.addTaggedData(MetricsEvent.PICTURE_IN_PICTURE_ASPECT_RATIO, params.getAspectRatio()); + MetricsLogger.action(lm); + } + } + + /** + * Checks the state of the system and the activity associated with the given {@param token} to + * verify that picture-in-picture is supported for that activity. + * + * @return the activity record for the given {@param token} if all the checks pass. + */ + private ActivityRecord ensureValidPictureInPictureActivityParamsLocked(String caller, + IBinder token, PictureInPictureParams params) { + if (!mAm.mSupportsPictureInPicture) { + throw new IllegalStateException(caller + + ": Device doesn't support picture-in-picture mode."); + } + + final ActivityRecord r = ActivityRecord.forTokenLocked(token); + if (r == null) { + throw new IllegalStateException(caller + + ": Can't find activity for token=" + token); + } + + if (!r.supportsPictureInPicture()) { + throw new IllegalStateException(caller + + ": Current activity does not support picture-in-picture."); + } + + if (params.hasSetAspectRatio() + && !mAm.mWindowManager.isValidPictureInPictureAspectRatio(r.getStack().mDisplayId, + params.getAspectRatio())) { + final float minAspectRatio = mContext.getResources().getFloat( + com.android.internal.R.dimen.config_pictureInPictureMinAspectRatio); + final float maxAspectRatio = mContext.getResources().getFloat( + com.android.internal.R.dimen.config_pictureInPictureMaxAspectRatio); + throw new IllegalArgumentException(String.format(caller + + ": Aspect ratio is too extreme (must be between %f and %f).", + minAspectRatio, maxAspectRatio)); + } + + // Truncate the number of actions if necessary + params.truncateActions(getMaxNumPictureInPictureActions(token)); + + return r; + } + + @Override + public IBinder getUriPermissionOwnerForActivity(IBinder activityToken) { + mAm.enforceNotIsolatedCaller("getUriPermissionOwnerForActivity"); + synchronized (mGlobalLock) { + ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); + if (r == null) { + throw new IllegalArgumentException("Activity does not exist; token=" + + activityToken); + } + return r.getUriPermissionsLocked().getExternalTokenLocked(); + } + } + + @Override + public void resizeDockedStack(Rect dockedBounds, Rect tempDockedTaskBounds, + Rect tempDockedTaskInsetBounds, + Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds) { + mAm.enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizeDockedStack()"); + long ident = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + mStackSupervisor.resizeDockedStackLocked(dockedBounds, tempDockedTaskBounds, + tempDockedTaskInsetBounds, tempOtherTaskBounds, tempOtherTaskInsetBounds, + PRESERVE_WINDOWS); + } + } finally { + Binder.restoreCallingIdentity(ident); + } + } + + @Override + public void setSplitScreenResizing(boolean resizing) { + mAm.enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "setSplitScreenResizing()"); + final long ident = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + mStackSupervisor.setSplitScreenResizing(resizing); + } + } finally { + Binder.restoreCallingIdentity(ident); + } + } + + @Override + public int setVrMode(IBinder token, boolean enabled, ComponentName packageName) { + mAm.enforceSystemHasVrFeature(); + + final VrManagerInternal vrService = LocalServices.getService(VrManagerInternal.class); + + ActivityRecord r; + synchronized (mGlobalLock) { + r = ActivityRecord.isInStackLocked(token); + } + + if (r == null) { + throw new IllegalArgumentException(); + } + + int err; + if ((err = vrService.hasVrPackage(packageName, r.userId)) != + VrManagerInternal.NO_ERROR) { + return err; + } + + // Clear the binder calling uid since this path may call moveToTask(). + final long callingId = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + r.requestedVrComponent = (enabled) ? packageName : null; + + // Update associated state if this activity is currently focused + if (r == mStackSupervisor.getResumedActivityLocked()) { + mAm.applyUpdateVrModeLocked(r); + } + return 0; + } + } finally { + Binder.restoreCallingIdentity(callingId); + } + } + + @Override + public void startLocalVoiceInteraction(IBinder callingActivity, Bundle options) { + Slog.i(TAG, "Activity tried to startLocalVoiceInteraction"); + synchronized (mGlobalLock) { + ActivityRecord activity = mAm.getFocusedStack().getTopActivity(); + if (ActivityRecord.forTokenLocked(callingActivity) != activity) { + throw new SecurityException("Only focused activity can call startVoiceInteraction"); + } + if (mAm.mRunningVoice != null || activity.getTask().voiceSession != null + || activity.voiceSession != null) { + Slog.w(TAG, "Already in a voice interaction, cannot start new voice interaction"); + return; + } + if (activity.pendingVoiceInteractionStart) { + Slog.w(TAG, "Pending start of voice interaction already."); + return; + } + activity.pendingVoiceInteractionStart = true; + } + LocalServices.getService(VoiceInteractionManagerInternal.class) + .startLocalVoiceInteraction(callingActivity, options); + } + + @Override + public void stopLocalVoiceInteraction(IBinder callingActivity) { + LocalServices.getService(VoiceInteractionManagerInternal.class) + .stopLocalVoiceInteraction(callingActivity); + } + + @Override + public boolean supportsLocalVoiceInteraction() { + return LocalServices.getService(VoiceInteractionManagerInternal.class) + .supportsLocalVoiceInteraction(); + } + + /** Notifies all listeners when the pinned stack animation starts. */ + @Override + public void notifyPinnedStackAnimationStarted() { + mAm.mTaskChangeNotificationController.notifyPinnedStackAnimationStarted(); + } + + /** Notifies all listeners when the pinned stack animation ends. */ + @Override + public void notifyPinnedStackAnimationEnded() { + mAm.mTaskChangeNotificationController.notifyPinnedStackAnimationEnded(); + } + + @Override + public void resizePinnedStack(Rect pinnedBounds, Rect tempPinnedTaskBounds) { + mAm.enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizePinnedStack()"); + final long ident = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + mStackSupervisor.resizePinnedStackLocked(pinnedBounds, tempPinnedTaskBounds); + } + } finally { + Binder.restoreCallingIdentity(ident); + } + } + + @Override + public boolean updateDisplayOverrideConfiguration(Configuration values, int displayId) { + mAm.enforceCallingPermission(CHANGE_CONFIGURATION, "updateDisplayOverrideConfiguration()"); + + synchronized (mGlobalLock) { + // Check if display is initialized in AM. + if (!mStackSupervisor.isDisplayAdded(displayId)) { + // Call might come when display is not yet added or has already been removed. + if (DEBUG_CONFIGURATION) { + Slog.w(TAG, "Trying to update display configuration for non-existing displayId=" + + displayId); + } + return false; + } + + if (values == null && mAm.mWindowManager != null) { + // sentinel: fetch the current configuration from the window manager + values = mAm.mWindowManager.computeNewConfiguration(displayId); + } + + if (mAm.mWindowManager != null) { + // Update OOM levels based on display size. + mAm.mProcessList.applyDisplaySize(mAm.mWindowManager); + } + + final long origId = Binder.clearCallingIdentity(); + try { + if (values != null) { + Settings.System.clearConfiguration(values); + } + mAm.updateDisplayOverrideConfigurationLocked(values, null /* starting */, + false /* deferResume */, displayId, mTmpUpdateConfigurationResult); + return mTmpUpdateConfigurationResult.changes != 0; + } finally { + Binder.restoreCallingIdentity(origId); + } + } + } + + @Override + public boolean updateConfiguration(Configuration values) { + mAm.enforceCallingPermission(CHANGE_CONFIGURATION, "updateConfiguration()"); + + synchronized (mGlobalLock) { + if (values == null && mAm.mWindowManager != null) { + // sentinel: fetch the current configuration from the window manager + values = mAm.mWindowManager.computeNewConfiguration(DEFAULT_DISPLAY); + } + + if (mAm.mWindowManager != null) { + // Update OOM levels based on display size. + mAm.mProcessList.applyDisplaySize(mAm.mWindowManager); + } + + final long origId = Binder.clearCallingIdentity(); + try { + if (values != null) { + Settings.System.clearConfiguration(values); + } + mAm.updateConfigurationLocked(values, null, false, false /* persistent */, + UserHandle.USER_NULL, false /* deferResume */, + mTmpUpdateConfigurationResult); + return mTmpUpdateConfigurationResult.changes != 0; + } finally { + Binder.restoreCallingIdentity(origId); + } + } + } + + @Override + public void dismissKeyguard(IBinder token, IKeyguardDismissCallback callback, + CharSequence message) { + if (message != null) { + mAm.enforceCallingPermission( + Manifest.permission.SHOW_KEYGUARD_MESSAGE, "dismissKeyguard()"); + } + final long callingId = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + mAm.mKeyguardController.dismissKeyguard(token, callback, message); + } + } finally { + Binder.restoreCallingIdentity(callingId); + } + } + + @Override + public void cancelTaskWindowTransition(int taskId) { + mAm.enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, + "cancelTaskWindowTransition()"); + final long ident = Binder.clearCallingIdentity(); + try { + synchronized (mGlobalLock) { + final TaskRecord task = mStackSupervisor.anyTaskForIdLocked(taskId, + MATCH_TASK_IN_STACKS_ONLY); + if (task == null) { + Slog.w(TAG, "cancelTaskWindowTransition: taskId=" + taskId + " not found"); + return; + } + task.cancelWindowTransition(); + } + } finally { + Binder.restoreCallingIdentity(ident); + } + } + + @Override + public ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean reducedResolution) { + mAm.enforceCallerIsRecentsOrHasPermission(READ_FRAME_BUFFER, "getTaskSnapshot()"); + final long ident = Binder.clearCallingIdentity(); + try { + final TaskRecord task; + synchronized (mGlobalLock) { + task = mStackSupervisor.anyTaskForIdLocked(taskId, + MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); + if (task == null) { + Slog.w(TAG, "getTaskSnapshot: taskId=" + taskId + " not found"); + return null; + } + } + // Don't call this while holding the lock as this operation might hit the disk. + return task.getSnapshot(reducedResolution); + } finally { + Binder.restoreCallingIdentity(ident); + } + } + + @Override + public void setDisablePreviewScreenshots(IBinder token, boolean disable) { + synchronized (mGlobalLock) { + final ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r == null) { + Slog.w(TAG, "setDisablePreviewScreenshots: Unable to find activity for token=" + + token); + return; + } + final long origId = Binder.clearCallingIdentity(); + try { + r.setDisablePreviewScreenshots(disable); + } finally { + Binder.restoreCallingIdentity(origId); + } + } + } + + /** Return the user id of the last resumed activity. */ + @Override + public @UserIdInt + int getLastResumedActivityUserId() { + mAm.enforceCallingPermission( + Manifest.permission.INTERACT_ACROSS_USERS_FULL, "getLastResumedActivityUserId()"); + synchronized (mGlobalLock) { + if (mAm.mLastResumedActivity == null) { + return mAm.mUserController.getCurrentUserId(); + } + return mAm.mLastResumedActivity.userId; + } + } + + @Override + public void updateLockTaskFeatures(int userId, int flags) { + final int callingUid = Binder.getCallingUid(); + if (callingUid != 0 && callingUid != SYSTEM_UID) { + mAm.enforceCallingPermission(android.Manifest.permission.UPDATE_LOCK_TASK_PACKAGES, + "updateLockTaskFeatures()"); + } + synchronized (mGlobalLock) { + if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "Allowing features " + userId + ":0x" + + Integer.toHexString(flags)); + mAm.getLockTaskController().updateLockTaskFeatures(userId, flags); + } + } + + @Override + public void setShowWhenLocked(IBinder token, boolean showWhenLocked) { + synchronized (mGlobalLock) { + final ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r == null) { + return; + } + final long origId = Binder.clearCallingIdentity(); + try { + r.setShowWhenLocked(showWhenLocked); + } finally { + Binder.restoreCallingIdentity(origId); + } + } + } + + @Override + public void setTurnScreenOn(IBinder token, boolean turnScreenOn) { + synchronized (mGlobalLock) { + final ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r == null) { + return; + } + final long origId = Binder.clearCallingIdentity(); + try { + r.setTurnScreenOn(turnScreenOn); + } finally { + Binder.restoreCallingIdentity(origId); + } + } + } + + @Override + public void registerRemoteAnimations(IBinder token, RemoteAnimationDefinition definition) { + mAm.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, + "registerRemoteAnimations"); + definition.setCallingPid(Binder.getCallingPid()); + synchronized (mGlobalLock) { + final ActivityRecord r = ActivityRecord.isInStackLocked(token); + if (r == null) { + return; + } + final long origId = Binder.clearCallingIdentity(); + try { + r.registerRemoteAnimations(definition); + } finally { + Binder.restoreCallingIdentity(origId); + } + } + } + + @Override + public void registerRemoteAnimationForNextActivityStart(String packageName, + RemoteAnimationAdapter adapter) { + mAm.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, + "registerRemoteAnimationForNextActivityStart"); + adapter.setCallingPid(Binder.getCallingPid()); + synchronized (mGlobalLock) { + final long origId = Binder.clearCallingIdentity(); + try { + mAm.getActivityStartController().registerRemoteAnimationForNextActivityStart( + packageName, adapter); + } finally { + Binder.restoreCallingIdentity(origId); + } + } + } + + /** @see android.app.ActivityManager#alwaysShowUnsupportedCompileSdkWarning */ + @Override + public void alwaysShowUnsupportedCompileSdkWarning(ComponentName activity) { + synchronized (mGlobalLock) { + final long origId = Binder.clearCallingIdentity(); + try { + mAm.mAppWarnings.alwaysShowUnsupportedCompileSdkWarning(activity); + } finally { + Binder.restoreCallingIdentity(origId); + } + } + } } diff --git a/services/core/java/com/android/server/am/AppErrors.java b/services/core/java/com/android/server/am/AppErrors.java index a6dafbb1db36..75090d4b9f90 100644 --- a/services/core/java/com/android/server/am/AppErrors.java +++ b/services/core/java/com/android/server/am/AppErrors.java @@ -471,7 +471,7 @@ class AppErrors { mService.removeProcessLocked(r, false, true, "crash"); if (task != null) { try { - mService.startActivityFromRecents(task.taskId, + mService.mActivityTaskManager.startActivityFromRecents(task.taskId, ActivityOptions.makeBasic().toBundle()); } catch (IllegalArgumentException e) { // Hmm, that didn't work, app might have crashed before creating a diff --git a/services/core/java/com/android/server/am/AssistDataRequester.java b/services/core/java/com/android/server/am/AssistDataRequester.java index 9f7621f2e78e..14d14982bf7d 100644 --- a/services/core/java/com/android/server/am/AssistDataRequester.java +++ b/services/core/java/com/android/server/am/AssistDataRequester.java @@ -21,6 +21,7 @@ import static android.app.ActivityManagerInternal.ASSIST_KEY_RECEIVER_EXTRAS; import static android.app.AppOpsManager.MODE_ALLOWED; import static android.app.AppOpsManager.OP_NONE; +import android.app.ActivityTaskManager; import android.app.AppOpsManager; import android.app.IActivityManager; import android.app.IAssistDataReceiver; @@ -163,7 +164,8 @@ public class AssistDataRequester extends IAssistDataReceiver.Stub { // Ensure that the current activity supports assist data boolean isAssistDataAllowed = false; try { - isAssistDataAllowed = mService.isAssistDataAllowedOnCurrentActivity(); + isAssistDataAllowed = + ActivityTaskManager.getService().isAssistDataAllowedOnCurrentActivity(); } catch (RemoteException e) { // Should never happen } @@ -188,9 +190,9 @@ public class AssistDataRequester extends IAssistDataReceiver.Stub { Bundle receiverExtras = new Bundle(); receiverExtras.putInt(KEY_RECEIVER_EXTRA_INDEX, i); receiverExtras.putInt(KEY_RECEIVER_EXTRA_COUNT, numActivities); - if (mService.requestAssistContextExtras(ASSIST_CONTEXT_FULL, this, - receiverExtras, topActivity, /* focused= */ i == 0, - /* newSessionId= */ i == 0)) { + if (ActivityTaskManager.getService().requestAssistContextExtras( + ASSIST_CONTEXT_FULL, this, receiverExtras, topActivity, + /* focused= */ i == 0, /* newSessionId= */ i == 0)) { mPendingDataCount++; } else if (i == 0) { // Wasn't allowed... given that, let's not do the screenshot either. diff --git a/services/core/java/com/android/server/am/LaunchParamsController.java b/services/core/java/com/android/server/am/LaunchParamsController.java index 7ab7f987d301..4330d2c6efaf 100644 --- a/services/core/java/com/android/server/am/LaunchParamsController.java +++ b/services/core/java/com/android/server/am/LaunchParamsController.java @@ -125,7 +125,7 @@ class LaunchParamsController { try { if (mTmpParams.hasPreferredDisplay() && mTmpParams.mPreferredDisplayId != task.getStack().getDisplay().mDisplayId) { - mService.moveStackToDisplay(task.getStackId(), mTmpParams.mPreferredDisplayId); + mService.mActivityTaskManager.moveStackToDisplay(task.getStackId(), mTmpParams.mPreferredDisplayId); } if (mTmpParams.hasWindowingMode() diff --git a/services/core/java/com/android/server/am/LockTaskController.java b/services/core/java/com/android/server/am/LockTaskController.java index 151ef4942432..4fd01cdeaa3b 100644 --- a/services/core/java/com/android/server/am/LockTaskController.java +++ b/services/core/java/com/android/server/am/LockTaskController.java @@ -361,7 +361,7 @@ public class LockTaskController { * @param task the task that requested the end of lock task mode ({@code null} for quitting app * pinning mode) * @param isSystemCaller indicates whether this request comes from the system via - * {@link ActivityManagerService#stopSystemLockTaskMode()}. If + * {@link ActivityTaskManagerService#stopSystemLockTaskMode()}. If * {@code true}, it means the user intends to stop pinned mode through UI; * otherwise, it's called by an app and we need to stop locked or pinned * mode, subject to checks. @@ -509,7 +509,7 @@ public class LockTaskController { * * @param task the task that should be locked. * @param isSystemCaller indicates whether this request was initiated by the system via - * {@link ActivityManagerService#startSystemLockTaskMode(int)}. If + * {@link ActivityTaskManagerService#startSystemLockTaskMode(int)}. If * {@code true}, this intends to start pinned mode; otherwise, we look * at the calling task's mLockTaskAuth to decide which mode to start. * @param callingUid the caller that requested the launch of lock task mode. diff --git a/services/core/java/com/android/server/am/PinnedActivityStack.java b/services/core/java/com/android/server/am/PinnedActivityStack.java index 27269791f568..4062f45b2ef7 100644 --- a/services/core/java/com/android/server/am/PinnedActivityStack.java +++ b/services/core/java/com/android/server/am/PinnedActivityStack.java @@ -55,7 +55,7 @@ class PinnedActivityStack extends ActivityStack<PinnedStackWindowController> void animateResizePinnedStack(Rect sourceHintBounds, Rect toBounds, int animationDuration, boolean fromFullscreen) { if (skipResizeAnimation(toBounds == null /* toFullscreen */)) { - mService.moveTasksToFullscreenStack(mStackId, true /* onTop */); + mService.mActivityTaskManager.moveTasksToFullscreenStack(mStackId, true /* onTop */); } else { getWindowContainerController().animateResizePinnedStack(toBounds, sourceHintBounds, animationDuration, fromFullscreen); diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java index c8410815f141..0ea49b26bf17 100644 --- a/services/core/java/com/android/server/am/TaskRecord.java +++ b/services/core/java/com/android/server/am/TaskRecord.java @@ -486,7 +486,7 @@ class TaskRecord extends ConfigurationContainer implements TaskWindowContainerLi // TODO: Consolidate this with the resize() method below. @Override public void requestResize(Rect bounds, int resizeMode) { - mService.resizeTask(taskId, bounds, resizeMode); + mService.mActivityTaskManager.resizeTask(taskId, bounds, resizeMode); } boolean resize(Rect bounds, int resizeMode, boolean preserveWindow, boolean deferResume) { @@ -1745,7 +1745,7 @@ class TaskRecord extends ConfigurationContainer implements TaskWindowContainerLi * @param bounds The bounds of the task. * @param insetBounds The bounds used to calculate the system insets, which is used here to * subtract the navigation bar/status bar size from the screen size reported - * to the application. See {@link IActivityManager#resizeDockedStack}. + * to the application. See {@link IActivityTaskManager#resizeDockedStack}. * @return True if the override configuration was updated. */ boolean updateOverrideConfiguration(Rect bounds, @Nullable Rect insetBounds) { diff --git a/services/core/java/com/android/server/display/BrightnessTracker.java b/services/core/java/com/android/server/display/BrightnessTracker.java index a568fe336f37..c473ef23db3e 100644 --- a/services/core/java/com/android/server/display/BrightnessTracker.java +++ b/services/core/java/com/android/server/display/BrightnessTracker.java @@ -19,6 +19,7 @@ package com.android.server.display; import android.annotation.Nullable; import android.annotation.UserIdInt; import android.app.ActivityManager; +import android.app.ActivityTaskManager; import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.Context; @@ -937,7 +938,7 @@ public class BrightnessTracker { } public ActivityManager.StackInfo getFocusedStack() throws RemoteException { - return ActivityManager.getService().getFocusedStackInfo(); + return ActivityTaskManager.getService().getFocusedStackInfo(); } public void scheduleIdleJob(Context context) { diff --git a/services/core/java/com/android/server/display/DisplayTransformManager.java b/services/core/java/com/android/server/display/DisplayTransformManager.java index 57a4f0dd526d..d6931e006479 100644 --- a/services/core/java/com/android/server/display/DisplayTransformManager.java +++ b/services/core/java/com/android/server/display/DisplayTransformManager.java @@ -17,6 +17,7 @@ package com.android.server.display; import android.app.ActivityManager; +import android.app.ActivityTaskManager; import android.opengl.Matrix; import android.os.IBinder; import android.os.Parcel; @@ -309,7 +310,7 @@ public class DisplayTransformManager { private void updateConfiguration() { try { - ActivityManager.getService().updateConfiguration(null); + ActivityTaskManager.getService().updateConfiguration(null); } catch (RemoteException e) { Log.e(TAG, "Could not update configuration", e); } diff --git a/services/core/java/com/android/server/fingerprint/FingerprintService.java b/services/core/java/com/android/server/fingerprint/FingerprintService.java index 06329e571b43..8e7782015691 100644 --- a/services/core/java/com/android/server/fingerprint/FingerprintService.java +++ b/services/core/java/com/android/server/fingerprint/FingerprintService.java @@ -25,9 +25,11 @@ import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREG import android.app.ActivityManager; import android.app.ActivityManager.RunningAppProcessInfo; +import android.app.ActivityTaskManager; import android.app.AlarmManager; import android.app.AppOpsManager; import android.app.IActivityManager; +import android.app.IActivityTaskManager; import android.app.PendingIntent; import android.app.SynchronousUserSwitchObserver; import android.app.TaskStackListener; @@ -140,6 +142,7 @@ public class FingerprintService extends SystemService implements IHwBinder.Death private IBiometricsFingerprint mDaemon; private IStatusBarService mStatusBarService; private final IActivityManager mActivityManager; + private final IActivityTaskManager mActivityTaskManager; private final PowerManager mPowerManager; private final AlarmManager mAlarmManager; private final UserManager mUserManager; @@ -229,7 +232,8 @@ public class FingerprintService extends SystemService implements IHwBinder.Death if (isKeyguard(currentClient)) { return; // Keyguard is always allowed } - List<ActivityManager.RunningTaskInfo> runningTasks = mActivityManager.getTasks(1); + List<ActivityManager.RunningTaskInfo> runningTasks = + mActivityTaskManager.getTasks(1); if (!runningTasks.isEmpty()) { final String topPackage = runningTasks.get(0).topActivity.getPackageName(); if (!topPackage.contentEquals(currentClient)) { @@ -261,6 +265,8 @@ public class FingerprintService extends SystemService implements IHwBinder.Death ServiceManager.getService(Context.STATUS_BAR_SERVICE)); mActivityManager = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)) .getService(); + mActivityTaskManager = ((ActivityTaskManager) context.getSystemService( + Context.ACTIVITY_TASK_SERVICE)).getService(); } @Override @@ -871,7 +877,7 @@ public class FingerprintService extends SystemService implements IHwBinder.Death @Override public void onStart() { try { - mActivityManager.registerTaskStackListener(mTaskStackListener); + mActivityTaskManager.registerTaskStackListener(mTaskStackListener); } catch (RemoteException e) { Slog.e(TAG, "Could not register task stack listener", e); } @@ -880,7 +886,7 @@ public class FingerprintService extends SystemService implements IHwBinder.Death @Override public void onStop() { try { - mActivityManager.unregisterTaskStackListener(mTaskStackListener); + mActivityTaskManager.unregisterTaskStackListener(mTaskStackListener); } catch (RemoteException e) { Slog.e(TAG, "Could not unregister task stack listener", e); } diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index 8b0375ffdcf8..32825f74fee9 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -156,6 +156,7 @@ import android.annotation.Nullable; import android.app.ActivityManager; import android.app.ActivityManagerInternal; import android.app.ActivityManagerInternal.SleepToken; +import android.app.ActivityTaskManager; import android.app.ActivityThread; import android.app.AppOpsManager; import android.app.IUiModeManager; @@ -7987,7 +7988,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { sendCloseSystemWindows(); Intent dock = createHomeDockIntent(); if (dock != null) { - int result = ActivityManager.getService() + int result = ActivityTaskManager.getService() .startActivityAsUser(null, null, dock, dock.resolveTypeIfNeeded(mContext.getContentResolver()), null, null, 0, @@ -7998,7 +7999,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } } - int result = ActivityManager.getService() + int result = ActivityTaskManager.getService() .startActivityAsUser(null, null, mHomeIntent, mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), null, null, 0, diff --git a/services/core/java/com/android/server/policy/keyguard/KeyguardServiceDelegate.java b/services/core/java/com/android/server/policy/keyguard/KeyguardServiceDelegate.java index 81a8c55c5aea..1e0b52adb2f4 100644 --- a/services/core/java/com/android/server/policy/keyguard/KeyguardServiceDelegate.java +++ b/services/core/java/com/android/server/policy/keyguard/KeyguardServiceDelegate.java @@ -8,6 +8,7 @@ import static com.android.server.wm.KeyguardServiceDelegateProto.SECURE; import static com.android.server.wm.KeyguardServiceDelegateProto.SHOWING; import android.app.ActivityManager; +import android.app.ActivityTaskManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -213,7 +214,7 @@ public class KeyguardServiceDelegate { // There are no longer any keyguard windows on secondary displays, so pass // INVALID_DISPLAY. All that means is that showWhenLocked activities on // secondary displays now get to show. - ActivityManager.getService().setLockScreenShown(true /* keyguardShowing */, + ActivityTaskManager.getService().setLockScreenShown(true /* keyguardShowing */, false /* aodShowing */, INVALID_DISPLAY); } catch (RemoteException e) { // Local call. diff --git a/services/core/java/com/android/server/search/SearchManagerService.java b/services/core/java/com/android/server/search/SearchManagerService.java index c3fa82344941..bc1a12fac393 100644 --- a/services/core/java/com/android/server/search/SearchManagerService.java +++ b/services/core/java/com/android/server/search/SearchManagerService.java @@ -17,7 +17,9 @@ package com.android.server.search; import android.app.ActivityManager; +import android.app.ActivityTaskManager; import android.app.IActivityManager; +import android.app.IActivityTaskManager; import android.app.ISearchManager; import android.app.SearchManager; import android.app.SearchableInfo; @@ -307,7 +309,7 @@ public class SearchManagerService extends ISearchManager.Stub { Intent intent = new Intent(VoiceInteractionService.SERVICE_INTERFACE); intent.setComponent(comp); - IActivityManager am = ActivityManager.getService(); + IActivityTaskManager am = ActivityTaskManager.getService(); if (args != null) { args.putInt(Intent.EXTRA_KEY_EVENT, android.view.KeyEvent.KEYCODE_ASSIST); } diff --git a/services/core/java/com/android/server/wm/DragAndDropPermissionsHandler.java b/services/core/java/com/android/server/wm/DragAndDropPermissionsHandler.java index 70478fe677ed..51d5eea14b44 100644 --- a/services/core/java/com/android/server/wm/DragAndDropPermissionsHandler.java +++ b/services/core/java/com/android/server/wm/DragAndDropPermissionsHandler.java @@ -17,6 +17,7 @@ package com.android.server.wm; import android.app.ActivityManager; +import android.app.ActivityTaskManager; import android.content.ClipData; import android.net.Uri; import android.os.Binder; @@ -61,7 +62,7 @@ class DragAndDropPermissionsHandler extends IDragAndDropPermissions.Stub mActivityToken = activityToken; // Will throw if Activity is not found. - IBinder permissionOwner = ActivityManager.getService(). + IBinder permissionOwner = ActivityTaskManager.getService(). getUriPermissionOwnerForActivity(mActivityToken); doTake(permissionOwner); @@ -101,7 +102,7 @@ class DragAndDropPermissionsHandler extends IDragAndDropPermissions.Stub IBinder permissionOwner = null; if (mActivityToken != null) { try { - permissionOwner = ActivityManager.getService(). + permissionOwner = ActivityTaskManager.getService(). getUriPermissionOwnerForActivity(mActivityToken); } catch (Exception e) { // Activity is destroyed, permissions already revoked. diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java index 16277d50897e..2da77a15b956 100644 --- a/services/core/java/com/android/server/wm/Task.java +++ b/services/core/java/com/android/server/wm/Task.java @@ -218,7 +218,7 @@ class Task extends WindowContainer<AppWindowToken> { } } - /** @see com.android.server.am.ActivityManagerService#positionTaskInStack(int, int, int). */ + /** @see com.android.server.am.ActivityTaskManagerService#positionTaskInStack(int, int, int). */ void positionAt(int position) { mStack.positionChildAt(position, this, false /* includingParents */); } @@ -298,7 +298,7 @@ class Task extends WindowContainer<AppWindowToken> { /** * Sets the bounds used to calculate the insets. See - * {@link android.app.IActivityManager#resizeDockedStack} why this is needed. + * {@link android.app.IActivityTaskManager#resizeDockedStack} why this is needed. */ void setTempInsetBounds(Rect tempInsetBounds) { if (tempInsetBounds != null) { @@ -310,7 +310,7 @@ class Task extends WindowContainer<AppWindowToken> { /** * Gets the bounds used to calculate the insets. See - * {@link android.app.IActivityManager#resizeDockedStack} why this is needed. + * {@link android.app.IActivityTaskManager#resizeDockedStack} why this is needed. */ void getTempInsetBounds(Rect out) { out.set(mTempInsetBounds); diff --git a/services/core/java/com/android/server/wm/TaskPositioner.java b/services/core/java/com/android/server/wm/TaskPositioner.java index 223c666e56ad..30f46a05cb72 100644 --- a/services/core/java/com/android/server/wm/TaskPositioner.java +++ b/services/core/java/com/android/server/wm/TaskPositioner.java @@ -30,6 +30,7 @@ import static com.android.server.wm.WindowState.MINIMUM_VISIBLE_WIDTH_IN_DP; import android.annotation.IntDef; import android.app.IActivityManager; +import android.app.IActivityTaskManager; import android.graphics.Point; import android.graphics.Rect; import android.os.Looper; @@ -94,7 +95,7 @@ class TaskPositioner { static final float MIN_ASPECT = 1.2f; private final WindowManagerService mService; - private final IActivityManager mActivityManager; + private final IActivityTaskManager mActivityManager; private WindowPositionerEventReceiver mInputEventReceiver; private Display mDisplay; private final DisplayMetrics mDisplayMetrics = new DisplayMetrics(); @@ -219,14 +220,14 @@ class TaskPositioner { } @VisibleForTesting - TaskPositioner(WindowManagerService service, IActivityManager activityManager) { + TaskPositioner(WindowManagerService service, IActivityTaskManager activityManager) { mService = service; mActivityManager = activityManager; } /** Use {@link #create(WindowManagerService)} instead **/ TaskPositioner(WindowManagerService service) { - this(service, service.mActivityManager); + this(service, service.mActivityTaskManager); } @VisibleForTesting diff --git a/services/core/java/com/android/server/wm/TaskPositioningController.java b/services/core/java/com/android/server/wm/TaskPositioningController.java index a3f4ee80dfcb..7d36650f375b 100644 --- a/services/core/java/com/android/server/wm/TaskPositioningController.java +++ b/services/core/java/com/android/server/wm/TaskPositioningController.java @@ -21,6 +21,7 @@ import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; import android.annotation.Nullable; import android.app.IActivityManager; +import android.app.IActivityTaskManager; import android.os.RemoteException; import android.os.Handler; import android.os.Looper; @@ -38,7 +39,7 @@ class TaskPositioningController { private final WindowManagerService mService; private final InputManagerService mInputManager; private final InputMonitor mInputMonitor; - private final IActivityManager mActivityManager; + private final IActivityTaskManager mActivityManager; private final Handler mHandler; @GuardedBy("WindowManagerSerivce.mWindowMap") @@ -53,7 +54,7 @@ class TaskPositioningController { } TaskPositioningController(WindowManagerService service, InputManagerService inputManager, - InputMonitor inputMonitor, IActivityManager activityManager, Looper looper) { + InputMonitor inputMonitor, IActivityTaskManager activityManager, Looper looper) { mService = service; mInputMonitor = inputMonitor; mInputManager = inputManager; diff --git a/services/core/java/com/android/server/wm/TaskStack.java b/services/core/java/com/android/server/wm/TaskStack.java index 731a06e299b3..e6db6d9919e8 100644 --- a/services/core/java/com/android/server/wm/TaskStack.java +++ b/services/core/java/com/android/server/wm/TaskStack.java @@ -1614,7 +1614,7 @@ public class TaskStack extends WindowContainer<Task> implements } try { - mService.mActivityManager.resizePinnedStack(stackBounds, tempTaskBounds); + mService.mActivityTaskManager.resizePinnedStack(stackBounds, tempTaskBounds); } catch (RemoteException e) { // I don't believe you. } @@ -1647,7 +1647,7 @@ public class TaskStack extends WindowContainer<Task> implements if (inPinnedWindowingMode()) { try { - mService.mActivityManager.notifyPinnedStackAnimationStarted(); + mService.mActivityTaskManager.notifyPinnedStackAnimationStarted(); } catch (RemoteException e) { // I don't believe you... } @@ -1689,9 +1689,9 @@ public class TaskStack extends WindowContainer<Task> implements } try { - mService.mActivityManager.notifyPinnedStackAnimationEnded(); + mService.mActivityTaskManager.notifyPinnedStackAnimationEnded(); if (moveToFullscreen) { - mService.mActivityManager.moveTasksToFullscreenStack(mStackId, + mService.mActivityTaskManager.moveTasksToFullscreenStack(mStackId, true /* onTop */); } } catch (RemoteException e) { diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index df3b16c17eee..c1753c0cc1d3 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -116,9 +116,11 @@ import android.annotation.Nullable; import android.app.ActivityManager; import android.app.ActivityManager.TaskSnapshot; import android.app.ActivityManagerInternal; +import android.app.ActivityTaskManager; import android.app.ActivityThread; import android.app.AppOpsManager; import android.app.IActivityManager; +import android.app.IActivityTaskManager; import android.app.IAssistDataReceiver; import android.app.admin.DevicePolicyCache; import android.content.BroadcastReceiver; @@ -427,6 +429,8 @@ public class WindowManagerService extends IWindowManager.Stub final WindowManagerPolicy mPolicy; final IActivityManager mActivityManager; + // TODO: Probably not needed once activities are fully in WM. + final IActivityTaskManager mActivityTaskManager; final ActivityManagerInternal mAmInternal; final AppOpsManager mAppOps; @@ -859,7 +863,7 @@ public class WindowManagerService extends IWindowManager.Stub } if (atoken.mLaunchTaskBehind) { try { - mActivityManager.notifyLaunchTaskBehindComplete(atoken.token); + mActivityTaskManager.notifyLaunchTaskBehindComplete(atoken.token); } catch (RemoteException e) { } atoken.mLaunchTaskBehind = false; @@ -876,7 +880,7 @@ public class WindowManagerService extends IWindowManager.Stub } else { atoken.mEnteringAnimation = false; try { - mActivityManager.notifyEnterAnimationComplete(atoken.token); + mActivityTaskManager.notifyEnterAnimationComplete(atoken.token); } catch (RemoteException e) { } } @@ -1009,6 +1013,7 @@ public class WindowManagerService extends IWindowManager.Stub AnimationThread.getHandler(), animationHandler); mActivityManager = ActivityManager.getService(); + mActivityTaskManager = ActivityTaskManager.getService(); mAmInternal = LocalServices.getService(ActivityManagerInternal.class); mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE); AppOpsManager.OnOpChangedInternalListener opListener = @@ -1066,7 +1071,7 @@ public class WindowManagerService extends IWindowManager.Stub com.android.internal.R.bool.config_allowTheaterModeWakeFromWindowLayout); mTaskPositioningController = new TaskPositioningController( - this, mInputManager, mInputMonitor, mActivityManager, mH.getLooper()); + this, mInputManager, mInputMonitor, mActivityTaskManager, mH.getLooper()); mDragDropController = new DragDropController(this, mH.getLooper()); LocalServices.addService(WindowManagerInternal.class, new LocalService()); @@ -4372,7 +4377,7 @@ public class WindowManagerService extends IWindowManager.Stub */ void sendNewConfiguration(int displayId) { try { - final boolean configUpdated = mActivityManager.updateDisplayOverrideConfiguration( + final boolean configUpdated = mActivityTaskManager.updateDisplayOverrideConfiguration( null /* values */, displayId); if (!configUpdated) { // Something changed (E.g. device rotation), but no configuration update is needed. @@ -4527,7 +4532,7 @@ public class WindowManagerService extends IWindowManager.Stub } try { - mActivityManager.updateConfiguration(null); + mActivityTaskManager.updateConfiguration(null); } catch (RemoteException e) { } @@ -4538,7 +4543,7 @@ public class WindowManagerService extends IWindowManager.Stub } try { - mActivityManager.updateConfiguration(null); + mActivityTaskManager.updateConfiguration(null); } catch (RemoteException e) { } @@ -4893,7 +4898,7 @@ public class WindowManagerService extends IWindowManager.Stub case NOTIFY_ACTIVITY_DRAWN: try { - mActivityManager.notifyActivityDrawn((IBinder) msg.obj); + mActivityTaskManager.notifyActivityDrawn((IBinder) msg.obj); } catch (RemoteException e) { } break; diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 1eb56178def9..cbe30cf65c94 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -445,7 +445,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP /** * Usually empty. Set to the task's tempInsetFrame. See - *{@link android.app.IActivityManager#resizeDockedStack}. + *{@link android.app.IActivityTaskManager#resizeDockedStack}. */ private final Rect mInsetFrame = new Rect(); @@ -2448,7 +2448,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP try { // Note: this calls into ActivityManager, so we must *not* hold the window // manager lock while calling this. - mService.mActivityManager.setSplitScreenResizing(false); + mService.mActivityTaskManager.setSplitScreenResizing(false); } catch (RemoteException e) { // Local call, shouldn't return RemoteException. throw e.rethrowAsRuntimeException(); diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index e605a4982e53..414cf478f84d 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -90,10 +90,12 @@ import android.annotation.UserIdInt; import android.app.Activity; import android.app.ActivityManager; import android.app.ActivityManagerInternal; +import android.app.ActivityTaskManager; import android.app.ActivityThread; import android.app.AlarmManager; import android.app.AppGlobals; import android.app.IActivityManager; +import android.app.IActivityTaskManager; import android.app.IApplicationThread; import android.app.IServiceConnection; import android.app.Notification; @@ -1865,6 +1867,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { return ActivityManager.getService(); } + IActivityTaskManager getIActivityTaskManager() { + return ActivityTaskManager.getService(); + } + ActivityManagerInternal getActivityManagerInternal() { return LocalServices.getService(ActivityManagerInternal.class); } @@ -3286,8 +3292,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { private void updateLockTaskFeaturesLocked(int flags, int userId) { long ident = mInjector.binderClearCallingIdentity(); try { - mInjector.getIActivityManager() - .updateLockTaskFeatures(userId, flags); + mInjector.getIActivityTaskManager().updateLockTaskFeatures(userId, flags); } catch (RemoteException e) { // Not gonna happen. } finally { @@ -10155,7 +10160,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (policy.mStatusBarDisabled != disabled) { boolean isLockTaskMode = false; try { - isLockTaskMode = mInjector.getIActivityManager().getLockTaskModeState() + isLockTaskMode = mInjector.getIActivityTaskManager().getLockTaskModeState() != LOCK_TASK_MODE_NONE; } catch (RemoteException e) { Slog.e(LOG_TAG, "Failed to get LockTask mode"); diff --git a/services/tests/servicestests/src/com/android/server/am/AssistDataRequesterTest.java b/services/tests/servicestests/src/com/android/server/am/AssistDataRequesterTest.java index ce88d849a1d4..0a436b956abc 100644 --- a/services/tests/servicestests/src/com/android/server/am/AssistDataRequesterTest.java +++ b/services/tests/servicestests/src/com/android/server/am/AssistDataRequesterTest.java @@ -35,6 +35,7 @@ import static org.mockito.Mockito.mock; import android.app.AppOpsManager; import android.app.IActivityManager; +import android.app.IActivityTaskManager; import android.content.Context; import android.graphics.Bitmap; import android.os.Bundle; @@ -87,6 +88,7 @@ public class AssistDataRequesterTest extends ActivityTestsBase { private Object mCallbacksLock; private Handler mHandler; private IActivityManager mAm; + private IActivityTaskManager mAtm; private IWindowManager mWm; private AppOpsManager mAppOpsManager; @@ -104,6 +106,7 @@ public class AssistDataRequesterTest extends ActivityTestsBase { public void setUp() throws Exception { super.setUp(); mAm = mock(IActivityManager.class); + mAtm = mock(IActivityTaskManager.class); mWm = mock(IWindowManager.class); mAppOpsManager = mock(AppOpsManager.class); mContext = InstrumentationRegistry.getContext(); @@ -125,7 +128,7 @@ public class AssistDataRequesterTest extends ActivityTestsBase { } }); return true; - }).when(mAm).requestAssistContextExtras(anyInt(), any(), any(), any(), anyBoolean(), + }).when(mAtm).requestAssistContextExtras(anyInt(), any(), any(), any(), anyBoolean(), anyBoolean()); doAnswer(invocation -> { mHandler.post(() -> { @@ -142,7 +145,7 @@ public class AssistDataRequesterTest extends ActivityTestsBase { private void setupMocks(boolean currentActivityAssistAllowed, boolean assistStructureAllowed, boolean assistScreenshotAllowed) throws Exception { - doReturn(currentActivityAssistAllowed).when(mAm).isAssistDataAllowedOnCurrentActivity(); + doReturn(currentActivityAssistAllowed).when(mAtm).isAssistDataAllowedOnCurrentActivity(); doReturn(assistStructureAllowed ? MODE_ALLOWED : MODE_ERRORED).when(mAppOpsManager) .checkOpNoThrow(eq(OP_ASSIST_STRUCTURE), anyInt(), anyString()); doReturn(assistScreenshotAllowed ? MODE_ALLOWED : MODE_ERRORED).when(mAppOpsManager) @@ -240,7 +243,7 @@ public class AssistDataRequesterTest extends ActivityTestsBase { public void testDisallowAssistContextExtras_expectNullDataCallbacks() throws Exception { setupMocks(CURRENT_ACTIVITY_ASSIST_ALLOWED, CALLER_ASSIST_STRUCTURE_ALLOWED, CALLER_ASSIST_SCREENSHOT_ALLOWED); - doReturn(false).when(mAm).requestAssistContextExtras(anyInt(), any(), any(), any(), + doReturn(false).when(mAtm).requestAssistContextExtras(anyInt(), any(), any(), any(), anyBoolean(), anyBoolean()); mDataRequester.requestAssistData(createActivityList(5), FETCH_DATA, FETCH_SCREENSHOTS, @@ -371,4 +374,4 @@ public class AssistDataRequesterTest extends ActivityTestsBase { }); } } -}
\ No newline at end of file +} diff --git a/services/tests/servicestests/src/com/android/server/am/LaunchParamsControllerTests.java b/services/tests/servicestests/src/com/android/server/am/LaunchParamsControllerTests.java index 161c2875bf49..93e0b5aa9082 100644 --- a/services/tests/servicestests/src/com/android/server/am/LaunchParamsControllerTests.java +++ b/services/tests/servicestests/src/com/android/server/am/LaunchParamsControllerTests.java @@ -200,9 +200,9 @@ public class LaunchParamsControllerTests extends ActivityTestsBase { mController.registerModifier(positioner); - doNothing().when(mService).moveStackToDisplay(anyInt(), anyInt()); + doNothing().when(mService.mActivityTaskManager).moveStackToDisplay(anyInt(), anyInt()); mController.layoutTask(task, null /* windowLayout */); - verify(mService, times(1)).moveStackToDisplay(eq(task.getStackId()), + verify(mService.mActivityTaskManager, times(1)).moveStackToDisplay(eq(task.getStackId()), eq(params.mPreferredDisplayId)); } diff --git a/services/tests/servicestests/src/com/android/server/am/RecentTasksTest.java b/services/tests/servicestests/src/com/android/server/am/RecentTasksTest.java index 57c3bcbb04c3..af6686f00113 100644 --- a/services/tests/servicestests/src/com/android/server/am/RecentTasksTest.java +++ b/services/tests/servicestests/src/com/android/server/am/RecentTasksTest.java @@ -696,7 +696,7 @@ public class RecentTasksTest extends ActivityTestsBase { } private void testRecentTasksApis(boolean expectCallable) { - assertSecurityException(expectCallable, () -> mService.removeStack(INVALID_STACK_ID)); + assertSecurityException(expectCallable, () -> mService.mActivityTaskManager.removeStack(INVALID_STACK_ID)); assertSecurityException(expectCallable, () -> mService.mActivityTaskManager.removeStacksInWindowingModes( new int[] {WINDOWING_MODE_UNDEFINED})); @@ -712,52 +712,42 @@ public class RecentTasksTest extends ActivityTestsBase { assertSecurityException(expectCallable, () -> mService.mActivityTaskManager.setTaskWindowingModeSplitScreenPrimary(0, SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, true, true, new Rect(), true)); - assertSecurityException(expectCallable, () -> mService.dismissSplitScreenMode(true)); - assertSecurityException(expectCallable, () -> mService.dismissPip(true, 0)); + assertSecurityException(expectCallable, () -> mService.mActivityTaskManager.dismissSplitScreenMode(true)); + assertSecurityException(expectCallable, () -> mService.mActivityTaskManager.dismissPip(true, 0)); assertSecurityException(expectCallable, - () -> mService.moveTopActivityToPinnedStack(INVALID_STACK_ID, new Rect())); + () -> mService.mActivityTaskManager.moveTopActivityToPinnedStack(INVALID_STACK_ID, new Rect())); assertSecurityException(expectCallable, () -> mService.resizeStack(INVALID_STACK_ID, new Rect(), true, true, true, 0)); assertSecurityException(expectCallable, - () -> mService.resizeDockedStack(new Rect(), new Rect(), new Rect(), new Rect(), + () -> mService.mActivityTaskManager.resizeDockedStack(new Rect(), new Rect(), new Rect(), new Rect(), new Rect())); assertSecurityException(expectCallable, - () -> mService.resizePinnedStack(new Rect(), new Rect())); - assertSecurityException(expectCallable, () -> mService.getAllStackInfos()); + () -> mService.mActivityTaskManager.resizePinnedStack(new Rect(), new Rect())); + assertSecurityException(expectCallable, () -> mService.mActivityTaskManager.getAllStackInfos()); assertSecurityException(expectCallable, - () -> mService.getStackInfo(WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_UNDEFINED)); + () -> mService.mActivityTaskManager.getStackInfo(WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_UNDEFINED)); assertSecurityException(expectCallable, () -> { try { - mService.getFocusedStackInfo(); + mService.mActivityTaskManager.getFocusedStackInfo(); } catch (RemoteException e) { // Ignore } }); assertSecurityException(expectCallable, - () -> mService.moveTasksToFullscreenStack(INVALID_STACK_ID, true)); + () -> mService.mActivityTaskManager.moveTasksToFullscreenStack(INVALID_STACK_ID, true)); assertSecurityException(expectCallable, - () -> mService.startActivityFromRecents(0, new Bundle())); + () -> mService.mActivityTaskManager.startActivityFromRecents(0, new Bundle())); assertSecurityException(expectCallable, - () -> mService.getTaskSnapshot(0, true)); - assertSecurityException(expectCallable, () -> { - try { - mService.registerTaskStackListener(null); - } catch (RemoteException e) { - // Ignore - } - }); - assertSecurityException(expectCallable, () -> { - try { - mService.unregisterTaskStackListener(null); - } catch (RemoteException e) { - // Ignore - } - }); - assertSecurityException(expectCallable, () -> mService.getTaskDescription(0)); - assertSecurityException(expectCallable, () -> mService.cancelTaskWindowTransition(0)); - assertSecurityException(expectCallable, () -> mService.startRecentsActivity(null, null, + () -> mService.mActivityTaskManager.getTaskSnapshot(0, true)); + assertSecurityException(expectCallable, + () -> mService.mActivityTaskManager.registerTaskStackListener(null)); + assertSecurityException(expectCallable, + () -> mService.mActivityTaskManager.unregisterTaskStackListener(null)); + assertSecurityException(expectCallable, () -> mService.mActivityTaskManager.getTaskDescription(0)); + assertSecurityException(expectCallable, () -> mService.mActivityTaskManager.cancelTaskWindowTransition(0)); + assertSecurityException(expectCallable, () -> mService.mActivityTaskManager.startRecentsActivity(null, null, null)); - assertSecurityException(expectCallable, () -> mService.cancelRecentsAnimation(true)); + assertSecurityException(expectCallable, () -> mService.mActivityTaskManager.cancelRecentsAnimation(true)); assertSecurityException(expectCallable, () -> mService.stopAppSwitches()); assertSecurityException(expectCallable, () -> mService.resumeAppSwitches()); } diff --git a/services/tests/servicestests/src/com/android/server/am/TaskStackChangedListenerTest.java b/services/tests/servicestests/src/com/android/server/am/TaskStackChangedListenerTest.java index 0359096892bb..8e87a5f2b689 100644 --- a/services/tests/servicestests/src/com/android/server/am/TaskStackChangedListenerTest.java +++ b/services/tests/servicestests/src/com/android/server/am/TaskStackChangedListenerTest.java @@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue; import android.app.Activity; import android.app.ActivityManager; import android.app.ActivityManager.TaskDescription; +import android.app.ActivityTaskManager; import android.app.IActivityManager; import android.app.ITaskStackListener; import android.app.Instrumentation.ActivityMonitor; @@ -68,7 +69,7 @@ public class TaskStackChangedListenerTest { @After public void tearDown() throws Exception { - mService.unregisterTaskStackListener(mTaskStackListener); + ActivityTaskManager.getService().unregisterTaskStackListener(mTaskStackListener); mTaskStackListener = null; } @@ -227,7 +228,7 @@ public class TaskStackChangedListenerTest { private void registerTaskStackChangedListener(ITaskStackListener listener) throws Exception { mTaskStackListener = listener; - mService.registerTaskStackListener(listener); + ActivityTaskManager.getService().registerTaskStackListener(listener); } private void waitForCallback(CountDownLatch latch) { diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceTestable.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceTestable.java index cd3928558c4b..2b5b812af4c7 100644 --- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceTestable.java +++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceTestable.java @@ -18,6 +18,7 @@ package com.android.server.devicepolicy; import android.app.ActivityManagerInternal; import android.app.AlarmManager; import android.app.IActivityManager; +import android.app.IActivityTaskManager; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.backup.IBackupManager; @@ -181,6 +182,11 @@ public class DevicePolicyManagerServiceTestable extends DevicePolicyManagerServi } @Override + IActivityTaskManager getIActivityTaskManager() { + return services.iactivityTaskManager; + } + + @Override ActivityManagerInternal getActivityManagerInternal() { return services.activityManagerInternal; } diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java index 1acecfc8cb05..a23636ca20dc 100644 --- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java +++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java @@ -3726,7 +3726,7 @@ public class DevicePolicyManagerTest extends DpmTestBase { private void verifyLockTaskState(int userId, String[] packages, int flags) throws Exception { verify(getServices().iactivityManager).updateLockTaskPackages(userId, packages); - verify(getServices().iactivityManager).updateLockTaskFeatures(userId, flags); + verify(getServices().iactivityTaskManager).updateLockTaskFeatures(userId, flags); } private void verifyCanSetLockTask(int uid, int userId, ComponentName who, String[] packages, @@ -3819,7 +3819,7 @@ public class DevicePolicyManagerTest extends DpmTestBase { // Lock task packages cleared when loading user data and when the user becomes unaffiliated. verify(getServices().iactivityManager, times(2)).updateLockTaskPackages( MANAGED_PROFILE_USER_ID, new String[0]); - verify(getServices().iactivityManager, times(2)).updateLockTaskFeatures( + verify(getServices().iactivityTaskManager, times(2)).updateLockTaskFeatures( MANAGED_PROFILE_USER_ID, DevicePolicyManager.LOCK_TASK_FEATURE_NONE); // Verify that lock task packages were not cleared for the DO diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/MockSystemServices.java b/services/tests/servicestests/src/com/android/server/devicepolicy/MockSystemServices.java index e753df1f30ec..4724f1cdd324 100644 --- a/services/tests/servicestests/src/com/android/server/devicepolicy/MockSystemServices.java +++ b/services/tests/servicestests/src/com/android/server/devicepolicy/MockSystemServices.java @@ -28,6 +28,7 @@ import android.accounts.AccountManager; import android.app.ActivityManagerInternal; import android.app.AlarmManager; import android.app.IActivityManager; +import android.app.IActivityTaskManager; import android.app.NotificationManager; import android.app.backup.IBackupManager; import android.app.usage.UsageStatsManagerInternal; @@ -91,6 +92,7 @@ public class MockSystemServices { public final IIpConnectivityMetrics iipConnectivityMetrics; public final IWindowManager iwindowManager; public final IActivityManager iactivityManager; + public final IActivityTaskManager iactivityTaskManager; public ActivityManagerInternal activityManagerInternal; public final IPackageManager ipackageManager; public final IBackupManager ibackupManager; @@ -129,6 +131,7 @@ public class MockSystemServices { iipConnectivityMetrics = mock(IIpConnectivityMetrics.class); iwindowManager = mock(IWindowManager.class); iactivityManager = mock(IActivityManager.class); + iactivityTaskManager = mock(IActivityTaskManager.class); activityManagerInternal = mock(ActivityManagerInternal.class); ipackageManager = mock(IPackageManager.class); ibackupManager = mock(IBackupManager.class); diff --git a/services/tests/servicestests/src/com/android/server/wm/TaskPositionerTests.java b/services/tests/servicestests/src/com/android/server/wm/TaskPositionerTests.java index 4447b26ac2d1..dc6bbbfe5285 100644 --- a/services/tests/servicestests/src/com/android/server/wm/TaskPositionerTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/TaskPositionerTests.java @@ -22,6 +22,7 @@ import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; +import android.app.IActivityTaskManager; import android.graphics.Rect; import android.support.test.filters.SmallTest; import android.support.test.runner.AndroidJUnit4; @@ -75,7 +76,7 @@ public class TaskPositionerTests extends WindowTestsBase { mMinVisibleWidth = dipToPixel(MINIMUM_VISIBLE_WIDTH_IN_DP, dm); mMinVisibleHeight = dipToPixel(MINIMUM_VISIBLE_HEIGHT_IN_DP, dm); - mPositioner = new TaskPositioner(sWm, Mockito.mock(IActivityManager.class)); + mPositioner = new TaskPositioner(sWm, Mockito.mock(IActivityTaskManager.class)); mPositioner.register(mDisplayContent); mWindow = Mockito.spy(createWindow(null, TYPE_BASE_APPLICATION, "window")); diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java index b26efd545828..ba94afe4de06 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java @@ -25,7 +25,9 @@ import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT; import android.app.ActivityManager; import android.app.ActivityManagerInternal; import android.app.ActivityOptions; +import android.app.ActivityTaskManager; import android.app.IActivityManager; +import android.app.IActivityTaskManager; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; @@ -70,6 +72,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne final int mUser; final ComponentName mComponent; final IActivityManager mAm; + final IActivityTaskManager mAtm; final VoiceInteractionServiceInfo mInfo; final ComponentName mSessionComponentName; final IWindowManager mIWindowManager; @@ -125,6 +128,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne mUser = userHandle; mComponent = service; mAm = ActivityManager.getService(); + mAtm = ActivityTaskManager.getService(); VoiceInteractionServiceInfo info; try { info = new VoiceInteractionServiceInfo(context.getPackageManager(), service, mUser); @@ -205,7 +209,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne intent = new Intent(intent); intent.addCategory(Intent.CATEGORY_VOICE); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); - return mAm.startVoiceActivity(mComponent.getPackageName(), callingPid, callingUid, + return mAtm.startVoiceActivity(mComponent.getPackageName(), callingPid, callingUid, intent, resolvedType, mActiveSession.mSession, mActiveSession.mInteractor, 0, null, null, mUser); } catch (RemoteException e) { @@ -228,7 +232,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); final ActivityOptions options = ActivityOptions.makeBasic(); options.setLaunchActivityType(ACTIVITY_TYPE_ASSISTANT); - return mAm.startAssistantActivity(mComponent.getPackageName(), callingPid, callingUid, + return mAtm.startAssistantActivity(mComponent.getPackageName(), callingPid, callingUid, intent, resolvedType, options.toBundle(), mUser); } catch (RemoteException e) { throw new IllegalStateException("Unexpected remote error", e); diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionSessionConnection.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionSessionConnection.java index e0d9c7397748..457bfcdf5a30 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionSessionConnection.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionSessionConnection.java @@ -27,6 +27,7 @@ import static android.view.Display.DEFAULT_DISPLAY; import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION; import android.app.ActivityManager; +import android.app.ActivityTaskManager; import android.app.AppOpsManager; import android.app.IActivityManager; import android.app.assist.AssistContent; @@ -359,7 +360,7 @@ final class VoiceInteractionSessionConnection implements ServiceConnection, } if (mSession != null) { try { - mAm.finishVoiceTask(mSession); + ActivityTaskManager.getService().finishVoiceTask(mSession); } catch (RemoteException e) { } } @@ -387,7 +388,7 @@ final class VoiceInteractionSessionConnection implements ServiceConnection, } if (finishTask && mSession != null) { try { - mAm.finishVoiceTask(mSession); + ActivityTaskManager.getService().finishVoiceTask(mSession); } catch (RemoteException e) { } } diff --git a/tests/MemoryUsage/src/com/android/tests/memoryusage/MemoryUsageTest.java b/tests/MemoryUsage/src/com/android/tests/memoryusage/MemoryUsageTest.java index 1ae318a96a50..653282d0d365 100644 --- a/tests/MemoryUsage/src/com/android/tests/memoryusage/MemoryUsageTest.java +++ b/tests/MemoryUsage/src/com/android/tests/memoryusage/MemoryUsageTest.java @@ -18,7 +18,9 @@ package com.android.tests.memoryusage; import android.app.ActivityManager; import android.app.ActivityManager.ProcessErrorStateInfo; import android.app.ActivityManager.RunningAppProcessInfo; +import android.app.ActivityTaskManager; import android.app.IActivityManager; +import android.app.IActivityTaskManager; import android.app.UiAutomation; import android.content.Context; import android.content.Intent; @@ -66,6 +68,7 @@ public class MemoryUsageTest extends InstrumentationTestCase { private Map<String, String> mNameToResultKey; private Set<String> mPersistentProcesses; private IActivityManager mAm; + private IActivityTaskManager mAtm; @Override protected void setUp() throws Exception { @@ -84,6 +87,7 @@ public class MemoryUsageTest extends InstrumentationTestCase { (MemoryUsageInstrumentation) getInstrumentation(); Bundle args = instrumentation.getBundle(); mAm = ActivityManager.getService(); + mAtm = ActivityTaskManager.getService(); createMappings(); parseArgs(args); @@ -316,7 +320,7 @@ public class MemoryUsageTest extends InstrumentationTestCase { UserHandle.USER_CURRENT); } - mAm.startActivityAndWait(null, null, mLaunchIntent, mimeType, + mAtm.startActivityAndWait(null, null, mLaunchIntent, mimeType, null, null, 0, mLaunchIntent.getFlags(), null, null, UserHandle.USER_CURRENT_OR_SELF); } catch (RemoteException e) { diff --git a/tests/permission/src/com/android/framework/permission/tests/ActivityManagerPermissionTests.java b/tests/permission/src/com/android/framework/permission/tests/ActivityManagerPermissionTests.java index 89bd8d8f1dd4..548a0c22c569 100644 --- a/tests/permission/src/com/android/framework/permission/tests/ActivityManagerPermissionTests.java +++ b/tests/permission/src/com/android/framework/permission/tests/ActivityManagerPermissionTests.java @@ -17,6 +17,7 @@ package com.android.framework.permission.tests; import android.app.ActivityManager; +import android.app.ActivityTaskManager; import android.app.IActivityManager; import android.content.res.Configuration; import android.os.RemoteException; @@ -47,22 +48,12 @@ public class ActivityManagerPermissionTests extends TestCase { } catch (RemoteException e) { fail("Unexpected remote exception"); } - - try { - mAm.moveTaskBackwards(-1); - fail("IActivityManager.moveTaskToFront did not throw SecurityException as" - + " expected"); - } catch (SecurityException e) { - // expected - } catch (RemoteException e) { - fail("Unexpected remote exception"); - } } @SmallTest public void testCHANGE_CONFIGURATION() { try { - mAm.updateConfiguration(new Configuration()); + ActivityTaskManager.getService().updateConfiguration(new Configuration()); fail("IActivityManager.updateConfiguration did not throw SecurityException as" + " expected"); } catch (SecurityException e) { |