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


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


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

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


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


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