From ccf3121eb12ac5dda4047ecfe319694b15035294 Mon Sep 17 00:00:00 2001 From: Josh Tsuji Date: Fri, 25 Mar 2022 11:30:28 -0400 Subject: [PATCH 1/2] Add unocclude animation. This is a simple downward translate/alpha animation to match the shade's current unocclude animation. We use this rather than activity lauch animator since we're not launching from a view/from the power button, so it's not needed. Bug: 202963722 Test: unocclude camera Test: unocclude home controls Test: unocclude google maps navigation Change-Id: Id62fcb75d9215d8b12d06fb8c2e7e6e884e457b9 --- .../keyguard/KeyguardViewMediator.java | 132 ++++++++++++------ 1 file changed, 89 insertions(+), 43 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java index 758609a541e2f..197b7b43be716 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java @@ -47,6 +47,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.UserInfo; +import android.graphics.Matrix; import android.hardware.biometrics.BiometricSourceType; import android.media.AudioAttributes; import android.media.AudioManager; @@ -236,6 +237,14 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable, */ private static final int KEYGUARD_DONE_DRAWING_TIMEOUT_MS = 2000; + private static final int UNOCCLUDE_ANIMATION_DURATION = 250; + + /** + * How far down to animate the unoccluding activity, in terms of percent of the activity's + * height. + */ + private static final float UNOCCLUDE_TRANSLATE_DISTANCE_PERCENT = 0.1f; + /** * Boolean option for doKeyguardLocked/doKeyguardTimeout which, when set to true, forces the * keyguard to show even if it is disabled for the current user. @@ -883,52 +892,89 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable, } }; - /** - * Animation controller for activities that unocclude the keyguard. This will play the launch - * animation in reverse. - */ - private final ActivityLaunchAnimator.Controller mUnoccludeAnimationController = - new ActivityLaunchAnimator.Controller() { - @Override - public void onLaunchAnimationEnd(boolean isExpandingFullyAbove) { - setOccluded(false /* isOccluded */, false /* animate */); - } - - @Override - public void onLaunchAnimationCancelled() { - setOccluded(false /* isOccluded */, false /* animate */); - } - - @NonNull - @Override - public ViewGroup getLaunchContainer() { - return ((ViewGroup) mKeyguardViewControllerLazy.get() - .getViewRootImpl().getView()); - } - - @Override - public void setLaunchContainer(@NonNull ViewGroup launchContainer) { - // No-op, launch container is always the shade. - Log.wtf(TAG, "Someone tried to change the launch container for the " - + "ActivityLaunchAnimator, which should never happen."); - } - - @NonNull - @Override - public LaunchAnimator.State createAnimatorState() { - final int width = getLaunchContainer().getWidth(); - final int height = getLaunchContainer().getHeight(); - - // TODO(b/207399883): Unocclude animation. This currently ends instantly. - return new LaunchAnimator.State( - 0, height, 0, width, mWindowCornerRadius, mWindowCornerRadius); - } - }; - private IRemoteAnimationRunner mOccludeAnimationRunner = new ActivityLaunchRemoteAnimationRunner(mOccludeAnimationController); + + /** + * 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 + * or the power button. + */ private IRemoteAnimationRunner mUnoccludeAnimationRunner = - new ActivityLaunchRemoteAnimationRunner(mUnoccludeAnimationController); + new IRemoteAnimationRunner.Stub() { + + @Nullable private ValueAnimator mUnoccludeAnimator; + private final Matrix mUnoccludeMatrix = new Matrix(); + + @Override + public void onAnimationCancelled() { + if (mUnoccludeAnimator != null) { + mUnoccludeAnimator.cancel(); + } + } + + @Override + public void onAnimationStart(int transit, RemoteAnimationTarget[] apps, + RemoteAnimationTarget[] wallpapers, + RemoteAnimationTarget[] nonApps, + IRemoteAnimationFinishedCallback finishedCallback) throws RemoteException { + final RemoteAnimationTarget primary = apps[0]; + + if (primary == null) { + finishedCallback.onAnimationFinished(); + return; + } + + final SyncRtSurfaceTransactionApplier applier = + new SyncRtSurfaceTransactionApplier( + mKeyguardViewControllerLazy.get().getViewRootImpl().getView()); + + + mContext.getMainExecutor().execute(() -> { + if (mUnoccludeAnimator != null) { + mUnoccludeAnimator.cancel(); + } + + mUnoccludeAnimator = ValueAnimator.ofFloat(1f, 0f); + mUnoccludeAnimator.setDuration(UNOCCLUDE_ANIMATION_DURATION); + mUnoccludeAnimator.setInterpolator(Interpolators.TOUCH_RESPONSE); + mUnoccludeAnimator.addUpdateListener( + animation -> { + final float animatedValue = + (float) animation.getAnimatedValue(); + + final float surfaceHeight = primary.screenSpaceBounds.height(); + + mUnoccludeMatrix.setTranslate( + 0f, + (1f - animatedValue) + * surfaceHeight + * UNOCCLUDE_TRANSLATE_DISTANCE_PERCENT); + + SyncRtSurfaceTransactionApplier.SurfaceParams params = + new SyncRtSurfaceTransactionApplier.SurfaceParams + .Builder(primary.leash) + .withMatrix(mUnoccludeMatrix) + .withCornerRadius(mWindowCornerRadius) + .withAlpha(animatedValue) + .build(); + applier.scheduleApply(params); + }); + mUnoccludeAnimator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + try { + finishedCallback.onAnimationFinished(); + } catch (RemoteException e) { + e.printStackTrace(); + } + } + }); + + mUnoccludeAnimator.start(); + }); + } + }; private DeviceConfigProxy mDeviceConfig; private DozeParameters mDozeParameters; From f1234b41eebbae69affbc3b1359fa295b47c6688 Mon Sep 17 00:00:00 2001 From: Josh Tsuji Date: Fri, 25 Mar 2022 11:27:21 -0400 Subject: [PATCH 2/2] Re-enable remote occlude/unocclude animations. This was previously disabled due to an issue where the bouncer would appear whenever the home controls (or other non-camera occluding activites) were launched. This issue appears to now be fixed on tm-dev, likely by some of our other fixes over the last month. Bug: 202963722 Test: With AOD enabled/disabled Test: With security/no security/no lockscreen Test: enable home controls, use home controls activity Change-Id: I486c7adeb23113fa98377d1d5b16c8b6a8be003c --- .../src/com/android/systemui/keyguard/KeyguardService.java | 2 +- .../com/android/systemui/keyguard/KeyguardViewMediator.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java index 88555edd1e8b9..b96eee717260f 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java @@ -102,7 +102,7 @@ public class KeyguardService extends Service { "persist.wm.enable_remote_keyguard_animation"; private static final int sEnableRemoteKeyguardAnimation = - SystemProperties.getInt(ENABLE_REMOTE_KEYGUARD_ANIMATION_PROPERTY, 1); + SystemProperties.getInt(ENABLE_REMOTE_KEYGUARD_ANIMATION_PROPERTY, 2); /** * @see #ENABLE_REMOTE_KEYGUARD_ANIMATION_PROPERTY diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java index 197b7b43be716..55bb2aecd379b 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java @@ -900,7 +900,7 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable, * ActivityLaunchAnimator since we're just translating down, rather than emerging from a view * or the power button. */ - private IRemoteAnimationRunner mUnoccludeAnimationRunner = + private final IRemoteAnimationRunner mUnoccludeAnimationRunner = new IRemoteAnimationRunner.Stub() { @Nullable private ValueAnimator mUnoccludeAnimator; @@ -965,6 +965,7 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable, public void onAnimationEnd(Animator animation) { try { finishedCallback.onAnimationFinished(); + mUnoccludeAnimator = null; } catch (RemoteException e) { e.printStackTrace(); }