diff --git a/core/java/android/app/StatusBarManager.java b/core/java/android/app/StatusBarManager.java index ae0fc09e35a64..719b5b64bbff9 100644 --- a/core/java/android/app/StatusBarManager.java +++ b/core/java/android/app/StatusBarManager.java @@ -229,6 +229,8 @@ public class StatusBarManager { public static final int CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP = 1; /** @hide */ public static final int CAMERA_LAUNCH_SOURCE_LIFT_TRIGGER = 2; + /** @hide */ + public static final int CAMERA_LAUNCH_SOURCE_QUICK_AFFORDANCE = 3; /** * Session flag for {@link #registerSessionListener} indicating the listener diff --git a/packages/SystemUI/src/com/android/systemui/flags/Flags.kt b/packages/SystemUI/src/com/android/systemui/flags/Flags.kt index ce9a1fc2778e6..db48a75b1c545 100644 --- a/packages/SystemUI/src/com/android/systemui/flags/Flags.kt +++ b/packages/SystemUI/src/com/android/systemui/flags/Flags.kt @@ -141,9 +141,9 @@ object Flags { /** * Whether to enable the code powering customizable lock screen quick affordances. * - * Note that this flag does not enable individual implementations of quick affordances like the - * new camera quick affordance. Look for individual flags for those. + * This flag enables any new prebuilt quick affordances as well. */ + // TODO(b/255618149): Tracking Bug @JvmField val CUSTOMIZABLE_LOCK_SCREEN_QUICK_AFFORDANCES = unreleasedFlag(216, "customizable_lock_screen_quick_affordances", teamfood = false) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/BuiltInKeyguardQuickAffordanceKeys.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/BuiltInKeyguardQuickAffordanceKeys.kt index a069582f6692f..f5220b8fae92e 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/BuiltInKeyguardQuickAffordanceKeys.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/BuiltInKeyguardQuickAffordanceKeys.kt @@ -24,6 +24,7 @@ package com.android.systemui.keyguard.data.quickaffordance */ object BuiltInKeyguardQuickAffordanceKeys { // Please keep alphabetical order of const names to simplify future maintenance. + const val CAMERA = "camera" const val HOME_CONTROLS = "home" const val QR_CODE_SCANNER = "qr_code_scanner" const val QUICK_ACCESS_WALLET = "wallet" diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/CameraQuickAffordanceConfig.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/CameraQuickAffordanceConfig.kt new file mode 100644 index 0000000000000..3c09aab604434 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/CameraQuickAffordanceConfig.kt @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2022 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.data.quickaffordance + +import android.app.StatusBarManager +import android.content.Context +import com.android.systemui.R +import com.android.systemui.animation.Expandable +import com.android.systemui.camera.CameraGestureHelper +import com.android.systemui.common.shared.model.ContentDescription +import com.android.systemui.common.shared.model.Icon +import com.android.systemui.dagger.SysUISingleton +import com.android.systemui.dagger.qualifiers.Application +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOf +import javax.inject.Inject + +@SysUISingleton +class CameraQuickAffordanceConfig @Inject constructor( + @Application private val context: Context, + private val cameraGestureHelper: CameraGestureHelper, +) : KeyguardQuickAffordanceConfig { + + override val key: String + get() = BuiltInKeyguardQuickAffordanceKeys.CAMERA + + override val pickerName: String + get() = context.getString(R.string.accessibility_camera_button) + + override val pickerIconResourceId: Int + get() = com.android.internal.R.drawable.perm_group_camera + + override val lockScreenState: Flow + get() = flowOf( + KeyguardQuickAffordanceConfig.LockScreenState.Visible( + icon = Icon.Resource( + com.android.internal.R.drawable.perm_group_camera, + ContentDescription.Resource(R.string.accessibility_camera_button) + ) + ) + ) + + override fun onTriggered(expandable: Expandable?): KeyguardQuickAffordanceConfig.OnTriggeredResult { + cameraGestureHelper.launchCamera(StatusBarManager.CAMERA_LAUNCH_SOURCE_QUICK_AFFORDANCE) + return KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled + } +} \ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/KeyguardDataQuickAffordanceModule.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/KeyguardDataQuickAffordanceModule.kt index bea9363efc81e..f7225a249eda7 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/KeyguardDataQuickAffordanceModule.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/KeyguardDataQuickAffordanceModule.kt @@ -29,8 +29,10 @@ object KeyguardDataQuickAffordanceModule { home: HomeControlsKeyguardQuickAffordanceConfig, quickAccessWallet: QuickAccessWalletKeyguardQuickAffordanceConfig, qrCodeScanner: QrCodeScannerKeyguardQuickAffordanceConfig, + camera: CameraQuickAffordanceConfig, ): Set { return setOf( + camera, home, quickAccessWallet, qrCodeScanner, diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/CameraQuickAffordanceConfigTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/CameraQuickAffordanceConfigTest.kt new file mode 100644 index 0000000000000..623becf166d36 --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/CameraQuickAffordanceConfigTest.kt @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2022 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.data.quickaffordance + +import android.app.StatusBarManager +import android.content.Context +import androidx.test.filters.SmallTest +import com.android.systemui.SysuiTestCase +import com.android.systemui.camera.CameraGestureHelper +import org.junit.Assert.assertEquals +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.mockito.Mock +import org.mockito.Mockito.verify +import org.mockito.MockitoAnnotations + +@SmallTest +@RunWith(JUnit4::class) +class CameraQuickAffordanceConfigTest : SysuiTestCase() { + + @Mock private lateinit var cameraGestureHelper: CameraGestureHelper + @Mock private lateinit var context: Context + private lateinit var underTest: CameraQuickAffordanceConfig + + @Before + fun setUp() { + MockitoAnnotations.initMocks(this) + underTest = CameraQuickAffordanceConfig( + context, + cameraGestureHelper, + ) + } + + @Test + fun `affordance triggered -- camera launch called`() { + //when + val result = underTest.onTriggered(null) + + //then + verify(cameraGestureHelper) + .launchCamera(StatusBarManager.CAMERA_LAUNCH_SOURCE_QUICK_AFFORDANCE) + assertEquals(KeyguardQuickAffordanceConfig.OnTriggeredResult.Handled, result) + } +} \ No newline at end of file