Merge "Signal a rerouted callback if display was set to SingleTaskInstance"

This commit is contained in:
Jeff Chang
2019-02-28 17:04:09 +00:00
committed by Android (Google) Code Review
6 changed files with 67 additions and 0 deletions

View File

@@ -80,6 +80,16 @@ oneway interface ITaskStackListener {
void onActivityLaunchOnSecondaryDisplayFailed(in ActivityManager.RunningTaskInfo taskInfo,
int requestedDisplayId);
/**
* Called when an activity was requested to be launched on a secondary display but was rerouted
* to default display.
*
* @param taskInfo info about the Activity's task
* @param requestedDisplayId the id of the requested launch display
*/
void onActivityLaunchOnSecondaryDisplayRerouted(in ActivityManager.RunningTaskInfo taskInfo,
int requestedDisplayId);
/**
* Called when a task is added.
*

View File

@@ -84,6 +84,12 @@ public abstract class TaskStackListener extends ITaskStackListener.Stub {
public void onActivityLaunchOnSecondaryDisplayFailed() throws RemoteException {
}
@Override
@UnsupportedAppUsage
public void onActivityLaunchOnSecondaryDisplayRerouted(ActivityManager.RunningTaskInfo taskInfo,
int requestedDisplayId) throws RemoteException {
}
@Override
public void onTaskCreated(int taskId, ComponentName componentName) throws RemoteException {
}

View File

@@ -48,6 +48,21 @@ public abstract class TaskStackChangeListener {
onActivityLaunchOnSecondaryDisplayFailed();
}
/**
* @see #onActivityLaunchOnSecondaryDisplayRerouted(RunningTaskInfo taskInfo)
*/
public void onActivityLaunchOnSecondaryDisplayRerouted() { }
/**
* Called when an activity was requested to be launched on a secondary display but was rerouted
* to default display.
*
* @param taskInfo info about the Activity's task
*/
public void onActivityLaunchOnSecondaryDisplayRerouted(RunningTaskInfo taskInfo) {
onActivityLaunchOnSecondaryDisplayRerouted();
}
public void onTaskProfileLocked(int taskId, int userId) { }
public void onTaskCreated(int taskId, ComponentName componentName) { }
public void onTaskRemoved(int taskId) { }

View File

@@ -140,6 +140,13 @@ public class TaskStackChangeListeners extends TaskStackListener {
taskInfo).sendToTarget();
}
@Override
public void onActivityLaunchOnSecondaryDisplayRerouted(RunningTaskInfo taskInfo,
int requestedDisplayId) throws RemoteException {
mHandler.obtainMessage(H.ON_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_REROUTED,
requestedDisplayId, 0 /* unused */, taskInfo).sendToTarget();
}
@Override
public void onTaskProfileLocked(int taskId, int userId) throws RemoteException {
mHandler.obtainMessage(H.ON_TASK_PROFILE_LOCKED, taskId, userId).sendToTarget();
@@ -189,6 +196,7 @@ public class TaskStackChangeListeners extends TaskStackListener {
private static final int ON_TASK_REMOVED = 13;
private static final int ON_TASK_MOVED_TO_FRONT = 14;
private static final int ON_ACTIVITY_REQUESTED_ORIENTATION_CHANGE = 15;
private static final int ON_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_REROUTED = 16;
public H(Looper looper) {
@@ -270,6 +278,14 @@ public class TaskStackChangeListeners extends TaskStackListener {
}
break;
}
case ON_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_REROUTED: {
final RunningTaskInfo info = (RunningTaskInfo) msg.obj;
for (int i = mTaskStackListeners.size() - 1; i >= 0; i--) {
mTaskStackListeners.get(i)
.onActivityLaunchOnSecondaryDisplayRerouted(info);
}
break;
}
case ON_TASK_PROFILE_LOCKED: {
for (int i = mTaskStackListeners.size() - 1; i >= 0; i--) {
mTaskStackListeners.get(i).onTaskProfileLocked(msg.arg1, msg.arg2);

View File

@@ -2351,6 +2351,9 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
// Suppress the warning toast if the preferredDisplay was set to singleTask.
// The singleTaskInstance displays will only contain one task and any attempt to
// launch new task will re-route to the default display.
mService.getTaskChangeNotificationController()
.notifyActivityLaunchOnSecondaryDisplayRerouted(task.getTaskInfo(),
preferredDisplayId);
return;
}

View File

@@ -50,6 +50,7 @@ class TaskChangeNotificationController {
private static final int NOTIFY_PINNED_STACK_ANIMATION_STARTED_LISTENERS_MSG = 16;
private static final int NOTIFY_ACTIVITY_UNPINNED_LISTENERS_MSG = 17;
private static final int NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG = 18;
private static final int NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_REROUTED_MSG = 19;
// Delay in notifying task stack change listeners (in millis)
private static final int NOTIFY_TASK_STACK_CHANGE_LISTENERS_DELAY = 100;
@@ -130,6 +131,10 @@ class TaskChangeNotificationController {
l.onActivityLaunchOnSecondaryDisplayFailed((RunningTaskInfo) m.obj, m.arg1);
};
private final TaskStackConsumer mNotifyActivityLaunchOnSecondaryDisplayRerouted = (l, m) -> {
l.onActivityLaunchOnSecondaryDisplayRerouted((RunningTaskInfo) m.obj, m.arg1);
};
private final TaskStackConsumer mNotifyTaskProfileLocked = (l, m) -> {
l.onTaskProfileLocked(m.arg1, m.arg2);
};
@@ -202,6 +207,9 @@ class TaskChangeNotificationController {
case NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_FAILED_MSG:
forAllRemoteListeners(mNotifyActivityLaunchOnSecondaryDisplayFailed, msg);
break;
case NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_REROUTED_MSG:
forAllRemoteListeners(mNotifyActivityLaunchOnSecondaryDisplayRerouted, msg);
break;
case NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG:
forAllRemoteListeners(mNotifyTaskProfileLocked, msg);
break;
@@ -355,6 +363,15 @@ class TaskChangeNotificationController {
msg.sendToTarget();
}
void notifyActivityLaunchOnSecondaryDisplayRerouted(TaskInfo ti, int requestedDisplayId) {
mHandler.removeMessages(NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_REROUTED_MSG);
final Message msg = mHandler.obtainMessage(
NOTIFY_ACTIVITY_LAUNCH_ON_SECONDARY_DISPLAY_REROUTED_MSG, requestedDisplayId,
0 /* unused */, ti);
forAllLocalListeners(mNotifyActivityLaunchOnSecondaryDisplayRerouted, msg);
msg.sendToTarget();
}
void notifyTaskCreated(int taskId, ComponentName componentName) {
final Message msg = mHandler.obtainMessage(NOTIFY_TASK_ADDED_LISTENERS_MSG,
taskId, 0 /* unused */, componentName);