diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/DragAndDropController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/DragAndDropController.java index b59fe1818780e..4cfaae6e51c72 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/DragAndDropController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/DragAndDropController.java @@ -36,6 +36,7 @@ import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_U import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; import android.content.ClipDescription; +import android.content.ComponentCallbacks2; import android.content.Context; import android.content.res.Configuration; import android.graphics.PixelFormat; @@ -58,9 +59,9 @@ import com.android.launcher3.icons.IconProvider; import com.android.wm.shell.R; import com.android.wm.shell.common.DisplayController; import com.android.wm.shell.common.ShellExecutor; +import com.android.wm.shell.common.annotations.ExternalMainThread; import com.android.wm.shell.protolog.ShellProtoLogGroup; import com.android.wm.shell.splitscreen.SplitScreenController; -import com.android.wm.shell.sysui.ConfigurationChangeListener; import com.android.wm.shell.sysui.ShellController; import com.android.wm.shell.sysui.ShellInit; @@ -70,7 +71,7 @@ import java.util.ArrayList; * Handles the global drag and drop handling for the Shell. */ public class DragAndDropController implements DisplayController.OnDisplaysChangedListener, - View.OnDragListener, ConfigurationChangeListener { + View.OnDragListener, ComponentCallbacks2 { private static final String TAG = DragAndDropController.class.getSimpleName(); @@ -119,7 +120,6 @@ public class DragAndDropController implements DisplayController.OnDisplaysChange mMainExecutor.executeDelayed(() -> { mDisplayController.addDisplayWindowListener(this); }, 0); - mShellController.addConfigurationChangeListener(this); } /** @@ -180,6 +180,7 @@ public class DragAndDropController implements DisplayController.OnDisplaysChange try { wm.addView(rootView, layoutParams); addDisplayDropTarget(displayId, context, wm, rootView, dragLayout); + context.registerComponentCallbacks(this); } catch (WindowManager.InvalidDisplayException e) { Slog.w(TAG, "Unable to add view for display id: " + displayId); } @@ -209,6 +210,7 @@ public class DragAndDropController implements DisplayController.OnDisplaysChange if (pd == null) { return; } + pd.context.unregisterComponentCallbacks(this); pd.wm.removeViewImmediate(pd.rootView); mDisplayDropTargets.remove(displayId); } @@ -328,18 +330,29 @@ public class DragAndDropController implements DisplayController.OnDisplaysChange return mimeTypes; } - @Override - public void onThemeChanged() { - for (int i = 0; i < mDisplayDropTargets.size(); i++) { - mDisplayDropTargets.get(i).dragLayout.onThemeChange(); - } - } - + // Note: Component callbacks are always called on the main thread of the process + @ExternalMainThread @Override public void onConfigurationChanged(Configuration newConfig) { - for (int i = 0; i < mDisplayDropTargets.size(); i++) { - mDisplayDropTargets.get(i).dragLayout.onConfigChanged(newConfig); - } + mMainExecutor.execute(() -> { + for (int i = 0; i < mDisplayDropTargets.size(); i++) { + mDisplayDropTargets.get(i).dragLayout.onConfigChanged(newConfig); + } + }); + } + + // Note: Component callbacks are always called on the main thread of the process + @ExternalMainThread + @Override + public void onTrimMemory(int level) { + // Do nothing + } + + // Note: Component callbacks are always called on the main thread of the process + @ExternalMainThread + @Override + public void onLowMemory() { + // Do nothing } private static class PerDisplay { diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/DragLayout.java b/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/DragLayout.java index bb6e3917ff3c9..c7876595882a8 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/DragLayout.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/DragLayout.java @@ -18,6 +18,8 @@ package com.android.wm.shell.draganddrop; import static android.app.StatusBarManager.DISABLE_NONE; import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; +import static android.content.pm.ActivityInfo.CONFIG_ASSETS_PATHS; +import static android.content.pm.ActivityInfo.CONFIG_UI_MODE; import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_BOTTOM_OR_RIGHT; @@ -72,6 +74,7 @@ public class DragLayout extends LinearLayout { private final SplitScreenController mSplitScreenController; private final IconProvider mIconProvider; private final StatusBarManager mStatusBarManager; + private final Configuration mLastConfiguration = new Configuration(); private DragAndDropPolicy.Target mCurrentTarget = null; private DropZoneView mDropZoneView1; @@ -92,6 +95,7 @@ public class DragLayout extends LinearLayout { mIconProvider = iconProvider; mPolicy = new DragAndDropPolicy(context, splitScreenController); mStatusBarManager = context.getSystemService(StatusBarManager.class); + mLastConfiguration.setTo(context.getResources().getConfiguration()); mDisplayMargin = context.getResources().getDimensionPixelSize( R.dimen.drop_layout_display_margin); @@ -132,11 +136,6 @@ public class DragLayout extends LinearLayout { return super.onApplyWindowInsets(insets); } - public void onThemeChange() { - mDropZoneView1.onThemeChange(); - mDropZoneView2.onThemeChange(); - } - public void onConfigChanged(Configuration newConfig) { if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE && getOrientation() != HORIZONTAL) { @@ -147,6 +146,15 @@ public class DragLayout extends LinearLayout { setOrientation(LinearLayout.VERTICAL); updateContainerMargins(newConfig.orientation); } + + final int diff = newConfig.diff(mLastConfiguration); + final boolean themeChanged = (diff & CONFIG_ASSETS_PATHS) != 0 + || (diff & CONFIG_UI_MODE) != 0; + if (themeChanged) { + mDropZoneView1.onThemeChange(); + mDropZoneView2.onThemeChange(); + } + mLastConfiguration.setTo(newConfig); } private void updateContainerMarginsForSingleTask() { diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/draganddrop/DragAndDropControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/draganddrop/DragAndDropControllerTest.java index b6dbcf204364b..523cb6629d9a3 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/draganddrop/DragAndDropControllerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/draganddrop/DragAndDropControllerTest.java @@ -48,7 +48,6 @@ import com.android.launcher3.icons.IconProvider; import com.android.wm.shell.ShellTestCase; import com.android.wm.shell.common.DisplayController; import com.android.wm.shell.common.ShellExecutor; -import com.android.wm.shell.splitscreen.SplitScreenController; import com.android.wm.shell.sysui.ShellController; import com.android.wm.shell.sysui.ShellInit; @@ -82,7 +81,7 @@ public class DragAndDropControllerTest extends ShellTestCase { @Mock private ShellExecutor mMainExecutor; @Mock - private SplitScreenController mSplitScreenController; + private WindowManager mWindowManager; private DragAndDropController mController; @@ -99,11 +98,6 @@ public class DragAndDropControllerTest extends ShellTestCase { verify(mShellInit, times(1)).addInitCallback(any(), any()); } - @Test - public void instantiateController_registerConfigChangeListener() { - verify(mShellController, times(1)).addConfigurationChangeListener(any()); - } - @Test public void testIgnoreNonDefaultDisplays() { final int nonDefaultDisplayId = 12345;