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

Commit 7bb59d87 authored by nadlabak's avatar nadlabak Committed by Steve Kondik
Browse files

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

[mikeioannina]: Adjust for 5.0 changes

Change-Id: I1b45da63b815aa1b3ddf7cda2b7afb0872ab433f
parent d2431aea
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -212,6 +212,7 @@ public class InputManagerService extends IInputManager.Stub
            InputChannel fromChannel, InputChannel toChannel);
    private static native void nativeSetPointerSpeed(long ptr, int speed);
    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 nativeReloadCalibration(long ptr);
    private static native void nativeVibrate(long ptr, int deviceId, long[] pattern,
@@ -324,6 +325,7 @@ public class InputManagerService extends IInputManager.Stub
        registerPointerSpeedSettingObserver();
        registerShowTouchesSettingObserver();
        registerAccessibilityLargePointerSettingObserver();
        registerVolumeKeysRotationSettingObserver();

        mContext.registerReceiver(new BroadcastReceiver() {
            @Override
@@ -331,12 +333,14 @@ public class InputManagerService extends IInputManager.Stub
                updatePointerSpeedFromSettings();
                updateShowTouchesFromSettings();
                updateAccessibilityLargePointerFromSettings();
                updateVolumeKeysRotationFromSettings();
            }
        }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler);

        updatePointerSpeedFromSettings();
        updateShowTouchesFromSettings();
        updateAccessibilityLargePointerFromSettings();
        updateVolumeKeysRotationFromSettings();
    }

    // TODO(BT) Pass in paramter for bluetooth system
@@ -1673,6 +1677,32 @@ public class InputManagerService extends IInputManager.Stub
        return result;
    }

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

    public void registerVolumeKeysRotationSettingObserver() {
        mContext.getContentResolver().registerContentObserver(
                Settings.System.getUriFor(Settings.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 = Settings.System.getIntForUser(mContext.getContentResolver(),
                    Settings.System.SWAP_VOLUME_KEYS_ON_ROTATION, UserHandle.USER_CURRENT);
        } catch (SettingNotFoundException snfe) {
        }
        return result;
    }

    // Binder call
    @Override
    public void vibrate(int deviceId, long[] pattern, int repeat, IBinder token) {
+31 −0
Original line number Diff line number Diff line
@@ -202,6 +202,7 @@ public:
    void setSystemUiVisibility(int32_t visibility);
    void setPointerSpeed(int32_t speed);
    void setShowTouches(bool enabled);
    void setVolumeKeysRotation(int mode);
    void setInteractive(bool interactive);
    void reloadCalibration();
    void setPointerIconType(int32_t iconId);
@@ -276,6 +277,9 @@ private:
        // Show touches feature enable/disable.
        bool showTouches;

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

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

@@ -312,6 +316,7 @@ NativeInputManager::NativeInputManager(jobject contextObj,
        mLocked.pointerSpeed = 0;
        mLocked.pointerGesturesEnabled = true;
        mLocked.showTouches = false;
        mLocked.volumeKeysRotationMode = 0;
    }
    mInteractive = true;

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

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

        outConfig->setDisplayInfo(false /*external*/, mLocked.internalViewport);
        outConfig->setDisplayInfo(true /*external*/, mLocked.externalViewport);
@@ -767,6 +773,22 @@ void NativeInputManager::setShowTouches(bool enabled) {
            InputReaderConfiguration::CHANGE_SHOW_TOUCHES);
}

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) {
    mInteractive = interactive;
}
@@ -1372,6 +1394,13 @@ static void nativeSetShowTouches(JNIEnv* /* env */,
    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,
        jclass clazz, jlong ptr, jboolean interactive) {
    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
@@ -1515,6 +1544,8 @@ static const JNINativeMethod gInputManagerMethods[] = {
            (void*) nativeSetPointerSpeed },
    { "nativeSetShowTouches", "(JZ)V",
            (void*) nativeSetShowTouches },
    { "nativeSetVolumeKeysRotation", "(JI)V",
            (void*) nativeSetVolumeKeysRotation },
    { "nativeSetInteractive", "(JZ)V",
            (void*) nativeSetInteractive },
    { "nativeReloadCalibration", "(J)V",