First bits of "add a mode"

* Preference below the modes list.
* Temporarily triggers addition of a mode with default name and type=SCHEDULE_TIME (type will be "manual only" later).
* Fixed sorting of modes in the list when refreshing (new modes were added at the bottom instead of where they should, the same would've happened for renamed modes).
* Minor polishes (extracted fragment launch to helper class, renamed item controller class for clarity).

Test: atest com.android.settings.notification.modes
Bug: 326442408
Fixes: 347198709
Flag: android.app.modes_ui
Change-Id: Ie276c92181c5374faf74592433595e7e15a5efc0
This commit is contained in:
Matías Hernández
2024-06-14 15:46:51 +02:00
parent 16f9205fb6
commit 8409c39d94
9 changed files with 263 additions and 40 deletions

View File

@@ -30,6 +30,8 @@ import android.provider.ContactsContract;
import android.provider.Settings;
import android.service.notification.Condition;
import android.service.notification.ConversationChannelWrapper;
import android.service.notification.SystemZenRules;
import android.service.notification.ZenAdapters;
import android.service.notification.ZenModeConfig;
import android.util.Log;
@@ -242,4 +244,32 @@ class ZenModesBackend {
}
mNotificationManager.removeAutomaticZenRule(mode.getId(), /* fromUser= */ true);
}
/**
* Creates a new custom mode with the provided {@code name}. The mode will be "manual" (i.e.
* not have a schedule), this can be later updated by the user in the mode settings page.
*
* @return the created mode. Only {@code null} if creation failed due to an internal error
*/
@Nullable
ZenMode addCustomMode(String name) {
ZenModeConfig.ScheduleInfo schedule = new ZenModeConfig.ScheduleInfo();
schedule.days = ZenModeConfig.ALL_DAYS;
schedule.startHour = 22;
schedule.endHour = 7;
// TODO: b/326442408 - Create as "manual" (i.e. no trigger) instead of schedule-time.
AutomaticZenRule rule = new AutomaticZenRule.Builder(name,
ZenModeConfig.toScheduleConditionId(schedule))
.setPackage(ZenModeConfig.getScheduleConditionProvider().getPackageName())
.setType(AutomaticZenRule.TYPE_SCHEDULE_CALENDAR)
.setOwner(ZenModeConfig.getScheduleConditionProvider())
.setTriggerDescription(SystemZenRules.getTriggerDescriptionForScheduleTime(
mContext, schedule))
.setManualInvocationAllowed(true)
.build();
String ruleId = mNotificationManager.addAutomaticZenRule(rule);
return getMode(ruleId);
}
}