From fd6d942220499bb218a99d1dd9cb85b870de706d Mon Sep 17 00:00:00 2001 From: Alex Chau Date: Thu, 22 Apr 2021 19:10:21 +0100 Subject: [PATCH] Pass WindowContext to DisplayInfoChangeListener - WindowContext (or updated DisplayContext for Pre-S) contains updated Resources to be used for the listener Fixes: 181215299 Fixes: 176656141 Test: Swap between large/small screen, large sreen UI is seen Test: Swap between font size, launcher icon text is updated Test: Start secondary home Test: Repeat the above tests with Utilities.ATLEAST_S hardcoded to false Change-Id: Ib33025ac0276c84fe2b3213e9946721e5988e3da --- .../launcher3/BaseQuickstepLauncher.java | 10 ++++---- .../RecentsAnimationDeviceState.java | 4 ++-- .../quickstep/RotationTouchHelper.java | 4 ++-- .../launcher3/BaseDraggingActivity.java | 3 ++- .../launcher3/InvariantDeviceProfile.java | 6 ++--- .../launcher3/util/DisplayController.java | 23 ++++++++++++------- 6 files changed, 28 insertions(+), 22 deletions(-) diff --git a/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java b/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java index caf52e3542..7aae38c7f1 100644 --- a/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java +++ b/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java @@ -27,12 +27,11 @@ import static com.android.systemui.shared.system.ActivityManagerWrapper.CLOSE_SY import android.animation.AnimatorSet; import android.animation.ValueAnimator; import android.app.ActivityOptions; +import android.content.Context; import android.content.Intent; import android.content.IntentSender; -import android.os.Binder; import android.os.Bundle; import android.os.CancellationSignal; -import android.os.IBinder; import android.view.View; import androidx.annotation.Nullable; @@ -41,7 +40,6 @@ import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.dragndrop.DragOptions; import com.android.launcher3.model.WellbeingModel; import com.android.launcher3.model.data.ItemInfo; -import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.popup.SystemShortcut; import com.android.launcher3.proxy.ProxyActivityStarter; import com.android.launcher3.proxy.StartActivityParams; @@ -73,7 +71,6 @@ import com.android.systemui.shared.system.ActivityManagerWrapper; import com.android.systemui.shared.system.ActivityOptionsCompat; import com.android.systemui.shared.system.RemoteAnimationTargetCompat; -import java.util.HashMap; import java.util.List; import java.util.stream.Stream; @@ -240,8 +237,9 @@ public abstract class BaseQuickstepLauncher extends Launcher } @Override - public void onDisplayInfoChanged(DisplayController.Info info, int flags) { - super.onDisplayInfoChanged(info, flags); + public void onDisplayInfoChanged(Context context, DisplayController.Info info, + int flags) { + super.onDisplayInfoChanged(context, info, flags); if ((flags & CHANGE_SIZE) != 0) { addTaskbarIfNecessary(); } diff --git a/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java b/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java index 6cf12a3865..b4f13307a4 100644 --- a/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java +++ b/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java @@ -241,7 +241,7 @@ public class RecentsAnimationDeviceState implements public void onNavigationModeChanged(SysUINavigationMode.Mode newMode) { mDisplayController.removeChangeListener(this); mDisplayController.addChangeListener(this); - onDisplayInfoChanged(mDisplayController.getInfo(), CHANGE_ALL); + onDisplayInfoChanged(mContext, mDisplayController.getInfo(), CHANGE_ALL); if (newMode == NO_BUTTON) { mExclusionListener.register(); @@ -254,7 +254,7 @@ public class RecentsAnimationDeviceState implements } @Override - public void onDisplayInfoChanged(Info info, int flags) { + public void onDisplayInfoChanged(Context context, Info info, int flags) { if (info.id != getDisplayId() || flags == CHANGE_FRAME_DELAY) { // ignore displays that aren't running launcher and frame refresh rate changes return; diff --git a/quickstep/src/com/android/quickstep/RotationTouchHelper.java b/quickstep/src/com/android/quickstep/RotationTouchHelper.java index d4ad1760ef..f4688a1dc1 100644 --- a/quickstep/src/com/android/quickstep/RotationTouchHelper.java +++ b/quickstep/src/com/android/quickstep/RotationTouchHelper.java @@ -225,7 +225,7 @@ public class RotationTouchHelper implements public void onNavigationModeChanged(SysUINavigationMode.Mode newMode) { mDisplayController.removeChangeListener(this); mDisplayController.addChangeListener(this); - onDisplayInfoChanged(mDisplayController.getInfo(), CHANGE_ALL); + onDisplayInfoChanged(mContext, mDisplayController.getInfo(), CHANGE_ALL); mOrientationTouchTransformer.setNavigationMode(newMode, mDisplayController.getInfo(), mContext.getResources()); @@ -243,7 +243,7 @@ public class RotationTouchHelper implements } @Override - public void onDisplayInfoChanged(Info info, int flags) { + public void onDisplayInfoChanged(Context context, Info info, int flags) { if (info.id != mDisplayId|| flags == CHANGE_FRAME_DELAY) { // ignore displays that aren't running launcher and frame refresh rate changes return; diff --git a/src/com/android/launcher3/BaseDraggingActivity.java b/src/com/android/launcher3/BaseDraggingActivity.java index cc9f594257..4c5f9f247f 100644 --- a/src/com/android/launcher3/BaseDraggingActivity.java +++ b/src/com/android/launcher3/BaseDraggingActivity.java @@ -21,6 +21,7 @@ import static com.android.launcher3.util.DisplayController.CHANGE_ROTATION; import android.app.ActivityOptions; import android.content.ActivityNotFoundException; +import android.content.Context; import android.content.Intent; import android.content.pm.LauncherApps; import android.content.res.Configuration; @@ -296,7 +297,7 @@ public abstract class BaseDraggingActivity extends BaseActivity } @Override - public void onDisplayInfoChanged(Info info, int flags) { + public void onDisplayInfoChanged(Context context, Info info, int flags) { if ((flags & CHANGE_ROTATION) != 0 && mDeviceProfile.updateIsSeascape(this)) { reapplyUi(); } diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java index 11dc0c4736..1332e14af0 100644 --- a/src/com/android/launcher3/InvariantDeviceProfile.java +++ b/src/com/android/launcher3/InvariantDeviceProfile.java @@ -203,9 +203,9 @@ public class InvariantDeviceProfile { .apply(); DisplayController.INSTANCE.get(context).addChangeListener( - (info, flags) -> { + (displayContext, info, flags) -> { if ((flags & (CHANGE_SIZE | CHANGE_DENSITY)) != 0) { - onConfigChanged(context); + onConfigChanged(displayContext); } }); mOverlayMonitor = new OverlayMonitor(context); @@ -226,7 +226,7 @@ public class InvariantDeviceProfile { */ public InvariantDeviceProfile(Context context, Display display) { // Ensure that the main device profile is initialized - InvariantDeviceProfile originalProfile = INSTANCE.get(context); + INSTANCE.get(context); String gridName = getCurrentGridName(context); // Get the display info based on default display and interpolate it to existing display diff --git a/src/com/android/launcher3/util/DisplayController.java b/src/com/android/launcher3/util/DisplayController.java index 07c89b9b43..75c089e754 100644 --- a/src/com/android/launcher3/util/DisplayController.java +++ b/src/com/android/launcher3/util/DisplayController.java @@ -87,7 +87,7 @@ public class DisplayController implements DisplayListener, ComponentCallbacks { new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED)); } - mInfo = createInfo(display); + mInfo = new Info(getContext(display), display); mDM.registerDisplayListener(this, UI_HELPER_EXECUTOR.getHandler()); } @@ -125,7 +125,13 @@ public class DisplayController implements DisplayListener, ComponentCallbacks { */ public interface DisplayInfoChangeListener { - void onDisplayInfoChanged(Info info, int flags); + /** + * Invoked when display info has changed. + * @param context updated context associated with the display. + * @param info updated display information. + * @param flags bitmask indicating type of change. + */ + void onDisplayInfoChanged(Context context, Info info, int flags); } /** @@ -172,14 +178,15 @@ public class DisplayController implements DisplayListener, ComponentCallbacks { return mInfo; } - private Info createInfo(Display display) { - return new Info(mContext.createDisplayContext(display), display); + private Context getContext(Display display) { + return Utilities.ATLEAST_S ? mWindowContext : mContext.createDisplayContext(display); } @AnyThread private void handleInfoChange(Display display) { Info oldInfo = mInfo; - Info newInfo = createInfo(display); + Context context = getContext(display); + Info newInfo = new Info(context, display); int change = 0; if (newInfo.hasDifferentSize(oldInfo)) { change |= CHANGE_SIZE; @@ -197,13 +204,13 @@ public class DisplayController implements DisplayListener, ComponentCallbacks { if (change != 0) { mInfo = newInfo; final int flags = change; - MAIN_EXECUTOR.execute(() -> notifyChange(flags)); + MAIN_EXECUTOR.execute(() -> notifyChange(context, flags)); } } - private void notifyChange(int flags) { + private void notifyChange(Context context, int flags) { for (int i = mListeners.size() - 1; i >= 0; i--) { - mListeners.get(i).onDisplayInfoChanged(mInfo, flags); + mListeners.get(i).onDisplayInfoChanged(context, mInfo, flags); } }