From 351107ec74e4361e59a00ab971c34ffae4619d59 Mon Sep 17 00:00:00 2001 From: Ilya Matyukhin Date: Mon, 10 May 2021 21:02:58 -0700 Subject: [PATCH] Make UdfpsHbmCallback a dependency of UdfpsController Bug: 187732246 Test: atest UdfpsControllerGoogle Change-Id: I1aead35213de9491538b6eaf5d4a45be569ecab8 --- .../fingerprint/IUdfpsHbmListener.aidl | 4 ++-- .../systemui/biometrics/UdfpsController.java | 23 +++++++------------ ...HbmCallback.java => UdfpsHbmCallback.java} | 8 +++---- .../{HbmTypes.java => UdfpsHbmTypes.java} | 2 +- .../systemui/biometrics/UdfpsIlluminator.java | 2 +- .../systemui/biometrics/UdfpsSurfaceView.java | 10 ++++---- .../systemui/biometrics/UdfpsView.java | 2 +- .../systemui/dagger/SystemUIModule.java | 4 ++++ .../biometrics/UdfpsControllerTest.java | 6 ++++- 9 files changed, 31 insertions(+), 30 deletions(-) rename packages/SystemUI/src/com/android/systemui/biometrics/{HbmCallback.java => UdfpsHbmCallback.java} (92%) rename packages/SystemUI/src/com/android/systemui/biometrics/{HbmTypes.java => UdfpsHbmTypes.java} (97%) diff --git a/core/java/android/hardware/fingerprint/IUdfpsHbmListener.aidl b/core/java/android/hardware/fingerprint/IUdfpsHbmListener.aidl index 1551e0742186b..f4d22dac3b72d 100644 --- a/core/java/android/hardware/fingerprint/IUdfpsHbmListener.aidl +++ b/core/java/android/hardware/fingerprint/IUdfpsHbmListener.aidl @@ -35,7 +35,7 @@ oneway interface IUdfpsHbmListener { * UdfpsController will call this method when the HBM is enabled. * * @param hbmType The type of HBM that was enabled. See - * {@link com.android.systemui.biometrics.HbmTypes}. + * {@link com.android.systemui.biometrics.UdfpsHbmTypes}. * @param displayId The displayId for which the HBM is enabled. See * {@link android.view.Display#getDisplayId()}. */ @@ -45,7 +45,7 @@ oneway interface IUdfpsHbmListener { * UdfpsController will call this method when the HBM is disabled. * * @param hbmType The type of HBM that was disabled. See - * {@link com.android.systemui.biometrics.HbmTypes}. + * {@link com.android.systemui.biometrics.UdfpsHbmTypes}. * @param displayId The displayId for which the HBM is disabled. See * {@link android.view.Display#getDisplayId()}. */ diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java index 5a50f0eed8338..875bfdbffff3c 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java @@ -59,7 +59,6 @@ import android.view.accessibility.AccessibilityManager; import com.android.internal.annotations.VisibleForTesting; import com.android.keyguard.KeyguardUpdateMonitor; import com.android.systemui.R; -import com.android.systemui.biometrics.HbmTypes.HbmType; import com.android.systemui.dagger.SysUISingleton; import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.doze.DozeReceiver; @@ -72,6 +71,8 @@ import com.android.systemui.statusbar.phone.StatusBar; import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; import com.android.systemui.util.concurrency.DelayableExecutor; +import java.util.Optional; + import javax.inject.Inject; /** @@ -87,7 +88,7 @@ import javax.inject.Inject; */ @SuppressWarnings("deprecation") @SysUISingleton -public class UdfpsController implements DozeReceiver, HbmCallback { +public class UdfpsController implements DozeReceiver { private static final String TAG = "UdfpsController"; private static final long AOD_INTERRUPT_TIMEOUT_MILLIS = 1000; @@ -110,6 +111,7 @@ public class UdfpsController implements DozeReceiver, HbmCallback { @NonNull private final FalsingManager mFalsingManager; @NonNull private final PowerManager mPowerManager; @NonNull private final AccessibilityManager mAccessibilityManager; + @Nullable private final UdfpsHbmCallback mHbmCallback; // Currently the UdfpsController supports a single UDFPS sensor. If devices have multiple // sensors, this, in addition to a lot of the code here, will be updated. @VisibleForTesting final FingerprintSensorPropertiesInternal mSensorProps; @@ -466,7 +468,8 @@ public class UdfpsController implements DozeReceiver, HbmCallback { @NonNull PowerManager powerManager, @NonNull AccessibilityManager accessibilityManager, @NonNull ScreenLifecycle screenLifecycle, - @Nullable Vibrator vibrator) { + @Nullable Vibrator vibrator, + @NonNull Optional hbmCallback) { mContext = context; // TODO (b/185124905): inject main handler and vibrator once done prototyping mMainHandler = new Handler(Looper.getMainLooper()); @@ -486,6 +489,7 @@ public class UdfpsController implements DozeReceiver, HbmCallback { mFalsingManager = falsingManager; mPowerManager = powerManager; mAccessibilityManager = accessibilityManager; + mHbmCallback = hbmCallback.orElse(null); screenLifecycle.addObserver(mScreenObserver); mScreenOn = screenLifecycle.getScreenState() == ScreenLifecycle.SCREEN_ON; @@ -619,7 +623,7 @@ public class UdfpsController implements DozeReceiver, HbmCallback { Log.v(TAG, "showUdfpsOverlay | adding window reason=" + reason); mView = (UdfpsView) mInflater.inflate(R.layout.udfps_view, null, false); mView.setSensorProperties(mSensorProps); - mView.setHbmCallback(this); + mView.setHbmCallback(mHbmCallback); UdfpsAnimationViewController animation = inflateUdfpsAnimation(reason); animation.init(); mView.setAnimationViewController(animation); @@ -791,17 +795,6 @@ public class UdfpsController implements DozeReceiver, HbmCallback { mView.stopIllumination(); } - @Override - public void enableHbm(@HbmType int hbmType, @Nullable Surface surface) { - // Do nothing. This method can be implemented for devices that require the high-brightness - // mode for fingerprint illumination. - } - - @Override - public void disableHbm(@HbmType int hbmType, @Nullable Surface surface) { - // Do nothing. This method can be implemented for devices that require the high-brightness - // mode for fingerprint illumination. - } private VibrationEffect getVibration(String effect, VibrationEffect defaultEffect) { if (TextUtils.isEmpty(effect)) { diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/HbmCallback.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsHbmCallback.java similarity index 92% rename from packages/SystemUI/src/com/android/systemui/biometrics/HbmCallback.java rename to packages/SystemUI/src/com/android/systemui/biometrics/UdfpsHbmCallback.java index d90d0f8d9f677..85f0d278e3f14 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/HbmCallback.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsHbmCallback.java @@ -19,18 +19,18 @@ package com.android.systemui.biometrics; import android.annotation.Nullable; import android.view.Surface; -import com.android.systemui.biometrics.HbmTypes.HbmType; +import com.android.systemui.biometrics.UdfpsHbmTypes.HbmType; /** * Interface for controlling the high-brightness mode (HBM). UdfpsView can use this callback to * enable the HBM while showing the fingerprint illumination, and to disable the HBM after the * illumination is no longer necessary. */ -public interface HbmCallback { +public interface UdfpsHbmCallback { /** * UdfpsView will call this to enable the HBM when the fingerprint illumination is needed. * - * @param hbmType The type of HBM that should be enabled. See {@link HbmTypes}. + * @param hbmType The type of HBM that should be enabled. See {@link UdfpsHbmTypes}. * @param surface The surface for which the HBM is requested, in case the HBM implementation * needs to set special surface flags to enable the HBM. Can be null. */ @@ -39,7 +39,7 @@ public interface HbmCallback { /** * UdfpsView will call this to disable the HBM when the illumination is not longer needed. * - * @param hbmType The type of HBM that should be disabled. See {@link HbmTypes}. + * @param hbmType The type of HBM that should be disabled. See {@link UdfpsHbmTypes}. * @param surface The surface for which the HBM is requested, in case the HBM implementation * needs to unset special surface flags to disable the HBM. Can be null. */ diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/HbmTypes.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsHbmTypes.java similarity index 97% rename from packages/SystemUI/src/com/android/systemui/biometrics/HbmTypes.java rename to packages/SystemUI/src/com/android/systemui/biometrics/UdfpsHbmTypes.java index f798005daabb1..3ab0bd62eec85 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/HbmTypes.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsHbmTypes.java @@ -25,7 +25,7 @@ import java.lang.annotation.RetentionPolicy; /** * Different high-brightness mode (HBM) types that are relevant to this package. */ -public final class HbmTypes { +public final class UdfpsHbmTypes { /** HBM that applies to the whole screen. */ public static final int GLOBAL_HBM = IUdfpsHbmListener.GLOBAL_HBM; diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsIlluminator.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsIlluminator.java index 8bea05b2b54f4..1676bcd57afc0 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsIlluminator.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsIlluminator.java @@ -26,7 +26,7 @@ interface UdfpsIlluminator { /** * @param callback Invoked when HBM should be enabled or disabled. */ - void setHbmCallback(@Nullable HbmCallback callback); + void setHbmCallback(@Nullable UdfpsHbmCallback callback); /** * Invoked when illumination should start. diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsSurfaceView.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsSurfaceView.java index 4d441bd288fef..aa5f0f6cf7f47 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsSurfaceView.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsSurfaceView.java @@ -31,7 +31,7 @@ import android.util.Log; import android.view.SurfaceHolder; import android.view.SurfaceView; -import com.android.systemui.biometrics.HbmTypes.HbmType; +import com.android.systemui.biometrics.UdfpsHbmTypes.HbmType; /** * Under-display fingerprint sensor Surface View. The surface should be used for HBM-specific things @@ -41,7 +41,7 @@ public class UdfpsSurfaceView extends SurfaceView implements UdfpsIlluminator { private static final String TAG = "UdfpsSurfaceView"; private static final String SETTING_HBM_TYPE = "com.android.systemui.biometrics.UdfpsSurfaceView.hbmType"; - private static final @HbmType int DEFAULT_HBM_TYPE = HbmTypes.GLOBAL_HBM; + private static final @HbmType int DEFAULT_HBM_TYPE = UdfpsHbmTypes.GLOBAL_HBM; /** * This is used instead of {@link android.graphics.drawable.Drawable}, because the latter has @@ -57,7 +57,7 @@ public class UdfpsSurfaceView extends SurfaceView implements UdfpsIlluminator { private final @HbmType int mHbmType; @NonNull private RectF mSensorRect; - @Nullable private HbmCallback mHbmCallback; + @Nullable private UdfpsHbmCallback mHbmCallback; public UdfpsSurfaceView(Context context, AttributeSet attrs) { super(context, attrs); @@ -90,7 +90,7 @@ public class UdfpsSurfaceView extends SurfaceView implements UdfpsIlluminator { } @Override - public void setHbmCallback(@Nullable HbmCallback callback) { + public void setHbmCallback(@Nullable UdfpsHbmCallback callback) { mHbmCallback = callback; } @@ -102,7 +102,7 @@ public class UdfpsSurfaceView extends SurfaceView implements UdfpsIlluminator { Log.e(TAG, "startIllumination | mHbmCallback is null"); } - if (mHbmType == HbmTypes.GLOBAL_HBM) { + if (mHbmType == UdfpsHbmTypes.GLOBAL_HBM) { drawImmediately(mIlluminationDotDrawable); } diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsView.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsView.java index f10d5f3bca1fd..a1d30403e0b8d 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsView.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsView.java @@ -101,7 +101,7 @@ public class UdfpsView extends FrameLayout implements DozeReceiver, UdfpsIllumin } @Override - public void setHbmCallback(@Nullable HbmCallback callback) { + public void setHbmCallback(@Nullable UdfpsHbmCallback callback) { mHbmSurfaceView.setHbmCallback(callback); } diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java index 7fa48d405643b..1396099db9488 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java @@ -29,6 +29,7 @@ import com.android.systemui.BootCompleteCacheImpl; import com.android.systemui.SystemUIFactory; import com.android.systemui.appops.dagger.AppOpsModule; import com.android.systemui.assist.AssistModule; +import com.android.systemui.biometrics.UdfpsHbmCallback; import com.android.systemui.classifier.FalsingModule; import com.android.systemui.controls.dagger.ControlsModule; import com.android.systemui.dagger.qualifiers.Main; @@ -160,6 +161,9 @@ public abstract class SystemUIModule { @BindsOptionalOf abstract StatusBar optionalStatusBar(); + @BindsOptionalOf + abstract UdfpsHbmCallback optionalUdfpsHbmCallback(); + @SysUISingleton @Binds abstract SystemClock bindSystemClock(SystemClockImpl systemClock); diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsControllerTest.java index 2530cfd70441b..46c18480c77b8 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsControllerTest.java @@ -70,6 +70,7 @@ import org.mockito.junit.MockitoRule; import java.util.ArrayList; import java.util.List; +import java.util.Optional; @SmallTest @RunWith(AndroidTestingRunner.class) @@ -94,6 +95,8 @@ public class UdfpsControllerTest extends SysuiTestCase { @Mock private WindowManager mWindowManager; @Mock + private UdfpsHbmCallback mHbmCallback; + @Mock private StatusBarStateController mStatusBarStateController; @Mock private StatusBar mStatusBar; @@ -174,7 +177,8 @@ public class UdfpsControllerTest extends SysuiTestCase { mPowerManager, mAccessibilityManager, mScreenLifecycle, - mVibrator); + mVibrator, + Optional.of(mHbmCallback)); verify(mFingerprintManager).setUdfpsOverlayController(mOverlayCaptor.capture()); mOverlayController = mOverlayCaptor.getValue(); verify(mScreenLifecycle).addObserver(mScreenObserverCaptor.capture());