Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd775d9f authored by Beverly's avatar Beverly
Browse files

ZenModeBackend gets newest notification policy

Previously, notification policy wouldn't be updated
so behavior zen mode settings pages wouldn't update
when an app changed the notification policy.  Now
notification policy will be updated on updateState of
each AbstractZenModePreferenceController.

Bug: 70662324
Test: make RunSettingsRoboTests -j40
Change-Id: Ibee20e4f27e0c833e05230ea8a3ea2cc75ae6bf0
parent 69294a5d
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import android.service.notification.ScheduleCalendar;
import android.service.notification.ZenModeConfig;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.util.Slog;

import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.core.PreferenceControllerMixin;
@@ -54,6 +53,7 @@ abstract public class AbstractZenModePreferenceController extends
    final private NotificationManager mNotificationManager;
    protected static ZenModeConfigWrapper mZenModeConfigWrapper;
    protected MetricsFeatureProvider mMetricsFeatureProvider;
    protected final ZenModeBackend mBackend;

    public AbstractZenModePreferenceController(Context context, String key,
            Lifecycle lifecycle) {
@@ -68,6 +68,7 @@ abstract public class AbstractZenModePreferenceController extends

        final FeatureFactory featureFactory = FeatureFactory.getFactory(mContext);
        mMetricsFeatureProvider = featureFactory.getMetricsFeatureProvider();
        mBackend = ZenModeBackend.getInstance(context);
    }

    @Override
@@ -90,6 +91,14 @@ abstract public class AbstractZenModePreferenceController extends
        }
    }

    @Override
    public void updateState(Preference preference) {
        super.updateState(preference);

        mBackend.updatePolicy();
        mBackend.updateZenMode();
    }

    protected NotificationManager.Policy getPolicy() {
        return mNotificationManager.getNotificationPolicy();
    }
@@ -99,8 +108,8 @@ abstract public class AbstractZenModePreferenceController extends
    }

    protected int getZenMode() {
        return Settings.Global.getInt(mContext.getContentResolver(),
                Settings.Global.ZEN_MODE, 0);
        return Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.ZEN_MODE,
                mBackend.mZenMode);
    }

    class SettingObserver extends ContentObserver {
@@ -188,7 +197,6 @@ abstract public class AbstractZenModePreferenceController extends
                    }
                }


                return endTimeMs;
            }

+0 −2
Original line number Diff line number Diff line
@@ -30,11 +30,9 @@ public class ZenModeAlarmsPreferenceController extends
        AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener {

    protected static final String KEY = "zen_mode_alarms";
    private final ZenModeBackend mBackend;

    public ZenModeAlarmsPreferenceController(Context context, Lifecycle lifecycle) {
        super(context, KEY, lifecycle);
        mBackend = ZenModeBackend.getInstance(context);
    }

    @Override
+0 −1
Original line number Diff line number Diff line
@@ -82,7 +82,6 @@ public class ZenModeBackend {
        mZenMode = zenMode;
    }

    /** gets last zen mode set by setZenMode or updateZenMode **/
    protected int getZenMode() {
        mZenMode = Settings.Global.getInt(mContext.getContentResolver(),
                Settings.Global.ZEN_MODE, mZenMode);
+0 −2
Original line number Diff line number Diff line
@@ -34,11 +34,9 @@ public class ZenModeButtonPreferenceController extends AbstractZenModePreference
    protected static final String KEY = "zen_mode_settings_button_container";
    private Button mZenButtonOn;
    private Button mZenButtonOff;
    private ZenModeBackend mBackend;

    public ZenModeButtonPreferenceController(Context context, Lifecycle lifecycle) {
        super(context, KEY, lifecycle);
        mBackend = ZenModeBackend.getInstance(context);
    }

    @Override
+0 −2
Original line number Diff line number Diff line
@@ -26,11 +26,9 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenModeCallsPreferenceController extends AbstractZenModePreferenceController {

    protected static final String KEY = "zen_mode_calls";
    private final ZenModeBackend mBackend;

    public ZenModeCallsPreferenceController(Context context, Lifecycle lifecycle) {
        super(context, KEY, lifecycle);
        mBackend = ZenModeBackend.getInstance(context);
    }

    @Override
Loading