Only register conditions receiver when needed.
1. Update the dnd receiver to listen when dashboard summary running. - remove the dnd receiver from Android manifest, and create it inside the dnd condition. - add lifecycle implementation to condition manager, so that the dnd condition can know when to register and unregister the receiver. - remove getReceiverClass() from dnd condition so that its receiver will not be disabled by the default condition handling when condition is silenced. 2. Remove all other conditions receiver from Android manifest. - the broadcast receivers for HotspotCondition, AirplaneModeCondition, CellularDataCondition from the manifest and create them inside the condition classes. - update Condition.onSilenceChanged() to register/unregister the receivers instead of enable/disable the receiver class. Change-Id: Iea6288382680df2b02884d1934b8db85daae404c Fix: 35968517 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -16,18 +16,17 @@
|
||||
|
||||
package com.android.settings.dashboard.conditional;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.IntentFilter;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.PersistableBundle;
|
||||
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
import static android.content.pm.PackageManager.DONT_KILL_APP;
|
||||
|
||||
public abstract class Condition {
|
||||
|
||||
private static final String KEY_SILENCE = "silence";
|
||||
@@ -49,12 +48,6 @@ public abstract class Condition {
|
||||
Condition(ConditionManager manager, MetricsFeatureProvider metricsFeatureProvider) {
|
||||
mManager = manager;
|
||||
mMetricsFeatureProvider = metricsFeatureProvider;
|
||||
Class<?> receiverClass = getReceiverClass();
|
||||
if (receiverClass != null && shouldAlwaysListenToBroadcast()) {
|
||||
PackageManager pm = mManager.getContext().getPackageManager();
|
||||
pm.setComponentEnabledSetting(new ComponentName(mManager.getContext(), receiverClass),
|
||||
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, DONT_KILL_APP);
|
||||
}
|
||||
}
|
||||
|
||||
void restoreState(PersistableBundle bundle) {
|
||||
@@ -110,29 +103,25 @@ public abstract class Condition {
|
||||
}
|
||||
}
|
||||
|
||||
private void onSilenceChanged(boolean silenced) {
|
||||
if (shouldAlwaysListenToBroadcast()) {
|
||||
// Don't try to disable BroadcastReceiver if we want it always on.
|
||||
@VisibleForTesting
|
||||
void onSilenceChanged(boolean silenced) {
|
||||
final BroadcastReceiver receiver = getReceiver();
|
||||
if (receiver == null) {
|
||||
return;
|
||||
}
|
||||
Class<?> clz = getReceiverClass();
|
||||
if (clz == null) {
|
||||
return;
|
||||
if (silenced) {
|
||||
mManager.getContext().registerReceiver(receiver, getIntentFilter());
|
||||
} else {
|
||||
mManager.getContext().unregisterReceiver(receiver);
|
||||
}
|
||||
// Only need to listen for changes when its been silenced.
|
||||
PackageManager pm = mManager.getContext().getPackageManager();
|
||||
pm.setComponentEnabledSetting(new ComponentName(mManager.getContext(), clz),
|
||||
silenced ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
|
||||
: PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||||
DONT_KILL_APP);
|
||||
}
|
||||
|
||||
protected Class<?> getReceiverClass() {
|
||||
protected BroadcastReceiver getReceiver() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected boolean shouldAlwaysListenToBroadcast() {
|
||||
return false;
|
||||
protected IntentFilter getIntentFilter() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean shouldShow() {
|
||||
@@ -143,6 +132,12 @@ public abstract class Condition {
|
||||
return mLastStateChange;
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
}
|
||||
|
||||
// State.
|
||||
public abstract void refreshState();
|
||||
|
||||
|
Reference in New Issue
Block a user