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

Commit 58df5223 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

Configure handwriting window with the IME's pid and uid for ANRs

When starting a handwriting session, update the handwriting input window
so that it is configured with the IME's pid and uid. This means any ANRs
that occur due to the handwriting input window will be directed to the
IME process.

Since oneway binder calls do not have pid information, we cannot use
Binder.getCallingPid() to get the pid of the IME. Instead, we report the
pid from IMS when starting handwriting.

Bug: 210978621
Test: manual with custom IME, verify ANR is directed to IME.
Change-Id: Ia6963eb02cad22c7f604896e6c78ed31c84e32f6
parent 7c88e66c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Process;
import android.os.ResultReceiver;
import android.os.SystemClock;
import android.os.SystemProperties;
@@ -926,7 +927,7 @@ public class InputMethodService extends AbstractInputMethodService {
                mOnPreparedStylusHwCalled = true;
            }
            if (onStartStylusHandwriting()) {
                mPrivOps.onStylusHandwritingReady(requestId);
                mPrivOps.onStylusHandwritingReady(requestId, Process.myPid());
            } else {
                Log.i(TAG, "IME is not ready. Can't start Stylus Handwriting");
                // TODO(b/210039666): see if it's valuable to propagate this back to IMM.
+1 −1
Original line number Diff line number Diff line
@@ -42,6 +42,6 @@ oneway interface IInputMethodPrivilegedOperations {
    void shouldOfferSwitchingToNextInputMethod(in AndroidFuture future /* T=Boolean */);
    void notifyUserActionAsync();
    void applyImeVisibilityAsync(IBinder showOrHideInputToken, boolean setVisible);
    void onStylusHandwritingReady(int requestId);
    void onStylusHandwritingReady(int requestId, int pid);
    void finishStylusHandwriting(int requestId);
}
+3 −3
Original line number Diff line number Diff line
@@ -396,16 +396,16 @@ public final class InputMethodPrivilegedOperations {
    }

    /**
     * Calls {@link IInputMethodPrivilegedOperations#onStylusHandwritingReady()}
     * Calls {@link IInputMethodPrivilegedOperations#onStylusHandwritingReady(int, int)}
     */
    @AnyThread
    public void onStylusHandwritingReady(int requestId) {
    public void onStylusHandwritingReady(int requestId, int pid) {
        final IInputMethodPrivilegedOperations ops = mOps.getAndWarnIfNull();
        if (ops == null) {
            return;
        }
        try {
            ops.onStylusHandwritingReady(requestId);
            ops.onStylusHandwritingReady(requestId, pid);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+7 −6
Original line number Diff line number Diff line
@@ -82,13 +82,14 @@ final class HandwritingEventReceiverSurface {
        mIsIntercepting = false;
    }

    void startIntercepting() {
        // TODO(b/210978621): Update the spy window's PID and UID to be associated with the IME so
        //  that ANRs are correctly attributed to the IME.
        final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
    void startIntercepting(int imePid, int imeUid) {
        mWindowHandle.ownerPid = imePid;
        mWindowHandle.ownerUid = imeUid;
        mWindowHandle.inputFeatures &= ~WindowManager.LayoutParams.INPUT_FEATURE_SPY;
        t.setInputWindowInfo(mInputSurface, mWindowHandle);
        t.apply();

        new SurfaceControl.Transaction()
                .setInputWindowInfo(mInputSurface, mWindowHandle)
                .apply();
        mIsIntercepting = true;
    }

+2 −2
Original line number Diff line number Diff line
@@ -136,7 +136,7 @@ final class HandwritingModeController {
     */
    @UiThread
    @Nullable
    HandwritingSession startHandwritingSession(int requestId) {
    HandwritingSession startHandwritingSession(int requestId, int imePid, int imeUid) {
        if (mHandwritingSurface == null) {
            Slog.e(TAG, "Cannot start handwriting session: Handwriting was not initialized.");
            return null;
@@ -160,7 +160,7 @@ final class HandwritingModeController {
            throw new IllegalStateException(
                    "Handwriting surface should not be already intercepting.");
        }
        mHandwritingSurface.startIntercepting();
        mHandwritingSurface.startIntercepting(imePid, imeUid);

        return new HandwritingSession(mCurrentRequestId, mHandwritingSurface.getInputChannel(),
                mHandwritingBuffer);
Loading