Don't show orphaned rule instances in Settings.

Bug: 25472361
Change-Id: Ic9bec4872777b720aa786679cbc960a9ee51dbe1
This commit is contained in:
Julia Reynolds
2015-12-17 08:46:09 -05:00
parent fa4813783f
commit 2ba71ad15d

View File

@@ -156,7 +156,10 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase {
root.removeAll();
final AutomaticZenRule[] sortedRules = sortedRules();
for (AutomaticZenRule sortedRule : sortedRules) {
root.addPreference(new ZenRulePreference(getPrefContext(), sortedRule));
ZenRulePreference pref = new ZenRulePreference(getPrefContext(), sortedRule);
if (pref.appExists) {
root.addPreference(pref);
}
}
final Preference p = new Preference(getPrefContext());
p.setIcon(R.drawable.ic_add);
@@ -264,6 +267,7 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase {
private class ZenRulePreference extends Preference {
final String mName;
final String mId;
final boolean appExists;
public ZenRulePreference(Context context, final AutomaticZenRule rule) {
super(context);
@@ -283,8 +287,11 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase {
setSummary(computeRuleSummary(rule, isSystemRule, info.loadLabel(mPm)));
} catch (PackageManager.NameNotFoundException e) {
setIcon(R.drawable.ic_label);
appExists = false;
return;
}
appExists = true;
setTitle(rule.getName());
setPersistent(false);