Make UdfpsHbmCallback a dependency of UdfpsController

Bug: 187732246
Test: atest UdfpsControllerGoogle
Change-Id: I1aead35213de9491538b6eaf5d4a45be569ecab8
This commit is contained in:
Ilya Matyukhin
2021-05-10 21:02:58 -07:00
parent dd3707adc0
commit 351107ec74
9 changed files with 31 additions and 30 deletions

View File

@@ -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()}.
*/

View File

@@ -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<UdfpsHbmCallback> 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)) {

View File

@@ -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.
*/

View File

@@ -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;

View File

@@ -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.

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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());