Merge "Log manual rules in the zen rule snapshot dump." into udc-dev
This commit is contained in:
@@ -1258,17 +1258,18 @@ public class ZenModeHelper {
|
||||
.addBooleanAnnotation(ANNOTATION_ID_IS_UID, true)
|
||||
.writeByteArray(config.toZenPolicy().toProto());
|
||||
events.add(data.build());
|
||||
if (config.manualRule != null && config.manualRule.enabler != null) {
|
||||
ruleToProtoLocked(user, config.manualRule, events);
|
||||
if (config.manualRule != null) {
|
||||
ruleToProtoLocked(user, config.manualRule, true, events);
|
||||
}
|
||||
for (ZenRule rule : config.automaticRules.values()) {
|
||||
ruleToProtoLocked(user, rule, events);
|
||||
ruleToProtoLocked(user, rule, false, events);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ruleToProtoLocked(int user, ZenRule rule, List<StatsEvent> events) {
|
||||
private void ruleToProtoLocked(int user, ZenRule rule, boolean isManualRule,
|
||||
List<StatsEvent> events) {
|
||||
// Make the ID safe.
|
||||
String id = rule.id == null ? "" : rule.id;
|
||||
if (!ZenModeConfig.DEFAULT_RULE_IDS.contains(id)) {
|
||||
@@ -1279,6 +1280,9 @@ public class ZenModeHelper {
|
||||
String pkg = rule.getPkg() == null ? "" : rule.getPkg();
|
||||
if (rule.enabler != null) {
|
||||
pkg = rule.enabler;
|
||||
}
|
||||
|
||||
if (isManualRule) {
|
||||
id = ZenModeConfig.MANUAL_RULE_ID;
|
||||
}
|
||||
|
||||
|
||||
@@ -884,18 +884,21 @@ public class ZenModeHelperTest extends UiServiceTestCase {
|
||||
@Test
|
||||
public void testProto() {
|
||||
mZenModeHelperSpy.mZenMode = ZEN_MODE_IMPORTANT_INTERRUPTIONS;
|
||||
// existence of manual rule means it should be in output
|
||||
mZenModeHelperSpy.mConfig.manualRule = new ZenModeConfig.ZenRule();
|
||||
mZenModeHelperSpy.mConfig.manualRule.pkg = "android"; // system
|
||||
|
||||
int n = mZenModeHelperSpy.mConfig.automaticRules.size();
|
||||
List<String> ids = new ArrayList<>(n);
|
||||
for (ZenModeConfig.ZenRule rule : mZenModeHelperSpy.mConfig.automaticRules.values()) {
|
||||
ids.add(rule.id);
|
||||
}
|
||||
ids.add("");
|
||||
ids.add(ZenModeConfig.MANUAL_RULE_ID);
|
||||
ids.add(""); // for ROOT_CONFIG, logged with empty string as id
|
||||
|
||||
List<StatsEvent> events = new LinkedList<>();
|
||||
mZenModeHelperSpy.pullRules(events);
|
||||
assertEquals(n + 1, events.size());
|
||||
assertEquals(n + 2, events.size()); // automatic rules + manual rule + root config
|
||||
for (WrappedSysUiStatsEvent.WrappedBuilder builder : mStatsEventBuilderFactory.builders) {
|
||||
if (builder.getAtomId() == DND_MODE_RULE) {
|
||||
if (builder.getInt(ZEN_MODE_FIELD_NUMBER) == ROOT_CONFIG) {
|
||||
@@ -1002,7 +1005,6 @@ public class ZenModeHelperTest extends UiServiceTestCase {
|
||||
mZenModeHelperSpy.mConfig.automaticRules = getCustomAutomaticRules();
|
||||
mZenModeHelperSpy.mConfig.manualRule = new ZenModeConfig.ZenRule();
|
||||
mZenModeHelperSpy.mConfig.manualRule.enabled = true;
|
||||
mZenModeHelperSpy.mConfig.manualRule.enabler = "com.enabler";
|
||||
|
||||
List<StatsEvent> events = new LinkedList<>();
|
||||
mZenModeHelperSpy.pullRules(events);
|
||||
|
||||
Reference in New Issue
Block a user