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

Commit 7186d0bb authored by ronish's avatar ronish
Browse files

Only enable scanner entry points if the scanner activity is callable

The first time scanner is enabled via an OTA, it might be available but
due to GMSCore version mismatch might not be callable. Hence only
enable the entry points once the scanner activity is callable.

Test: Manually
Bug: 223608369
Change-Id: I755df37738aca9c8aa65d4779b3e341968d1f48d
parent 62ca047a
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);