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

Commit 4267835c authored by Matías Hernández's avatar Matías Hernández Committed by Android (Google) Code Review
Browse files

Merge "Populate new fields in modes created via Settings" into main

parents 1236e94c a1d8044c
Loading
Loading
Loading
Loading
+15 −6
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.settings.notification.zen;
import static android.app.NotificationManager.EXTRA_AUTOMATIC_RULE_ID;

import android.app.AutomaticZenRule;
import android.app.Flags;
import android.app.NotificationManager;
import android.app.settings.SettingsEnums;
import android.content.ComponentName;
@@ -28,11 +29,9 @@ import android.content.pm.ActivityInfo;
import android.content.pm.ComponentInfo;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.os.Binder;
import android.provider.Settings;
import android.service.notification.ConditionProviderService;
import android.util.Log;
import android.util.Slog;

import androidx.fragment.app.Fragment;
import androidx.preference.Preference;
@@ -41,7 +40,6 @@ import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.Lifecycle;

import java.util.Map;
import java.util.Objects;

abstract public class AbstractZenModeAutomaticRulePreferenceController extends
        AbstractZenModePreferenceController implements PreferenceControllerMixin {
@@ -166,9 +164,20 @@ abstract public class AbstractZenModeAutomaticRulePreferenceController extends
        public void onOk(String ruleName, Fragment parent) {
            mMetricsFeatureProvider.action(mContext,
                    SettingsEnums.ACTION_ZEN_MODE_RULE_NAME_CHANGE_OK);
            AutomaticZenRule rule = new AutomaticZenRule(ruleName, mRuleInfo.serviceComponent,
            AutomaticZenRule rule;
            if (Flags.modesApi() && Flags.modesUi()) {
                rule = new AutomaticZenRule.Builder(ruleName, mRuleInfo.defaultConditionId)
                        .setType(mRuleInfo.type)
                        .setOwner(mRuleInfo.serviceComponent)
                        .setConfigurationActivity(mRuleInfo.configurationActivity)
                        .setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_PRIORITY)
                        .setTriggerDescription(mRuleInfo.defaultTriggerDescription)
                        .build();
            } else {
                rule = new AutomaticZenRule(ruleName, mRuleInfo.serviceComponent,
                        mRuleInfo.configurationActivity, mRuleInfo.defaultConditionId, null,
                        NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
            }
            String savedRuleId = mBackend.addZenRule(rule);
            if (savedRuleId != null) {
                parent.startActivity(getRuleIntent(mRuleInfo.settingsAction, null,
+2 −2
Original line number Diff line number Diff line
@@ -138,7 +138,7 @@ public class ZenModeEventRuleSettings extends ZenModeRuleSettingsBase {
                mEvent.userId = Integer.parseInt(key[0]);
                mEvent.calendarId = key[1].equals("") ? null : Long.parseLong(key[1]);
                mEvent.calName = key[2].equals("") ? null : key[2];
                updateRule(ZenModeConfig.toEventConditionId(mEvent));
                updateEventRule(mEvent);
                return true;
            }
        });
@@ -160,7 +160,7 @@ public class ZenModeEventRuleSettings extends ZenModeRuleSettingsBase {
                final int reply = Integer.parseInt((String) newValue);
                if (reply == mEvent.reply) return false;
                mEvent.reply = reply;
                updateRule(ZenModeConfig.toEventConditionId(mEvent));
                updateEventRule(mEvent);
                return true;
            }
        });
+17 −3
Original line number Diff line number Diff line
@@ -24,9 +24,10 @@ import android.app.NotificationManager;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.service.notification.ConditionProviderService;
import android.service.notification.SystemZenRules;
import android.service.notification.ZenModeConfig;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
@@ -162,8 +163,21 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase {
        updatePreference(mActionButtons);
    }

    protected void updateRule(Uri newConditionId) {
        mRule.setConditionId(newConditionId);
    protected void updateScheduleRule(ZenModeConfig.ScheduleInfo schedule) {
        mRule.setConditionId(ZenModeConfig.toScheduleConditionId(schedule));
        if (Flags.modesApi() && Flags.modesUi()) {
            mRule.setTriggerDescription(
                    SystemZenRules.getTriggerDescriptionForScheduleTime(mContext, schedule));
        }
        mBackend.updateZenRule(mId, mRule);
    }

    protected void updateEventRule(ZenModeConfig.EventInfo event) {
        mRule.setConditionId(ZenModeConfig.toEventConditionId(event));
        if (Flags.modesApi() && Flags.modesUi()) {
            mRule.setTriggerDescription(
                    SystemZenRules.getTriggerDescriptionForScheduleEvent(mContext, event));
        }
        mBackend.updateZenRule(mId, mRule);
    }

+4 −4
Original line number Diff line number Diff line
@@ -108,7 +108,7 @@ public class ZenModeScheduleRuleSettings extends ZenModeRuleSettingsBase {
                if (DEBUG) Log.d(TAG, "onPrefChange start h=" + hour + " m=" + minute);
                mSchedule.startHour = hour;
                mSchedule.startMinute = minute;
                updateRule(ZenModeConfig.toScheduleConditionId(mSchedule));
                updateScheduleRule(mSchedule);
                return true;
            }
        });
@@ -130,7 +130,7 @@ public class ZenModeScheduleRuleSettings extends ZenModeRuleSettingsBase {
                if (DEBUG) Log.d(TAG, "onPrefChange end h=" + hour + " m=" + minute);
                mSchedule.endHour = hour;
                mSchedule.endMinute = minute;
                updateRule(ZenModeConfig.toScheduleConditionId(mSchedule));
                updateScheduleRule(mSchedule);
                return true;
            }
        });
@@ -142,7 +142,7 @@ public class ZenModeScheduleRuleSettings extends ZenModeRuleSettingsBase {
            @Override
            public boolean onPreferenceChange(Preference preference, Object o) {
                mSchedule.exitAtAlarm = (Boolean) o;
                updateRule(ZenModeConfig.toScheduleConditionId(mSchedule));
                updateScheduleRule(mSchedule);
                return true;
            }
        });
@@ -214,7 +214,7 @@ public class ZenModeScheduleRuleSettings extends ZenModeRuleSettingsBase {
                        if (Arrays.equals(days, mSchedule.days)) return;
                        if (DEBUG) Log.d(TAG, "days.onChanged days=" + Arrays.toString(days));
                        mSchedule.days = days;
                        updateRule(ZenModeConfig.toScheduleConditionId(mSchedule));
                        updateScheduleRule(mSchedule);
                    }
                })
                .setOnDismissListener(new OnDismissListener() {
+7 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.util.Log;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;

import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.dashboard.RestrictedDashboardFragment;
import com.android.settingslib.core.AbstractPreferenceController;

@@ -59,7 +60,12 @@ abstract public class ZenModeSettingsBase extends RestrictedDashboardFragment {
    public void onAttach(Context context) {
        super.onAttach(context);
        mContext = context;
        mBackend = ZenModeBackend.getInstance(mContext);
        setBackend(ZenModeBackend.getInstance(mContext));
    }

    @VisibleForTesting
    void setBackend(ZenModeBackend backend) {
        mBackend = backend;
    }

    @Override
Loading