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

Commit 05083386 authored by David Padlipsky's avatar David Padlipsky Committed by Android (Google) Code Review
Browse files

Merge "Persist input gestures on IoThread in background" into main

parents 8084813e 07e00aad
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -143,6 +143,7 @@ import com.android.internal.policy.KeyInterceptionInfo;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.Preconditions;
import com.android.server.DisplayThread;
import com.android.server.IoThread;
import com.android.server.LocalServices;
import com.android.server.SystemService;
import com.android.server.Watchdog;
@@ -469,11 +470,13 @@ public class InputManagerService extends IInputManager.Stub
    static class Injector {
        private final Context mContext;
        private final Looper mLooper;
        private final Looper mIoLooper;
        private final UEventManager mUEventManager;

        Injector(Context context, Looper looper, UEventManager uEventManager) {
        Injector(Context context, Looper looper, Looper ioLooper, UEventManager uEventManager) {
            mContext = context;
            mLooper = looper;
            mIoLooper = ioLooper;
            mUEventManager = uEventManager;
        }

@@ -485,6 +488,10 @@ public class InputManagerService extends IInputManager.Stub
            return mLooper;
        }

        Looper getIoLooper() {
            return mIoLooper;
        }

        UEventManager getUEventManager() {
            return mUEventManager;
        }
@@ -505,8 +512,8 @@ public class InputManagerService extends IInputManager.Stub
    }

    public InputManagerService(Context context) {
        this(new Injector(context, DisplayThread.get().getLooper(), new UEventManager() {}),
                context.getSystemService(PermissionEnforcer.class));
        this(new Injector(context, DisplayThread.get().getLooper(), IoThread.get().getLooper(),
                new UEventManager() {}), context.getSystemService(PermissionEnforcer.class));
    }

    @VisibleForTesting
@@ -532,7 +539,7 @@ public class InputManagerService extends IInputManager.Stub
        mStickyModifierStateController = new StickyModifierStateController();
        mInputDataStore = new InputDataStore();
        mKeyGestureController = new KeyGestureController(mContext, injector.getLooper(),
                mInputDataStore);
                injector.getIoLooper(), mInputDataStore);
        mKeyboardLedController = new KeyboardLedController(mContext, injector.getLooper(),
                mNative);
        mKeyRemapper = new KeyRemapper(mContext, mNative, mDataStore, injector.getLooper());
+15 −7
Original line number Diff line number Diff line
@@ -121,6 +121,7 @@ final class KeyGestureController {

    private final Context mContext;
    private final Handler mHandler;
    private final Handler mIoHandler;
    private final int mSystemPid;
    private final KeyCombinationManager mKeyCombinationManager;
    private final SettingsObserver mSettingsObserver;
@@ -171,9 +172,11 @@ final class KeyGestureController {

    private final boolean mVisibleBackgroundUsersEnabled = isVisibleBackgroundUsersEnabled();

    KeyGestureController(Context context, Looper looper, InputDataStore inputDataStore) {
    KeyGestureController(Context context, Looper looper, Looper ioLooper,
            InputDataStore inputDataStore) {
        mContext = context;
        mHandler = new Handler(looper, this::handleMessage);
        mIoHandler = new Handler(ioLooper, this::handleIoMessage);
        mSystemPid = Process.myPid();
        mKeyGestureHandlerRecords = new TreeMap<>((p1, p2) -> {
            if (Objects.equals(p1, p2)) {
@@ -458,7 +461,7 @@ final class KeyGestureController {
            userId = mCurrentUserId;
        }
        // Load the system user's input gestures.
        mHandler.obtainMessage(MSG_LOAD_CUSTOM_GESTURES, userId).sendToTarget();
        mIoHandler.obtainMessage(MSG_LOAD_CUSTOM_GESTURES, userId).sendToTarget();
    }

    public boolean interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
@@ -1032,7 +1035,7 @@ final class KeyGestureController {
        synchronized (mUserLock) {
            mCurrentUserId = userId;
        }
        mHandler.obtainMessage(MSG_LOAD_CUSTOM_GESTURES, userId).sendToTarget();
        mIoHandler.obtainMessage(MSG_LOAD_CUSTOM_GESTURES, userId).sendToTarget();
    }

    @MainThread
@@ -1073,6 +1076,12 @@ final class KeyGestureController {
                AidlKeyGestureEvent event = (AidlKeyGestureEvent) msg.obj;
                notifyKeyGestureEvent(event);
                break;
        }
        return true;
    }

    private boolean handleIoMessage(Message msg) {
        switch (msg.what) {
            case MSG_PERSIST_CUSTOM_GESTURES: {
                final int userId = (Integer) msg.obj;
                persistInputGestures(userId);
@@ -1083,7 +1092,6 @@ final class KeyGestureController {
                loadInputGestures(userId);
                break;
            }

        }
        return true;
    }
@@ -1144,7 +1152,7 @@ final class KeyGestureController {
        final int result = mInputGestureManager.addCustomInputGesture(userId,
                new InputGestureData(inputGestureData));
        if (result == InputManager.CUSTOM_INPUT_GESTURE_RESULT_SUCCESS) {
            mHandler.obtainMessage(MSG_PERSIST_CUSTOM_GESTURES, userId).sendToTarget();
            mIoHandler.obtainMessage(MSG_PERSIST_CUSTOM_GESTURES, userId).sendToTarget();
        }
        return result;
    }
@@ -1156,7 +1164,7 @@ final class KeyGestureController {
        final int result = mInputGestureManager.removeCustomInputGesture(userId,
                new InputGestureData(inputGestureData));
        if (result == InputManager.CUSTOM_INPUT_GESTURE_RESULT_SUCCESS) {
            mHandler.obtainMessage(MSG_PERSIST_CUSTOM_GESTURES, userId).sendToTarget();
            mIoHandler.obtainMessage(MSG_PERSIST_CUSTOM_GESTURES, userId).sendToTarget();
        }
        return result;
    }
@@ -1165,7 +1173,7 @@ final class KeyGestureController {
    public void removeAllCustomInputGestures(@UserIdInt int userId,
            @Nullable InputGestureData.Filter filter) {
        mInputGestureManager.removeAllCustomInputGestures(userId, filter);
        mHandler.obtainMessage(MSG_PERSIST_CUSTOM_GESTURES, userId).sendToTarget();
        mIoHandler.obtainMessage(MSG_PERSIST_CUSTOM_GESTURES, userId).sendToTarget();
    }

    @BinderThread
+1 −1
Original line number Diff line number Diff line
@@ -160,7 +160,7 @@ class InputManagerServiceTests {
        testLooper = TestLooper()
        service =
            InputManagerService(object : InputManagerService.Injector(
                    context, testLooper.looper, uEventManager) {
                    context, testLooper.looper, testLooper.looper, uEventManager) {
                override fun getNativeService(
                    service: InputManagerService?
                ): NativeInputManagerService {
+1 −1
Original line number Diff line number Diff line
@@ -207,7 +207,7 @@ class KeyGestureControllerTests {

    private fun setupKeyGestureController() {
        keyGestureController =
            KeyGestureController(context, testLooper.looper, inputDataStore)
            KeyGestureController(context, testLooper.looper, testLooper.looper, inputDataStore)
        Mockito.`when`(iInputManager.getAppLaunchBookmarks())
            .thenReturn(keyGestureController.appLaunchBookmarks)
        keyGestureController.systemRunning()