summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2022-01-15 04:27:54 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2022-01-15 04:27:54 +0000
commitff6577fd10869384e58b95c3ffa2882e90db3626 (patch)
tree83ecdbf36da095513b0942923f79a13dc61c63a2
parent63f3810ee1147aa82e1c26c2c68ff318f7e57147 (diff)
parent29de30597b65c9111418278d04f03c35eb37d700 (diff)
downloadbase-ff6577fd10869384e58b95c3ffa2882e90db3626.tar.gz
Merge "Fix IME shrunk by WindowTokenClient mis-detach" into sc-v2-dev
-rw-r--r--core/java/android/app/ContextImpl.java11
-rw-r--r--core/java/android/window/WindowTokenClient.java34
2 files changed, 32 insertions, 13 deletions
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index fc1884a41653..06af6b180d07 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -311,6 +311,14 @@ class ContextImpl extends Context {
@ContextType
private int mContextType;
+ /**
+ * {@code true} to indicate that the {@link Context} owns the {@link #getWindowContextToken()}
+ * and is responsible for detaching the token when the Context is released.
+ *
+ * @see #finalize()
+ */
+ private boolean mOwnsToken = false;
+
@GuardedBy("mSync")
private File mDatabasesDir;
@GuardedBy("mSync")
@@ -2979,7 +2987,7 @@ class ContextImpl extends Context {
// WindowContainer. We should detach from WindowContainer when the Context is finalized
// if this Context is not a WindowContext. WindowContext finalization is handled in
// WindowContext class.
- if (mToken instanceof WindowTokenClient && mContextType != CONTEXT_TYPE_WINDOW_CONTEXT) {
+ if (mToken instanceof WindowTokenClient && mOwnsToken) {
((WindowTokenClient) mToken).detachFromWindowContainerIfNeeded();
}
super.finalize();
@@ -3010,6 +3018,7 @@ class ContextImpl extends Context {
token.attachContext(context);
token.attachToDisplayContent(displayId);
context.mContextType = CONTEXT_TYPE_SYSTEM_OR_SYSTEM_UI;
+ context.mOwnsToken = true;
return context;
}
diff --git a/core/java/android/window/WindowTokenClient.java b/core/java/android/window/WindowTokenClient.java
index 4ba7ef26e9cb..547535d90e5a 100644
--- a/core/java/android/window/WindowTokenClient.java
+++ b/core/java/android/window/WindowTokenClient.java
@@ -19,9 +19,10 @@ import static android.window.ConfigurationHelper.freeTextLayoutCachesIfNeeded;
import static android.window.ConfigurationHelper.isDifferentDisplay;
import static android.window.ConfigurationHelper.shouldUpdateResources;
+import android.annotation.BinderThread;
+import android.annotation.MainThread;
import android.annotation.NonNull;
import android.annotation.Nullable;
-import android.app.ActivityThread;
import android.app.IWindowToken;
import android.app.ResourcesManager;
import android.content.Context;
@@ -30,7 +31,9 @@ import android.inputmethodservice.AbstractInputMethodService;
import android.os.Build;
import android.os.Bundle;
import android.os.Debug;
+import android.os.Handler;
import android.os.IBinder;
+import android.os.Looper;
import android.os.RemoteException;
import android.util.Log;
import android.view.IWindowManager;
@@ -71,6 +74,8 @@ public class WindowTokenClient extends IWindowToken.Stub {
private boolean mAttachToWindowContainer;
+ private final Handler mHandler = new Handler(Looper.getMainLooper());
+
/**
* Attaches {@code context} to this {@link WindowTokenClient}. Each {@link WindowTokenClient}
* can only attach one {@link Context}.
@@ -132,7 +137,8 @@ public class WindowTokenClient extends IWindowToken.Stub {
if (configuration == null) {
return false;
}
- onConfigurationChanged(configuration, displayId, false /* shouldReportConfigChange */);
+ mHandler.post(() -> onConfigurationChanged(configuration, displayId,
+ false /* shouldReportConfigChange */));
mAttachToWindowContainer = true;
return true;
} catch (RemoteException e) {
@@ -179,9 +185,11 @@ public class WindowTokenClient extends IWindowToken.Stub {
* @param newConfig the updated {@link Configuration}
* @param newDisplayId the updated {@link android.view.Display} ID
*/
+ @BinderThread
@Override
public void onConfigurationChanged(Configuration newConfig, int newDisplayId) {
- onConfigurationChanged(newConfig, newDisplayId, true /* shouldReportConfigChange */);
+ mHandler.post(() -> onConfigurationChanged(newConfig, newDisplayId,
+ true /* shouldReportConfigChange */));
}
// TODO(b/192048581): rewrite this method based on WindowContext and WindowProviderService
@@ -192,6 +200,7 @@ public class WindowTokenClient extends IWindowToken.Stub {
* Similar to {@link #onConfigurationChanged(Configuration, int)}, but adds a flag to control
* whether to dispatch configuration update or not.
*/
+ @MainThread
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
public void onConfigurationChanged(Configuration newConfig, int newDisplayId,
boolean shouldReportConfigChange) {
@@ -217,16 +226,14 @@ public class WindowTokenClient extends IWindowToken.Stub {
if (shouldReportConfigChange && context instanceof WindowContext) {
final WindowContext windowContext = (WindowContext) context;
- ActivityThread.currentActivityThread().getHandler().post(
- () -> windowContext.dispatchConfigurationChanged(newConfig));
+ windowContext.dispatchConfigurationChanged(newConfig);
}
final int diff = mConfiguration.diffPublicOnly(newConfig);
if (shouldReportConfigChange && diff != 0
&& context instanceof WindowProviderService) {
final WindowProviderService windowProviderService = (WindowProviderService) context;
- ActivityThread.currentActivityThread().getHandler().post(
- () -> windowProviderService.onConfigurationChanged(newConfig));
+ windowProviderService.onConfigurationChanged(newConfig);
}
freeTextLayoutCachesIfNeeded(diff);
if (mShouldDumpConfigForIme) {
@@ -248,12 +255,15 @@ public class WindowTokenClient extends IWindowToken.Stub {
}
}
+ @BinderThread
@Override
public void onWindowTokenRemoved() {
- final Context context = mContextRef.get();
- if (context != null) {
- context.destroy();
- mContextRef.clear();
- }
+ mHandler.post(() -> {
+ final Context context = mContextRef.get();
+ if (context != null) {
+ context.destroy();
+ mContextRef.clear();
+ }
+ });
}
}