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

Commit 11ad3503 authored by Ronish Kalia's avatar Ronish Kalia Committed by Automerger Merge Worker
Browse files

Merge "Only enable scanner entry points if the scanner activity is callable"...

Merge "Only enable scanner entry points if the scanner activity is callable" into tm-dev am: 65858d10

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17136589

Change-Id: I888093106d03654444468ebebdb16fc90ea57d43
parents 72ea0b3c 65858d10
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -160,14 +160,15 @@ public class QRCodeScannerController implements
     * Returns true if lock screen entry point for QR Code Scanner is to be enabled.
     */
    public boolean isEnabledForLockScreenButton() {
        return mQRCodeScannerEnabled && mIntent != null && mConfigEnableLockScreenButton;
        return mQRCodeScannerEnabled && mIntent != null && mConfigEnableLockScreenButton
                && isActivityCallable(mIntent);
    }

    /**
     * Returns true if quick settings entry point for QR Code Scanner is to be enabled.
     */
    public boolean isEnabledForQuickSettings() {
        return mIntent != null;
        return mIntent != null && isActivityCallable(mIntent);
    }

    /**
@@ -278,7 +279,7 @@ public class QRCodeScannerController implements
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        }

        if (isActivityCallable(intent)) {
        if (isActivityAvailable(intent)) {
            mQRCodeScannerActivity = qrCodeScannerActivity;
            mComponentName = componentName;
            mIntent = intent;
@@ -293,7 +294,7 @@ public class QRCodeScannerController implements
        }
    }

    private boolean isActivityCallable(Intent intent) {
    private boolean isActivityAvailable(Intent intent) {
        // Our intent should always be explicit and should have a component set
        if (intent.getComponent() == null) return false;

@@ -307,6 +308,17 @@ public class QRCodeScannerController implements
                flags).isEmpty();
    }

    private boolean isActivityCallable(Intent intent) {
        // Our intent should always be explicit and should have a component set
        if (intent.getComponent() == null) return false;

        int flags = PackageManager.MATCH_DIRECT_BOOT_AWARE
                | PackageManager.MATCH_DIRECT_BOOT_UNAWARE
                | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS;
        return !mContext.getPackageManager().queryIntentActivities(intent,
                flags).isEmpty();
    }

    private void unregisterUserChangeObservers() {
        mUserTracker.removeCallback(mUserChangedListener);