Merge "Use context-specific configuration signal when updating drag layout" into tm-qpr-dev

This commit is contained in:
Winson Chung
2023-02-24 17:34:26 +00:00
committed by Android (Google) Code Review
3 changed files with 40 additions and 25 deletions

View File

@@ -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 static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
import android.content.ClipDescription; import android.content.ClipDescription;
import android.content.ComponentCallbacks2;
import android.content.Context; import android.content.Context;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.PixelFormat; 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.R;
import com.android.wm.shell.common.DisplayController; import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.ShellExecutor; 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.protolog.ShellProtoLogGroup;
import com.android.wm.shell.splitscreen.SplitScreenController; 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.ShellController;
import com.android.wm.shell.sysui.ShellInit; 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. * Handles the global drag and drop handling for the Shell.
*/ */
public class DragAndDropController implements DisplayController.OnDisplaysChangedListener, public class DragAndDropController implements DisplayController.OnDisplaysChangedListener,
View.OnDragListener, ConfigurationChangeListener { View.OnDragListener, ComponentCallbacks2 {
private static final String TAG = DragAndDropController.class.getSimpleName(); private static final String TAG = DragAndDropController.class.getSimpleName();
@@ -119,7 +120,6 @@ public class DragAndDropController implements DisplayController.OnDisplaysChange
mMainExecutor.executeDelayed(() -> { mMainExecutor.executeDelayed(() -> {
mDisplayController.addDisplayWindowListener(this); mDisplayController.addDisplayWindowListener(this);
}, 0); }, 0);
mShellController.addConfigurationChangeListener(this);
} }
/** /**
@@ -180,6 +180,7 @@ public class DragAndDropController implements DisplayController.OnDisplaysChange
try { try {
wm.addView(rootView, layoutParams); wm.addView(rootView, layoutParams);
addDisplayDropTarget(displayId, context, wm, rootView, dragLayout); addDisplayDropTarget(displayId, context, wm, rootView, dragLayout);
context.registerComponentCallbacks(this);
} catch (WindowManager.InvalidDisplayException e) { } catch (WindowManager.InvalidDisplayException e) {
Slog.w(TAG, "Unable to add view for display id: " + displayId); Slog.w(TAG, "Unable to add view for display id: " + displayId);
} }
@@ -209,6 +210,7 @@ public class DragAndDropController implements DisplayController.OnDisplaysChange
if (pd == null) { if (pd == null) {
return; return;
} }
pd.context.unregisterComponentCallbacks(this);
pd.wm.removeViewImmediate(pd.rootView); pd.wm.removeViewImmediate(pd.rootView);
mDisplayDropTargets.remove(displayId); mDisplayDropTargets.remove(displayId);
} }
@@ -328,18 +330,29 @@ public class DragAndDropController implements DisplayController.OnDisplaysChange
return mimeTypes; return mimeTypes;
} }
@Override // Note: Component callbacks are always called on the main thread of the process
public void onThemeChanged() { @ExternalMainThread
for (int i = 0; i < mDisplayDropTargets.size(); i++) {
mDisplayDropTargets.get(i).dragLayout.onThemeChange();
}
}
@Override @Override
public void onConfigurationChanged(Configuration newConfig) { public void onConfigurationChanged(Configuration newConfig) {
for (int i = 0; i < mDisplayDropTargets.size(); i++) { mMainExecutor.execute(() -> {
mDisplayDropTargets.get(i).dragLayout.onConfigChanged(newConfig); 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 { private static class PerDisplay {

View File

@@ -18,6 +18,8 @@ package com.android.wm.shell.draganddrop;
import static android.app.StatusBarManager.DISABLE_NONE; import static android.app.StatusBarManager.DISABLE_NONE;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; 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 android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_BOTTOM_OR_RIGHT; 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 SplitScreenController mSplitScreenController;
private final IconProvider mIconProvider; private final IconProvider mIconProvider;
private final StatusBarManager mStatusBarManager; private final StatusBarManager mStatusBarManager;
private final Configuration mLastConfiguration = new Configuration();
private DragAndDropPolicy.Target mCurrentTarget = null; private DragAndDropPolicy.Target mCurrentTarget = null;
private DropZoneView mDropZoneView1; private DropZoneView mDropZoneView1;
@@ -92,6 +95,7 @@ public class DragLayout extends LinearLayout {
mIconProvider = iconProvider; mIconProvider = iconProvider;
mPolicy = new DragAndDropPolicy(context, splitScreenController); mPolicy = new DragAndDropPolicy(context, splitScreenController);
mStatusBarManager = context.getSystemService(StatusBarManager.class); mStatusBarManager = context.getSystemService(StatusBarManager.class);
mLastConfiguration.setTo(context.getResources().getConfiguration());
mDisplayMargin = context.getResources().getDimensionPixelSize( mDisplayMargin = context.getResources().getDimensionPixelSize(
R.dimen.drop_layout_display_margin); R.dimen.drop_layout_display_margin);
@@ -132,11 +136,6 @@ public class DragLayout extends LinearLayout {
return super.onApplyWindowInsets(insets); return super.onApplyWindowInsets(insets);
} }
public void onThemeChange() {
mDropZoneView1.onThemeChange();
mDropZoneView2.onThemeChange();
}
public void onConfigChanged(Configuration newConfig) { public void onConfigChanged(Configuration newConfig) {
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE
&& getOrientation() != HORIZONTAL) { && getOrientation() != HORIZONTAL) {
@@ -147,6 +146,15 @@ public class DragLayout extends LinearLayout {
setOrientation(LinearLayout.VERTICAL); setOrientation(LinearLayout.VERTICAL);
updateContainerMargins(newConfig.orientation); 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() { private void updateContainerMarginsForSingleTask() {

View File

@@ -48,7 +48,6 @@ import com.android.launcher3.icons.IconProvider;
import com.android.wm.shell.ShellTestCase; import com.android.wm.shell.ShellTestCase;
import com.android.wm.shell.common.DisplayController; import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.ShellExecutor; 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.ShellController;
import com.android.wm.shell.sysui.ShellInit; import com.android.wm.shell.sysui.ShellInit;
@@ -82,7 +81,7 @@ public class DragAndDropControllerTest extends ShellTestCase {
@Mock @Mock
private ShellExecutor mMainExecutor; private ShellExecutor mMainExecutor;
@Mock @Mock
private SplitScreenController mSplitScreenController; private WindowManager mWindowManager;
private DragAndDropController mController; private DragAndDropController mController;
@@ -99,11 +98,6 @@ public class DragAndDropControllerTest extends ShellTestCase {
verify(mShellInit, times(1)).addInitCallback(any(), any()); verify(mShellInit, times(1)).addInitCallback(any(), any());
} }
@Test
public void instantiateController_registerConfigChangeListener() {
verify(mShellController, times(1)).addConfigurationChangeListener(any());
}
@Test @Test
public void testIgnoreNonDefaultDisplays() { public void testIgnoreNonDefaultDisplays() {
final int nonDefaultDisplayId = 12345; final int nonDefaultDisplayId = 12345;