Log manual rules in the zen rule snapshot dump.
This adds a parameter to explicitly indicate whether a rule to be dumped is actually a manual rule rather than using guesswork (that didn't work because manual rules don't actually have enabler set). This change only catches when manual DND happens to be on at the time of the snapshot (roughly once per 12h), but it still provides more info than none. Bug: 271469690 Test: atest ZenModeHelperTest, manual via statsd_testdrive Change-Id: I76bc1d98990950de5515cdcedeff4be06dd3f4e8
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