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

Commit 779efaca authored by Jerry Chang's avatar Jerry Chang
Browse files

Guard swipe to notification gesture with system settings preference

Bug: 154080211
Test: make and install, check the gesture works as expectedly
Change-Id: Ibd6bbd595d2fba5d68e66eb54e4a7fec160b9bf8
parent 0b51b916
Loading
Loading
Loading
Loading
+5 −9
Original line number Diff line number Diff line
@@ -130,18 +130,14 @@ public class OneHandedModeInputConsumer extends DelegateInputConsumer {
    }

    private void onStartGestureDetected() {
        if (mDeviceState.isOneHandedModeActive()) {
            return;
        }

        if (mDeviceState.isOneHandedModeEnabled()) {
            if (!mDeviceState.isOneHandedModeActive()) {
                SystemUiProxy.INSTANCE.get(mContext).startOneHandedMode();
            return;
            }

        // Hook one-handed gesture to expand notification panel by default
        } else if (mDeviceState.isSwipeToNotificationEnabled()) {
            SystemUiProxy.INSTANCE.get(mContext).expandNotificationPanel();
        }
    }

    private void onStopGestureDetected() {
        if (!mDeviceState.isOneHandedModeEnabled() || !mDeviceState.isOneHandedModeActive()) {
+22 −7
Original line number Diff line number Diff line
@@ -96,12 +96,12 @@ public class RecentsAnimationDeviceState implements
    private @SystemUiStateFlags int mSystemUiStateFlags;
    private SysUINavigationMode.Mode mMode = THREE_BUTTONS;
    private NavBarPosition mNavBarPosition;
    private SecureSettingsObserver mOneHandedEnabledObserver;

    private final Region mDeferredGestureRegion = new Region();
    private boolean mAssistantAvailable;
    private float mAssistantVisibility;
    private boolean mIsOneHandedModeEnabled;
    private boolean mIsSwipeToNotificationEnabled;

    private boolean mIsUserUnlocked;
    private final ArrayList<Runnable> mUserUnlockedActions = new ArrayList<>();
@@ -240,12 +240,21 @@ public class RecentsAnimationDeviceState implements
        }

        if (SystemProperties.getBoolean("ro.support_one_handed_mode", false)) {
            mOneHandedEnabledObserver = SecureSettingsObserver.newOneHandedSettingsObserver(
                    mContext, this::onOneHandedEnabledSettingsChanged);
            mOneHandedEnabledObserver.register();
            mOneHandedEnabledObserver.dispatchOnChange();
            SecureSettingsObserver oneHandedEnabledObserver =
                    SecureSettingsObserver.newOneHandedSettingsObserver(
                            mContext, enabled -> mIsOneHandedModeEnabled = enabled);
            oneHandedEnabledObserver.register();
            oneHandedEnabledObserver.dispatchOnChange();
            runOnDestroy(oneHandedEnabledObserver::unregister);
        }

        SecureSettingsObserver swipeBottomEnabledObserver =
                SecureSettingsObserver.newSwipeToNotificationSettingsObserver(
                        mContext, enabled -> mIsSwipeToNotificationEnabled = enabled);
        swipeBottomEnabledObserver.register();
        swipeBottomEnabledObserver.dispatchOnChange();
        runOnDestroy(swipeBottomEnabledObserver::unregister);

        SecureSettingsObserver userSetupObserver = new SecureSettingsObserver(
                context.getContentResolver(),
                e -> mIsUserSetupComplete = e,
@@ -666,6 +675,10 @@ public class RecentsAnimationDeviceState implements
     * @return whether the given motion event can trigger the one handed mode.
     */
    public boolean canTriggerOneHandedAction(MotionEvent ev) {
        if (!mIsOneHandedModeEnabled && !mIsSwipeToNotificationEnabled) {
            return false;
        }

        final DefaultDisplay.Info displayInfo = mDefaultDisplay.getInfo();
        return (mOrientationTouchTransformer.touchInOneHandedModeRegion(ev)
                && displayInfo.rotation != Surface.ROTATION_90
@@ -677,8 +690,8 @@ public class RecentsAnimationDeviceState implements
        return mIsOneHandedModeEnabled;
    }

    private void onOneHandedEnabledSettingsChanged(boolean isOneHandedEnabled) {
        mIsOneHandedModeEnabled = isOneHandedEnabled;
    public boolean isSwipeToNotificationEnabled() {
        return mIsSwipeToNotificationEnabled;
    }

    /**
@@ -790,6 +803,8 @@ public class RecentsAnimationDeviceState implements
        pw.println("  currentActiveRotation=" + getCurrentActiveRotation());
        pw.println("  displayRotation=" + getDisplayRotation());
        pw.println("  isUserUnlocked=" + mIsUserUnlocked);
        pw.println("  isOneHandedModeEnabled=" + mIsOneHandedModeEnabled);
        pw.println("  isSwipeToNotificationEnabled=" + mIsSwipeToNotificationEnabled);
        mOrientationTouchTransformer.dump(pw);
    }
}
+14 −0
Original line number Diff line number Diff line
@@ -31,6 +31,9 @@ public class SecureSettingsObserver extends ContentObserver {
    public static final String NOTIFICATION_BADGING = "notification_badging";
    /** Hidden field Settings.Secure.ONE_HANDED_MODE_ENABLED */
    public static final String ONE_HANDED_ENABLED = "one_handed_mode_enabled";
    /** Hidden field Settings.Secure.SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED */
    public static final String ONE_HANDED_SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED =
            "swipe_bottom_to_notification_enabled";

    private final ContentResolver mResolver;
    private final String mKeySetting;
@@ -87,4 +90,15 @@ public class SecureSettingsObserver extends ContentObserver {
        return new SecureSettingsObserver(
                context.getContentResolver(), listener, ONE_HANDED_ENABLED, 1);
    }

    /**
     * Constructs settings observer for {@link #ONE_HANDED_SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED}
     * preference.
     */
    public static SecureSettingsObserver newSwipeToNotificationSettingsObserver(Context context,
            OnChangeListener listener) {
        return new SecureSettingsObserver(
                context.getContentResolver(), listener,
                ONE_HANDED_SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED, 1);
    }
}