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

Commit edaf4952 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
[bgcngm]: Adjust for 13.0 changes

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

import lineageos.providers.LineageSettings;

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

@@ -485,6 +487,7 @@ public class InputManagerService extends IInputManager.Stub
        registerLongPressTimeoutObserver();
        registerMaximumObscuringOpacityForTouchSettingObserver();
        registerBlockUntrustedTouchesModeSettingObserver();
        registerVolumeKeysRotationSettingObserver();

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

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

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

    public void updateVolumeKeysRotationFromSettings() {
        int mode = getVolumeKeysRotationSetting(0);
        mNative.setVolumeKeysRotation(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
    @Override
    public void vibrate(int deviceId, VibrationEffect effect, IBinder token) {
+5 −0
Original line number Diff line number Diff line
@@ -113,6 +113,8 @@ public interface NativeInputManagerService {

    void setShowTouches(boolean enabled);

    void setVolumeKeysRotation(int mode);

    void setInteractive(boolean interactive);

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

        @Override
        public native void setVolumeKeysRotation(int mode);

        @Override
        public native void setInteractive(boolean interactive);

+29 −0
Original line number Diff line number Diff line
@@ -281,6 +281,7 @@ public:
    void setPointerAcceleration(float acceleration);
    void setInputDeviceEnabled(uint32_t deviceId, bool enabled);
    void setShowTouches(bool enabled);
    void setVolumeKeysRotation(int mode);
    void setInteractive(bool interactive);
    void reloadCalibration();
    void setPointerIconType(int32_t iconId);
@@ -375,6 +376,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;

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

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

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

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

        outConfig->pointerCaptureRequest = mLocked.pointerCaptureRequest;

@@ -1109,6 +1115,22 @@ void NativeInputManager::requestPointerCapture(const sp<IBinder>& windowToken, b
    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) {
    mInteractive = interactive;
}
@@ -1874,6 +1896,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 nativeSetInteractive(JNIEnv* env, jobject nativeImplObj, jboolean interactive) {
    NativeInputManager* im = getNativeInputManager(env, nativeImplObj);

@@ -2347,6 +2375,7 @@ static const JNINativeMethod gInputManagerMethods[] = {
        {"setPointerSpeed", "(I)V", (void*)nativeSetPointerSpeed},
        {"setPointerAcceleration", "(F)V", (void*)nativeSetPointerAcceleration},
        {"setShowTouches", "(Z)V", (void*)nativeSetShowTouches},
        {"setVolumeKeysRotation", "(I)V", (void*)nativeSetVolumeKeysRotation},
        {"setInteractive", "(Z)V", (void*)nativeSetInteractive},
        {"reloadCalibration", "()V", (void*)nativeReloadCalibration},
        {"vibrate", "(I[J[III)V", (void*)nativeVibrate},