DO NOT MERGE Only rely on developer option for back animation

BackNavigationController was still relying on a debug setting. Now the
animation request is handled via a boolean parameter passed by sysui,
which has access to the developer option.

Test: Existing test modified
Bug: 231502692
Change-Id: Icda4692e05396407d961610de0ce709492adadc1
Merged-In: Icda4692e05396407d961610de0ce709492adadc1
This commit is contained in:
Vadim Caen
2022-05-11 20:36:53 +02:00
parent a3f6dae96f
commit ab58191c7f
7 changed files with 21 additions and 21 deletions

View File

@@ -348,6 +348,7 @@ interface IActivityTaskManager {
/** /**
* Prepare the back navigation in the server. This setups the leashed for sysui to animate * Prepare the back navigation in the server. This setups the leashed for sysui to animate
* the back gesture and returns the data needed for the animation. * the back gesture and returns the data needed for the animation.
* @param requestAnimation true if the caller wishes to animate the back navigation
*/ */
android.window.BackNavigationInfo startBackNavigation(); android.window.BackNavigationInfo startBackNavigation(in boolean requestAnimation);
} }

View File

@@ -91,7 +91,7 @@ public class BackNavigationTest {
private void assertCallbackIsCalled(CountDownLatch latch) { private void assertCallbackIsCalled(CountDownLatch latch) {
try { try {
mInstrumentation.getUiAutomation().waitForIdle(500, 1000); mInstrumentation.getUiAutomation().waitForIdle(500, 1000);
BackNavigationInfo info = ActivityTaskManager.getService().startBackNavigation(); BackNavigationInfo info = ActivityTaskManager.getService().startBackNavigation(true);
assertNotNull("BackNavigationInfo is null", info); assertNotNull("BackNavigationInfo is null", info);
assertNotNull("OnBackInvokedCallback is null", info.getOnBackInvokedCallback()); assertNotNull("OnBackInvokedCallback is null", info.getOnBackInvokedCallback());
info.getOnBackInvokedCallback().onBackInvoked(); info.getOnBackInvokedCallback().onBackInvoked();

View File

@@ -272,7 +272,8 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
mBackGestureStarted = true; mBackGestureStarted = true;
try { try {
mBackNavigationInfo = mActivityTaskManager.startBackNavigation(); boolean requestAnimation = mEnableAnimations.get();
mBackNavigationInfo = mActivityTaskManager.startBackNavigation(requestAnimation);
onBackNavigationInfoReceived(mBackNavigationInfo); onBackNavigationInfoReceived(mBackNavigationInfo);
} catch (RemoteException remoteException) { } catch (RemoteException remoteException) {
Log.e(TAG, "Failed to initAnimation", remoteException); Log.e(TAG, "Failed to initAnimation", remoteException);

View File

@@ -20,6 +20,7 @@ import static android.window.BackNavigationInfo.KEY_TRIGGER_BACK;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.atLeastOnce;
@@ -126,7 +127,7 @@ public class BackAnimationControllerTest {
new RemoteCallback((bundle) -> {}), new RemoteCallback((bundle) -> {}),
onBackInvokedCallback); onBackInvokedCallback);
try { try {
doReturn(navigationInfo).when(mActivityTaskManager).startBackNavigation(); doReturn(navigationInfo).when(mActivityTaskManager).startBackNavigation(anyBoolean());
} catch (RemoteException ex) { } catch (RemoteException ex) {
ex.rethrowFromSystemServer(); ex.rethrowFromSystemServer();
} }
@@ -134,7 +135,7 @@ public class BackAnimationControllerTest {
private void createNavigationInfo(BackNavigationInfo.Builder builder) { private void createNavigationInfo(BackNavigationInfo.Builder builder) {
try { try {
doReturn(builder.build()).when(mActivityTaskManager).startBackNavigation(); doReturn(builder.build()).when(mActivityTaskManager).startBackNavigation(anyBoolean());
} catch (RemoteException ex) { } catch (RemoteException ex) {
ex.rethrowFromSystemServer(); ex.rethrowFromSystemServer();
} }

View File

@@ -1789,13 +1789,13 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
} }
@Override @Override
public BackNavigationInfo startBackNavigation() { public BackNavigationInfo startBackNavigation(boolean requestAnimation) {
mAmInternal.enforceCallingPermission(START_TASKS_FROM_RECENTS, mAmInternal.enforceCallingPermission(START_TASKS_FROM_RECENTS,
"startBackNavigation()"); "startBackNavigation()");
if (mBackNavigationController == null) { if (mBackNavigationController == null) {
return null; return null;
} }
return mBackNavigationController.startBackNavigation(mWindowManager); return mBackNavigationController.startBackNavigation(mWindowManager, requestAnimation);
} }
/** /**

View File

@@ -61,10 +61,6 @@ class BackNavigationController {
return SystemProperties.getInt("persist.wm.debug.predictive_back_screenshot", 0) != 0; return SystemProperties.getInt("persist.wm.debug.predictive_back_screenshot", 0) != 0;
} }
private static boolean isAnimationEnabled() {
return SystemProperties.getInt("persist.wm.debug.predictive_back_anim", 0) != 0;
}
/** /**
* Set up the necessary leashes and build a {@link BackNavigationInfo} instance for an upcoming * Set up the necessary leashes and build a {@link BackNavigationInfo} instance for an upcoming
* back gesture animation. * back gesture animation.
@@ -74,20 +70,21 @@ class BackNavigationController {
* fallback on dispatching the key event. * fallback on dispatching the key event.
*/ */
@Nullable @Nullable
BackNavigationInfo startBackNavigation(@NonNull WindowManagerService wmService) { BackNavigationInfo startBackNavigation(@NonNull WindowManagerService wmService,
return startBackNavigation(wmService, null); boolean requestAnimation) {
return startBackNavigation(wmService, null, requestAnimation);
} }
/** /**
* @param tx, a transaction to be used for the attaching the animation leash. * @param tx, a transaction to be used for the attaching the animation leash.
* This is used in tests. If null, the object will be initialized with a new {@link * This is used in tests. If null, the object will be initialized with a new {@link
* SurfaceControl.Transaction} * SurfaceControl.Transaction}
* @see #startBackNavigation(WindowManagerService) * @see #startBackNavigation(WindowManagerService, boolean)
*/ */
@VisibleForTesting @VisibleForTesting
@Nullable @Nullable
BackNavigationInfo startBackNavigation(WindowManagerService wmService, BackNavigationInfo startBackNavigation(WindowManagerService wmService,
@Nullable SurfaceControl.Transaction tx) { @Nullable SurfaceControl.Transaction tx, boolean requestAnimation) {
if (tx == null) { if (tx == null) {
tx = new SurfaceControl.Transaction(); tx = new SurfaceControl.Transaction();
@@ -272,7 +269,7 @@ class BackNavigationController {
} }
// Special handling for back to home animation // Special handling for back to home animation
if (backType == BackNavigationInfo.TYPE_RETURN_TO_HOME && isAnimationEnabled() if (backType == BackNavigationInfo.TYPE_RETURN_TO_HOME && requestAnimation
&& prevTask != null) { && prevTask != null) {
currentTask.mBackGestureStarted = true; currentTask.mBackGestureStarted = true;
// Make launcher show from behind by marking its top activity as visible and // Make launcher show from behind by marking its top activity as visible and
@@ -327,7 +324,7 @@ class BackNavigationController {
Task finalTask = currentTask; Task finalTask = currentTask;
RemoteCallback onBackNavigationDone = new RemoteCallback(result -> onBackNavigationDone( RemoteCallback onBackNavigationDone = new RemoteCallback(result -> onBackNavigationDone(
result, finalRemovedWindowContainer, finalBackType, finalTask, result, finalRemovedWindowContainer, finalBackType, finalTask,
finalprevActivity)); finalprevActivity, requestAnimation));
infoBuilder.setOnBackNavigationDone(onBackNavigationDone); infoBuilder.setOnBackNavigationDone(onBackNavigationDone);
} }
@@ -361,14 +358,14 @@ class BackNavigationController {
private void onBackNavigationDone( private void onBackNavigationDone(
Bundle result, WindowContainer<?> windowContainer, int backType, Bundle result, WindowContainer<?> windowContainer, int backType,
Task task, ActivityRecord prevActivity) { Task task, ActivityRecord prevActivity, boolean requestAnimation) {
SurfaceControl surfaceControl = windowContainer.getSurfaceControl(); SurfaceControl surfaceControl = windowContainer.getSurfaceControl();
boolean triggerBack = result != null && result.getBoolean( boolean triggerBack = result != null && result.getBoolean(
BackNavigationInfo.KEY_TRIGGER_BACK); BackNavigationInfo.KEY_TRIGGER_BACK);
ProtoLog.d(WM_DEBUG_BACK_PREVIEW, "onBackNavigationDone backType=%s, " ProtoLog.d(WM_DEBUG_BACK_PREVIEW, "onBackNavigationDone backType=%s, "
+ "task=%s, prevActivity=%s", backType, task, prevActivity); + "task=%s, prevActivity=%s", backType, task, prevActivity);
if (backType == BackNavigationInfo.TYPE_RETURN_TO_HOME && isAnimationEnabled()) { if (backType == BackNavigationInfo.TYPE_RETURN_TO_HOME && requestAnimation) {
if (triggerBack) { if (triggerBack) {
if (surfaceControl != null && surfaceControl.isValid()) { if (surfaceControl != null && surfaceControl.isValid()) {
// When going back to home, hide the task surface before it is re-parented to // When going back to home, hide the task surface before it is re-parented to

View File

@@ -86,7 +86,7 @@ public class BackNavigationControllerTests extends WindowTestsBase {
SurfaceControl.Transaction tx = mock(SurfaceControl.Transaction.class); SurfaceControl.Transaction tx = mock(SurfaceControl.Transaction.class);
BackNavigationInfo backNavigationInfo = mBackNavigationController.startBackNavigation(mWm, BackNavigationInfo backNavigationInfo = mBackNavigationController.startBackNavigation(mWm,
tx); tx, true);
assertWithMessage("BackNavigationInfo").that(backNavigationInfo).isNotNull(); assertWithMessage("BackNavigationInfo").that(backNavigationInfo).isNotNull();
assertThat(backNavigationInfo.getDepartingAnimationTarget()).isNotNull(); assertThat(backNavigationInfo.getDepartingAnimationTarget()).isNotNull();
assertThat(backNavigationInfo.getTaskWindowConfiguration()).isNotNull(); assertThat(backNavigationInfo.getTaskWindowConfiguration()).isNotNull();
@@ -242,7 +242,7 @@ public class BackNavigationControllerTests extends WindowTestsBase {
@Nullable @Nullable
private BackNavigationInfo startBackNavigation() { private BackNavigationInfo startBackNavigation() {
return mBackNavigationController.startBackNavigation(mWm, new StubTransaction()); return mBackNavigationController.startBackNavigation(mWm, new StubTransaction(), true);
} }
@NonNull @NonNull