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

Commit 48df48d6 authored by nadlabak's avatar nadlabak Committed by Bruno Martins
Browse files

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

[mikeioannina]: Adjust for 5.0 changes

Change-Id: I1b45da63b815aa1b3ddf7cda2b7afb0872ab433f
parent 64991987
Loading
Loading
Loading
Loading
+33 −0
Original line number Original line Diff line number Diff line
@@ -95,6 +95,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;


@@ -230,6 +232,7 @@ public class InputManagerService extends IInputManager.Stub
            IBinder fromChannelToken, IBinder toChannelToken);
            IBinder fromChannelToken, IBinder toChannelToken);
    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,
@@ -360,6 +363,7 @@ public class InputManagerService extends IInputManager.Stub
        registerShowTouchesSettingObserver();
        registerShowTouchesSettingObserver();
        registerAccessibilityLargePointerSettingObserver();
        registerAccessibilityLargePointerSettingObserver();
        registerLongPressTimeoutObserver();
        registerLongPressTimeoutObserver();
        registerVolumeKeysRotationSettingObserver();


        mContext.registerReceiver(new BroadcastReceiver() {
        mContext.registerReceiver(new BroadcastReceiver() {
            @Override
            @Override
@@ -368,6 +372,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);


@@ -375,6 +380,7 @@ public class InputManagerService extends IInputManager.Stub
        updateShowTouchesFromSettings();
        updateShowTouchesFromSettings();
        updateAccessibilityLargePointerFromSettings();
        updateAccessibilityLargePointerFromSettings();
        updateDeepPressStatusFromSettings("just booted");
        updateDeepPressStatusFromSettings("just booted");
        updateVolumeKeysRotationFromSettings();
    }
    }


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


    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, long[] pattern, int repeat, IBinder token) {
    public void vibrate(int deviceId, long[] pattern, int repeat, IBinder token) {
+30 −0
Original line number Original line Diff line number Diff line
@@ -214,6 +214,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);
@@ -295,6 +296,9 @@ private:
        // Pointer capture feature enable/disable.
        // Pointer capture feature enable/disable.
        bool pointerCapture;
        bool pointerCapture;


        // 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;


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


@@ -533,6 +538,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->pointerCapture = mLocked.pointerCapture;
        outConfig->pointerCapture = mLocked.pointerCapture;


@@ -880,6 +886,22 @@ void NativeInputManager::setPointerCapture(bool enabled) {
            InputReaderConfiguration::CHANGE_POINTER_CAPTURE);
            InputReaderConfiguration::CHANGE_POINTER_CAPTURE);
}
}


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;
}
}
@@ -1604,6 +1626,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);
@@ -1789,6 +1818,7 @@ static const JNINativeMethod gInputManagerMethods[] = {
         (void*)nativeTransferTouchFocus},
         (void*)nativeTransferTouchFocus},
        {"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[JII)V", (void*)nativeVibrate},
        {"nativeVibrate", "(JI[JII)V", (void*)nativeVibrate},