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

Commit c07e94c0 authored by eray orçunus's avatar eray orçunus
Browse files

SystemUI: Fix double-tap to cam. opens right lockscreen shortcut



* Users who haven't used lockscreen tuner aren't affected.

Change-Id: I4fe46c2ae911a1a8126ded1e7e81355862f971cf
Signed-off-by: default avatareray orçunus <erayorcunus@gmail.com>
parent 85a929ea
Loading
Loading
Loading
Loading
+39 −10
Original line number Diff line number Diff line
@@ -382,10 +382,18 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
        refreshAffordance();
    }

    private Intent getCameraIntent() {
    private Intent getRightIntent() {
        return mRightButton.getIntent();
    }

    private Intent getCameraIntent() {
        KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
        boolean canSkipBouncer = updateMonitor.getUserCanSkipBouncer(
                KeyguardUpdateMonitor.getCurrentUser());
        boolean secure = mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser());
        return (secure && !canSkipBouncer) ? SECURE_CAMERA_INTENT : INSECURE_CAMERA_INTENT;
    }

    /**
     * Resolves the intent to launch the camera application.
     */
@@ -395,6 +403,12 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
                KeyguardUpdateMonitor.getCurrentUser());
    }

    public ResolveInfo resolveRightIntent() {
        return mContext.getPackageManager().resolveActivityAsUser(getRightIntent(),
                PackageManager.MATCH_DEFAULT_ONLY,
                KeyguardUpdateMonitor.getCurrentUser());
    }

    /**
     * Refreshes affordance buttons, to let
     *   - Left affordance switch between Phone <-> Voice shortcuts
@@ -403,7 +417,7 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
     */
    private void refreshAffordance() {
        if (mRightAffordanceView != null) {
            if (mRightButton instanceof DefaultRightButton) {
            if (isRightAffordanceDefault()) {
                updateRightAffordanceIcon();
            } else if (mRightAffordanceView.getVisibility() != View.VISIBLE) {
                // Also includes inflating preview
@@ -441,6 +455,11 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
        return mLeftIsVoiceAssist;
    }

    // Default means camera - Pie default is camera too, but not visible
    public boolean isRightAffordanceDefault() {
        return (mRightButton instanceof DefaultRightButton);
    }

    private boolean isPhoneVisible() {
        PackageManager pm = mContext.getPackageManager();
        return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)
@@ -487,6 +506,11 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
    }

    public void bindCameraPrewarmService() {
        // This method only called at onSwipingStarted. If there's no camera, no need to it.
        if (!isRightAffordanceDefault()) {
            return;
        }

        Intent intent = getCameraIntent();
        ActivityInfo targetInfo = PreviewInflater.getTargetActivityInfo(mContext, intent,
                KeyguardUpdateMonitor.getCurrentUser(), true /* onlyDirectBootAware */);
@@ -527,8 +551,16 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
    }

    public void launchCamera(String source) {
        final Intent intent = getCameraIntent();
        final Intent intent;
        if (source.equals(CAMERA_LAUNCH_SOURCE_AFFORDANCE)) {
            intent = getRightIntent();
            if (isRightAffordanceDefault()) {
                intent.putExtra(EXTRA_CAMERA_LAUNCH_SOURCE, source);
            }
        } else {
            intent = getCameraIntent();
            intent.putExtra(EXTRA_CAMERA_LAUNCH_SOURCE, source);
        }
        boolean wouldLaunchResolverActivity = PreviewInflater.wouldLaunchResolverActivity(
                mContext, intent, KeyguardUpdateMonitor.getCurrentUser());
        if (intent == SECURE_CAMERA_INTENT && !wouldLaunchResolverActivity) {
@@ -688,6 +720,7 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
        refreshAffordance();
    }

    // Not camera anymore, it's right affordance
    private void inflateCameraPreview() {
        View previewBefore = mCameraPreview;
        boolean visibleBefore = false;
@@ -695,7 +728,7 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
            mPreviewContainer.removeView(previewBefore);
            visibleBefore = previewBefore.getVisibility() == View.VISIBLE;
        }
        mCameraPreview = mPreviewInflater.inflatePreview(getCameraIntent());
        mCameraPreview = mPreviewInflater.inflatePreview(getRightIntent());
        if (mCameraPreview != null) {
            mPreviewContainer.addView(mCameraPreview);
            mCameraPreview.setVisibility(visibleBefore ? View.VISIBLE : View.INVISIBLE);
@@ -968,11 +1001,7 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL

        @Override
        public Intent getIntent() {
            KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
            boolean canSkipBouncer = updateMonitor.getUserCanSkipBouncer(
                    KeyguardUpdateMonitor.getCurrentUser());
            boolean secure = mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser());
            return (secure && !canSkipBouncer) ? SECURE_CAMERA_INTENT : INSECURE_CAMERA_INTENT;
            return getCameraIntent();
        }
    }

+32 −11
Original line number Diff line number Diff line
@@ -2632,29 +2632,37 @@ public class NotificationPanelView extends PanelView implements
        return !mDozing;
    }

    public void launchCamera(boolean animate, int source) {
    private String convertCameraLaunchSource(int source) {
        if (source == StatusBarManager.CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP) {
            mLastCameraLaunchSource = KeyguardBottomAreaView.CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP;
            return KeyguardBottomAreaView.CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP;
        } else if (source == StatusBarManager.CAMERA_LAUNCH_SOURCE_WIGGLE) {
            mLastCameraLaunchSource = KeyguardBottomAreaView.CAMERA_LAUNCH_SOURCE_WIGGLE;
            return KeyguardBottomAreaView.CAMERA_LAUNCH_SOURCE_WIGGLE;
        } else if (source == StatusBarManager.CAMERA_LAUNCH_SOURCE_LIFT_TRIGGER) {
            mLastCameraLaunchSource = KeyguardBottomAreaView.CAMERA_LAUNCH_SOURCE_LIFT_TRIGGER;
            return KeyguardBottomAreaView.CAMERA_LAUNCH_SOURCE_LIFT_TRIGGER;
        } else {

            // Default.
            mLastCameraLaunchSource = KeyguardBottomAreaView.CAMERA_LAUNCH_SOURCE_AFFORDANCE;
            return KeyguardBottomAreaView.CAMERA_LAUNCH_SOURCE_AFFORDANCE;
        }
    }

    public void launchCamera(boolean animate, int source) {
        mLastCameraLaunchSource = convertCameraLaunchSource(source);
        mAffordanceHasPreview = mKeyguardBottomArea.getRightPreview() != null;

        // If we are launching it when we are occluded already we don't want it to animate,
        // nor setting these flags, since the occluded state doesn't change anymore, hence it's
        // never reset.
        if (!isFullyCollapsed()) {
        if (!isFullyCollapsed() && (mLastCameraLaunchSource ==
                KeyguardBottomAreaView.CAMERA_LAUNCH_SOURCE_AFFORDANCE ||
                mKeyguardBottomArea.isRightAffordanceDefault())) {
            mLaunchingAffordance = true;
            setLaunchingAffordance(true);
        } else {
            animate = false;
            mAffordanceHasPreview = mAffordanceHasPreview &&
                    mKeyguardBottomArea.isRightAffordanceDefault();
        }
        mAffordanceHasPreview = mKeyguardBottomArea.getRightPreview() != null;
        mAffordanceHelper.launchAffordance(animate, getLayoutDirection() == LAYOUT_DIRECTION_RTL);
    }

@@ -2709,14 +2717,27 @@ public class NotificationPanelView extends PanelView implements
    /**
     * Whether the camera application can be launched for the camera launch gesture.
     *
     * @param source is StatusBarManager constant that tells the gesture source
     * @param keyguardIsShowing whether keyguard is being shown
     */
    public boolean canCameraGestureBeLaunched(boolean keyguardIsShowing) {
        if (!mStatusBar.isCameraAllowedByAdmin()) {
    public boolean canCameraGestureBeLaunched(int source, boolean keyguardIsShowing) {
        ResolveInfo resolveInfo;
        boolean adminAllowsCamera = mStatusBar.isCameraAllowedByAdmin();

        if (!(convertCameraLaunchSource(source).equals(
                KeyguardBottomAreaView.CAMERA_LAUNCH_SOURCE_AFFORDANCE))) {

            if (!adminAllowsCamera) {
                return false;
            }
            resolveInfo = mKeyguardBottomArea.resolveCameraIntent();
        } else {
            if (mKeyguardBottomArea.isRightAffordanceDefault() && !adminAllowsCamera) {
                return false;
            }
            resolveInfo = mKeyguardBottomArea.resolveRightIntent();
        }

        ResolveInfo resolveInfo = mKeyguardBottomArea.resolveCameraIntent();
        String packageToLaunch = (resolveInfo == null || resolveInfo.activityInfo == null)
                ? null : resolveInfo.activityInfo.packageName;
        return packageToLaunch != null &&
+1 −1
Original line number Diff line number Diff line
@@ -4936,7 +4936,7 @@ public class StatusBar extends SystemUI implements DemoMode, TunerService.Tunabl
            mLaunchCameraOnFinishedGoingToSleep = true;
            return;
        }
        if (!mNotificationPanel.canCameraGestureBeLaunched(
        if (!mNotificationPanel.canCameraGestureBeLaunched(source,
                mStatusBarKeyguardViewManager.isShowing() && mExpandedVisible)) {
            if (DEBUG_CAMERA_LIFT) Slog.d(TAG, "Can't launch camera right now, mExpandedVisible: " +
                    mExpandedVisible);