diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java index 6582df2b78..f081303148 100644 --- a/src/com/android/launcher3/InvariantDeviceProfile.java +++ b/src/com/android/launcher3/InvariantDeviceProfile.java @@ -20,7 +20,10 @@ import static com.android.launcher3.config.FeatureFlags.APPLY_CONFIG_AT_RUNTIME; import static com.android.launcher3.Utilities.getDevicePrefs; import android.annotation.TargetApi; +import android.content.BroadcastReceiver; import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; @@ -114,6 +117,7 @@ public class InvariantDeviceProfile { private final ArrayList mChangeListeners = new ArrayList<>(); private ConfigMonitor mConfigMonitor; + private OverlayMonitor mOverlayMonitor; @VisibleForTesting public InvariantDeviceProfile() {} @@ -131,6 +135,7 @@ public class InvariantDeviceProfile { defaultLayoutId = p.defaultLayoutId; demoModeLayoutId = p.demoModeLayoutId; mExtraAttrs = p.mExtraAttrs; + mOverlayMonitor = p.mOverlayMonitor; } @TargetApi(23) @@ -138,8 +143,12 @@ public class InvariantDeviceProfile { initGrid(context, Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null)); mConfigMonitor = new ConfigMonitor(context, APPLY_CONFIG_AT_RUNTIME.get() ? this::onConfigChanged : this::killProcess); + mOverlayMonitor = new OverlayMonitor(context); } + /** + * This constructor should NOT have any monitors by design. + */ public InvariantDeviceProfile(Context context, String gridName) { String newName = initGrid(context, gridName); if (newName == null || !newName.equals(gridName)) { @@ -555,4 +564,20 @@ public class InvariantDeviceProfile { return this; } } + + private class OverlayMonitor extends BroadcastReceiver { + + private final String ACTION_OVERLAY_CHANGED = "android.intent.action.OVERLAY_CHANGED"; + + OverlayMonitor(Context context) { + IntentFilter filter = new IntentFilter(ACTION_OVERLAY_CHANGED); + filter.addDataScheme("package"); + context.registerReceiver(this, filter); + } + + @Override + public void onReceive(Context context, Intent intent) { + onConfigChanged(context); + } + } } \ No newline at end of file diff --git a/src/com/android/launcher3/util/ConfigMonitor.java b/src/com/android/launcher3/util/ConfigMonitor.java index 12280f82c4..12d35e9628 100644 --- a/src/com/android/launcher3/util/ConfigMonitor.java +++ b/src/com/android/launcher3/util/ConfigMonitor.java @@ -41,8 +41,6 @@ public class ConfigMonitor extends BroadcastReceiver implements DisplayListener private static final String TAG = "ConfigMonitor"; - private final String ACTION_OVERLAY_CHANGED = "android.intent.action.OVERLAY_CHANGED"; - private final Point mTmpPoint1 = new Point(); private final Point mTmpPoint2 = new Point(); @@ -78,11 +76,6 @@ public class ConfigMonitor extends BroadcastReceiver implements DisplayListener // Listen for configuration change mContext.registerReceiver(this, new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED)); - // Listen for {@link OverlayManager} change - IntentFilter filter = new IntentFilter(ACTION_OVERLAY_CHANGED); - filter.addDataScheme("package"); - mContext.registerReceiver(this, filter); - // Listen for display manager change mContext.getSystemService(DisplayManager.class) .registerDisplayListener(this, new Handler(UiThreadHelper.getBackgroundLooper())); @@ -91,12 +84,6 @@ public class ConfigMonitor extends BroadcastReceiver implements DisplayListener @Override public void onReceive(Context context, Intent intent) { Configuration config = context.getResources().getConfiguration(); - // TODO: when overlay manager service encodes more information to the Uri such as category - // of the overlay, only listen to the ones that are of interest to launcher. - if (intent != null && ACTION_OVERLAY_CHANGED.equals(intent.getAction())) { - Log.d(TAG, "Overlay changed."); - notifyChange(); - } if (mFontScale != config.fontScale || mDensity != config.densityDpi) { Log.d(TAG, "Configuration changed."); notifyChange();