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

Commit 32352217 authored by Beverly's avatar Beverly
Browse files

Updates to automatic rule pages in Settings

- Re-added metrics for zen behavior preference controllers
- Dialogs in zen mode settings are rotate-friendly
- Automatic rules are refreshed on update state
- User-created (and default) automatic rules are always priority only and user cannot change this
- Automatic rules redesigned to have headers

Test: make ROBOTEST_FILTER=ZenModeAutomaticRulesPreferenceControllerTest RunSettingsRoboTests -j40
Bug: 63077372
Fixes: 68324465
Fixes: 69057696
Change-Id: I163acef2715dd4e60bfc08207f0e22352c4c0e28
parent 91fff309
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -6741,6 +6741,9 @@
    <!--  Do not disturb: Title for the zen mode automatic rules page in settings. [CHAR LIMIT=30] -->
    <string name="zen_mode_automation_settings_page_title">Automatic rules</string>
    <!--  Do not disturb: Title for a specific zen mode automatic rule in settings. [CHAR LIMIT=30] -->
    <string name="zen_mode_automatic_rule_settings_page_title">Automatic rule</string>
    <!--  Do not disturb: Title for the zen mode automation option Suggestion. [CHAR LIMIT=50] -->
    <string name="zen_mode_automation_suggestion_title">Set Do Not Disturb rules</string>
+12 −8
Original line number Diff line number Diff line
@@ -15,8 +15,18 @@
     limitations under the License.
-->

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    android:key="zen_mode_event_rule_settings" >
<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:key="zen_mode_event_rule_settings"
    android:title="@string/zen_mode_automatic_rule_settings_page_title">

    <com.android.settings.applications.LayoutPreference
        android:key="pref_app_header"
        android:layout="@layout/settings_entity_header" />

    <com.android.settings.applications.LayoutPreference
        android:key="zen_automatic_rule_switch"
        android:layout="@layout/styled_switch_bar" />

    <!-- Rule name -->
    <Preference
@@ -36,10 +46,4 @@
        android:title="@string/zen_mode_event_rule_reply"
        android:summary="%s" />

    <!-- Zen mode -->
    <DropDownPreference
        android:key="zen_mode"
        android:title="@string/zen_mode_settings_title"
        android:summary="%s" />

</PreferenceScreen>
+12 −9
Original line number Diff line number Diff line
@@ -15,8 +15,18 @@
     limitations under the License.
-->

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    android:key="zen_mode_schedule_rule_settings" >
<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:key="zen_mode_schedule_rule_settings"
    android:title="@string/zen_mode_automatic_rule_settings_page_title">

    <com.android.settings.applications.LayoutPreference
        android:key="pref_app_header"
        android:layout="@layout/settings_entity_header" />

    <com.android.settings.applications.LayoutPreference
        android:key="zen_automatic_rule_switch"
        android:layout="@layout/styled_switch_bar" />

    <!-- Rule name -->
    <Preference
@@ -39,11 +49,4 @@
        android:summary="@string/zen_mode_schedule_alarm_summary"
        android:order="99" />

    <!-- Zen mode -->
    <DropDownPreference
            android:key="zen_mode"
            android:title="@string/zen_mode_settings_title"
            android:order="100"
            android:summary="%s" />

</PreferenceScreen>
+32 −19
Original line number Diff line number Diff line
@@ -29,8 +29,9 @@ import android.service.notification.ConditionProviderService;
import android.service.notification.ZenModeConfig;
import android.support.v7.preference.Preference;

import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;

import java.util.Arrays;
import java.util.Comparator;
@@ -38,19 +39,19 @@ import java.util.Map;
import java.util.Set;

abstract public class AbstractZenModeAutomaticRulePreferenceController extends
        AbstractPreferenceController implements PreferenceControllerMixin {
        AbstractZenModePreferenceController implements PreferenceControllerMixin {

    private static final String TAG = "ZenModeAutomaticRule";
    protected ZenModeBackend mBackend;
    protected Fragment mParent;
    protected Set<Map.Entry<String, AutomaticZenRule>> mRules;
    protected PackageManager mPm;

    public AbstractZenModeAutomaticRulePreferenceController(Context context, Fragment parent) {
        super(context);
    public AbstractZenModeAutomaticRulePreferenceController(Context context, String key, Fragment
            parent, Lifecycle lifecycle) {
        super(context, key, lifecycle);
        mBackend = ZenModeBackend.getInstance(context);
        mParent = parent;
        mPm = mContext.getPackageManager();
        mParent = parent;
    }

    @Override
@@ -65,19 +66,9 @@ abstract public class AbstractZenModeAutomaticRulePreferenceController extends
        return ruleMap.entrySet();
    }

    protected void showNameRuleDialog(final ZenRuleInfo ri) {
        new ZenRuleNameDialog(mContext, null, ri.defaultConditionId) {
            @Override
            public void onOk(String ruleName) {
                AutomaticZenRule rule = new AutomaticZenRule(ruleName, ri.serviceComponent,
                        ri.defaultConditionId, NotificationManager.INTERRUPTION_FILTER_PRIORITY,
                        true);
                String savedRuleId = mBackend.addZenRule(rule);
                if (savedRuleId != null) {
                    mParent.startActivity(getRuleIntent(ri.settingsAction, null, savedRuleId));
                }
            }
        }.show();
    protected void showNameRuleDialog(final ZenRuleInfo ri, Fragment parent) {
        ZenRuleNameDialog.show(parent, null, ri.defaultConditionId, new
                RuleNameChangeListener(ri));
    }

    protected Map.Entry<String, AutomaticZenRule>[] sortedRules() {
@@ -157,4 +148,26 @@ abstract public class AbstractZenModeAutomaticRulePreferenceController extends
        }
        return null;
    }

    public class RuleNameChangeListener implements ZenRuleNameDialog.PositiveClickListener {
        ZenRuleInfo mRuleInfo;

        public RuleNameChangeListener(ZenRuleInfo ruleInfo) {
            mRuleInfo = ruleInfo;
        }

        @Override
        public void onOk(String ruleName, Fragment parent) {
            mMetricsFeatureProvider.action(mContext,
                    MetricsProto.MetricsEvent.ACTION_ZEN_MODE_RULE_NAME_CHANGE_OK);
            AutomaticZenRule rule = new AutomaticZenRule(ruleName, mRuleInfo.serviceComponent,
                    mRuleInfo.defaultConditionId,
                    NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
            String savedRuleId = mBackend.addZenRule(rule);
            if (savedRuleId != null) {
                parent.startActivity(getRuleIntent(mRuleInfo.settingsAction, null,
                        savedRuleId));
            }
        }
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@ import android.util.Slog;

import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
@@ -51,6 +53,7 @@ abstract public class AbstractZenModePreferenceController extends
    private final String KEY;
    final private NotificationManager mNotificationManager;
    protected static ZenModeConfigWrapper mZenModeConfigWrapper;
    protected MetricsFeatureProvider mMetricsFeatureProvider;

    public AbstractZenModePreferenceController(Context context, String key,
            Lifecycle lifecycle) {
@@ -62,6 +65,9 @@ abstract public class AbstractZenModePreferenceController extends
        KEY = key;
        mNotificationManager = (NotificationManager) context.getSystemService(
                Context.NOTIFICATION_SERVICE);

        final FeatureFactory featureFactory = FeatureFactory.getFactory(mContext);
        mMetricsFeatureProvider = featureFactory.getMetricsFeatureProvider();
    }

    @Override
Loading