use of android.service.notification.ZenModeConfig in project android_frameworks_base by ResurrectionRemix.
the class ZenModeHelper method updateAutomaticZenRule.
public boolean updateAutomaticZenRule(String ruleId, AutomaticZenRule automaticZenRule, String reason) {
ZenModeConfig newConfig;
synchronized (mConfig) {
if (mConfig == null)
return false;
if (DEBUG) {
Log.d(TAG, "updateAutomaticZenRule zenRule=" + automaticZenRule + " reason=" + reason);
}
newConfig = mConfig.copy();
ZenModeConfig.ZenRule rule;
if (ruleId == null) {
throw new IllegalArgumentException("Rule doesn't exist");
} else {
rule = newConfig.automaticRules.get(ruleId);
if (rule == null || !canManageAutomaticZenRule(rule)) {
throw new SecurityException("Cannot update rules not owned by your condition provider");
}
}
populateZenRule(automaticZenRule, rule, false);
newConfig.automaticRules.put(ruleId, rule);
return setConfigLocked(newConfig, reason, true);
}
}
use of android.service.notification.ZenModeConfig in project android_frameworks_base by crdroidandroid.
the class ZenModeHelper method loadConfigForUser.
private void loadConfigForUser(int user, String reason) {
if (mUser == user || user < UserHandle.USER_SYSTEM)
return;
mUser = user;
if (DEBUG)
Log.d(TAG, reason + " u=" + user);
ZenModeConfig config = mConfigs.get(user);
if (config == null) {
if (DEBUG)
Log.d(TAG, reason + " generating default config for user " + user);
config = mDefaultConfig.copy();
config.user = user;
}
synchronized (mConfig) {
setConfigLocked(config, reason);
}
cleanUpZenRules();
}
use of android.service.notification.ZenModeConfig in project android_frameworks_base by crdroidandroid.
the class ZenModeHelper method readXml.
public void readXml(XmlPullParser parser, boolean forRestore) throws XmlPullParserException, IOException {
final ZenModeConfig config = ZenModeConfig.readXml(parser, mConfigMigration);
if (config != null) {
if (forRestore) {
//TODO: http://b/22388012
if (config.user != UserHandle.USER_SYSTEM) {
return;
}
// don't restore the manual rule
config.manualRule = null;
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) {
setConfigLocked(config, "readXml");
}
}
}
use of android.service.notification.ZenModeConfig in project android_frameworks_base by crdroidandroid.
the class ZenModeHelper method updateAutomaticZenRule.
public boolean updateAutomaticZenRule(String ruleId, AutomaticZenRule automaticZenRule, String reason) {
ZenModeConfig newConfig;
synchronized (mConfig) {
if (mConfig == null)
return false;
if (DEBUG) {
Log.d(TAG, "updateAutomaticZenRule zenRule=" + automaticZenRule + " reason=" + reason);
}
newConfig = mConfig.copy();
ZenModeConfig.ZenRule rule;
if (ruleId == null) {
throw new IllegalArgumentException("Rule doesn't exist");
} else {
rule = newConfig.automaticRules.get(ruleId);
if (rule == null || !canManageAutomaticZenRule(rule)) {
throw new SecurityException("Cannot update rules not owned by your condition provider");
}
}
populateZenRule(automaticZenRule, rule, false);
newConfig.automaticRules.put(ruleId, rule);
return setConfigLocked(newConfig, reason, true);
}
}
use of android.service.notification.ZenModeConfig in project android_frameworks_base by crdroidandroid.
the class ZenModeHelper method cleanUpZenRules.
/**
* 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(), PackageManager.MATCH_UNINSTALLED_PACKAGES);
} catch (PackageManager.NameNotFoundException e) {
newConfig.automaticRules.removeAt(i);
}
}
}
}
setConfigLocked(newConfig, "cleanUpZenRules");
}
}
Aggregations