From 71223c6e6244be947bc05d1737d4127f3edafb7c Mon Sep 17 00:00:00 2001 From: Xiaowen Lei Date: Sat, 23 Jul 2022 05:58:29 +0000 Subject: [PATCH] Add AppTransition type and remote animation for Dream in occluding Keyguard. The existing Keyguard Occlude Animation Runner doesn't match the spec for Dream in. It animates activity expanding from the center of the screen. For Dream in, we have: - Dream fading in - DreamOverlay complications fading in slightly delayed, with each part starting at different times. This CL adds dedicated AppTransitionType and remote animation runner, which animates Dream fading in. It doesn't implement the separate animation for DreamOverlay complications. Bug: 222507937 Bug: 240477956 Bug: 242864189 Fix: 240477956 Test: on device, wait for Keyguard to time out to Dream. Change-Id: I5517ded2eea77ea962ca1551ed51dd997ff09993 --- core/java/android/view/WindowManager.java | 8 +- .../systemui/keyguard/KeyguardService.java | 10 +++ .../keyguard/KeyguardViewMediator.java | 84 +++++++++++++++++++ .../com/android/server/wm/AppTransition.java | 8 +- .../server/wm/AppTransitionController.java | 11 ++- 5 files changed, 117 insertions(+), 4 deletions(-) diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java index a49caafc63f1b..8656af2151d9e 100644 --- a/core/java/android/view/WindowManager.java +++ b/core/java/android/view/WindowManager.java @@ -285,11 +285,17 @@ public interface WindowManager extends ViewManager { int TRANSIT_OLD_KEYGUARD_GOING_AWAY_ON_WALLPAPER = 21; /** - * Keyguard is being occluded. + * Keyguard is being occluded by non-Dream. * @hide */ int TRANSIT_OLD_KEYGUARD_OCCLUDE = 22; + /** + * Keyguard is being occluded by Dream. + * @hide + */ + int TRANSIT_OLD_KEYGUARD_OCCLUDE_BY_DREAM = 33; + /** * Keyguard is being unoccluded. * @hide diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java index 898959e6eb585..ee5ef99058192 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java @@ -29,6 +29,7 @@ import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE; import static android.view.WindowManager.TRANSIT_OLD_KEYGUARD_GOING_AWAY; import static android.view.WindowManager.TRANSIT_OLD_KEYGUARD_GOING_AWAY_ON_WALLPAPER; import static android.view.WindowManager.TRANSIT_OLD_KEYGUARD_OCCLUDE; +import static android.view.WindowManager.TRANSIT_OLD_KEYGUARD_OCCLUDE_BY_DREAM; import static android.view.WindowManager.TRANSIT_OLD_KEYGUARD_UNOCCLUDE; import static android.view.WindowManager.TRANSIT_OLD_NONE; import static android.view.WindowManager.TRANSIT_OPEN; @@ -160,6 +161,9 @@ public class KeyguardService extends Service { return apps.length == 0 ? TRANSIT_OLD_KEYGUARD_GOING_AWAY_ON_WALLPAPER : TRANSIT_OLD_KEYGUARD_GOING_AWAY; } else if (type == TRANSIT_KEYGUARD_OCCLUDE) { + boolean isOccludeByDream = apps.length > 0 && apps[0].taskInfo.topActivityType + == WindowConfiguration.ACTIVITY_TYPE_DREAM; + if (isOccludeByDream) return TRANSIT_OLD_KEYGUARD_OCCLUDE_BY_DREAM; return TRANSIT_OLD_KEYGUARD_OCCLUDE; } else if (type == TRANSIT_KEYGUARD_UNOCCLUDE) { return TRANSIT_OLD_KEYGUARD_UNOCCLUDE; @@ -271,6 +275,12 @@ public class KeyguardService extends Service { definition.addRemoteAnimation(TRANSIT_OLD_KEYGUARD_OCCLUDE, occludeAnimationAdapter); + final RemoteAnimationAdapter occludeByDreamAnimationAdapter = + new RemoteAnimationAdapter( + mKeyguardViewMediator.getOccludeByDreamAnimationRunner(), 0, 0); + definition.addRemoteAnimation(TRANSIT_OLD_KEYGUARD_OCCLUDE_BY_DREAM, + occludeByDreamAnimationAdapter); + final RemoteAnimationAdapter unoccludeAnimationAdapter = new RemoteAnimationAdapter( mKeyguardViewMediator.getUnoccludeAnimationRunner(), 0, 0); diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java index 2c60d5d67dac6..dc034360ad091 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java @@ -887,6 +887,86 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable, private IRemoteAnimationRunner mOccludeAnimationRunner = new OccludeActivityLaunchRemoteAnimationRunner(mOccludeAnimationController); + private final IRemoteAnimationRunner mOccludeByDreamAnimationRunner = + new IRemoteAnimationRunner.Stub() { + @Nullable private ValueAnimator mOccludeByDreamAnimator; + + @Override + public void onAnimationCancelled(boolean isKeyguardOccluded) { + if (mOccludeByDreamAnimator != null) { + mOccludeByDreamAnimator.cancel(); + } + setOccluded(isKeyguardOccluded /* isOccluded */, false /* animate */); + if (DEBUG) { + Log.d(TAG, "Occlude by Dream animation cancelled. Occluded state is now: " + + mOccluded); + } + } + + @Override + public void onAnimationStart(int transit, RemoteAnimationTarget[] apps, + RemoteAnimationTarget[] wallpapers, RemoteAnimationTarget[] nonApps, + IRemoteAnimationFinishedCallback finishedCallback) throws RemoteException { + setOccluded(true /* isOccluded */, true /* animate */); + + if (apps == null || apps.length == 0 || apps[0] == null) { + if (DEBUG) { + Log.d(TAG, "No apps provided to the OccludeByDream runner; " + + "skipping occluding animation."); + } + finishedCallback.onAnimationFinished(); + return; + } + + final RemoteAnimationTarget primary = apps[0]; + final boolean isDream = (apps[0].taskInfo.topActivityType + == WindowConfiguration.ACTIVITY_TYPE_DREAM); + if (!isDream) { + Log.w(TAG, "The occluding app isn't Dream; " + + "finishing up. Please check that the config is correct."); + finishedCallback.onAnimationFinished(); + return; + } + + final SyncRtSurfaceTransactionApplier applier = + new SyncRtSurfaceTransactionApplier( + mKeyguardViewControllerLazy.get().getViewRootImpl().getView()); + + mContext.getMainExecutor().execute(() -> { + if (mOccludeByDreamAnimator != null) { + mOccludeByDreamAnimator.cancel(); + } + + mOccludeByDreamAnimator = ValueAnimator.ofFloat(0f, 1f); + // Use the same duration as for the UNOCCLUDE. + mOccludeByDreamAnimator.setDuration(UNOCCLUDE_ANIMATION_DURATION); + mOccludeByDreamAnimator.setInterpolator(Interpolators.LINEAR); + mOccludeByDreamAnimator.addUpdateListener( + animation -> { + SyncRtSurfaceTransactionApplier.SurfaceParams.Builder + paramsBuilder = + new SyncRtSurfaceTransactionApplier.SurfaceParams + .Builder(primary.leash) + .withAlpha(animation.getAnimatedFraction()); + applier.scheduleApply(paramsBuilder.build()); + }); + mOccludeByDreamAnimator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + try { + finishedCallback.onAnimationFinished(); + mOccludeByDreamAnimator = null; + } catch (RemoteException e) { + e.printStackTrace(); + } + } + }); + + mOccludeByDreamAnimator.start(); + }); + } + }; + /** * Animation controller for activities that unocclude the keyguard. This does not use the * ActivityLaunchAnimator since we're just translating down, rather than emerging from a view @@ -1682,6 +1762,10 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable, return mOccludeAnimationRunner; } + public IRemoteAnimationRunner getOccludeByDreamAnimationRunner() { + return mOccludeByDreamAnimationRunner; + } + public IRemoteAnimationRunner getUnoccludeAnimationRunner() { return mUnoccludeAnimationRunner; } diff --git a/services/core/java/com/android/server/wm/AppTransition.java b/services/core/java/com/android/server/wm/AppTransition.java index c940a658015de..d2c098b73e714 100644 --- a/services/core/java/com/android/server/wm/AppTransition.java +++ b/services/core/java/com/android/server/wm/AppTransition.java @@ -39,6 +39,7 @@ import static android.view.WindowManager.TRANSIT_OLD_DREAM_ACTIVITY_OPEN; import static android.view.WindowManager.TRANSIT_OLD_KEYGUARD_GOING_AWAY; import static android.view.WindowManager.TRANSIT_OLD_KEYGUARD_GOING_AWAY_ON_WALLPAPER; import static android.view.WindowManager.TRANSIT_OLD_KEYGUARD_OCCLUDE; +import static android.view.WindowManager.TRANSIT_OLD_KEYGUARD_OCCLUDE_BY_DREAM; import static android.view.WindowManager.TRANSIT_OLD_KEYGUARD_UNOCCLUDE; import static android.view.WindowManager.TRANSIT_OLD_NONE; import static android.view.WindowManager.TRANSIT_OLD_TASK_CHANGE_WINDOWING_MODE; @@ -746,7 +747,8 @@ public class AppTransition implements Dump { if (isKeyguardGoingAwayTransitOld(transit) && enter) { a = mTransitionAnimation.loadKeyguardExitAnimation(mNextAppTransitionFlags, transit == TRANSIT_OLD_KEYGUARD_GOING_AWAY_ON_WALLPAPER); - } else if (transit == TRANSIT_OLD_KEYGUARD_OCCLUDE) { + } else if (transit == TRANSIT_OLD_KEYGUARD_OCCLUDE + || transit == TRANSIT_OLD_KEYGUARD_OCCLUDE_BY_DREAM) { a = null; } else if (transit == TRANSIT_OLD_KEYGUARD_UNOCCLUDE && !enter) { a = mTransitionAnimation.loadKeyguardUnoccludeAnimation(); @@ -1158,6 +1160,9 @@ public class AppTransition implements Dump { case TRANSIT_OLD_KEYGUARD_OCCLUDE: { return "TRANSIT_OLD_KEYGUARD_OCCLUDE"; } + case TRANSIT_OLD_KEYGUARD_OCCLUDE_BY_DREAM: { + return "TRANSIT_OLD_KEYGUARD_OCCLUDE_BY_DREAM"; + } case TRANSIT_OLD_KEYGUARD_UNOCCLUDE: { return "TRANSIT_OLD_KEYGUARD_UNOCCLUDE"; } @@ -1413,6 +1418,7 @@ public class AppTransition implements Dump { static boolean isKeyguardOccludeTransitOld(@TransitionOldType int transit) { return transit == TRANSIT_OLD_KEYGUARD_OCCLUDE + || transit == TRANSIT_OLD_KEYGUARD_OCCLUDE_BY_DREAM || transit == TRANSIT_OLD_KEYGUARD_UNOCCLUDE; } diff --git a/services/core/java/com/android/server/wm/AppTransitionController.java b/services/core/java/com/android/server/wm/AppTransitionController.java index 4b0005d77e40d..7e62c61572d6d 100644 --- a/services/core/java/com/android/server/wm/AppTransitionController.java +++ b/services/core/java/com/android/server/wm/AppTransitionController.java @@ -34,6 +34,7 @@ import static android.view.WindowManager.TRANSIT_OLD_DREAM_ACTIVITY_OPEN; import static android.view.WindowManager.TRANSIT_OLD_KEYGUARD_GOING_AWAY; import static android.view.WindowManager.TRANSIT_OLD_KEYGUARD_GOING_AWAY_ON_WALLPAPER; import static android.view.WindowManager.TRANSIT_OLD_KEYGUARD_OCCLUDE; +import static android.view.WindowManager.TRANSIT_OLD_KEYGUARD_OCCLUDE_BY_DREAM; import static android.view.WindowManager.TRANSIT_OLD_KEYGUARD_UNOCCLUDE; import static android.view.WindowManager.TRANSIT_OLD_NONE; import static android.view.WindowManager.TRANSIT_OLD_TASK_CHANGE_WINDOWING_MODE; @@ -357,8 +358,14 @@ public class AppTransitionController { // When there is a closing app, the keyguard has already been occluded by an // activity, and another activity has started on top of that activity, so normal // app transition animation should be used. - return closingApps.isEmpty() ? TRANSIT_OLD_KEYGUARD_OCCLUDE - : TRANSIT_OLD_ACTIVITY_OPEN; + if (!closingApps.isEmpty()) { + return TRANSIT_OLD_ACTIVITY_OPEN; + } + if (!openingApps.isEmpty() && openingApps.valueAt(0).getActivityType() + == ACTIVITY_TYPE_DREAM) { + return TRANSIT_OLD_KEYGUARD_OCCLUDE_BY_DREAM; + } + return TRANSIT_OLD_KEYGUARD_OCCLUDE; case TRANSIT_KEYGUARD_UNOCCLUDE: return TRANSIT_OLD_KEYGUARD_UNOCCLUDE; }