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:
@@ -21,11 +21,13 @@ import android.app.StatusBarManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.PersistableBundle;
|
||||
import android.provider.Settings;
|
||||
import android.provider.Settings.Global;
|
||||
import android.service.notification.ZenModeConfig;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
@@ -35,11 +37,21 @@ public class DndCondition extends Condition {
|
||||
private static final String TAG = "DndCondition";
|
||||
private static final String KEY_STATE = "state";
|
||||
|
||||
private boolean mRegistered;
|
||||
|
||||
@VisibleForTesting
|
||||
static final IntentFilter DND_FILTER =
|
||||
new IntentFilter(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED_INTERNAL);
|
||||
|
||||
private int mZen;
|
||||
private ZenModeConfig mConfig;
|
||||
private final Receiver mReceiver;
|
||||
|
||||
public DndCondition(ConditionManager manager) {
|
||||
super(manager);
|
||||
mReceiver = new Receiver();
|
||||
mManager.getContext().registerReceiver(mReceiver, DND_FILTER);
|
||||
mRegistered = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -68,11 +80,6 @@ public class DndCondition extends Condition {
|
||||
mZen = bundle.getInt(KEY_STATE, Global.ZEN_MODE_OFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?> getReceiverClass() {
|
||||
return Receiver.class;
|
||||
}
|
||||
|
||||
private CharSequence getZenState() {
|
||||
switch (mZen) {
|
||||
case Settings.Global.ZEN_MODE_ALARMS:
|
||||
@@ -149,7 +156,16 @@ public class DndCondition extends Condition {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldAlwaysListenToBroadcast() {
|
||||
return true;
|
||||
public void onResume() {
|
||||
if (!mRegistered) {
|
||||
mManager.getContext().registerReceiver(mReceiver, DND_FILTER);
|
||||
mRegistered = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
mManager.getContext().unregisterReceiver(mReceiver);
|
||||
mRegistered = false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user