Merge "Hide ZenMode.getRule() - Settings" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
a8b18f953d
@@ -48,21 +48,22 @@ class ConfigurationActivityHelper {
|
|||||||
Intent getConfigurationActivityIntentForMode(ZenMode zenMode,
|
Intent getConfigurationActivityIntentForMode(ZenMode zenMode,
|
||||||
Function<ComponentName, ComponentInfo> approvedServiceFinder) {
|
Function<ComponentName, ComponentInfo> approvedServiceFinder) {
|
||||||
|
|
||||||
String owner = zenMode.getRule().getPackageName();
|
ZenMode.Owner owner = zenMode.getOwner();
|
||||||
ComponentName configActivity = null;
|
ComponentName configActivity = null;
|
||||||
if (zenMode.getRule().getConfigurationActivity() != null) {
|
if (owner.configurationActivity() != null) {
|
||||||
// If a configuration activity is present, use that directly in the intent
|
// If a configuration activity is present, use that directly in the intent
|
||||||
configActivity = zenMode.getRule().getConfigurationActivity();
|
configActivity = owner.configurationActivity();
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, look for a condition provider service for the rule's package
|
// Otherwise, look for a condition provider service for the rule's package
|
||||||
ComponentInfo ci = approvedServiceFinder.apply(zenMode.getRule().getOwner());
|
ComponentInfo ci = approvedServiceFinder.apply(owner.conditionProvider());
|
||||||
if (ci != null) {
|
if (ci != null) {
|
||||||
configActivity = extractConfigurationActivityFromComponent(ci);
|
configActivity = extractConfigurationActivityFromComponent(ci);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configActivity != null
|
if (configActivity != null
|
||||||
&& (owner == null || isSameOwnerPackage(owner, configActivity))
|
&& (owner.packageName() == null
|
||||||
|
|| isSameOwnerPackage(owner.packageName(), configActivity))
|
||||||
&& isResolvableActivity(configActivity)) {
|
&& isResolvableActivity(configActivity)) {
|
||||||
return new Intent()
|
return new Intent()
|
||||||
.setComponent(configActivity)
|
.setComponent(configActivity)
|
||||||
|
@@ -51,7 +51,7 @@ class ZenModeButtonPreferenceController extends AbstractZenModePreferenceControl
|
|||||||
@Override
|
@Override
|
||||||
public boolean isAvailable(ZenMode zenMode) {
|
public boolean isAvailable(ZenMode zenMode) {
|
||||||
return zenMode.isEnabled()
|
return zenMode.isEnabled()
|
||||||
&& (zenMode.isActive() || zenMode.getRule().isManualInvocationAllowed());
|
&& (zenMode.isActive() || zenMode.isManualInvocationAllowed());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -54,8 +54,8 @@ public class ZenModeEditNameIconFragment extends ZenModeEditNameIconFragmentBase
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
modeToUpdate.getRule().setName(mode.getRule().getName());
|
modeToUpdate.setName(mode.getName());
|
||||||
modeToUpdate.getRule().setIconResId(mode.getRule().getIconResId());
|
modeToUpdate.setIconResId(mode.getIconResId());
|
||||||
requireBackend().updateMode(modeToUpdate);
|
requireBackend().updateMode(modeToUpdate);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
@@ -128,13 +128,13 @@ public abstract class ZenModeEditNameIconFragmentBase extends DashboardFragment
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
final void setModeName(String name) {
|
final void setModeName(String name) {
|
||||||
checkNotNull(mZenMode).getRule().setName(Strings.nullToEmpty(name));
|
checkNotNull(mZenMode).setName(Strings.nullToEmpty(name));
|
||||||
forceUpdatePreferences(); // Updates confirmation button.
|
forceUpdatePreferences(); // Updates confirmation button.
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
final void setModeIcon(@DrawableRes int iconResId) {
|
final void setModeIcon(@DrawableRes int iconResId) {
|
||||||
checkNotNull(mZenMode).getRule().setIconResId(iconResId);
|
checkNotNull(mZenMode).setIconResId(iconResId);
|
||||||
forceUpdatePreferences(); // Updates icon at the top.
|
forceUpdatePreferences(); // Updates icon at the top.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settings.notification.modes;
|
package com.android.settings.notification.modes;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.service.notification.ZenModeConfig;
|
import android.service.notification.ZenModeConfig;
|
||||||
|
|
||||||
@@ -24,6 +26,7 @@ import androidx.preference.Preference;
|
|||||||
import androidx.preference.TwoStatePreference;
|
import androidx.preference.TwoStatePreference;
|
||||||
|
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
import com.android.settingslib.notification.modes.ZenMode;
|
||||||
|
import com.android.settingslib.notification.modes.ZenModeSchedules;
|
||||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,7 +43,7 @@ class ZenModeExitAtAlarmPreferenceController extends
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference, @NonNull ZenMode zenMode) {
|
public void updateState(Preference preference, @NonNull ZenMode zenMode) {
|
||||||
mSchedule = ZenModeConfig.tryParseScheduleConditionId(zenMode.getRule().getConditionId());
|
mSchedule = checkNotNull(ZenModeSchedules.getTimeSchedule(zenMode));
|
||||||
((TwoStatePreference) preference).setChecked(mSchedule.exitAtAlarm);
|
((TwoStatePreference) preference).setChecked(mSchedule.exitAtAlarm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -47,8 +47,7 @@ public class ZenModeNewCustomFragment extends ZenModeEditNameIconFragmentBase {
|
|||||||
? requireContext().getString(R.string.zen_mode_new_custom_default_name)
|
? requireContext().getString(R.string.zen_mode_new_custom_default_name)
|
||||||
: mode.getName();
|
: mode.getName();
|
||||||
|
|
||||||
ZenMode created = requireBackend().addCustomManualMode(modeName,
|
ZenMode created = requireBackend().addCustomManualMode(modeName, mode.getIconResId());
|
||||||
mode.getRule().getIconResId());
|
|
||||||
if (created != null) {
|
if (created != null) {
|
||||||
// Open the mode view fragment and close the "add mode" fragment, so exiting the mode
|
// Open the mode view fragment and close the "add mode" fragment, so exiting the mode
|
||||||
// view goes back to previous screen (which should be the modes list).
|
// view goes back to previous screen (which should be the modes list).
|
||||||
|
@@ -32,6 +32,7 @@ import androidx.preference.PreferenceCategory;
|
|||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
import com.android.settingslib.notification.modes.ZenMode;
|
||||||
|
import com.android.settingslib.notification.modes.ZenModeSchedules;
|
||||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -85,7 +86,7 @@ class ZenModeSetCalendarPreferenceController extends AbstractZenModePreferenceCo
|
|||||||
mReply.setOnPreferenceChangeListener(mReplyChangeListener);
|
mReply.setOnPreferenceChangeListener(mReplyChangeListener);
|
||||||
|
|
||||||
// Parse the zen mode's condition to update our EventInfo object.
|
// Parse the zen mode's condition to update our EventInfo object.
|
||||||
mEvent = ZenModeConfig.tryParseEventConditionId(zenMode.getRule().getConditionId());
|
mEvent = ZenModeSchedules.getCalendarSchedule(zenMode);
|
||||||
if (mEvent != null) {
|
if (mEvent != null) {
|
||||||
reloadCalendar();
|
reloadCalendar();
|
||||||
updatePrefValues();
|
updatePrefValues();
|
||||||
|
@@ -32,6 +32,7 @@ import androidx.preference.Preference;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
import com.android.settingslib.notification.modes.ZenMode;
|
||||||
|
import com.android.settingslib.notification.modes.ZenModeSchedules;
|
||||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||||
import com.android.settingslib.widget.LayoutPreference;
|
import com.android.settingslib.widget.LayoutPreference;
|
||||||
|
|
||||||
@@ -62,7 +63,7 @@ class ZenModeSetSchedulePreferenceController extends AbstractZenModePreferenceCo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference, @NonNull ZenMode zenMode) {
|
public void updateState(Preference preference, @NonNull ZenMode zenMode) {
|
||||||
mSchedule = ZenModeConfig.tryParseScheduleConditionId(zenMode.getRule().getConditionId());
|
mSchedule = ZenModeSchedules.getTimeSchedule(zenMode);
|
||||||
LayoutPreference layoutPref = (LayoutPreference) preference;
|
LayoutPreference layoutPref = (LayoutPreference) preference;
|
||||||
|
|
||||||
TextView start = layoutPref.findViewById(R.id.start_time);
|
TextView start = layoutPref.findViewById(R.id.start_time);
|
||||||
|
@@ -20,7 +20,6 @@ import static android.app.AutomaticZenRule.TYPE_BEDTIME;
|
|||||||
import static android.app.AutomaticZenRule.TYPE_DRIVING;
|
import static android.app.AutomaticZenRule.TYPE_DRIVING;
|
||||||
import static android.app.AutomaticZenRule.TYPE_SCHEDULE_CALENDAR;
|
import static android.app.AutomaticZenRule.TYPE_SCHEDULE_CALENDAR;
|
||||||
import static android.app.AutomaticZenRule.TYPE_SCHEDULE_TIME;
|
import static android.app.AutomaticZenRule.TYPE_SCHEDULE_TIME;
|
||||||
import static android.service.notification.ZenModeConfig.tryParseScheduleConditionId;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
@@ -43,6 +42,7 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settingslib.PrimarySwitchPreference;
|
import com.android.settingslib.PrimarySwitchPreference;
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
import com.android.settingslib.notification.modes.ZenMode;
|
||||||
|
import com.android.settingslib.notification.modes.ZenModeSchedules;
|
||||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
@@ -105,8 +105,7 @@ class ZenModeTriggerUpdatePreferenceController extends AbstractZenModePreference
|
|||||||
|
|
||||||
// [Clock Icon] 9:00 - 17:00 / Sun-Mon
|
// [Clock Icon] 9:00 - 17:00 / Sun-Mon
|
||||||
preference.setIcon(com.android.internal.R.drawable.ic_zen_mode_type_schedule_time);
|
preference.setIcon(com.android.internal.R.drawable.ic_zen_mode_type_schedule_time);
|
||||||
ZenModeConfig.ScheduleInfo schedule =
|
ZenModeConfig.ScheduleInfo schedule = ZenModeSchedules.getTimeSchedule(mode);
|
||||||
tryParseScheduleConditionId(mode.getRule().getConditionId());
|
|
||||||
if (schedule != null) {
|
if (schedule != null) {
|
||||||
preference.setTitle(SystemZenRules.getTimeSummary(mContext, schedule));
|
preference.setTitle(SystemZenRules.getTimeSummary(mContext, schedule));
|
||||||
String shortDaysSummary = SystemZenRules.getDaysOfWeekShort(mContext, schedule);
|
String shortDaysSummary = SystemZenRules.getDaysOfWeekShort(mContext, schedule);
|
||||||
@@ -138,7 +137,7 @@ class ZenModeTriggerUpdatePreferenceController extends AbstractZenModePreference
|
|||||||
@SuppressLint("SwitchIntDef")
|
@SuppressLint("SwitchIntDef")
|
||||||
private void setUpForAppTrigger(Preference preference, ZenMode mode) {
|
private void setUpForAppTrigger(Preference preference, ZenMode mode) {
|
||||||
// App-owned mode may have triggerDescription, configurationActivity, or both/neither.
|
// App-owned mode may have triggerDescription, configurationActivity, or both/neither.
|
||||||
mServiceListing.loadApprovedComponents(mode.getRule().getPackageName());
|
mServiceListing.loadApprovedComponents(mode.getOwnerPackage());
|
||||||
Intent configurationIntent =
|
Intent configurationIntent =
|
||||||
mConfigurationActivityHelper.getConfigurationActivityIntentForMode(
|
mConfigurationActivityHelper.getConfigurationActivityIntentForMode(
|
||||||
mode, mServiceListing::findService);
|
mode, mServiceListing::findService);
|
||||||
@@ -152,11 +151,11 @@ class ZenModeTriggerUpdatePreferenceController extends AbstractZenModePreference
|
|||||||
String summary;
|
String summary;
|
||||||
if (!Strings.isNullOrEmpty(mode.getTriggerDescription())) {
|
if (!Strings.isNullOrEmpty(mode.getTriggerDescription())) {
|
||||||
summary = mode.getTriggerDescription();
|
summary = mode.getTriggerDescription();
|
||||||
} else if (!Strings.isNullOrEmpty(mode.getRule().getPackageName())) {
|
} else if (!Strings.isNullOrEmpty(mode.getOwnerPackage())) {
|
||||||
String appName = null;
|
String appName = null;
|
||||||
try {
|
try {
|
||||||
ApplicationInfo appInfo = mPackageManager.getApplicationInfo(
|
ApplicationInfo appInfo = mPackageManager.getApplicationInfo(
|
||||||
mode.getRule().getPackageName(), 0);
|
mode.getOwnerPackage(), 0);
|
||||||
appName = appInfo.loadLabel(mPackageManager).toString();
|
appName = appInfo.loadLabel(mPackageManager).toString();
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
Log.e(TAG, "Couldn't resolve owner for mode: " + mode);
|
Log.e(TAG, "Couldn't resolve owner for mode: " + mode);
|
||||||
@@ -219,7 +218,7 @@ class ZenModeTriggerUpdatePreferenceController extends AbstractZenModePreference
|
|||||||
private void setModeEnabled(boolean enabled) {
|
private void setModeEnabled(boolean enabled) {
|
||||||
saveMode((zenMode) -> {
|
saveMode((zenMode) -> {
|
||||||
if (enabled != zenMode.isEnabled()) {
|
if (enabled != zenMode.isEnabled()) {
|
||||||
zenMode.getRule().setEnabled(enabled);
|
zenMode.setEnabled(enabled);
|
||||||
}
|
}
|
||||||
return zenMode;
|
return zenMode;
|
||||||
});
|
});
|
||||||
|
@@ -125,7 +125,7 @@ public class ZenModesListFragment extends ZenModesFragmentBase {
|
|||||||
// If we find a new mode owned by the same package, presumably that's it. Open its page.
|
// If we find a new mode owned by the same package, presumably that's it. Open its page.
|
||||||
Optional<ZenMode> createdZenMode = mBackend.getModes().stream()
|
Optional<ZenMode> createdZenMode = mBackend.getModes().stream()
|
||||||
.filter(m -> !previousIds.contains(m.getId()))
|
.filter(m -> !previousIds.contains(m.getId()))
|
||||||
.filter(m -> m.getRule().getPackageName().equals(activityInvoked.getPackageName()))
|
.filter(m -> activityInvoked.getPackageName().equals(m.getOwnerPackage()))
|
||||||
.findFirst();
|
.findFirst();
|
||||||
createdZenMode.ifPresent(
|
createdZenMode.ifPresent(
|
||||||
mode ->
|
mode ->
|
||||||
|
@@ -130,7 +130,7 @@ public final class InterruptionFilterPreferenceControllerTest {
|
|||||||
verify(mBackend).updateMode(captor.capture());
|
verify(mBackend).updateMode(captor.capture());
|
||||||
assertThat(captor.getValue().getPolicy().getPriorityCategoryAlarms())
|
assertThat(captor.getValue().getPolicy().getPriorityCategoryAlarms())
|
||||||
.isEqualTo(STATE_DISALLOW);
|
.isEqualTo(STATE_DISALLOW);
|
||||||
assertThat(captor.getValue().getRule().getInterruptionFilter())
|
assertThat(captor.getValue().getInterruptionFilter())
|
||||||
.isEqualTo(INTERRUPTION_FILTER_PRIORITY);
|
.isEqualTo(INTERRUPTION_FILTER_PRIORITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,7 +162,7 @@ public final class InterruptionFilterPreferenceControllerTest {
|
|||||||
verify(mBackend).updateMode(captor.capture());
|
verify(mBackend).updateMode(captor.capture());
|
||||||
assertThat(captor.getValue().getPolicy().getPriorityCategoryAlarms())
|
assertThat(captor.getValue().getPolicy().getPriorityCategoryAlarms())
|
||||||
.isEqualTo(STATE_DISALLOW);
|
.isEqualTo(STATE_DISALLOW);
|
||||||
assertThat(captor.getValue().getRule().getInterruptionFilter())
|
assertThat(captor.getValue().getInterruptionFilter())
|
||||||
.isEqualTo(INTERRUPTION_FILTER_ALL);
|
.isEqualTo(INTERRUPTION_FILTER_ALL);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -183,7 +183,7 @@ public final class ZenModeAppsPreferenceControllerTest {
|
|||||||
// NONE is not actually propagated to the backend as an interruption filter;
|
// NONE is not actually propagated to the backend as an interruption filter;
|
||||||
// the filter is set to priority, and sounds and visual effects are disallowed.
|
// the filter is set to priority, and sounds and visual effects are disallowed.
|
||||||
// See AbstractZenModePreferenceController.
|
// See AbstractZenModePreferenceController.
|
||||||
assertThat(captor.getValue().getRule().getInterruptionFilter())
|
assertThat(captor.getValue().getInterruptionFilter())
|
||||||
.isEqualTo(INTERRUPTION_FILTER_PRIORITY);
|
.isEqualTo(INTERRUPTION_FILTER_PRIORITY);
|
||||||
|
|
||||||
// After screen is refreshed, NONE is now checked; others are unchecked.
|
// After screen is refreshed, NONE is now checked; others are unchecked.
|
||||||
@@ -217,7 +217,7 @@ public final class ZenModeAppsPreferenceControllerTest {
|
|||||||
ArgumentCaptor<ZenMode> captor = ArgumentCaptor.forClass(ZenMode.class);
|
ArgumentCaptor<ZenMode> captor = ArgumentCaptor.forClass(ZenMode.class);
|
||||||
verify(mBackend).updateMode(captor.capture());
|
verify(mBackend).updateMode(captor.capture());
|
||||||
// Checks the policy value for PRIORITY is propagated to the backend.
|
// Checks the policy value for PRIORITY is propagated to the backend.
|
||||||
assertThat(captor.getValue().getRule().getInterruptionFilter())
|
assertThat(captor.getValue().getInterruptionFilter())
|
||||||
.isEqualTo(INTERRUPTION_FILTER_PRIORITY);
|
.isEqualTo(INTERRUPTION_FILTER_PRIORITY);
|
||||||
|
|
||||||
// After screen is refreshed, PRIORITY is now checked; others are unchecked.
|
// After screen is refreshed, PRIORITY is now checked; others are unchecked.
|
||||||
|
@@ -124,7 +124,7 @@ public class ZenModeEditNameIconFragmentTest {
|
|||||||
verify(mBackend).updateMode(captor.capture());
|
verify(mBackend).updateMode(captor.capture());
|
||||||
ZenMode savedMode = captor.getValue();
|
ZenMode savedMode = captor.getValue();
|
||||||
assertThat(savedMode.getName()).isEqualTo("A newer name");
|
assertThat(savedMode.getName()).isEqualTo("A newer name");
|
||||||
assertThat(savedMode.getRule().getIconResId()).isEqualTo(
|
assertThat(savedMode.getIconKey().resId()).isEqualTo(
|
||||||
R.drawable.ic_zen_mode_type_theater);
|
R.drawable.ic_zen_mode_type_theater);
|
||||||
|
|
||||||
assertThat(mActivity.isFinishing()).isTrue();
|
assertThat(mActivity.isFinishing()).isTrue();
|
||||||
|
@@ -34,6 +34,7 @@ import androidx.test.core.app.ApplicationProvider;
|
|||||||
|
|
||||||
import com.android.settingslib.notification.modes.TestModeBuilder;
|
import com.android.settingslib.notification.modes.TestModeBuilder;
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
import com.android.settingslib.notification.modes.ZenMode;
|
||||||
|
import com.android.settingslib.notification.modes.ZenModeSchedules;
|
||||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -89,7 +90,7 @@ public class ZenModeExitAtAlarmPreferenceControllerTest {
|
|||||||
|
|
||||||
// Now update state after changing exitAtAlarm
|
// Now update state after changing exitAtAlarm
|
||||||
scheduleInfo.exitAtAlarm = true;
|
scheduleInfo.exitAtAlarm = true;
|
||||||
mode.getRule().setConditionId(ZenModeConfig.toScheduleConditionId(scheduleInfo));
|
mode.setCustomModeConditionId(mContext, ZenModeConfig.toScheduleConditionId(scheduleInfo));
|
||||||
|
|
||||||
// now can just call updateState
|
// now can just call updateState
|
||||||
mPrefController.updateState(preference, mode);
|
mPrefController.updateState(preference, mode);
|
||||||
@@ -117,8 +118,8 @@ public class ZenModeExitAtAlarmPreferenceControllerTest {
|
|||||||
mPrefController.onPreferenceChange(preference, false);
|
mPrefController.onPreferenceChange(preference, false);
|
||||||
ArgumentCaptor<ZenMode> captor = ArgumentCaptor.forClass(ZenMode.class);
|
ArgumentCaptor<ZenMode> captor = ArgumentCaptor.forClass(ZenMode.class);
|
||||||
verify(mBackend).updateMode(captor.capture());
|
verify(mBackend).updateMode(captor.capture());
|
||||||
ZenModeConfig.ScheduleInfo newSchedule = ZenModeConfig.tryParseScheduleConditionId(
|
ZenModeConfig.ScheduleInfo newSchedule = ZenModeSchedules.getTimeSchedule(
|
||||||
captor.getValue().getRule().getConditionId());
|
captor.getValue());
|
||||||
assertThat(newSchedule.exitAtAlarm).isFalse();
|
assertThat(newSchedule.exitAtAlarm).isFalse();
|
||||||
|
|
||||||
// other properties remain the same
|
// other properties remain the same
|
||||||
|
@@ -41,6 +41,7 @@ import androidx.test.core.app.ApplicationProvider;
|
|||||||
|
|
||||||
import com.android.settingslib.notification.modes.TestModeBuilder;
|
import com.android.settingslib.notification.modes.TestModeBuilder;
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
import com.android.settingslib.notification.modes.ZenMode;
|
||||||
|
import com.android.settingslib.notification.modes.ZenModeSchedules;
|
||||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -102,10 +103,10 @@ public class ZenModeSetCalendarPreferenceControllerTest {
|
|||||||
// apply event mode updater to existing mode
|
// apply event mode updater to existing mode
|
||||||
ZenMode out = mPrefController.updateEventMode(eventInfo).apply(mode);
|
ZenMode out = mPrefController.updateEventMode(eventInfo).apply(mode);
|
||||||
|
|
||||||
assertThat(out.getRule().getOwner()).isEqualTo(ZenModeConfig.getEventConditionProvider());
|
assertThat(ZenModeSchedules.getCalendarSchedule(out)).isEqualTo(eventInfo);
|
||||||
assertThat(out.getRule().getConditionId()).isEqualTo(
|
assertThat(out.getOwner().conditionProvider()).isEqualTo(
|
||||||
ZenModeConfig.toEventConditionId(eventInfo));
|
ZenModeConfig.getEventConditionProvider());
|
||||||
assertThat(out.getRule().getTriggerDescription()).isEqualTo("My events");
|
assertThat(out.getTriggerDescription()).isEqualTo("My events");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -38,6 +38,7 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settingslib.notification.modes.TestModeBuilder;
|
import com.android.settingslib.notification.modes.TestModeBuilder;
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
import com.android.settingslib.notification.modes.ZenMode;
|
||||||
|
import com.android.settingslib.notification.modes.ZenModeSchedules;
|
||||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -92,11 +93,10 @@ public class ZenModeSetSchedulePreferenceControllerTest {
|
|||||||
scheduleInfo.endHour = 2;
|
scheduleInfo.endHour = 2;
|
||||||
ZenMode out = mPrefController.updateScheduleMode(scheduleInfo).apply(mode);
|
ZenMode out = mPrefController.updateScheduleMode(scheduleInfo).apply(mode);
|
||||||
|
|
||||||
assertThat(out.getRule().getConditionId())
|
assertThat(ZenModeSchedules.getTimeSchedule(out)).isEqualTo(scheduleInfo);
|
||||||
.isEqualTo(ZenModeConfig.toScheduleConditionId(scheduleInfo));
|
assertThat(out.getOwner().conditionProvider()).isEqualTo(
|
||||||
assertThat(out.getRule().getTriggerDescription()).isNotEmpty();
|
|
||||||
assertThat(out.getRule().getOwner()).isEqualTo(
|
|
||||||
ZenModeConfig.getScheduleConditionProvider());
|
ZenModeConfig.getScheduleConditionProvider());
|
||||||
|
assertThat(out.getTriggerDescription()).isNotEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -44,6 +44,7 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settingslib.notification.modes.TestModeBuilder;
|
import com.android.settingslib.notification.modes.TestModeBuilder;
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
import com.android.settingslib.notification.modes.ZenMode;
|
||||||
|
import com.android.settingslib.notification.modes.ZenModeSchedules;
|
||||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -168,9 +169,9 @@ public class ZenModeTriggerAddPreferenceControllerTest {
|
|||||||
verify(mBackend).updateMode(captor.capture());
|
verify(mBackend).updateMode(captor.capture());
|
||||||
ZenMode updatedMode = captor.getValue();
|
ZenMode updatedMode = captor.getValue();
|
||||||
assertThat(updatedMode.getType()).isEqualTo(TYPE_SCHEDULE_TIME);
|
assertThat(updatedMode.getType()).isEqualTo(TYPE_SCHEDULE_TIME);
|
||||||
assertThat(updatedMode.getRule().getConditionId()).isEqualTo(scheduleUri);
|
assertThat(ZenModeSchedules.getTimeSchedule(updatedMode)).isEqualTo(scheduleInfo);
|
||||||
assertThat(updatedMode.getRule().getTriggerDescription()).isNotEmpty();
|
assertThat(updatedMode.getTriggerDescription()).isNotEmpty();
|
||||||
assertThat(updatedMode.getRule().getOwner()).isEqualTo(
|
assertThat(updatedMode.getOwner().conditionProvider()).isEqualTo(
|
||||||
ZenModeConfig.getScheduleConditionProvider());
|
ZenModeConfig.getScheduleConditionProvider());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -161,7 +161,7 @@ public class ZenModeTriggerUpdatePreferenceControllerTest {
|
|||||||
assertThat(mPreference.getCheckedState()).isFalse();
|
assertThat(mPreference.getCheckedState()).isFalse();
|
||||||
|
|
||||||
// Now with the rule enabled
|
// Now with the rule enabled
|
||||||
zenMode.getRule().setEnabled(true);
|
zenMode.setEnabled(true);
|
||||||
mController.updateZenMode(mPreference, zenMode);
|
mController.updateZenMode(mPreference, zenMode);
|
||||||
assertThat(mPreference.getCheckedState()).isTrue();
|
assertThat(mPreference.getCheckedState()).isTrue();
|
||||||
}
|
}
|
||||||
@@ -189,7 +189,7 @@ public class ZenModeTriggerUpdatePreferenceControllerTest {
|
|||||||
// Verify the backend got asked to update the mode to be enabled
|
// Verify the backend got asked to update the mode to be enabled
|
||||||
ArgumentCaptor<ZenMode> captor = ArgumentCaptor.forClass(ZenMode.class);
|
ArgumentCaptor<ZenMode> captor = ArgumentCaptor.forClass(ZenMode.class);
|
||||||
verify(mBackend).updateMode(captor.capture());
|
verify(mBackend).updateMode(captor.capture());
|
||||||
assertThat(captor.getValue().getRule().isEnabled()).isTrue();
|
assertThat(captor.getValue().isEnabled()).isTrue();
|
||||||
assertThat(ShadowAlertDialog.getLatestAlertDialog().isShowing()).isFalse();
|
assertThat(ShadowAlertDialog.getLatestAlertDialog().isShowing()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,7 +216,7 @@ public class ZenModeTriggerUpdatePreferenceControllerTest {
|
|||||||
// Verify the backend got asked to update the mode to be disabled
|
// Verify the backend got asked to update the mode to be disabled
|
||||||
ArgumentCaptor<ZenMode> captor = ArgumentCaptor.forClass(ZenMode.class);
|
ArgumentCaptor<ZenMode> captor = ArgumentCaptor.forClass(ZenMode.class);
|
||||||
verify(mBackend).updateMode(captor.capture());
|
verify(mBackend).updateMode(captor.capture());
|
||||||
assertThat(captor.getValue().getRule().isEnabled()).isFalse();
|
assertThat(captor.getValue().isEnabled()).isFalse();
|
||||||
assertThat(ShadowAlertDialog.getLatestAlertDialog().isShowing()).isFalse();
|
assertThat(ShadowAlertDialog.getLatestAlertDialog().isShowing()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user