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

Commit 68871a3d authored by Marvin Bernal's avatar Marvin Bernal Committed by Android (Google) Code Review
Browse files

Merge "Add System Back function to SystemUiProxy" into sc-dev

parents 48c52c21 38644e35
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -134,5 +134,10 @@ interface ISystemUiProxy {
     */
    void expandNotificationPanel() = 29;

    // Next id = 44
    /**
     * Notifies SystemUI to invoke Back.
     */
    void onBackPressed() = 44;

    // Next id = 45
}
+33 −0
Original line number Diff line number Diff line
@@ -58,9 +58,12 @@ import android.os.IBinder;
import android.os.Looper;
import android.os.PatternMatcher;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.UserHandle;
import android.util.Log;
import android.view.InputDevice;
import android.view.InputMonitor;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.Surface;
@@ -239,6 +242,36 @@ public class OverviewProxyService extends CurrentUserTracker implements
            }
        }

        @Override
        public void onBackPressed() throws RemoteException {
            if (!verifyCaller("onBackPressed")) {
                return;
            }
            final long token = Binder.clearCallingIdentity();
            try {
                mHandler.post(() -> {
                    sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
                    sendEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK);

                    notifyBackAction(true, -1, -1, true, false);
                });
            } finally {
                Binder.restoreCallingIdentity(token);
            }
        }

        private boolean sendEvent(int action, int code) {
            long when = SystemClock.uptimeMillis();
            final KeyEvent ev = new KeyEvent(when, when, action, code, 0 /* repeat */,
                    0 /* metaState */, KeyCharacterMap.VIRTUAL_KEYBOARD, 0 /* scancode */,
                    KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY,
                    InputDevice.SOURCE_KEYBOARD);

            ev.setDisplayId(mContext.getDisplay().getDisplayId());
            return InputManager.getInstance()
                    .injectInputEvent(ev, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
        }

        @Override
        public void onOverviewShown(boolean fromHome) {
            if (!verifyCaller("onOverviewShown")) {