Loading services/core/java/com/android/server/notification/ZenModeConditions.java +0 −1 Original line number Diff line number Diff line Loading @@ -109,7 +109,6 @@ public class ZenModeConditions implements ConditionProviders.Callback { if (DEBUG) Log.d(TAG, "onConditionChanged " + id + " " + condition); ZenModeConfig config = mHelper.getConfig(); if (config == null) return; config = config.copy(); boolean updated = updateCondition(id, condition, config.manualRule); for (ZenRule automaticRule : config.automaticRules.values()) { updated |= updateCondition(id, condition, automaticRule); Loading services/core/java/com/android/server/notification/ZenModeHelper.java +113 −72 Original line number Diff line number Diff line Loading @@ -77,6 +77,9 @@ public class ZenModeHelper { static final String TAG = "ZenModeHelper"; static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); // The amount of time rules instances can exist without their owning app being installed. private static final int RULE_INSTANCE_GRACE_PERIOD = 1000 * 60 * 60 * 72; private final Context mContext; private final H mHandler; private final SettingsObserver mSettingsObserver; Loading @@ -93,6 +96,7 @@ public class ZenModeHelper { private int mUser = UserHandle.USER_SYSTEM; private ZenModeConfig mConfig; private AudioManagerInternal mAudioManager; private PackageManager mPm; private boolean mEffectsSuppressed; public ZenModeHelper(Context context, Looper looper, ConditionProviders conditionProviders) { Loading Loading @@ -170,7 +174,9 @@ public class ZenModeHelper { if (mAudioManager != null) { mAudioManager.setRingerModeDelegate(mRingerModeDelegate); } mPm = mContext.getPackageManager(); mHandler.postMetricsTimer(); cleanUpZenRules(); evaluateZenMode("onSystemReady", true); } Loading @@ -184,8 +190,11 @@ public class ZenModeHelper { config = mDefaultConfig.copy(); config.user = user; } synchronized (mConfig) { setConfig(config, "onUserSwitched"); } cleanUpZenRules(); } public void onUserRemoved(int user) { if (user < UserHandle.USER_SYSTEM) return; Loading Loading @@ -253,7 +262,7 @@ public class ZenModeHelper { throw new IllegalArgumentException("Rule already exists"); } newConfig = mConfig.copy(); } ZenRule rule = new ZenRule(); populateZenRule(automaticZenRule, rule, true); newConfig.automaticRules.put(rule.id, rule); Loading @@ -263,6 +272,7 @@ public class ZenModeHelper { return null; } } } public boolean updateAutomaticZenRule(AutomaticZenRule automaticZenRule, String reason) { ZenModeConfig newConfig; Loading @@ -273,7 +283,6 @@ public class ZenModeHelper { + " reason=" + reason); } newConfig = mConfig.copy(); } final String ruleId = automaticZenRule.getId(); ZenModeConfig.ZenRule rule; if (ruleId == null) { Loading @@ -289,13 +298,13 @@ public class ZenModeHelper { newConfig.automaticRules.put(ruleId, rule); return setConfig(newConfig, reason, true); } } public boolean removeAutomaticZenRule(String id, String reason) { ZenModeConfig newConfig; synchronized (mConfig) { if (mConfig == null) return false; newConfig = mConfig.copy(); } ZenRule rule = newConfig.automaticRules.get(id); if (rule == null) return false; if (canManageAutomaticZenRule(rule)) { Loading @@ -307,13 +316,13 @@ public class ZenModeHelper { } return setConfig(newConfig, reason, true); } } public boolean removeAutomaticZenRules(String packageName, String reason) { ZenModeConfig newConfig; synchronized (mConfig) { if (mConfig == null) return false; newConfig = mConfig.copy(); } for (int i = newConfig.automaticRules.size() - 1; i >= 0; i--) { ZenRule rule = newConfig.automaticRules.get(newConfig.automaticRules.keyAt(i)); if (rule.component.getPackageName().equals(packageName) Loading @@ -323,6 +332,7 @@ public class ZenModeHelper { } return setConfig(newConfig, reason, true); } } public boolean canManageAutomaticZenRule(ZenRule rule) { final int callingUid = Binder.getCallingUid(); Loading @@ -332,8 +342,7 @@ public class ZenModeHelper { == PackageManager.PERMISSION_GRANTED) { return true; } else { String[] packages = mContext.getPackageManager().getPackagesForUid(Binder.getCallingUid()); String[] packages = mPm.getPackagesForUid(Binder.getCallingUid()); if (packages != null) { final int packageCount = packages.length; for (int i = 0; i < packageCount; i++) { Loading Loading @@ -384,7 +393,6 @@ public class ZenModeHelper { + " conditionId=" + conditionId + " reason=" + reason + " setRingerMode=" + setRingerMode); newConfig = mConfig.copy(); } if (zenMode == Global.ZEN_MODE_OFF) { newConfig.manualRule = null; for (ZenRule automaticRule : newConfig.automaticRules.values()) { Loading @@ -401,6 +409,7 @@ public class ZenModeHelper { } setConfig(newConfig, reason, setRingerMode); } } public void dump(PrintWriter pw, String prefix) { pw.print(prefix); pw.print("mZenMode="); Loading Loading @@ -450,18 +459,22 @@ public class ZenModeHelper { return; } config.manualRule = null; // don't restore the manual rule long time = System.currentTimeMillis(); if (config.automaticRules != null) { for (ZenRule automaticRule : config.automaticRules.values()) { // don't restore transient state from restored automatic rules automaticRule.snoozing = false; automaticRule.condition = null; automaticRule.creationTime = time; } } } if (DEBUG) Log.d(TAG, "readXml"); synchronized (mConfig) { setConfig(config, "readXml"); } } } public void writeXml(XmlSerializer out, boolean forBackup) throws IOException { final int N = mConfigs.size(); Loading @@ -484,11 +497,39 @@ public class ZenModeHelper { public void setNotificationPolicy(Policy policy) { if (policy == null || mConfig == null) return; synchronized (mConfig) { final ZenModeConfig newConfig = mConfig.copy(); newConfig.applyNotificationPolicy(policy); setConfig(newConfig, "setNotificationPolicy"); } } /** * Removes old rule instances whose owner is not installed. */ private void cleanUpZenRules() { long currentTime = System.currentTimeMillis(); synchronized (mConfig) { final ZenModeConfig newConfig = mConfig.copy(); if (newConfig.automaticRules != null) { for (int i = newConfig.automaticRules.size() - 1; i >= 0; i--) { ZenRule rule = newConfig.automaticRules.get(newConfig.automaticRules.keyAt(i)); if (RULE_INSTANCE_GRACE_PERIOD < (currentTime - rule.creationTime)) { try { mPm.getPackageInfo(rule.component.getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { newConfig.automaticRules.removeAt(i); } } } } setConfig(newConfig, "cleanUpZenRules"); } } /** * @return a copy of the zen mode configuration */ public ZenModeConfig getConfig() { synchronized (mConfig) { return mConfig.copy(); Loading Loading @@ -517,7 +558,6 @@ public class ZenModeHelper { return true; } mConditions.evaluateConfig(config, false /*processSubscriptions*/); // may modify config synchronized (mConfig) { mConfigs.put(config.user, config); if (DEBUG) Log.d(TAG, "setConfig reason=" + reason, new Throwable()); ZenLog.traceConfig(reason, mConfig, config); Loading @@ -530,7 +570,6 @@ public class ZenModeHelper { if (policyChanged) { dispatchOnPolicyChanged(); } } final String val = Integer.toString(config.hashCode()); Global.putString(mContext.getContentResolver(), Global.ZEN_MODE_CONFIG_ETAG, val); if (!evaluateZenMode(reason, setRingerMode)) { Loading Loading @@ -994,7 +1033,9 @@ public class ZenModeHelper { break; case MSG_SET_CONFIG: ConfigMessageData configData = (ConfigMessageData)msg.obj; synchronized (mConfig) { setConfig(configData.config, configData.reason); } break; } } Loading Loading
services/core/java/com/android/server/notification/ZenModeConditions.java +0 −1 Original line number Diff line number Diff line Loading @@ -109,7 +109,6 @@ public class ZenModeConditions implements ConditionProviders.Callback { if (DEBUG) Log.d(TAG, "onConditionChanged " + id + " " + condition); ZenModeConfig config = mHelper.getConfig(); if (config == null) return; config = config.copy(); boolean updated = updateCondition(id, condition, config.manualRule); for (ZenRule automaticRule : config.automaticRules.values()) { updated |= updateCondition(id, condition, automaticRule); Loading
services/core/java/com/android/server/notification/ZenModeHelper.java +113 −72 Original line number Diff line number Diff line Loading @@ -77,6 +77,9 @@ public class ZenModeHelper { static final String TAG = "ZenModeHelper"; static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); // The amount of time rules instances can exist without their owning app being installed. private static final int RULE_INSTANCE_GRACE_PERIOD = 1000 * 60 * 60 * 72; private final Context mContext; private final H mHandler; private final SettingsObserver mSettingsObserver; Loading @@ -93,6 +96,7 @@ public class ZenModeHelper { private int mUser = UserHandle.USER_SYSTEM; private ZenModeConfig mConfig; private AudioManagerInternal mAudioManager; private PackageManager mPm; private boolean mEffectsSuppressed; public ZenModeHelper(Context context, Looper looper, ConditionProviders conditionProviders) { Loading Loading @@ -170,7 +174,9 @@ public class ZenModeHelper { if (mAudioManager != null) { mAudioManager.setRingerModeDelegate(mRingerModeDelegate); } mPm = mContext.getPackageManager(); mHandler.postMetricsTimer(); cleanUpZenRules(); evaluateZenMode("onSystemReady", true); } Loading @@ -184,8 +190,11 @@ public class ZenModeHelper { config = mDefaultConfig.copy(); config.user = user; } synchronized (mConfig) { setConfig(config, "onUserSwitched"); } cleanUpZenRules(); } public void onUserRemoved(int user) { if (user < UserHandle.USER_SYSTEM) return; Loading Loading @@ -253,7 +262,7 @@ public class ZenModeHelper { throw new IllegalArgumentException("Rule already exists"); } newConfig = mConfig.copy(); } ZenRule rule = new ZenRule(); populateZenRule(automaticZenRule, rule, true); newConfig.automaticRules.put(rule.id, rule); Loading @@ -263,6 +272,7 @@ public class ZenModeHelper { return null; } } } public boolean updateAutomaticZenRule(AutomaticZenRule automaticZenRule, String reason) { ZenModeConfig newConfig; Loading @@ -273,7 +283,6 @@ public class ZenModeHelper { + " reason=" + reason); } newConfig = mConfig.copy(); } final String ruleId = automaticZenRule.getId(); ZenModeConfig.ZenRule rule; if (ruleId == null) { Loading @@ -289,13 +298,13 @@ public class ZenModeHelper { newConfig.automaticRules.put(ruleId, rule); return setConfig(newConfig, reason, true); } } public boolean removeAutomaticZenRule(String id, String reason) { ZenModeConfig newConfig; synchronized (mConfig) { if (mConfig == null) return false; newConfig = mConfig.copy(); } ZenRule rule = newConfig.automaticRules.get(id); if (rule == null) return false; if (canManageAutomaticZenRule(rule)) { Loading @@ -307,13 +316,13 @@ public class ZenModeHelper { } return setConfig(newConfig, reason, true); } } public boolean removeAutomaticZenRules(String packageName, String reason) { ZenModeConfig newConfig; synchronized (mConfig) { if (mConfig == null) return false; newConfig = mConfig.copy(); } for (int i = newConfig.automaticRules.size() - 1; i >= 0; i--) { ZenRule rule = newConfig.automaticRules.get(newConfig.automaticRules.keyAt(i)); if (rule.component.getPackageName().equals(packageName) Loading @@ -323,6 +332,7 @@ public class ZenModeHelper { } return setConfig(newConfig, reason, true); } } public boolean canManageAutomaticZenRule(ZenRule rule) { final int callingUid = Binder.getCallingUid(); Loading @@ -332,8 +342,7 @@ public class ZenModeHelper { == PackageManager.PERMISSION_GRANTED) { return true; } else { String[] packages = mContext.getPackageManager().getPackagesForUid(Binder.getCallingUid()); String[] packages = mPm.getPackagesForUid(Binder.getCallingUid()); if (packages != null) { final int packageCount = packages.length; for (int i = 0; i < packageCount; i++) { Loading Loading @@ -384,7 +393,6 @@ public class ZenModeHelper { + " conditionId=" + conditionId + " reason=" + reason + " setRingerMode=" + setRingerMode); newConfig = mConfig.copy(); } if (zenMode == Global.ZEN_MODE_OFF) { newConfig.manualRule = null; for (ZenRule automaticRule : newConfig.automaticRules.values()) { Loading @@ -401,6 +409,7 @@ public class ZenModeHelper { } setConfig(newConfig, reason, setRingerMode); } } public void dump(PrintWriter pw, String prefix) { pw.print(prefix); pw.print("mZenMode="); Loading Loading @@ -450,18 +459,22 @@ public class ZenModeHelper { return; } config.manualRule = null; // don't restore the manual rule long time = System.currentTimeMillis(); if (config.automaticRules != null) { for (ZenRule automaticRule : config.automaticRules.values()) { // don't restore transient state from restored automatic rules automaticRule.snoozing = false; automaticRule.condition = null; automaticRule.creationTime = time; } } } if (DEBUG) Log.d(TAG, "readXml"); synchronized (mConfig) { setConfig(config, "readXml"); } } } public void writeXml(XmlSerializer out, boolean forBackup) throws IOException { final int N = mConfigs.size(); Loading @@ -484,11 +497,39 @@ public class ZenModeHelper { public void setNotificationPolicy(Policy policy) { if (policy == null || mConfig == null) return; synchronized (mConfig) { final ZenModeConfig newConfig = mConfig.copy(); newConfig.applyNotificationPolicy(policy); setConfig(newConfig, "setNotificationPolicy"); } } /** * Removes old rule instances whose owner is not installed. */ private void cleanUpZenRules() { long currentTime = System.currentTimeMillis(); synchronized (mConfig) { final ZenModeConfig newConfig = mConfig.copy(); if (newConfig.automaticRules != null) { for (int i = newConfig.automaticRules.size() - 1; i >= 0; i--) { ZenRule rule = newConfig.automaticRules.get(newConfig.automaticRules.keyAt(i)); if (RULE_INSTANCE_GRACE_PERIOD < (currentTime - rule.creationTime)) { try { mPm.getPackageInfo(rule.component.getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { newConfig.automaticRules.removeAt(i); } } } } setConfig(newConfig, "cleanUpZenRules"); } } /** * @return a copy of the zen mode configuration */ public ZenModeConfig getConfig() { synchronized (mConfig) { return mConfig.copy(); Loading Loading @@ -517,7 +558,6 @@ public class ZenModeHelper { return true; } mConditions.evaluateConfig(config, false /*processSubscriptions*/); // may modify config synchronized (mConfig) { mConfigs.put(config.user, config); if (DEBUG) Log.d(TAG, "setConfig reason=" + reason, new Throwable()); ZenLog.traceConfig(reason, mConfig, config); Loading @@ -530,7 +570,6 @@ public class ZenModeHelper { if (policyChanged) { dispatchOnPolicyChanged(); } } final String val = Integer.toString(config.hashCode()); Global.putString(mContext.getContentResolver(), Global.ZEN_MODE_CONFIG_ETAG, val); if (!evaluateZenMode(reason, setRingerMode)) { Loading Loading @@ -994,7 +1033,9 @@ public class ZenModeHelper { break; case MSG_SET_CONFIG: ConfigMessageData configData = (ConfigMessageData)msg.obj; synchronized (mConfig) { setConfig(configData.config, configData.reason); } break; } } Loading