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

Commit 8b4a5b3a authored by Winson Chung's avatar Winson Chung
Browse files

Expose calls to get the inset sensitivity for the calling user

- Launcher is a per-user process so we should only use the per-user
  settings calls (since it doesn't hold INTERACT_ACROSS_USERS)

Bug: 231648761
Bug: 269392826
Test: Unable to reproduce 269392826, but verified this doesn't
      break existing paths to adjust the insets
Change-Id: I4dfaed2b393e44e0455448222c997facbb3f3116
parent 3800ea7c
Loading
Loading
Loading
Loading
+45 −7
Original line number Diff line number Diff line
@@ -56,6 +56,9 @@ public class GestureNavigationSettingsObserver extends ContentObserver {
        }
    };

    /**
     * Registers the observer for all users.
     */
    public void register() {
        ContentResolver r = mContext.getContentResolver();
        r.registerContentObserver(
@@ -73,7 +76,10 @@ public class GestureNavigationSettingsObserver extends ContentObserver {
                mOnPropertiesChangedListener);
    }

    public void registerForCurrentUser() {
    /**
     * Registers the observer for the calling user.
     */
    public void registerForCallingUser() {
        ContentResolver r = mContext.getContentResolver();
        r.registerContentObserver(
                Settings.Secure.getUriFor(Settings.Secure.BACK_GESTURE_INSET_SCALE_LEFT),
@@ -103,12 +109,46 @@ public class GestureNavigationSettingsObserver extends ContentObserver {
        }
    }

    /**
     * Returns the left sensitivity for the current user.  To be used in code that runs primarily
     * in one user's process.
     */
    public int getLeftSensitivity(Resources userRes) {
        return getSensitivity(userRes, Settings.Secure.BACK_GESTURE_INSET_SCALE_LEFT);
        final float scale = Settings.Secure.getFloatForUser(mContext.getContentResolver(),
                Settings.Secure.BACK_GESTURE_INSET_SCALE_LEFT, 1.0f, UserHandle.USER_CURRENT);
        return (int) (getUnscaledInset(userRes) * scale);
    }

    /**
     * Returns the left sensitivity for the calling user.  To be used in code that runs in a
     * per-user process.
     */
    @SuppressWarnings("NonUserGetterCalled")
    public int getLeftSensitivityForCallingUser(Resources userRes) {
        final float scale = Settings.Secure.getFloat(mContext.getContentResolver(),
                Settings.Secure.BACK_GESTURE_INSET_SCALE_LEFT, 1.0f);
        return (int) (getUnscaledInset(userRes) * scale);
    }

    /**
     * Returns the right sensitivity for the current user.  To be used in code that runs primarily
     * in one user's process.
     */
    public int getRightSensitivity(Resources userRes) {
        return getSensitivity(userRes, Settings.Secure.BACK_GESTURE_INSET_SCALE_RIGHT);
        final float scale = Settings.Secure.getFloatForUser(mContext.getContentResolver(),
                Settings.Secure.BACK_GESTURE_INSET_SCALE_RIGHT, 1.0f, UserHandle.USER_CURRENT);
        return (int) (getUnscaledInset(userRes) * scale);
    }

    /**
     * Returns the right sensitivity for the calling user.  To be used in code that runs in a
     * per-user process.
     */
    @SuppressWarnings("NonUserGetterCalled")
    public int getRightSensitivityForCallingUser(Resources userRes) {
        final float scale = Settings.Secure.getFloat(mContext.getContentResolver(),
                Settings.Secure.BACK_GESTURE_INSET_SCALE_RIGHT, 1.0f);
        return (int) (getUnscaledInset(userRes) * scale);
    }

    public boolean areNavigationButtonForcedVisible() {
@@ -116,7 +156,7 @@ public class GestureNavigationSettingsObserver extends ContentObserver {
                Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) == 0;
    }

    private int getSensitivity(Resources userRes, String side) {
    private float getUnscaledInset(Resources userRes) {
        final DisplayMetrics dm = userRes.getDisplayMetrics();
        final float defaultInset = userRes.getDimension(
                com.android.internal.R.dimen.config_backGestureInset) / dm.density;
@@ -127,8 +167,6 @@ public class GestureNavigationSettingsObserver extends ContentObserver {
                : defaultInset;
        final float inset = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, backGestureInset,
                dm);
        final float scale = Settings.Secure.getFloatForUser(
                mContext.getContentResolver(), side, 1.0f, UserHandle.USER_CURRENT);
        return (int) (inset * scale);
        return inset;
    }
}