Merge "Move overlay monitoring logic out of config monitor Bug: 126417894" into ub-launcher3-master
This commit is contained in:
commit
bc2b330528
|
@ -20,7 +20,10 @@ import static com.android.launcher3.config.FeatureFlags.APPLY_CONFIG_AT_RUNTIME;
|
||||||
import static com.android.launcher3.Utilities.getDevicePrefs;
|
import static com.android.launcher3.Utilities.getDevicePrefs;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
|
@ -114,6 +117,7 @@ public class InvariantDeviceProfile {
|
||||||
|
|
||||||
private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
|
private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
|
||||||
private ConfigMonitor mConfigMonitor;
|
private ConfigMonitor mConfigMonitor;
|
||||||
|
private OverlayMonitor mOverlayMonitor;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public InvariantDeviceProfile() {}
|
public InvariantDeviceProfile() {}
|
||||||
|
@ -131,6 +135,7 @@ public class InvariantDeviceProfile {
|
||||||
defaultLayoutId = p.defaultLayoutId;
|
defaultLayoutId = p.defaultLayoutId;
|
||||||
demoModeLayoutId = p.demoModeLayoutId;
|
demoModeLayoutId = p.demoModeLayoutId;
|
||||||
mExtraAttrs = p.mExtraAttrs;
|
mExtraAttrs = p.mExtraAttrs;
|
||||||
|
mOverlayMonitor = p.mOverlayMonitor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(23)
|
@TargetApi(23)
|
||||||
|
@ -138,8 +143,12 @@ public class InvariantDeviceProfile {
|
||||||
initGrid(context, Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null));
|
initGrid(context, Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null));
|
||||||
mConfigMonitor = new ConfigMonitor(context,
|
mConfigMonitor = new ConfigMonitor(context,
|
||||||
APPLY_CONFIG_AT_RUNTIME.get() ? this::onConfigChanged : this::killProcess);
|
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) {
|
public InvariantDeviceProfile(Context context, String gridName) {
|
||||||
String newName = initGrid(context, gridName);
|
String newName = initGrid(context, gridName);
|
||||||
if (newName == null || !newName.equals(gridName)) {
|
if (newName == null || !newName.equals(gridName)) {
|
||||||
|
@ -555,4 +564,20 @@ public class InvariantDeviceProfile {
|
||||||
return this;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -41,8 +41,6 @@ public class ConfigMonitor extends BroadcastReceiver implements DisplayListener
|
||||||
|
|
||||||
private static final String TAG = "ConfigMonitor";
|
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 mTmpPoint1 = new Point();
|
||||||
private final Point mTmpPoint2 = new Point();
|
private final Point mTmpPoint2 = new Point();
|
||||||
|
|
||||||
|
@ -78,11 +76,6 @@ public class ConfigMonitor extends BroadcastReceiver implements DisplayListener
|
||||||
// Listen for configuration change
|
// Listen for configuration change
|
||||||
mContext.registerReceiver(this, new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED));
|
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
|
// Listen for display manager change
|
||||||
mContext.getSystemService(DisplayManager.class)
|
mContext.getSystemService(DisplayManager.class)
|
||||||
.registerDisplayListener(this, new Handler(UiThreadHelper.getBackgroundLooper()));
|
.registerDisplayListener(this, new Handler(UiThreadHelper.getBackgroundLooper()));
|
||||||
|
@ -91,12 +84,6 @@ public class ConfigMonitor extends BroadcastReceiver implements DisplayListener
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
Configuration config = context.getResources().getConfiguration();
|
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) {
|
if (mFontScale != config.fontScale || mDensity != config.densityDpi) {
|
||||||
Log.d(TAG, "Configuration changed.");
|
Log.d(TAG, "Configuration changed.");
|
||||||
notifyChange();
|
notifyChange();
|
||||||
|
|
Loading…
Reference in New Issue