Merge "Fix IME shrunk by WindowTokenClient mis-detach" into sc-v2-dev

This commit is contained in:
TreeHugger Robot
2022-01-15 04:27:54 +00:00
committed by Android (Google) Code Review
2 changed files with 32 additions and 13 deletions

View File

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

View File

@@ -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();
}
});
}
}