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

Commit b4ba6932 authored by ronish's avatar ronish
Browse files

Add a lock screen entry point for QR Code scanner

This change add a new button on the lockscreen that can be used to open
a QR code scanner. The visibility of this button is controlled by
QRCodeScannerController.

Bug: 200536509
Test: atest QRCodeScannerControllerTest

Change-Id: Ie47e143b3253258addd1b84b5978f2185f6dea21
parent 4212416c
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -94,6 +94,20 @@
        android:contentDescription="@string/accessibility_wallet_button"
        android:visibility="gone" />

    <ImageView
        android:id="@+id/qr_code_scanner_button"
        android:layout_height="@dimen/keyguard_affordance_fixed_height"
        android:layout_width="@dimen/keyguard_affordance_fixed_width"
        android:layout_gravity="bottom|end"
        android:scaleType="center"
        android:tint="?android:attr/textColorPrimary"
        android:src="@drawable/ic_qr_code_scanner"
        android:background="@drawable/keyguard_bottom_affordance_bg"
        android:layout_marginEnd="@dimen/keyguard_affordance_horizontal_offset"
        android:layout_marginBottom="@dimen/keyguard_affordance_vertical_offset"
        android:contentDescription="@string/accessibility_qr_code_scanner_button"
        android:visibility="gone" />

    <ImageView
        android:id="@+id/controls_button"
        android:layout_height="@dimen/keyguard_affordance_fixed_height"
+2 −0
Original line number Diff line number Diff line
@@ -266,6 +266,8 @@
    <string name="accessibility_voice_assist_button">Voice Assist</string>
    <!-- Content description of the wallet button for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
    <string name="accessibility_wallet_button">Wallet</string>
    <!-- Content description of the QR Code scanner for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
    <string name="accessibility_qr_code_scanner_button">QR Code Scanner</string>
    <!-- Content description of the unlock button for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
    <string name="accessibility_unlock_button">Unlock</string>
    <!-- Content description of the lock icon for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+69 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.app.ActivityManager;
import android.app.ActivityOptions;
import android.app.ActivityTaskManager;
import android.app.admin.DevicePolicyManager;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
@@ -94,6 +95,7 @@ import com.android.systemui.plugins.FalsingManager;
import com.android.systemui.plugins.IntentButtonProvider;
import com.android.systemui.plugins.IntentButtonProvider.IntentButton;
import com.android.systemui.plugins.IntentButtonProvider.IntentButton.IconState;
import com.android.systemui.qrcodescanner.controller.QRCodeScannerController;
import com.android.systemui.statusbar.KeyguardAffordanceView;
import com.android.systemui.statusbar.policy.AccessibilityController;
import com.android.systemui.statusbar.policy.ExtensionController;
@@ -143,10 +145,12 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
    private KeyguardAffordanceView mLeftAffordanceView;

    private ImageView mWalletButton;
    private ImageView mQRCodeScannerButton;
    private ImageView mControlsButton;
    private boolean mHasCard = false;
    private WalletCardRetriever mCardRetriever = new WalletCardRetriever();
    private QuickAccessWalletController mQuickAccessWalletController;
    private QRCodeScannerController mQRCodeScannerController;
    private ControlsComponent mControlsComponent;
    private boolean mControlServicesAvailable = false;

@@ -281,6 +285,7 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
        mRightAffordanceView = findViewById(R.id.camera_button);
        mLeftAffordanceView = findViewById(R.id.left_button);
        mWalletButton = findViewById(R.id.wallet_button);
        mQRCodeScannerButton = findViewById(R.id.qr_code_scanner_button);
        mControlsButton = findViewById(R.id.controls_button);
        mIndicationArea = findViewById(R.id.keyguard_indication_area);
        mIndicationText = findViewById(R.id.keyguard_indication_text);
@@ -305,6 +310,7 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
        mIndicationPadding = getResources().getDimensionPixelSize(
                R.dimen.keyguard_indication_area_padding);
        updateWalletVisibility();
        updateQRCodeButtonVisibility();
        updateControlsVisibility();
    }

@@ -359,6 +365,12 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
                    WALLET_PREFERENCE_CHANGE, DEFAULT_PAYMENT_APP_CHANGE);
        }

        if (mQRCodeScannerController != null) {
            mQRCodeScannerController.unregisterQRCodeScannerChangeObservers(
                    QRCodeScannerController.DEFAULT_QR_CODE_SCANNER_CHANGE,
                    QRCodeScannerController.QR_CODE_SCANNER_PREFERENCE_CHANGE);
        }

        if (mControlsComponent != null) {
            mControlsComponent.getControlsListingController().ifPresent(
                    c -> c.removeCallback(mListingCallback));
@@ -408,6 +420,11 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
        lp.height = getResources().getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_height);
        mWalletButton.setLayoutParams(lp);

        lp = mQRCodeScannerButton.getLayoutParams();
        lp.width = getResources().getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_width);
        lp.height = getResources().getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_height);
        mQRCodeScannerButton.setLayoutParams(lp);

        lp = mControlsButton.getLayoutParams();
        lp.width = getResources().getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_width);
        lp.height = getResources().getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_height);
@@ -417,6 +434,7 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
                R.dimen.keyguard_indication_area_padding);

        updateWalletVisibility();
        updateQRCodeButtonVisibility();
        updateAffordanceColors();
    }

@@ -809,6 +827,9 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
        if (mWalletButton.getVisibility() == View.VISIBLE) {
            startFinishDozeAnimationElement(mWalletButton, delay);
        }
        if (mQRCodeScannerButton.getVisibility() == View.VISIBLE) {
            startFinishDozeAnimationElement(mQRCodeScannerButton, delay);
        }
        if (mControlsButton.getVisibility() == View.VISIBLE) {
            startFinishDozeAnimationElement(mControlsButton, delay);
        }
@@ -886,6 +907,7 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
        updateLeftAffordanceIcon();
        updateWalletVisibility();
        updateControlsVisibility();
        updateQRCodeButtonVisibility();

        if (dozing) {
            mOverlayContainer.setVisibility(INVISIBLE);
@@ -919,6 +941,7 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
        mRightAffordanceView.setAlpha(alpha);
        mIndicationArea.setAlpha(alpha);
        mWalletButton.setAlpha(alpha);
        mQRCodeScannerButton.setAlpha(alpha);
        mControlsButton.setAlpha(alpha);
    }

@@ -1016,18 +1039,64 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
        updateAffordanceColors();
    }

    /**
     * Initialize the qr code scanner feature, controlled by QRCodeScannerController.
     */
    public void initQRCodeScanner(QRCodeScannerController qrCodeScannerController) {
        mQRCodeScannerController = qrCodeScannerController;
        mQRCodeScannerController.registerQRCodeScannerChangeObservers(
                QRCodeScannerController.DEFAULT_QR_CODE_SCANNER_CHANGE,
                QRCodeScannerController.QR_CODE_SCANNER_PREFERENCE_CHANGE);
        updateQRCodeButtonVisibility();
        updateAffordanceColors();
    }

    private void updateQRCodeButtonVisibility() {
        if (mQuickAccessWalletController != null
                && mQuickAccessWalletController.isWalletEnabled()) {
            // Don't enable if quick access wallet is enabled
            return;
        }

        if (mQRCodeScannerController != null
                && mQRCodeScannerController.isEnabledForLockScreenButton()) {
            mQRCodeScannerButton.setVisibility(VISIBLE);
            mQRCodeScannerButton.setOnClickListener(this::onQRCodeScannerClicked);
            mIndicationArea.setPadding(mIndicationPadding, 0, mIndicationPadding, 0);
        } else {
            mQRCodeScannerButton.setVisibility(GONE);
            mIndicationArea.setPadding(0, 0, 0, 0);
        }
    }

    private void onQRCodeScannerClicked(View view) {
        Intent intent = mQRCodeScannerController.getIntent();
        if (intent != null) {
            try {
                mContext.startActivity(intent);
            } catch (ActivityNotFoundException e) {
                // This is unexpected. Nonetheless, just log the error and prevent the UI from
                // crashing
                Log.e(TAG, "Unexpected intent: " + intent
                        + " when the QR code scanner button was clicked");
            }
        }
    }

    private void updateAffordanceColors() {
        int iconColor = Utils.getColorAttrDefaultColor(
                mContext,
                com.android.internal.R.attr.textColorPrimary);
        mWalletButton.getDrawable().setTint(iconColor);
        mControlsButton.getDrawable().setTint(iconColor);
        mQRCodeScannerButton.getDrawable().setTint(iconColor);

        ColorStateList bgColor = Utils.getColorAttr(
                mContext,
                com.android.internal.R.attr.colorSurface);
        mWalletButton.setBackgroundTintList(bgColor);
        mControlsButton.setBackgroundTintList(bgColor);
        mQRCodeScannerButton.setBackgroundTintList(bgColor);
    }

    /**
+5 −0
Original line number Diff line number Diff line
@@ -142,6 +142,7 @@ import com.android.systemui.plugins.qs.DetailAdapter;
import com.android.systemui.plugins.qs.QS;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener;
import com.android.systemui.qrcodescanner.controller.QRCodeScannerController;
import com.android.systemui.qs.QSDetailDisplayer;
import com.android.systemui.screenrecord.RecordingController;
import com.android.systemui.shared.system.QuickStepContract;
@@ -310,6 +311,7 @@ public class NotificationPanelViewController extends PanelViewController {
    private final ScrimController mScrimController;
    private final PrivacyDotViewController mPrivacyDotViewController;
    private final QuickAccessWalletController mQuickAccessWalletController;
    private final QRCodeScannerController mQRCodeScannerController;
    private final ControlsComponent mControlsComponent;
    private final NotificationRemoteInputManager mRemoteInputManager;

@@ -767,6 +769,7 @@ public class NotificationPanelViewController extends PanelViewController {
            FragmentService fragmentService,
            ContentResolver contentResolver,
            QuickAccessWalletController quickAccessWalletController,
            QRCodeScannerController qrCodeScannerController,
            RecordingController recordingController,
            @Main Executor uiExecutor,
            SecureSettings secureSettings,
@@ -795,6 +798,7 @@ public class NotificationPanelViewController extends PanelViewController {
        mKeyguardMediaController = keyguardMediaController;
        mPrivacyDotViewController = privacyDotViewController;
        mQuickAccessWalletController = quickAccessWalletController;
        mQRCodeScannerController = qrCodeScannerController;
        mControlsComponent = controlsComponent;
        mMetricsLogger = metricsLogger;
        mActivityManager = activityManager;
@@ -1268,6 +1272,7 @@ public class NotificationPanelViewController extends PanelViewController {
        mKeyguardBottomArea.setFalsingManager(mFalsingManager);
        mKeyguardBottomArea.initWallet(mQuickAccessWalletController);
        mKeyguardBottomArea.initControls(mControlsComponent);
        mKeyguardBottomArea.initQRCodeScanner(mQRCodeScannerController);
    }

    private void updateMaxDisplayedNotifications(boolean recompute) {
+4 −0
Original line number Diff line number Diff line
@@ -107,6 +107,7 @@ import com.android.systemui.media.MediaDataManager;
import com.android.systemui.media.MediaHierarchyManager;
import com.android.systemui.navigationbar.NavigationModeController;
import com.android.systemui.plugins.FalsingManager;
import com.android.systemui.qrcodescanner.controller.QRCodeScannerController;
import com.android.systemui.qs.QSDetailDisplayer;
import com.android.systemui.screenrecord.RecordingController;
import com.android.systemui.statusbar.CommandQueue;
@@ -337,6 +338,8 @@ public class NotificationPanelViewControllerTest extends SysuiTestCase {
    @Mock
    private QuickAccessWalletController mQuickAccessWalletController;
    @Mock
    private QRCodeScannerController mQrCodeScannerController;
    @Mock
    private NotificationRemoteInputManager mNotificationRemoteInputManager;
    @Mock
    private RecordingController mRecordingController;
@@ -506,6 +509,7 @@ public class NotificationPanelViewControllerTest extends SysuiTestCase {
                mFragmentService,
                mContentResolver,
                mQuickAccessWalletController,
                mQrCodeScannerController,
                mRecordingController,
                new FakeExecutor(new FakeSystemClock()),
                mSecureSettings,