Merge "Add new callback for when activity rotates" into rvc-dev am: 38dbc97939

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

Change-Id: I16d2689f35a21899955b9913e34c373d2a2954b6
This commit is contained in:
Vinit Nayak
2020-06-04 04:33:03 +00:00
committed by Automerger Merge Worker
6 changed files with 49 additions and 0 deletions

View File

@@ -216,4 +216,14 @@ oneway interface ITaskStackListener {
* in {@link android.content.pm.ActivityInfo}.
*/
void onTaskRequestedOrientationChanged(int taskId, int requestedOrientation);
/**
* Called when a rotation is about to start on the foreground activity.
* This applies for:
* * free sensor rotation
* * forced rotation
* * rotation settings set through adb command line
* * rotation that occurs when rotation tile is toggled in quick settings
*/
void onActivityRotation();
}

View File

@@ -199,4 +199,8 @@ public abstract class TaskStackListener extends ITaskStackListener.Stub {
@Override
public void onTaskRequestedOrientationChanged(int taskId, int requestedOrientation) {
}
@Override
public void onActivityRotation() {
}
}

View File

@@ -114,4 +114,7 @@ public abstract class TaskStackChangeListener {
/** @see ITaskStackListener#onRecentTaskListFrozenChanged(boolean) */
public void onRecentTaskListFrozenChanged(boolean frozen) { }
/** @see ITaskStackListener#onActivityRotation()*/
public void onActivityRotation() { }
}

View File

@@ -237,6 +237,11 @@ public class TaskStackChangeListeners extends TaskStackListener {
mHandler.obtainMessage(H.ON_TASK_DESCRIPTION_CHANGED, taskInfo).sendToTarget();
}
@Override
public void onActivityRotation() {
mHandler.obtainMessage(H.ON_ACTIVITY_ROTATION).sendToTarget();
}
private final class H extends Handler {
private static final int ON_TASK_STACK_CHANGED = 1;
private static final int ON_TASK_SNAPSHOT_CHANGED = 2;
@@ -260,6 +265,7 @@ public class TaskStackChangeListeners extends TaskStackListener {
private static final int ON_SINGLE_TASK_DISPLAY_EMPTY = 22;
private static final int ON_TASK_LIST_FROZEN_UNFROZEN = 23;
private static final int ON_TASK_DESCRIPTION_CHANGED = 24;
private static final int ON_ACTIVITY_ROTATION = 25;
public H(Looper looper) {
@@ -427,6 +433,12 @@ public class TaskStackChangeListeners extends TaskStackListener {
}
break;
}
case ON_ACTIVITY_ROTATION: {
for (int i = mTaskStackListeners.size() - 1; i >= 0; i--) {
mTaskStackListeners.get(i).onActivityRotation();
}
break;
}
}
}
if (msg.obj instanceof SomeArgs) {

View File

@@ -61,6 +61,7 @@ class TaskChangeNotificationController {
private static final int NOTIFY_TASK_LIST_FROZEN_UNFROZEN_MSG = 26;
private static final int NOTIFY_TASK_FOCUS_CHANGED_MSG = 27;
private static final int NOTIFY_TASK_REQUESTED_ORIENTATION_CHANGED_MSG = 28;
private static final int NOTIFY_ACTIVITY_ROTATED_MSG = 29;
// Delay in notifying task stack change listeners (in millis)
private static final int NOTIFY_TASK_STACK_CHANGE_LISTENERS_DELAY = 100;
@@ -183,6 +184,10 @@ class TaskChangeNotificationController {
l.onTaskRequestedOrientationChanged(m.arg1, m.arg2);
};
private final TaskStackConsumer mNotifyOnActivityRotation = (l, m) -> {
l.onActivityRotation();
};
@FunctionalInterface
public interface TaskStackConsumer {
void accept(ITaskStackListener t, Message m) throws RemoteException;
@@ -277,6 +282,9 @@ class TaskChangeNotificationController {
case NOTIFY_TASK_REQUESTED_ORIENTATION_CHANGED_MSG:
forAllRemoteListeners(mNotifyTaskRequestedOrientationChanged, msg);
break;
case NOTIFY_ACTIVITY_ROTATED_MSG:
forAllRemoteListeners(mNotifyOnActivityRotation, msg);
break;
}
if (msg.obj instanceof SomeArgs) {
((SomeArgs) msg.obj).recycle();
@@ -574,4 +582,11 @@ class TaskChangeNotificationController {
forAllLocalListeners(mNotifyTaskRequestedOrientationChanged, msg);
msg.sendToTarget();
}
/** @see android.app.ITaskStackListener#onActivityRotation() */
void notifyOnActivityRotation() {
final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_ROTATED_MSG);
forAllLocalListeners(mNotifyOnActivityRotation, msg);
msg.sendToTarget();
}
}

View File

@@ -3848,6 +3848,11 @@ public class WindowManagerService extends IWindowManager.Stub
final boolean rotationChanged = displayContent.updateRotationUnchecked();
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
if (rotationChanged) {
mAtmService.getTaskChangeNotificationController()
.notifyOnActivityRotation();
}
if (!rotationChanged || forceRelayout) {
displayContent.setLayoutNeeded();
layoutNeeded = true;