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

Commit 5716b670 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 da3d2a82
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -2202,6 +2202,15 @@ public final class Settings {
         */
        public static final String VOLBTN_MUSIC_CONTROLS = "volbtn_music_controls";

        /**
         * Swap volume buttons when the screen is rotated
         * 0 - Disabled
         * 1 - Enabled (screen is rotated by 90 or 180 degrees: phone, hybrid)
         * 2 - Enabled (screen is rotated by 180 or 270 degrees: tablet)
         * @hide
         */
        public static final String SWAP_VOLUME_KEYS_ON_ROTATION = "swap_volume_keys_on_rotation";

        /**
         * Microphone mute (int 1 = mute, 0 = not muted).
         *
+30 −0
Original line number Diff line number Diff line
@@ -188,6 +188,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,
@@ -290,17 +291,20 @@ public class InputManagerService extends IInputManager.Stub

        registerPointerSpeedSettingObserver();
        registerShowTouchesSettingObserver();
        registerVolumeKeysRotationSettingObserver();

        mContext.registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                updatePointerSpeedFromSettings();
                updateShowTouchesFromSettings();
                updateVolumeKeysRotationFromSettings();
            }
        }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler);

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

    // TODO(BT) Pass in paramter for bluetooth system
@@ -1329,6 +1333,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
@@ -189,6 +189,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();

@@ -255,6 +256,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;

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

    sp<EventHub> eventHub = new EventHub();
@@ -422,6 +427,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);
@@ -746,6 +752,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;
}
@@ -1266,6 +1288,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);
@@ -1383,6 +1412,8 @@ static JNINativeMethod gInputManagerMethods[] = {
            (void*) nativeSetPointerSpeed },
    { "nativeSetShowTouches", "(JZ)V",
            (void*) nativeSetShowTouches },
    { "nativeSetVolumeKeysRotation", "(JI)V",
            (void*) nativeSetVolumeKeysRotation },
    { "nativeSetInteractive", "(JZ)V",
            (void*) nativeSetInteractive },
    { "nativeReloadCalibration", "(J)V",