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

Unverified Commit a2ac939d 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 324e1c54
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -37,6 +37,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;

@@ -131,7 +133,10 @@ class InputSettingsObserver extends ContentObserver {
                        (reason) -> updatePointerScaleFromSettings()),
                Map.entry(Settings.System.getUriFor(
                                Settings.System.TOUCHPAD_THREE_FINGER_TAP_CUSTOMIZATION),
                        (reason) -> updateTouchpadThreeFingerTapShortcutEnabled()));
                        (reason) -> updateTouchpadThreeFingerTapShortcutEnabled()),
                Map.entry(LineageSettings.System.getUriFor(
                                LineageSettings.System.SWAP_VOLUME_KEYS_ON_ROTATION),
                        (reason) -> updateVolumeKeysRotation()));
    }

    /**
@@ -265,6 +270,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
@@ -162,6 +162,8 @@ interface NativeInputManagerService {

    void setShowTouches(boolean enabled);

    void setVolumeKeysRotation(int mode);

    void setNonInteractiveDisplays(int[] displayIds);

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

        @Override
        public native void setVolumeKeysRotation(int mode);

        @Override
        public native void setNonInteractiveDisplays(int[] displayIds);

+29 −0
Original line number Diff line number Diff line
@@ -360,6 +360,7 @@ public:
    void setTouchpadAccelerationEnabled(bool enabled);
    void setInputDeviceEnabled(uint32_t deviceId, bool enabled);
    void setShowTouches(bool enabled);
    void setVolumeKeysRotation(int mode);
    void setNonInteractiveDisplays(const std::set<ui::LogicalDisplayId>& displayIds);
    void reloadCalibration();
    void reloadPointerIcons();
@@ -486,6 +487,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{};

@@ -823,6 +827,8 @@ void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outCon
                : exp2f(mLocked.mouseScrollingSpeed * POINTER_SPEED_EXPONENT);
        outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled;

        outConfig->volumeKeysRotationMode = mLocked.volumeKeysRotationMode;

        outConfig->pointerCaptureRequest = mLocked.pointerCaptureRequest;

        outConfig->setDisplayViewports(mLocked.viewports);
@@ -1709,6 +1715,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::setNonInteractiveDisplays(
        const std::set<ui::LogicalDisplayId>& displayIds) {
    std::scoped_lock _l(mLock);
@@ -2665,6 +2687,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 nativeSetNonInteractiveDisplays(JNIEnv* env, jobject nativeImplObj,
                                            jintArray displayIds) {
    NativeInputManager* im = getNativeInputManager(env, nativeImplObj);
@@ -3377,6 +3405,7 @@ static const JNINativeMethod gInputManagerMethods[] = {
        {"setTouchpadSystemGesturesEnabled", "(Z)V", (void*)nativeSetTouchpadSystemGesturesEnabled},
        {"setTouchpadAccelerationEnabled", "(Z)V", (void*)nativeSetTouchpadAccelerationEnabled},
        {"setShowTouches", "(Z)V", (void*)nativeSetShowTouches},
        {"setVolumeKeysRotation", "(I)V", (void*)nativeSetVolumeKeysRotation},
        {"setNonInteractiveDisplays", "([I)V", (void*)nativeSetNonInteractiveDisplays},
        {"reloadCalibration", "()V", (void*)nativeReloadCalibration},
        {"vibrate", "(I[J[III)V", (void*)nativeVibrate},