From f7791d75bfea69e40ccb7e1a411d657249ed16f3 Mon Sep 17 00:00:00 2001 From: Thecrazyskull Date: Thu, 2 Mar 2017 14:55:59 -0500 Subject: [PATCH] ConditionManager: don't crash when trying to add unexpected condition * Instead, just don't add the unexpected condition Test: none Change-Id: Id768d54e90fac6cbbfdca514e769cb3b331fbc46 --- .../dashboard/conditional/ConditionManager.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/com/android/settings/dashboard/conditional/ConditionManager.java b/src/com/android/settings/dashboard/conditional/ConditionManager.java index 691821a776f..aeeec28388d 100644 --- a/src/com/android/settings/dashboard/conditional/ConditionManager.java +++ b/src/com/android/settings/dashboard/conditional/ConditionManager.java @@ -91,8 +91,12 @@ public class ConditionManager { Condition condition = createCondition(Class.forName(clz)); PersistableBundle bundle = PersistableBundle.restoreFromXml(parser); if (DEBUG) Log.d(TAG, "Reading " + clz + " -- " + bundle); - condition.restoreState(bundle); - conditions.add(condition); + if (condition != null) { + condition.restoreState(bundle); + conditions.add(condition); + } else { + Log.e(TAG, "failed to add condition: " + clz); + } while (parser.getDepth() > depth) { parser.next(); } @@ -150,7 +154,10 @@ public class ConditionManager { private void addIfMissing(Class clz, ArrayList conditions) { if (getCondition(clz, conditions) == null) { if (DEBUG) Log.d(TAG, "Adding missing " + clz.getName()); - conditions.add(createCondition(clz)); + Condition condition = createCondition(clz); + if (condition != null) { + conditions.add(condition); + } } } @@ -172,7 +179,8 @@ public class ConditionManager { } else if (NightDisplayCondition.class == clz) { return new NightDisplayCondition(this); } - throw new RuntimeException("Unexpected Condition " + clz); + Log.e(TAG, "unknown condition class: " + clz.getSimpleName()); + return null; } Context getContext() {