Move overlay monitoring logic out of config monitor

Bug: 126417894

Change-Id: I5b474a2a41bbd951fa0a99673fa8bf4342adade5
This commit is contained in:
Hyunyoung Song 2019-03-19 15:05:21 -07:00
parent 0825e414f0
commit e11eb47c4e
2 changed files with 25 additions and 13 deletions

View File

@ -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<OnIDPChangeListener> 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);
}
}
}

View File

@ -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();