summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2020-06-09 03:42:04 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2020-06-09 03:42:04 +0000
commit854b0d1a89bd8fbbd6ca0fa8b2417c9729328edf (patch)
tree798759e4918838bd716b25a0c3e732e6ef668f5b
parentf6795b105fe1b1f09a3681a6301c1fbddac45095 (diff)
parent10e6217a8de772395d9b74174eeb1280bfe821aa (diff)
Merge "Fix NPE in InlineContentView" into rvc-dev
-rw-r--r--core/java/android/view/inputmethod/InlineSuggestion.java22
-rw-r--r--core/java/android/widget/inline/InlineContentView.java4
2 files changed, 24 insertions, 2 deletions
diff --git a/core/java/android/view/inputmethod/InlineSuggestion.java b/core/java/android/view/inputmethod/InlineSuggestion.java
index e4ac5889a3c0..b8893cee834d 100644
--- a/core/java/android/view/inputmethod/InlineSuggestion.java
+++ b/core/java/android/view/inputmethod/InlineSuggestion.java
@@ -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
diff --git a/core/java/android/widget/inline/InlineContentView.java b/core/java/android/widget/inline/InlineContentView.java
index 8657e828a3f6..6a85de5ca757 100644
--- a/core/java/android/widget/inline/InlineContentView.java
+++ b/core/java/android/widget/inline/InlineContentView.java
@@ -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);
+ }
});
}
}