Merge "Remove face auth wallpaper" into sc-v2-dev

This commit is contained in:
TreeHugger Robot
2021-10-25 16:59:50 +00:00
committed by Android (Google) Code Review
7 changed files with 0 additions and 401 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 692 KiB

View File

@@ -1,195 +0,0 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.systemui.keyguard
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.ValueAnimator
import android.content.res.Resources
import android.database.ContentObserver
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.hardware.biometrics.BiometricSourceType
import android.os.Handler
import android.provider.Settings.System.SCREEN_BRIGHTNESS_FLOAT
import android.util.MathUtils
import android.view.View
import android.view.WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
import android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
import com.android.internal.annotations.VisibleForTesting
import com.android.keyguard.KeyguardUpdateMonitor
import com.android.keyguard.KeyguardUpdateMonitorCallback
import com.android.systemui.Dumpable
import com.android.systemui.R
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dump.DumpManager
import com.android.systemui.statusbar.NotificationShadeWindowController
import com.android.systemui.util.settings.GlobalSettings
import com.android.systemui.util.settings.SystemSettings
import java.io.FileDescriptor
import java.io.PrintWriter
import java.lang.Float.max
import java.util.concurrent.TimeUnit
val DEFAULT_ANIMATION_DURATION = TimeUnit.SECONDS.toMillis(4)
val MAX_SCREEN_BRIGHTNESS = 100 // 0..100
val MAX_SCRIM_OPACTY = 50 // 0..100
val DEFAULT_USE_FACE_WALLPAPER = false
/**
* This class is responsible for ramping up the display brightness (and white overlay) in order
* to mitigate low light conditions when running face auth without an IR camera.
*/
@SysUISingleton
open class FaceAuthScreenBrightnessController(
private val notificationShadeWindowController: NotificationShadeWindowController,
private val keyguardUpdateMonitor: KeyguardUpdateMonitor,
private val resources: Resources,
private val globalSettings: GlobalSettings,
private val systemSettings: SystemSettings,
private val mainHandler: Handler,
private val dumpManager: DumpManager,
private val enabled: Boolean
) : Dumpable {
private var userDefinedBrightness: Float = 1f
@VisibleForTesting
var useFaceAuthWallpaper = globalSettings
.getInt("sysui.use_face_auth_wallpaper", if (DEFAULT_USE_FACE_WALLPAPER) 1 else 0) == 1
private val brightnessAnimationDuration = globalSettings
.getLong("sysui.face_brightness_anim_duration", DEFAULT_ANIMATION_DURATION)
private val maxScreenBrightness = globalSettings
.getInt("sysui.face_max_brightness", MAX_SCREEN_BRIGHTNESS) / 100f
private val maxScrimOpacity = globalSettings
.getInt("sysui.face_max_scrim_opacity", MAX_SCRIM_OPACTY) / 100f
private val keyguardUpdateCallback = object : KeyguardUpdateMonitorCallback() {
override fun onBiometricRunningStateChanged(
running: Boolean,
biometricSourceType: BiometricSourceType?
) {
if (biometricSourceType != BiometricSourceType.FACE) {
return
}
// TODO enable only when receiving a low-light error
overridingBrightness = if (enabled) running else false
}
}
private lateinit var whiteOverlay: View
private var brightnessAnimator: ValueAnimator? = null
private var overridingBrightness = false
set(value) {
if (field == value) {
return
}
field = value
brightnessAnimator?.cancel()
if (!value) {
notificationShadeWindowController.setFaceAuthDisplayBrightness(BRIGHTNESS_OVERRIDE_NONE)
if (whiteOverlay.alpha > 0) {
brightnessAnimator = createAnimator(whiteOverlay.alpha, 0f).apply {
duration = 200
addUpdateListener {
whiteOverlay.alpha = it.animatedValue as Float
}
addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator?) {
whiteOverlay.visibility = View.INVISIBLE
brightnessAnimator = null
}
})
start()
}
}
return
}
val targetBrightness = max(maxScreenBrightness, userDefinedBrightness)
whiteOverlay.visibility = View.VISIBLE
brightnessAnimator = createAnimator(0f, 1f).apply {
duration = brightnessAnimationDuration
addUpdateListener {
val progress = it.animatedValue as Float
val brightnessProgress = MathUtils.constrainedMap(
userDefinedBrightness, targetBrightness, 0f, 0.5f, progress)
val scrimProgress = MathUtils.constrainedMap(
0f, maxScrimOpacity, 0.5f, 1f, progress)
notificationShadeWindowController.setFaceAuthDisplayBrightness(brightnessProgress)
whiteOverlay.alpha = scrimProgress
}
addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator?) {
brightnessAnimator = null
}
})
start()
}
}
@VisibleForTesting
open fun createAnimator(start: Float, end: Float) = ValueAnimator.ofFloat(start, end)
/**
* Returns a bitmap that should be used by the lock screen as a wallpaper, if face auth requires
* a secure wallpaper.
*/
var faceAuthWallpaper: Bitmap? = null
get() {
val user = KeyguardUpdateMonitor.getCurrentUser()
if (useFaceAuthWallpaper && keyguardUpdateMonitor.isFaceAuthEnabledForUser(user)) {
val options = BitmapFactory.Options().apply {
inScaled = false
}
return BitmapFactory.decodeResource(resources, R.drawable.face_auth_wallpaper, options)
}
return null
}
private set
fun attach(overlayView: View) {
whiteOverlay = overlayView
whiteOverlay.focusable = FLAG_NOT_FOCUSABLE
whiteOverlay.background = ColorDrawable(Color.WHITE)
whiteOverlay.isEnabled = false
whiteOverlay.alpha = 0f
whiteOverlay.visibility = View.INVISIBLE
dumpManager.registerDumpable(this.javaClass.name, this)
keyguardUpdateMonitor.registerCallback(keyguardUpdateCallback)
systemSettings.registerContentObserver(SCREEN_BRIGHTNESS_FLOAT,
object : ContentObserver(mainHandler) {
override fun onChange(selfChange: Boolean) {
userDefinedBrightness = systemSettings.getFloat(SCREEN_BRIGHTNESS_FLOAT)
}
})
userDefinedBrightness = systemSettings.getFloat(SCREEN_BRIGHTNESS_FLOAT, 1f)
}
override fun dump(fd: FileDescriptor, pw: PrintWriter, args: Array<out String>) {
pw.apply {
println("overridingBrightness: $overridingBrightness")
println("useFaceAuthWallpaper: $useFaceAuthWallpaper")
println("brightnessAnimator: $brightnessAnimator")
println("brightnessAnimationDuration: $brightnessAnimationDuration")
println("maxScreenBrightness: $maxScreenBrightness")
println("userDefinedBrightness: $userDefinedBrightness")
println("enabled: $enabled")
}
}
}

View File

@@ -20,9 +20,6 @@ import android.annotation.Nullable;
import android.app.trust.TrustManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.hardware.face.FaceManager;
import android.os.Handler;
import android.os.PowerManager;
import com.android.internal.widget.LockPatternUtils;
@@ -37,17 +34,14 @@ import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.classifier.FalsingCollector;
import com.android.systemui.classifier.FalsingModule;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dagger.qualifiers.UiBackground;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.keyguard.DismissCallbackRegistry;
import com.android.systemui.keyguard.FaceAuthScreenBrightnessController;
import com.android.systemui.keyguard.KeyguardUnlockAnimationController;
import com.android.systemui.keyguard.KeyguardViewMediator;
import com.android.systemui.navigationbar.NavigationModeController;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.NotificationShadeDepthController;
import com.android.systemui.statusbar.NotificationShadeWindowController;
import com.android.systemui.statusbar.SysuiStatusBarStateController;
import com.android.systemui.statusbar.phone.DozeParameters;
import com.android.systemui.statusbar.phone.KeyguardLiftController;
@@ -59,10 +53,7 @@ import com.android.systemui.unfold.UnfoldLightRevealOverlayAnimation;
import com.android.systemui.unfold.config.UnfoldTransitionConfig;
import com.android.systemui.util.DeviceConfigProxy;
import com.android.systemui.util.sensors.AsyncSensorManager;
import com.android.systemui.util.settings.GlobalSettings;
import com.android.systemui.util.settings.SystemSettings;
import java.util.Optional;
import java.util.concurrent.Executor;
import dagger.Lazy;
@@ -150,35 +141,4 @@ public class KeyguardModule {
return new KeyguardLiftController(statusBarStateController, asyncSensorManager,
keyguardUpdateMonitor, dumpManager);
}
@SysUISingleton
@Provides
static Optional<FaceAuthScreenBrightnessController> provideFaceAuthScreenBrightnessController(
Context context,
NotificationShadeWindowController notificationShadeWindowController,
@Main Resources resources,
Handler handler,
@Nullable FaceManager faceManager,
PackageManager packageManager,
KeyguardUpdateMonitor keyguardUpdateMonitor,
GlobalSettings globalSetting,
SystemSettings systemSettings,
DumpManager dumpManager) {
if (faceManager == null || !packageManager.hasSystemFeature(PackageManager.FEATURE_FACE)) {
return Optional.empty();
}
// Cameras that support "self illumination," via IR for example, don't need low light
// environment mitigation.
boolean needsLowLightMitigation = faceManager.getSensorPropertiesInternal().stream()
.anyMatch((properties) -> !properties.supportsSelfIllumination);
if (!needsLowLightMitigation) {
return Optional.empty();
}
// currently disabled (doesn't ramp up brightness or use scrim) see b/175918367
return Optional.of(new FaceAuthScreenBrightnessController(
notificationShadeWindowController, keyguardUpdateMonitor, resources,
globalSetting, systemSettings, handler, dumpManager, false));
}
}

View File

@@ -45,7 +45,6 @@ import com.android.systemui.Dumpable;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.keyguard.FaceAuthScreenBrightnessController;
import com.android.systemui.statusbar.NotificationMediaManager;
import libcore.io.IoUtils;
@@ -53,7 +52,6 @@ import libcore.io.IoUtils;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.Objects;
import java.util.Optional;
import javax.inject.Inject;
@@ -70,7 +68,6 @@ public class LockscreenWallpaper extends IWallpaperManagerCallback.Stub implemen
private final WallpaperManager mWallpaperManager;
private final KeyguardUpdateMonitor mUpdateMonitor;
private final Handler mH;
private final Optional<FaceAuthScreenBrightnessController> mFaceAuthScreenBrightnessController;
private boolean mCached;
private Bitmap mCache;
@@ -86,14 +83,12 @@ public class LockscreenWallpaper extends IWallpaperManagerCallback.Stub implemen
KeyguardUpdateMonitor keyguardUpdateMonitor,
DumpManager dumpManager,
NotificationMediaManager mediaManager,
Optional<FaceAuthScreenBrightnessController> faceAuthScreenBrightnessController,
@Main Handler mainHandler) {
dumpManager.registerDumpable(getClass().getSimpleName(), this);
mWallpaperManager = wallpaperManager;
mCurrentUserId = ActivityManager.getCurrentUser();
mUpdateMonitor = keyguardUpdateMonitor;
mMediaManager = mediaManager;
mFaceAuthScreenBrightnessController = faceAuthScreenBrightnessController;
mH = mainHandler;
if (iWallpaperManager != null) {
@@ -132,14 +127,6 @@ public class LockscreenWallpaper extends IWallpaperManagerCallback.Stub implemen
return LoaderResult.success(null);
}
Bitmap faceAuthWallpaper = null;
if (mFaceAuthScreenBrightnessController.isPresent()) {
faceAuthWallpaper = mFaceAuthScreenBrightnessController.get().getFaceAuthWallpaper();
if (faceAuthWallpaper != null) {
return LoaderResult.success(faceAuthWallpaper);
}
}
// Prefer the selected user (when specified) over the current user for the FLAG_SET_LOCK
// wallpaper.
final int lockWallpaperUserId =

View File

@@ -51,7 +51,6 @@ import com.android.keyguard.ViewMediatorCallback;
import com.android.systemui.DejankUtils;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dock.DockManager;
import com.android.systemui.keyguard.FaceAuthScreenBrightnessController;
import com.android.systemui.keyguard.WakefulnessLifecycle;
import com.android.systemui.navigationbar.NavigationBarView;
import com.android.systemui.navigationbar.NavigationModeController;
@@ -70,7 +69,6 @@ import com.android.systemui.statusbar.policy.KeyguardStateController;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Objects;
import java.util.Optional;
import javax.inject.Inject;
@@ -109,7 +107,6 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
private final ConfigurationController mConfigurationController;
private final NavigationModeController mNavigationModeController;
private final NotificationShadeWindowController mNotificationShadeWindowController;
private final Optional<FaceAuthScreenBrightnessController> mFaceAuthScreenBrightnessController;
private final KeyguardBouncer.Factory mKeyguardBouncerFactory;
private final WakefulnessLifecycle mWakefulnessLifecycle;
private final UnlockedScreenOffAnimationController mUnlockedScreenOffAnimationController;
@@ -242,7 +239,6 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
DockManager dockManager,
NotificationShadeWindowController notificationShadeWindowController,
KeyguardStateController keyguardStateController,
Optional<FaceAuthScreenBrightnessController> faceAuthScreenBrightnessController,
NotificationMediaManager notificationMediaManager,
KeyguardBouncer.Factory keyguardBouncerFactory,
WakefulnessLifecycle wakefulnessLifecycle,
@@ -260,7 +256,6 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
mKeyguardUpdateManager = keyguardUpdateMonitor;
mStatusBarStateController = sysuiStatusBarStateController;
mDockManager = dockManager;
mFaceAuthScreenBrightnessController = faceAuthScreenBrightnessController;
mKeyguardBouncerFactory = keyguardBouncerFactory;
mWakefulnessLifecycle = wakefulnessLifecycle;
mUnlockedScreenOffAnimationController = unlockedScreenOffAnimationController;
@@ -285,11 +280,6 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
mNotificationContainer = notificationContainer;
mKeyguardMessageAreaController = mKeyguardMessageAreaFactory.create(
KeyguardMessageArea.findSecurityMessageDisplay(container));
mFaceAuthScreenBrightnessController.ifPresent((it) -> {
View overlay = new View(mContext);
container.addView(overlay);
it.attach(overlay);
});
registerListeners();
}

View File

@@ -1,137 +0,0 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.systemui.keyguard
import android.animation.ValueAnimator
import android.content.res.Resources
import android.hardware.biometrics.BiometricSourceType
import android.os.Handler
import android.provider.Settings.System.SCREEN_BRIGHTNESS_FLOAT
import android.testing.AndroidTestingRunner
import android.util.TypedValue
import android.view.View
import androidx.test.filters.SmallTest
import com.android.keyguard.KeyguardUpdateMonitor
import com.android.keyguard.KeyguardUpdateMonitorCallback
import com.android.systemui.Dumpable
import com.android.systemui.SysuiTestCase
import com.android.systemui.dump.DumpManager
import com.android.systemui.statusbar.NotificationShadeWindowController
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.capture
import com.android.systemui.util.mockito.eq
import com.android.systemui.util.settings.GlobalSettings
import com.android.systemui.util.settings.SystemSettings
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentCaptor
import org.mockito.Captor
import org.mockito.Mock
import org.mockito.Mockito.`when`
import org.mockito.Mockito.anyInt
import org.mockito.Mockito.anyString
import org.mockito.Mockito.clearInvocations
import org.mockito.Mockito.never
import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations
const val INITIAL_BRIGHTNESS = 0.5f
@RunWith(AndroidTestingRunner::class)
@SmallTest
class FaceAuthScreenBrightnessControllerTest : SysuiTestCase() {
@Mock
lateinit var whiteOverlay: View
@Mock
lateinit var dumpManager: DumpManager
@Mock
lateinit var resources: Resources
@Mock
lateinit var mainHandler: Handler
@Mock
lateinit var globalSettings: GlobalSettings
@Mock
lateinit var systemSettings: SystemSettings
@Mock
lateinit var keyguardUpdateMonitor: KeyguardUpdateMonitor
@Mock
lateinit var notificationShadeWindowController: NotificationShadeWindowController
@Mock
lateinit var animator: ValueAnimator
@Captor
lateinit var keyguardUpdateCallback: ArgumentCaptor<KeyguardUpdateMonitorCallback>
lateinit var faceAuthScreenBrightnessController: FaceAuthScreenBrightnessController
@Before
fun setup() {
MockitoAnnotations.initMocks(this)
faceAuthScreenBrightnessController = object : FaceAuthScreenBrightnessController(
notificationShadeWindowController, keyguardUpdateMonitor, resources, globalSettings,
systemSettings, mainHandler, dumpManager, true) {
override fun createAnimator(start: Float, end: Float) = animator
}
`when`(systemSettings.getFloat(eq(SCREEN_BRIGHTNESS_FLOAT))).thenReturn(INITIAL_BRIGHTNESS)
`when`(systemSettings.getFloat(eq(SCREEN_BRIGHTNESS_FLOAT), eq(1f)))
.thenReturn(INITIAL_BRIGHTNESS)
faceAuthScreenBrightnessController.attach(whiteOverlay)
verify(keyguardUpdateMonitor).registerCallback(capture(keyguardUpdateCallback))
}
@Test
fun init_registersDumpManager() {
verify(dumpManager).registerDumpable(anyString(), any(Dumpable::class.java))
}
@Test
fun init_registersKeyguardCallback() {
verify(keyguardUpdateMonitor)
.registerCallback(any(KeyguardUpdateMonitorCallback::class.java))
}
@Test
fun onBiometricRunningChanged_animatesBrightness() {
clearInvocations(whiteOverlay)
keyguardUpdateCallback.value
.onBiometricRunningStateChanged(true, BiometricSourceType.FACE)
verify(whiteOverlay).visibility = eq(View.VISIBLE)
verify(animator).start()
}
@Test
fun faceAuthWallpaper_whenFaceIsDisabledForUser() {
faceAuthScreenBrightnessController.useFaceAuthWallpaper = true
faceAuthScreenBrightnessController.faceAuthWallpaper
verify(resources, never()).openRawResource(anyInt(), any(TypedValue::class.java))
}
@Test
fun faceAuthWallpaper_whenFaceFlagIsDisabled() {
faceAuthScreenBrightnessController.useFaceAuthWallpaper = true
faceAuthScreenBrightnessController.faceAuthWallpaper
verify(resources, never()).openRawResource(anyInt(), any(TypedValue::class.java))
}
@Test
fun faceAuthWallpaper_whenFaceIsEnabledForUser() {
faceAuthScreenBrightnessController.useFaceAuthWallpaper = true
`when`(keyguardUpdateMonitor.isFaceAuthEnabledForUser(anyInt())).thenReturn(true)
faceAuthScreenBrightnessController.faceAuthWallpaper
verify(resources).openRawResource(anyInt(), any(TypedValue::class.java))
}
}

View File

@@ -44,7 +44,6 @@ import com.android.systemui.SysuiTestCase;
import com.android.systemui.dock.DockManager;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.keyguard.DismissCallbackRegistry;
import com.android.systemui.keyguard.FaceAuthScreenBrightnessController;
import com.android.systemui.keyguard.WakefulnessLifecycle;
import com.android.systemui.navigationbar.NavigationModeController;
import com.android.systemui.plugins.ActivityStarter.OnDismissAction;
@@ -60,8 +59,6 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.Optional;
import dagger.Lazy;
@SmallTest
@@ -92,8 +89,6 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {
@Mock
private KeyguardBypassController mBypassController;
@Mock
private FaceAuthScreenBrightnessController mFaceAuthScreenBrightnessController;
@Mock
private KeyguardBouncer.Factory mKeyguardBouncerFactory;
@Mock
private KeyguardMessageAreaController.Factory mKeyguardMessageAreaFactory;
@@ -133,7 +128,6 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {
mock(DockManager.class),
mock(NotificationShadeWindowController.class),
mKeyguardStateController,
Optional.of(mFaceAuthScreenBrightnessController),
mock(NotificationMediaManager.class),
mKeyguardBouncerFactory,
mWakefulnessLifecycle,