Merge "Fix NPE in InlineContentView" into rvc-dev

This commit is contained in:
TreeHugger Robot
2020-06-09 03:42:04 +00:00
committed by Android (Google) Code Review
2 changed files with 24 additions and 2 deletions

View File

@@ -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

View File

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