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

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

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

[mikeioannina]: Adjust for 5.0 changes

Change-Id: I1b45da63b815aa1b3ddf7cda2b7afb0872ab433f
parent 48cfa12b
Loading
Loading
Loading
Loading
+33 −0
Original line number Original line Diff line number Diff line
@@ -121,6 +121,8 @@ import com.android.server.LocalServices;
import com.android.server.Watchdog;
import com.android.server.Watchdog;
import com.android.server.policy.WindowManagerPolicy;
import com.android.server.policy.WindowManagerPolicy;


import lineageos.providers.LineageSettings;

import libcore.io.IoUtils;
import libcore.io.IoUtils;
import libcore.io.Streams;
import libcore.io.Streams;


@@ -316,6 +318,7 @@ public class InputManagerService extends IInputManager.Stub
    private static native boolean nativeTransferTouch(long ptr, IBinder destChannelToken);
    private static native boolean nativeTransferTouch(long ptr, IBinder destChannelToken);
    private static native void nativeSetPointerSpeed(long ptr, int speed);
    private static native void nativeSetPointerSpeed(long ptr, int speed);
    private static native void nativeSetShowTouches(long ptr, boolean enabled);
    private static native void nativeSetShowTouches(long ptr, boolean enabled);
    private static native void nativeSetVolumeKeysRotation(long ptr, int mode);
    private static native void nativeSetInteractive(long ptr, boolean interactive);
    private static native void nativeSetInteractive(long ptr, boolean interactive);
    private static native void nativeReloadCalibration(long ptr);
    private static native void nativeReloadCalibration(long ptr);
    private static native void nativeVibrate(long ptr, int deviceId, long[] pattern,
    private static native void nativeVibrate(long ptr, int deviceId, long[] pattern,
@@ -486,6 +489,7 @@ public class InputManagerService extends IInputManager.Stub
        registerLongPressTimeoutObserver();
        registerLongPressTimeoutObserver();
        registerMaximumObscuringOpacityForTouchSettingObserver();
        registerMaximumObscuringOpacityForTouchSettingObserver();
        registerBlockUntrustedTouchesModeSettingObserver();
        registerBlockUntrustedTouchesModeSettingObserver();
        registerVolumeKeysRotationSettingObserver();


        mContext.registerReceiver(new BroadcastReceiver() {
        mContext.registerReceiver(new BroadcastReceiver() {
            @Override
            @Override
@@ -494,6 +498,7 @@ public class InputManagerService extends IInputManager.Stub
                updateShowTouchesFromSettings();
                updateShowTouchesFromSettings();
                updateAccessibilityLargePointerFromSettings();
                updateAccessibilityLargePointerFromSettings();
                updateDeepPressStatusFromSettings("user switched");
                updateDeepPressStatusFromSettings("user switched");
                updateVolumeKeysRotationFromSettings();
            }
            }
        }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler);
        }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler);


@@ -503,6 +508,7 @@ public class InputManagerService extends IInputManager.Stub
        updateDeepPressStatusFromSettings("just booted");
        updateDeepPressStatusFromSettings("just booted");
        updateMaximumObscuringOpacityForTouchFromSettings();
        updateMaximumObscuringOpacityForTouchFromSettings();
        updateBlockUntrustedTouchesModeFromSettings();
        updateBlockUntrustedTouchesModeFromSettings();
        updateVolumeKeysRotationFromSettings();
    }
    }


    // TODO(BT) Pass in parameter for bluetooth system
    // TODO(BT) Pass in parameter for bluetooth system
@@ -2066,6 +2072,33 @@ public class InputManagerService extends IInputManager.Stub
        return v;
        return v;
    }
    }


    public void updateVolumeKeysRotationFromSettings() {
        int mode = getVolumeKeysRotationSetting(0);
        nativeSetVolumeKeysRotation(mPtr, mode);
    }

    public void registerVolumeKeysRotationSettingObserver() {
        mContext.getContentResolver().registerContentObserver(
                LineageSettings.System.getUriFor(
                        LineageSettings.System.SWAP_VOLUME_KEYS_ON_ROTATION), false,
                new ContentObserver(mHandler) {
                    @Override
                    public void onChange(boolean selfChange) {
                        updateVolumeKeysRotationFromSettings();
                    }
                });
    }

    private int getVolumeKeysRotationSetting(int defaultValue) {
        int result = defaultValue;
        try {
            result = LineageSettings.System.getIntForUser(mContext.getContentResolver(),
                    LineageSettings.System.SWAP_VOLUME_KEYS_ON_ROTATION, UserHandle.USER_CURRENT);
        } catch (LineageSettings.LineageSettingNotFoundException snfe) {
        }
        return result;
    }

    // Binder call
    // Binder call
    @Override
    @Override
    public void vibrate(int deviceId, VibrationEffect effect, IBinder token) {
    public void vibrate(int deviceId, VibrationEffect effect, IBinder token) {
+30 −0
Original line number Original line Diff line number Diff line
@@ -283,6 +283,7 @@ public:
    void setPointerSpeed(int32_t speed);
    void setPointerSpeed(int32_t speed);
    void setInputDeviceEnabled(uint32_t deviceId, bool enabled);
    void setInputDeviceEnabled(uint32_t deviceId, bool enabled);
    void setShowTouches(bool enabled);
    void setShowTouches(bool enabled);
    void setVolumeKeysRotation(int mode);
    void setInteractive(bool interactive);
    void setInteractive(bool interactive);
    void reloadCalibration();
    void reloadCalibration();
    void setPointerIconType(int32_t iconId);
    void setPointerIconType(int32_t iconId);
@@ -375,6 +376,9 @@ private:
        // The latest request to enable or disable Pointer Capture.
        // The latest request to enable or disable Pointer Capture.
        PointerCaptureRequest pointerCaptureRequest;
        PointerCaptureRequest pointerCaptureRequest;


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

        // Sprite controller singleton, created on first use.
        // Sprite controller singleton, created on first use.
        sp<SpriteController> spriteController;
        sp<SpriteController> spriteController;


@@ -418,6 +422,7 @@ NativeInputManager::NativeInputManager(jobject contextObj,
        mLocked.pointerGesturesEnabled = true;
        mLocked.pointerGesturesEnabled = true;
        mLocked.showTouches = false;
        mLocked.showTouches = false;
        mLocked.pointerDisplayId = ADISPLAY_ID_DEFAULT;
        mLocked.pointerDisplayId = ADISPLAY_ID_DEFAULT;
        mLocked.volumeKeysRotationMode = 0;
    }
    }
    mInteractive = true;
    mInteractive = true;


@@ -634,6 +639,7 @@ void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outCon
        outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled;
        outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled;


        outConfig->showTouches = mLocked.showTouches;
        outConfig->showTouches = mLocked.showTouches;
        outConfig->volumeKeysRotationMode = mLocked.volumeKeysRotationMode;


        outConfig->pointerCaptureRequest = mLocked.pointerCaptureRequest;
        outConfig->pointerCaptureRequest = mLocked.pointerCaptureRequest;


@@ -1093,6 +1099,22 @@ void NativeInputManager::requestPointerCapture(const sp<IBinder>& windowToken, b
    mInputManager->getDispatcher()->requestPointerCapture(windowToken, enabled);
    mInputManager->getDispatcher()->requestPointerCapture(windowToken, enabled);
}
}


void NativeInputManager::setVolumeKeysRotation(int mode) {
    { // acquire lock
        AutoMutex _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) {
void NativeInputManager::setInteractive(bool interactive) {
    mInteractive = interactive;
    mInteractive = interactive;
}
}
@@ -1859,6 +1881,13 @@ static void nativeSetShowTouches(JNIEnv* /* env */,
    im->setShowTouches(enabled);
    im->setShowTouches(enabled);
}
}


static void nativeSetVolumeKeysRotation(JNIEnv* env,
        jclass clazz, jlong ptr, int mode) {
    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);

    im->setVolumeKeysRotation(mode);
}

static void nativeSetInteractive(JNIEnv* env,
static void nativeSetInteractive(JNIEnv* env,
        jclass clazz, jlong ptr, jboolean interactive) {
        jclass clazz, jlong ptr, jboolean interactive) {
    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
@@ -2316,6 +2345,7 @@ static const JNINativeMethod gInputManagerMethods[] = {
        {"nativeTransferTouch", "(JLandroid/os/IBinder;)Z", (void*)nativeTransferTouch},
        {"nativeTransferTouch", "(JLandroid/os/IBinder;)Z", (void*)nativeTransferTouch},
        {"nativeSetPointerSpeed", "(JI)V", (void*)nativeSetPointerSpeed},
        {"nativeSetPointerSpeed", "(JI)V", (void*)nativeSetPointerSpeed},
        {"nativeSetShowTouches", "(JZ)V", (void*)nativeSetShowTouches},
        {"nativeSetShowTouches", "(JZ)V", (void*)nativeSetShowTouches},
        {"nativeSetVolumeKeysRotation", "(JI)V", (void*)nativeSetVolumeKeysRotation},
        {"nativeSetInteractive", "(JZ)V", (void*)nativeSetInteractive},
        {"nativeSetInteractive", "(JZ)V", (void*)nativeSetInteractive},
        {"nativeReloadCalibration", "(J)V", (void*)nativeReloadCalibration},
        {"nativeReloadCalibration", "(J)V", (void*)nativeReloadCalibration},
        {"nativeVibrate", "(JI[J[III)V", (void*)nativeVibrate},
        {"nativeVibrate", "(JI[J[III)V", (void*)nativeVibrate},