Add ability to listen to LockTask state changes
Bug: 176211023 Test: Presubmit Change-Id: I1e9e7151d45751ec6398588788c512f23b2f9fb5
This commit is contained in:
@@ -209,4 +209,10 @@ oneway interface ITaskStackListener {
|
||||
* @param taskInfo info about the task which moved
|
||||
*/
|
||||
void onTaskMovedToBack(in ActivityManager.RunningTaskInfo taskInfo);
|
||||
|
||||
/**
|
||||
* Called when the lock task mode changes. See ActivityManager#LOCK_TASK_MODE_* and
|
||||
* LockTaskController.
|
||||
*/
|
||||
void onLockTaskModeChanged(int mode);
|
||||
}
|
||||
|
||||
@@ -193,4 +193,8 @@ public abstract class TaskStackListener extends ITaskStackListener.Stub {
|
||||
@Override
|
||||
public void onTaskMovedToBack(RunningTaskInfo taskInfo) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLockTaskModeChanged(int mode) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,4 +100,10 @@ public abstract class TaskStackChangeListener {
|
||||
|
||||
/** @see ITaskStackListener#onActivityRotation(int)*/
|
||||
public void onActivityRotation(int displayId) { }
|
||||
|
||||
/**
|
||||
* Called when the lock task mode changes. See ActivityManager#LOCK_TASK_MODE_* and
|
||||
* LockTaskController.
|
||||
*/
|
||||
public void onLockTaskModeChanged(int mode) { }
|
||||
}
|
||||
|
||||
@@ -93,6 +93,7 @@ public class TaskStackChangeListeners {
|
||||
private static final int ON_TASK_LIST_FROZEN_UNFROZEN = 20;
|
||||
private static final int ON_TASK_DESCRIPTION_CHANGED = 21;
|
||||
private static final int ON_ACTIVITY_ROTATION = 22;
|
||||
private static final int ON_LOCK_TASK_MODE_CHANGED = 23;
|
||||
|
||||
/**
|
||||
* List of {@link TaskStackChangeListener} registered from {@link #addListener}.
|
||||
@@ -272,6 +273,11 @@ public class TaskStackChangeListeners {
|
||||
.sendToTarget();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLockTaskModeChanged(int mode) {
|
||||
mHandler.obtainMessage(ON_LOCK_TASK_MODE_CHANGED, mode, 0 /* unused */).sendToTarget();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(Message msg) {
|
||||
synchronized (mTaskStackListeners) {
|
||||
@@ -421,6 +427,12 @@ public class TaskStackChangeListeners {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ON_LOCK_TASK_MODE_CHANGED: {
|
||||
for (int i = mTaskStackListeners.size() - 1; i >= 0; i--) {
|
||||
mTaskStackListeners.get(i).onLockTaskModeChanged(msg.arg1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (msg.obj instanceof SomeArgs) {
|
||||
|
||||
@@ -863,7 +863,8 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
|
||||
|
||||
mTaskChangeNotificationController =
|
||||
new TaskChangeNotificationController(mGlobalLock, mTaskSupervisor, mH);
|
||||
mLockTaskController = new LockTaskController(mContext, mTaskSupervisor, mH);
|
||||
mLockTaskController = new LockTaskController(mContext, mTaskSupervisor, mH,
|
||||
mTaskChangeNotificationController);
|
||||
mActivityStartController = new ActivityStartController(this);
|
||||
setRecentTasks(new RecentTasks(this, mTaskSupervisor));
|
||||
mVrController = new VrController(mGlobalLock);
|
||||
|
||||
@@ -141,6 +141,7 @@ public class LockTaskController {
|
||||
private final IBinder mToken = new LockTaskToken();
|
||||
private final ActivityTaskSupervisor mSupervisor;
|
||||
private final Context mContext;
|
||||
private final TaskChangeNotificationController mTaskChangeNotificationController;
|
||||
|
||||
// The following system services cannot be final, because they do not exist when this class
|
||||
// is instantiated during device boot
|
||||
@@ -204,10 +205,11 @@ public class LockTaskController {
|
||||
private int mPendingDisableFromDismiss = UserHandle.USER_NULL;
|
||||
|
||||
LockTaskController(Context context, ActivityTaskSupervisor supervisor,
|
||||
Handler handler) {
|
||||
Handler handler, TaskChangeNotificationController taskChangeNotificationController) {
|
||||
mContext = context;
|
||||
mSupervisor = supervisor;
|
||||
mHandler = handler;
|
||||
mTaskChangeNotificationController = taskChangeNotificationController;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -532,6 +534,7 @@ public class LockTaskController {
|
||||
// thread, which makes it guarded by ATMS#mGlobalLock as ATMS#getLockTaskModeState.
|
||||
final int oldLockTaskModeState = mLockTaskModeState;
|
||||
mLockTaskModeState = LOCK_TASK_MODE_NONE;
|
||||
mTaskChangeNotificationController.notifyLockTaskModeChanged(mLockTaskModeState);
|
||||
// When lock task ends, we enable the status bars.
|
||||
try {
|
||||
setStatusBarState(mLockTaskModeState, userId);
|
||||
@@ -661,6 +664,7 @@ public class LockTaskController {
|
||||
}
|
||||
mWindowManager.onLockTaskStateChanged(lockTaskModeState);
|
||||
mLockTaskModeState = lockTaskModeState;
|
||||
mTaskChangeNotificationController.notifyLockTaskModeChanged(mLockTaskModeState);
|
||||
setStatusBarState(lockTaskModeState, userId);
|
||||
setKeyguardState(lockTaskModeState, userId);
|
||||
if (getDevicePolicyManager() != null) {
|
||||
|
||||
@@ -59,6 +59,7 @@ class TaskChangeNotificationController {
|
||||
private static final int NOTIFY_TASK_REQUESTED_ORIENTATION_CHANGED_MSG = 25;
|
||||
private static final int NOTIFY_ACTIVITY_ROTATED_MSG = 26;
|
||||
private static final int NOTIFY_TASK_MOVED_TO_BACK_LISTENERS_MSG = 27;
|
||||
private static final int NOTIFY_LOCK_TASK_MODE_CHANGED_MSG = 28;
|
||||
|
||||
// Delay in notifying task stack change listeners (in millis)
|
||||
private static final int NOTIFY_TASK_STACK_CHANGE_LISTENERS_DELAY = 100;
|
||||
@@ -177,6 +178,10 @@ class TaskChangeNotificationController {
|
||||
l.onTaskMovedToBack((RunningTaskInfo) m.obj);
|
||||
};
|
||||
|
||||
private final TaskStackConsumer mNotifyLockTaskModeChanged = (l, m) -> {
|
||||
l.onLockTaskModeChanged(m.arg1);
|
||||
};
|
||||
|
||||
@FunctionalInterface
|
||||
public interface TaskStackConsumer {
|
||||
void accept(ITaskStackListener t, Message m) throws RemoteException;
|
||||
@@ -268,6 +273,9 @@ class TaskChangeNotificationController {
|
||||
case NOTIFY_TASK_MOVED_TO_BACK_LISTENERS_MSG:
|
||||
forAllRemoteListeners(mNotifyTaskMovedToBack, msg);
|
||||
break;
|
||||
case NOTIFY_LOCK_TASK_MODE_CHANGED_MSG:
|
||||
forAllRemoteListeners(mNotifyLockTaskModeChanged, msg);
|
||||
break;
|
||||
}
|
||||
if (msg.obj instanceof SomeArgs) {
|
||||
((SomeArgs) msg.obj).recycle();
|
||||
@@ -550,4 +558,11 @@ class TaskChangeNotificationController {
|
||||
forAllLocalListeners(mNotifyTaskMovedToBack, msg);
|
||||
msg.sendToTarget();
|
||||
}
|
||||
|
||||
void notifyLockTaskModeChanged(int lockTaskModeState) {
|
||||
final Message msg = mHandler.obtainMessage(NOTIFY_LOCK_TASK_MODE_CHANGED_MSG,
|
||||
lockTaskModeState, 0 /* unused */);
|
||||
forAllLocalListeners(mNotifyLockTaskModeChanged, msg);
|
||||
msg.sendToTarget();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,6 +122,7 @@ public class LockTaskControllerTest {
|
||||
@Mock private StatusBarManagerInternal mStatusBarManagerInternal;
|
||||
@Mock private TelecomManager mTelecomManager;
|
||||
@Mock private RecentTasks mRecentTasks;
|
||||
@Mock private TaskChangeNotificationController mTaskChangeNotificationController;
|
||||
|
||||
private LockTaskController mLockTaskController;
|
||||
private Context mContext;
|
||||
@@ -145,7 +146,7 @@ public class LockTaskControllerTest {
|
||||
mSupervisor.mRootWindowContainer = mRootWindowContainer;
|
||||
|
||||
mLockTaskController = new LockTaskController(mContext, mSupervisor,
|
||||
new ImmediatelyExecuteHandler());
|
||||
new ImmediatelyExecuteHandler(), mTaskChangeNotificationController);
|
||||
mLockTaskController.setWindowManager(mWindowManager);
|
||||
mLockTaskController.mStatusBarService = mStatusBarService;
|
||||
mLockTaskController.mDevicePolicyManager = mDevicePolicyManager;
|
||||
|
||||
Reference in New Issue
Block a user