Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 798c8fff authored by Avinash Vadlamudi's avatar Avinash Vadlamudi Committed by Android (Google) Code Review
Browse files

Merge "[QR Scanner]: Fix the logic to initialize intent with default activity" into udc-qpr-dev

parents 8e516c17 41805a9b
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -3052,13 +3052,6 @@
    -->
    <string name="wallet_quick_affordance_unavailable_configure_the_app">To add the Wallet app as a shortcut, make sure at least one card has been added</string>

    <!--
    Requirement for the QR code scanner functionality to be available for the user to use. This is
    shown as part of a bulleted list of requirements. When all requirements are met, the piece of
    functionality can be accessed through a shortcut button on the lock screen. [CHAR LIMIT=NONE].
    -->
    <string name="qr_scanner_quick_affordance_unavailable_explanation">To add the QR code scanner as a shortcut, make sure a camera app is installed</string>

    <!--
    Explains that the lock screen shortcut for the "home" app is not available because the app isn't
    installed. This is shown as part of a dialog that explains to the user why they cannot select
+6 −9
Original line number Diff line number Diff line
@@ -78,16 +78,8 @@ constructor(

    override suspend fun getPickerScreenState(): KeyguardQuickAffordanceConfig.PickerScreenState {
        return when {
            !controller.isAvailableOnDevice ->
            !isEnabledForPickerStateOption() ->
                KeyguardQuickAffordanceConfig.PickerScreenState.UnavailableOnDevice
            !controller.isAbleToOpenCameraApp -> {
                KeyguardQuickAffordanceConfig.PickerScreenState.Disabled(
                    explanation =
                        context.getString(
                            R.string.qr_scanner_quick_affordance_unavailable_explanation
                        ),
                )
            }
            else -> KeyguardQuickAffordanceConfig.PickerScreenState.Default()
        }
    }
@@ -118,6 +110,11 @@ constructor(
        }
    }

    /** Returns whether QR scanner be shown as one of available lockscreen shortcut option. */
    private fun isEnabledForPickerStateOption(): Boolean {
        return controller.isAbleToLaunchScannerActivity && controller.isAllowedOnLockScreen
    }

    companion object {
        private const val TAG = "QrCodeScannerKeyguardQuickAffordanceConfig"
    }
+6 −8
Original line number Diff line number Diff line
@@ -120,6 +120,7 @@ public class QRCodeScannerController implements
        mUserTracker = userTracker;
        mConfigEnableLockScreenButton = mContext.getResources().getBoolean(
            android.R.bool.config_enableQrCodeScannerOnLockScreen);
        mExecutor.execute(this::updateQRCodeScannerActivityDetails);
    }

    /**
@@ -158,18 +159,18 @@ public class QRCodeScannerController implements
     * Returns true if lock screen entry point for QR Code Scanner is to be enabled.
     */
    public boolean isEnabledForLockScreenButton() {
        return mQRCodeScannerEnabled && isAbleToOpenCameraApp() && isAvailableOnDevice();
        return mQRCodeScannerEnabled && isAbleToLaunchScannerActivity() && isAllowedOnLockScreen();
    }

    /** Returns whether the feature is available on the device. */
    public boolean isAvailableOnDevice() {
    /** Returns whether the QR scanner button is allowed on lockscreen. */
    public boolean isAllowedOnLockScreen() {
        return mConfigEnableLockScreenButton;
    }

    /**
     * Returns true if the feature can open a camera app on the device.
     * Returns true if the feature can open the configured QR scanner activity.
     */
    public boolean isAbleToOpenCameraApp() {
    public boolean isAbleToLaunchScannerActivity() {
        return mIntent != null && isActivityCallable(mIntent);
    }

@@ -355,9 +356,6 @@ public class QRCodeScannerController implements

        // Reset cached values to default as we are no longer listening
        mOnDefaultQRCodeScannerChangedListener = null;
        mQRCodeScannerActivity = null;
        mIntent = null;
        mComponentName = null;
    }

    private void notifyQRCodeScannerActivityChanged() {
+1 −1
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ public class QRCodeScannerTile extends QSTileImpl<QSTile.State> {
        state.label = mContext.getString(R.string.qr_code_scanner_title);
        state.contentDescription = state.label;
        state.icon = ResourceIcon.get(R.drawable.ic_qr_code_scanner);
        state.state = mQRCodeScannerController.isAbleToOpenCameraApp() ? Tile.STATE_INACTIVE
        state.state = mQRCodeScannerController.isAbleToLaunchScannerActivity() ? Tile.STATE_INACTIVE
                : Tile.STATE_UNAVAILABLE;
        // The assumption is that if the OEM has the QR code scanner module enabled then the scanner
        // would go to "Unavailable" state only when GMS core is updating.
+6 −15
Original line number Diff line number Diff line
@@ -137,27 +137,18 @@ class QrCodeScannerKeyguardQuickAffordanceConfigTest : SysuiTestCase() {
    }

    @Test
    fun getPickerScreenState_enabledIfConfiguredOnDevice_canOpenCamera() = runTest {
        whenever(controller.isAvailableOnDevice).thenReturn(true)
        whenever(controller.isAbleToOpenCameraApp).thenReturn(true)
    fun getPickerScreenState_enabledIfConfiguredOnDevice_isEnabledForPickerState() = runTest {
        whenever(controller.isAllowedOnLockScreen).thenReturn(true)
        whenever(controller.isAbleToLaunchScannerActivity).thenReturn(true)

        assertThat(underTest.getPickerScreenState())
            .isEqualTo(KeyguardQuickAffordanceConfig.PickerScreenState.Default())
    }

    @Test
    fun getPickerScreenState_disabledIfConfiguredOnDevice_cannotOpenCamera() = runTest {
        whenever(controller.isAvailableOnDevice).thenReturn(true)
        whenever(controller.isAbleToOpenCameraApp).thenReturn(false)

        assertThat(underTest.getPickerScreenState())
            .isInstanceOf(KeyguardQuickAffordanceConfig.PickerScreenState.Disabled::class.java)
    }

    @Test
    fun getPickerScreenState_unavailableIfNotConfiguredOnDevice() = runTest {
        whenever(controller.isAvailableOnDevice).thenReturn(false)
        whenever(controller.isAbleToOpenCameraApp).thenReturn(true)
    fun getPickerScreenState_disabledIfConfiguredOnDevice_isDisabledForPickerState() = runTest {
        whenever(controller.isAllowedOnLockScreen).thenReturn(true)
        whenever(controller.isAbleToLaunchScannerActivity).thenReturn(false)

        assertThat(underTest.getPickerScreenState())
            .isEqualTo(KeyguardQuickAffordanceConfig.PickerScreenState.UnavailableOnDevice)
Loading