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

Unverified Commit b5ab51a1 authored by nadlabak's avatar nadlabak Committed by Michael Bestas
Browse files

Forward port 'Swap volume buttons' (1/3)



Co-authored-by: default avatarBruno Martins <bgcngm@gmail.com>
Co-authored-by: default avatarLuK1337 <priv.luk@gmail.com>
Co-authored-by: default avatarMichael Bestas <mkbestas@lineageos.org>
Change-Id: I1b45da63b815aa1b3ddf7cda2b7afb0872ab433f
parent f74e546c
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -36,6 +36,8 @@ import android.provider.Settings;
import android.util.Log;
import android.view.ViewConfiguration;

import lineageos.providers.LineageSettings;

import java.util.Map;
import java.util.function.Consumer;

@@ -104,7 +106,10 @@ class InputSettingsObserver extends ContentObserver {
                Map.entry(Settings.System.getUriFor(Settings.System.POINTER_FILL_STYLE),
                        (reason) -> updatePointerFillStyleFromSettings()),
                Map.entry(Settings.System.getUriFor(Settings.System.POINTER_SCALE),
                        (reason) -> updatePointerScaleFromSettings()));
                        (reason) -> updatePointerScaleFromSettings()),
                Map.entry(LineageSettings.System.getUriFor(
                        LineageSettings.System.SWAP_VOLUME_KEYS_ON_ROTATION),
                        (reason) -> updateVolumeKeysRotation()));
    }

    /**
@@ -195,6 +200,13 @@ class InputSettingsObserver extends ContentObserver {
        mService.updateShowRotaryInput(getBoolean(Settings.System.SHOW_ROTARY_INPUT, false));
    }

    private void updateVolumeKeysRotation() {
        mNative.setVolumeKeysRotation(
                LineageSettings.System.getIntForUser(mContext.getContentResolver(),
                        LineageSettings.System.SWAP_VOLUME_KEYS_ON_ROTATION, 0,
                        UserHandle.USER_CURRENT));
    }

    private void updateAccessibilityLargePointer() {
        final int accessibilityConfig = Settings.Secure.getIntForUser(
                mContext.getContentResolver(), Settings.Secure.ACCESSIBILITY_LARGE_POINTER_ICON,
+5 −0
Original line number Diff line number Diff line
@@ -139,6 +139,8 @@ interface NativeInputManagerService {

    void setShowTouches(boolean enabled);

    void setVolumeKeysRotation(int mode);

    void setInteractive(boolean interactive);

    void reloadCalibration();
@@ -400,6 +402,9 @@ interface NativeInputManagerService {
        @Override
        public native void setShowTouches(boolean enabled);

        @Override
        public native void setVolumeKeysRotation(int mode);

        @Override
        public native void setInteractive(boolean interactive);

+29 −0
Original line number Diff line number Diff line
@@ -295,6 +295,7 @@ public:
    void setTouchpadRightClickZoneEnabled(bool enabled);
    void setInputDeviceEnabled(uint32_t deviceId, bool enabled);
    void setShowTouches(bool enabled);
    void setVolumeKeysRotation(int mode);
    void setInteractive(bool interactive);
    void reloadCalibration();
    void reloadPointerIcons();
@@ -413,6 +414,9 @@ private:
        // The latest request to enable or disable Pointer Capture.
        PointerCaptureRequest pointerCaptureRequest{};

        // Volume keys rotation mode (0 - off, 1 - phone, 2 - tablet)
        int32_t volumeKeysRotationMode{0};

        // Sprite controller singleton, created on first use.
        std::shared_ptr<SpriteController> spriteController{};

@@ -689,6 +693,8 @@ void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outCon
                : 1;
        outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled;

        outConfig->volumeKeysRotationMode = mLocked.volumeKeysRotationMode;

        outConfig->pointerCaptureRequest = mLocked.pointerCaptureRequest;

        outConfig->setDisplayViewports(mLocked.viewports);
@@ -1317,6 +1323,22 @@ void NativeInputManager::requestPointerCapture(const sp<IBinder>& windowToken, b
    mInputManager->getDispatcher().requestPointerCapture(windowToken, enabled);
}

void NativeInputManager::setVolumeKeysRotation(int mode) {
    { // acquire lock
        std::scoped_lock _l(mLock);

        if (mLocked.volumeKeysRotationMode == mode) {
            return;
        }

        ALOGI("Volume keys: rotation mode set to %d.", mode);
        mLocked.volumeKeysRotationMode = mode;
    } // release lock

    mInputManager->getReader().requestRefreshConfiguration(
            InputReaderConfiguration::Change::VOLUME_KEYS_ROTATION);
}

void NativeInputManager::setInteractive(bool interactive) {
    mInteractive = interactive;
}
@@ -2170,6 +2192,12 @@ static void nativeSetShowTouches(JNIEnv* env, jobject nativeImplObj, jboolean en
    im->setShowTouches(enabled);
}

static void nativeSetVolumeKeysRotation(JNIEnv* env, jobject nativeImplObj, int mode) {
    NativeInputManager* im = getNativeInputManager(env, nativeImplObj);

    im->setVolumeKeysRotation(mode);
}

static void nativeSetInteractive(JNIEnv* env, jobject nativeImplObj, jboolean interactive) {
    NativeInputManager* im = getNativeInputManager(env, nativeImplObj);

@@ -2777,6 +2805,7 @@ static const JNINativeMethod gInputManagerMethods[] = {
        {"setTouchpadTapDraggingEnabled", "(Z)V", (void*)nativeSetTouchpadTapDraggingEnabled},
        {"setTouchpadRightClickZoneEnabled", "(Z)V", (void*)nativeSetTouchpadRightClickZoneEnabled},
        {"setShowTouches", "(Z)V", (void*)nativeSetShowTouches},
        {"setVolumeKeysRotation", "(I)V", (void*)nativeSetVolumeKeysRotation},
        {"setInteractive", "(Z)V", (void*)nativeSetInteractive},
        {"reloadCalibration", "()V", (void*)nativeReloadCalibration},
        {"vibrate", "(I[J[III)V", (void*)nativeVibrate},