Merge "Fix memory usage issue on WindowTokenClient" into tm-dev

This commit is contained in:
TreeHugger Robot
2022-05-09 07:16:15 +00:00
committed by Android (Google) Code Review

View File

@@ -21,8 +21,10 @@ import static android.window.ConfigurationHelper.shouldUpdateResources;
import android.annotation.AnyThread;
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;
@@ -33,7 +35,6 @@ 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;
@@ -42,6 +43,7 @@ import android.view.WindowManagerGlobal;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.function.pooled.PooledLambda;
import java.lang.ref.WeakReference;
@@ -76,7 +78,7 @@ public class WindowTokenClient extends IWindowToken.Stub {
private boolean mAttachToWindowContainer;
private final Handler mHandler = new Handler(Looper.getMainLooper());
private final Handler mHandler = ActivityThread.currentActivityThread().getHandler();
/**
* Attaches {@code context} to this {@link WindowTokenClient}. Each {@link WindowTokenClient}
@@ -188,8 +190,8 @@ public class WindowTokenClient extends IWindowToken.Stub {
@BinderThread
@Override
public void onConfigurationChanged(Configuration newConfig, int newDisplayId) {
mHandler.post(() -> onConfigurationChanged(newConfig, newDisplayId,
true /* shouldReportConfigChange */));
mHandler.post(PooledLambda.obtainRunnable(this::onConfigurationChanged, newConfig,
newDisplayId, true /* shouldReportConfigChange */).recycleOnUse());
}
// TODO(b/192048581): rewrite this method based on WindowContext and WindowProviderService
@@ -279,12 +281,16 @@ public class WindowTokenClient extends IWindowToken.Stub {
@BinderThread
@Override
public void onWindowTokenRemoved() {
mHandler.post(() -> {
final Context context = mContextRef.get();
if (context != null) {
context.destroy();
mContextRef.clear();
}
});
mHandler.post(PooledLambda.obtainRunnable(
WindowTokenClient::onWindowTokenRemovedInner, this).recycleOnUse());
}
@MainThread
private void onWindowTokenRemovedInner() {
final Context context = mContextRef.get();
if (context != null) {
context.destroy();
mContextRef.clear();
}
}
}