Fix NPE when deleting old zen rules

Test: manually revoke access for a DND app that has rules
created before and after b/189332346
Bug: 191773100
Bug: 189332346
Bug: 235823407

Change-Id: I069fcc124af24227fa50b61d4fc55d6dadc7a20b
Merged-In: I069fcc124af24227fa50b61d4fc55d6dadc7a20b
(cherry picked from commit b4fe101e5e)
This commit is contained in:
Julia Reynolds
2021-06-22 13:30:37 -04:00
committed by Yuri Lin
parent eda171cffa
commit 7bb9cd92bf

View File

@@ -383,7 +383,14 @@ public class ZenModeHelper {
newConfig = mConfig.copy();
for (int i = newConfig.automaticRules.size() - 1; i >= 0; i--) {
ZenRule rule = newConfig.automaticRules.get(newConfig.automaticRules.keyAt(i));
if (rule.pkg.equals(packageName) && canManageAutomaticZenRule(rule)) {
String pkg = rule.pkg != null
? rule.pkg
: (rule.component != null)
? rule.component.getPackageName()
: (rule.configurationActivity != null)
? rule.configurationActivity.getPackageName()
: null;
if (Objects.equals(pkg, packageName) && canManageAutomaticZenRule(rule)) {
newConfig.automaticRules.removeAt(i);
}
}