Merge "Move activity related operations to ActivityClientController" into sc-dev am: 0269ea9f8c

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13406091

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I4e687f27e194c960e45223559b0d0598df8afc2b
This commit is contained in:
TreeHugger Robot
2021-01-28 06:17:04 +00:00
committed by Automerger Merge Worker
9 changed files with 127 additions and 104 deletions

View File

@@ -26,6 +26,8 @@ import android.os.RemoteException;
import android.util.Singleton; import android.util.Singleton;
import android.view.RemoteAnimationDefinition; import android.view.RemoteAnimationDefinition;
import com.android.internal.policy.IKeyguardDismissCallback;
/** /**
* Provides the activity associated operations that communicate with system. * Provides the activity associated operations that communicate with system.
* *
@@ -431,6 +433,37 @@ public class ActivityClient {
} }
} }
/**
* Restart the process and activity to adopt the latest configuration for size compat mode.
* This only takes effect for visible activity because invisible background activity can be
* restarted naturally when it becomes visible.
*/
public void restartActivityProcessIfVisible(IBinder token) {
try {
getActivityClientController().restartActivityProcessIfVisible(token);
} catch (RemoteException e) {
e.rethrowFromSystemServer();
}
}
/** Removes the snapshot of home task. */
public void invalidateHomeTaskSnapshot(IBinder homeToken) {
try {
getActivityClientController().invalidateHomeTaskSnapshot(homeToken);
} catch (RemoteException e) {
e.rethrowFromSystemServer();
}
}
void dismissKeyguard(IBinder token, IKeyguardDismissCallback callback,
CharSequence message) {
try {
getActivityClientController().dismissKeyguard(token, callback, message);
} catch (RemoteException e) {
e.rethrowFromSystemServer();
}
}
void registerRemoteAnimations(IBinder token, RemoteAnimationDefinition definition) { void registerRemoteAnimations(IBinder token, RemoteAnimationDefinition definition) {
try { try {
getActivityClientController().registerRemoteAnimations(token, definition); getActivityClientController().registerRemoteAnimations(token, definition);

View File

@@ -25,6 +25,8 @@ import android.os.Bundle;
import android.os.PersistableBundle; import android.os.PersistableBundle;
import android.view.RemoteAnimationDefinition; import android.view.RemoteAnimationDefinition;
import com.android.internal.policy.IKeyguardDismissCallback;
/** /**
* Interface for the callback and request from an activity to system. * Interface for the callback and request from an activity to system.
* *
@@ -95,6 +97,27 @@ interface IActivityClientController {
/** See {@link android.app.Activity#setDisablePreviewScreenshots}. */ /** See {@link android.app.Activity#setDisablePreviewScreenshots}. */
oneway void setDisablePreviewScreenshots(in IBinder token, boolean disable); oneway void setDisablePreviewScreenshots(in IBinder token, boolean disable);
/**
* Restarts the activity by killing its process if it is visible. If the activity is not
* visible, the activity will not be restarted immediately and just keep the activity record in
* the stack. It also resets the current override configuration so the activity will use the
* configuration according to the latest state.
*
* @param activityToken The token of the target activity to restart.
*/
void restartActivityProcessIfVisible(in IBinder activityToken);
/**
* It should only be called from home activity to remove its outdated snapshot. The home
* snapshot is used to speed up entering home from screen off. If the content of home activity
* is significantly different from before taking the snapshot, then the home activity can use
* this method to avoid inconsistent transition.
*/
void invalidateHomeTaskSnapshot(IBinder homeToken);
void dismissKeyguard(in IBinder token, in IKeyguardDismissCallback callback,
in CharSequence message);
/** Registers remote animations for a specific activity. */ /** Registers remote animations for a specific activity. */
void registerRemoteAnimations(in IBinder token, in RemoteAnimationDefinition definition); void registerRemoteAnimations(in IBinder token, in RemoteAnimationDefinition definition);

View File

@@ -72,7 +72,6 @@ import android.view.RemoteAnimationAdapter;
import android.window.IWindowOrganizerController; import android.window.IWindowOrganizerController;
import com.android.internal.app.IVoiceInteractor; import com.android.internal.app.IVoiceInteractor;
import com.android.internal.os.IResultReceiver; import com.android.internal.os.IResultReceiver;
import com.android.internal.policy.IKeyguardDismissCallback;
import java.util.List; import java.util.List;
@@ -85,8 +84,6 @@ import java.util.List;
// TODO(b/174040395): Make this interface private to ActivityTaskManager.java and have external // TODO(b/174040395): Make this interface private to ActivityTaskManager.java and have external
// caller go through that call instead. This would help us better separate and control the API // caller go through that call instead. This would help us better separate and control the API
// surface exposed. // surface exposed.
// TODO(b/174041144): Move callback methods from Activity (Things that take param 'IBinder token')
// to a separate interface that is only available to the Activity.
// TODO(b/174041603): Create a builder interface for things like startActivityXXX(...) to reduce // TODO(b/174041603): Create a builder interface for things like startActivityXXX(...) to reduce
// interface duplication. // interface duplication.
// TODO(b/174040691): Clean-up/remove all obsolete or unused interfaces like things that should be // TODO(b/174040691): Clean-up/remove all obsolete or unused interfaces like things that should be
@@ -294,9 +291,6 @@ interface IActivityTaskManager {
// Get device configuration // Get device configuration
ConfigurationInfo getDeviceConfigurationInfo(); ConfigurationInfo getDeviceConfigurationInfo();
void dismissKeyguard(in IBinder token, in IKeyguardDismissCallback callback,
in CharSequence message);
/** Cancels the window transitions for the given task. */ /** Cancels the window transitions for the given task. */
void cancelTaskWindowTransition(int taskId); void cancelTaskWindowTransition(int taskId);
@@ -308,14 +302,6 @@ interface IActivityTaskManager {
*/ */
android.window.TaskSnapshot getTaskSnapshot(int taskId, boolean isLowResolution); android.window.TaskSnapshot getTaskSnapshot(int taskId, boolean isLowResolution);
/**
* It should only be called from home activity to remove its outdated snapshot. The home
* snapshot is used to speed up entering home from screen off. If the content of home activity
* is significantly different from before taking the snapshot, then the home activity can use
* this method to avoid inconsistent transition.
*/
void invalidateHomeTaskSnapshot(IBinder homeToken);
/** /**
* Return the user id of last resumed activity. * Return the user id of last resumed activity.
*/ */
@@ -362,14 +348,4 @@ interface IActivityTaskManager {
* Clears launch params for given packages. * Clears launch params for given packages.
*/ */
void clearLaunchParamsForPackages(in List<String> packageNames); void clearLaunchParamsForPackages(in List<String> packageNames);
/**
* Restarts the activity by killing its process if it is visible. If the activity is not
* visible, the activity will not be restarted immediately and just keep the activity record in
* the stack. It also resets the current override configuration so the activity will use the
* configuration according to the latest state.
*
* @param activityToken The token of the target activity to restart.
*/
void restartActivityProcessIfVisible(in IBinder activityToken);
} }

View File

@@ -598,33 +598,29 @@ public class KeyguardManager {
@SystemApi @SystemApi
public void requestDismissKeyguard(@NonNull Activity activity, @Nullable CharSequence message, public void requestDismissKeyguard(@NonNull Activity activity, @Nullable CharSequence message,
@Nullable KeyguardDismissCallback callback) { @Nullable KeyguardDismissCallback callback) {
try { ActivityClient.getInstance().dismissKeyguard(
ActivityTaskManager.getService().dismissKeyguard( activity.getActivityToken(), new IKeyguardDismissCallback.Stub() {
activity.getActivityToken(), new IKeyguardDismissCallback.Stub() { @Override
@Override public void onDismissError() throws RemoteException {
public void onDismissError() throws RemoteException { if (callback != null && !activity.isDestroyed()) {
if (callback != null && !activity.isDestroyed()) { activity.mHandler.post(callback::onDismissError);
activity.mHandler.post(callback::onDismissError);
}
} }
}
@Override @Override
public void onDismissSucceeded() throws RemoteException { public void onDismissSucceeded() throws RemoteException {
if (callback != null && !activity.isDestroyed()) { if (callback != null && !activity.isDestroyed()) {
activity.mHandler.post(callback::onDismissSucceeded); activity.mHandler.post(callback::onDismissSucceeded);
}
} }
}
@Override @Override
public void onDismissCancelled() throws RemoteException { public void onDismissCancelled() throws RemoteException {
if (callback != null && !activity.isDestroyed()) { if (callback != null && !activity.isDestroyed()) {
activity.mHandler.post(callback::onDismissCancelled); activity.mHandler.post(callback::onDismissCancelled);
}
} }
}, message); }
} catch (RemoteException e) { }, message);
throw e.rethrowFromSystemServer();
}
} }
/** /**

View File

@@ -24,6 +24,7 @@ import static android.app.ActivityTaskManager.getService;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.app.Activity; import android.app.Activity;
import android.app.ActivityClient;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.ActivityManager.RecentTaskInfo; import android.app.ActivityManager.RecentTaskInfo;
import android.app.ActivityManager.RunningTaskInfo; import android.app.ActivityManager.RunningTaskInfo;
@@ -140,8 +141,9 @@ public class ActivityManagerWrapper {
*/ */
public void invalidateHomeTaskSnapshot(final Activity homeActivity) { public void invalidateHomeTaskSnapshot(final Activity homeActivity) {
try { try {
getService().invalidateHomeTaskSnapshot(homeActivity.getActivityToken()); ActivityClient.getInstance().invalidateHomeTaskSnapshot(
} catch (RemoteException e) { homeActivity.getActivityToken());
} catch (Throwable e) {
Log.w(TAG, "Failed to invalidate home snapshot", e); Log.w(TAG, "Failed to invalidate home snapshot", e);
} }
} }

View File

@@ -16,7 +16,7 @@
package com.android.systemui; package com.android.systemui;
import android.app.ActivityTaskManager; import android.app.ActivityClient;
import android.content.Context; import android.content.Context;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.graphics.Color; import android.graphics.Color;
@@ -27,7 +27,6 @@ import android.graphics.drawable.RippleDrawable;
import android.hardware.display.DisplayManager; import android.hardware.display.DisplayManager;
import android.inputmethodservice.InputMethodService; import android.inputmethodservice.InputMethodService;
import android.os.IBinder; import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log; import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import android.view.Display; import android.view.Display;
@@ -237,12 +236,7 @@ public class SizeCompatModeActivityController extends SystemUI implements Comman
@Override @Override
public void onClick(View v) { public void onClick(View v) {
try { ActivityClient.getInstance().restartActivityProcessIfVisible(mLastActivityToken);
ActivityTaskManager.getService().restartActivityProcessIfVisible(
mLastActivityToken);
} catch (RemoteException e) {
Log.w(TAG, "Unable to restart activity", e);
}
} }
@Override @Override

View File

@@ -63,6 +63,7 @@ import android.util.Slog;
import android.view.RemoteAnimationDefinition; import android.view.RemoteAnimationDefinition;
import com.android.internal.app.AssistUtils; import com.android.internal.app.AssistUtils;
import com.android.internal.policy.IKeyguardDismissCallback;
import com.android.internal.protolog.common.ProtoLog; import com.android.internal.protolog.common.ProtoLog;
import com.android.server.LocalServices; import com.android.server.LocalServices;
import com.android.server.Watchdog; import com.android.server.Watchdog;
@@ -1018,6 +1019,50 @@ class ActivityClientController extends IActivityClientController.Stub {
} }
} }
@Override
public void restartActivityProcessIfVisible(IBinder token) {
ActivityTaskManagerService.enforceTaskPermission("restartActivityProcess");
final long callingId = Binder.clearCallingIdentity();
try {
synchronized (mGlobalLock) {
final ActivityRecord r = ActivityRecord.isInRootTaskLocked(token);
if (r != null) {
r.restartProcessIfVisible();
}
}
} finally {
Binder.restoreCallingIdentity(callingId);
}
}
@Override
public void invalidateHomeTaskSnapshot(IBinder token) {
synchronized (mGlobalLock) {
final ActivityRecord r = ActivityRecord.isInRootTaskLocked(token);
if (r != null && r.isActivityTypeHome()) {
mService.mWindowManager.mTaskSnapshotController.removeSnapshotCache(
r.getTask().mTaskId);
}
}
}
@Override
public void dismissKeyguard(IBinder token, IKeyguardDismissCallback callback,
CharSequence message) {
if (message != null) {
mService.mAmInternal.enforceCallingPermission(
android.Manifest.permission.SHOW_KEYGUARD_MESSAGE, "dismissKeyguard");
}
final long callingId = Binder.clearCallingIdentity();
try {
synchronized (mGlobalLock) {
mService.mKeyguardController.dismissKeyguard(token, callback, message);
}
} finally {
Binder.restoreCallingIdentity(callingId);
}
}
@Override @Override
public void registerRemoteAnimations(IBinder token, RemoteAnimationDefinition definition) { public void registerRemoteAnimations(IBinder token, RemoteAnimationDefinition definition) {
mService.mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, mService.mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS,

View File

@@ -231,7 +231,6 @@ import com.android.internal.app.ProcessMap;
import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
import com.android.internal.notification.SystemNotificationChannels; import com.android.internal.notification.SystemNotificationChannels;
import com.android.internal.os.TransferPipe; import com.android.internal.os.TransferPipe;
import com.android.internal.policy.IKeyguardDismissCallback;
import com.android.internal.policy.KeyguardDismissCallback; import com.android.internal.policy.KeyguardDismissCallback;
import com.android.internal.protolog.common.ProtoLog; import com.android.internal.protolog.common.ProtoLog;
import com.android.internal.util.ArrayUtils; import com.android.internal.util.ArrayUtils;
@@ -1795,23 +1794,6 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
} }
} }
@Override
public void restartActivityProcessIfVisible(IBinder activityToken) {
enforceTaskPermission("restartActivityProcess()");
final long callingId = Binder.clearCallingIdentity();
try {
synchronized (mGlobalLock) {
final ActivityRecord r = ActivityRecord.isInRootTaskLocked(activityToken);
if (r == null) {
return;
}
r.restartProcessIfVisible();
}
} finally {
Binder.restoreCallingIdentity(callingId);
}
}
@Override @Override
public boolean removeTask(int taskId) { public boolean removeTask(int taskId) {
enforceCallerIsRecentsOrHasPermission(REMOVE_TASKS, "removeTask()"); enforceCallerIsRecentsOrHasPermission(REMOVE_TASKS, "removeTask()");
@@ -3263,7 +3245,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
// If the keyguard is showing or occluded, then try and dismiss it before // 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 // entering picture-in-picture (this will prompt the user to authenticate if the
// device is currently locked). // device is currently locked).
dismissKeyguard(r.appToken, new KeyguardDismissCallback() { mActivityClientController.dismissKeyguard(r.appToken, new KeyguardDismissCallback() {
@Override @Override
public void onDismissSucceeded() { public void onDismissSucceeded() {
mH.post(enterPipRunnable); mH.post(enterPipRunnable);
@@ -3387,23 +3369,6 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
} }
} }
@Override
public void dismissKeyguard(IBinder token, IKeyguardDismissCallback callback,
CharSequence message) {
if (message != null) {
mAmInternal.enforceCallingPermission(
Manifest.permission.SHOW_KEYGUARD_MESSAGE, "dismissKeyguard()");
}
final long callingId = Binder.clearCallingIdentity();
try {
synchronized (mGlobalLock) {
mKeyguardController.dismissKeyguard(token, callback, message);
}
} finally {
Binder.restoreCallingIdentity(callingId);
}
}
@Override @Override
public void cancelTaskWindowTransition(int taskId) { public void cancelTaskWindowTransition(int taskId) {
enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_TASKS, enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_TASKS,
@@ -3450,17 +3415,6 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
return task.getSnapshot(isLowResolution, restoreFromDisk); return task.getSnapshot(isLowResolution, restoreFromDisk);
} }
@Override
public void invalidateHomeTaskSnapshot(IBinder token) {
synchronized (mGlobalLock) {
final ActivityRecord r = ActivityRecord.isInRootTaskLocked(token);
if (r == null || !r.isActivityTypeHome()) {
return;
}
mWindowManager.mTaskSnapshotController.removeSnapshotCache(r.getTask().mTaskId);
}
}
/** Return the user id of the last resumed activity. */ /** Return the user id of the last resumed activity. */
@Override @Override
public @UserIdInt public @UserIdInt

View File

@@ -109,7 +109,7 @@ public class SizeCompatTests extends WindowTestsBase {
final Rect originalOverrideBounds = new Rect(mActivity.getBounds()); final Rect originalOverrideBounds = new Rect(mActivity.getBounds());
resizeDisplay(mTask.mDisplayContent, 600, 1200); resizeDisplay(mTask.mDisplayContent, 600, 1200);
// The visible activity should recompute configuration according to the last parent bounds. // The visible activity should recompute configuration according to the last parent bounds.
mAtm.restartActivityProcessIfVisible(mActivity.appToken); mAtm.mActivityClientController.restartActivityProcessIfVisible(mActivity.appToken);
assertEquals(Task.ActivityState.RESTARTING_PROCESS, mActivity.getState()); assertEquals(Task.ActivityState.RESTARTING_PROCESS, mActivity.getState());
assertNotEquals(originalOverrideBounds, mActivity.getBounds()); assertNotEquals(originalOverrideBounds, mActivity.getBounds());