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

Commit 10e6217a authored by Feng Cao's avatar Feng Cao
Browse files

Fix NPE in InlineContentView

* The NPE is due to in the InlineContentView we try to reparent the
  surface view which is no longer attached to the window, this can
  happen if the InlineContentView is attached to window and then
  immediately detached from the window, before the surface package
  is returned from the remote view process.
* Release the surface package immediately in this case, so the
  remote view can be released.

Test: atest android.autofillservice.cts.inline
Bug: 158139090

Change-Id: I9efdf8ba182a1d66334362edcfb6ba58fcdc222a
parent 8083336a
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -317,8 +317,24 @@ public final class InlineSuggestion implements Parcelable {
         */
        @MainThread
        private void handleOnSurfacePackage(SurfaceControlViewHost.SurfacePackage surfacePackage) {
            if (surfacePackage == null) {
                return;
            }
            if (mSurfacePackage != null || mSurfacePackageConsumer == null) {
                // The surface package is not consumed, release it immediately.
                surfacePackage.release();
                try {
                    mInlineContentProvider.onSurfacePackageReleased();
                } catch (RemoteException e) {
                    Slog.w(TAG, "Error calling onSurfacePackageReleased(): " + e);
                }
                return;
            }
            mSurfacePackage = surfacePackage;
            if (mSurfacePackage != null && mSurfacePackageConsumer != null) {
            if (mSurfacePackage == null) {
                return;
            }
            if (mSurfacePackageConsumer != null) {
                mSurfacePackageConsumer.accept(mSurfacePackage);
                mSurfacePackageConsumer = null;
            }
@@ -334,6 +350,10 @@ public final class InlineSuggestion implements Parcelable {
                }
                mSurfacePackage = null;
            }
            // Clear the pending surface package consumer, if any. This can happen if the IME
            // attaches the view to window and then quickly detaches it from the window, before
            // the surface package requested upon attaching to window was returned.
            mSurfacePackageConsumer = null;
        }

        @MainThread
+3 −1
Original line number Diff line number Diff line
@@ -197,7 +197,9 @@ public class InlineContentView extends ViewGroup {
            mSurfacePackageUpdater.getSurfacePackage(
                    sp -> {
                        if (DEBUG) Log.v(TAG, "Received new SurfacePackage");
                        if (getViewRootImpl() != null) {
                            mSurfaceView.setChildSurfacePackage(sp);
                        }
                    });
        }
    }