Search in sources :

Example 1 with AutomaticZenRule

use of android.app.AutomaticZenRule in project platform_frameworks_base by android.

the class ZenModeHelper method addAutomaticZenRule.

public String addAutomaticZenRule(AutomaticZenRule automaticZenRule, String reason) {
    if (!isSystemRule(automaticZenRule)) {
        ServiceInfo owner = getServiceInfo(automaticZenRule.getOwner());
        if (owner == null) {
            throw new IllegalArgumentException("Owner is not a condition provider service");
        }
        int ruleInstanceLimit = -1;
        if (owner.metaData != null) {
            ruleInstanceLimit = owner.metaData.getInt(ConditionProviderService.META_DATA_RULE_INSTANCE_LIMIT, -1);
        }
        if (ruleInstanceLimit > 0 && ruleInstanceLimit < (getCurrentInstanceCount(automaticZenRule.getOwner()) + 1)) {
            throw new IllegalArgumentException("Rule instance limit exceeded");
        }
    }
    ZenModeConfig newConfig;
    synchronized (mConfig) {
        if (mConfig == null) {
            throw new AndroidRuntimeException("Could not create rule");
        }
        if (DEBUG) {
            Log.d(TAG, "addAutomaticZenRule rule= " + automaticZenRule + " reason=" + reason);
        }
        newConfig = mConfig.copy();
        ZenRule rule = new ZenRule();
        populateZenRule(automaticZenRule, rule, true);
        newConfig.automaticRules.put(rule.id, rule);
        if (setConfigLocked(newConfig, reason, true)) {
            return rule.id;
        } else {
            throw new AndroidRuntimeException("Could not create rule");
        }
    }
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) AutomaticZenRule(android.app.AutomaticZenRule) ZenRule(android.service.notification.ZenModeConfig.ZenRule) AndroidRuntimeException(android.util.AndroidRuntimeException) ZenModeConfig(android.service.notification.ZenModeConfig)

Example 2 with AutomaticZenRule

use of android.app.AutomaticZenRule in project android_frameworks_base by ResurrectionRemix.

the class ZenModeHelper method addAutomaticZenRule.

public String addAutomaticZenRule(AutomaticZenRule automaticZenRule, String reason) {
    if (!isSystemRule(automaticZenRule)) {
        ServiceInfo owner = getServiceInfo(automaticZenRule.getOwner());
        if (owner == null) {
            throw new IllegalArgumentException("Owner is not a condition provider service");
        }
        int ruleInstanceLimit = -1;
        if (owner.metaData != null) {
            ruleInstanceLimit = owner.metaData.getInt(ConditionProviderService.META_DATA_RULE_INSTANCE_LIMIT, -1);
        }
        if (ruleInstanceLimit > 0 && ruleInstanceLimit < (getCurrentInstanceCount(automaticZenRule.getOwner()) + 1)) {
            throw new IllegalArgumentException("Rule instance limit exceeded");
        }
    }
    ZenModeConfig newConfig;
    synchronized (mConfig) {
        if (mConfig == null) {
            throw new AndroidRuntimeException("Could not create rule");
        }
        if (DEBUG) {
            Log.d(TAG, "addAutomaticZenRule rule= " + automaticZenRule + " reason=" + reason);
        }
        newConfig = mConfig.copy();
        ZenRule rule = new ZenRule();
        populateZenRule(automaticZenRule, rule, true);
        newConfig.automaticRules.put(rule.id, rule);
        if (setConfigLocked(newConfig, reason, true)) {
            return rule.id;
        } else {
            throw new AndroidRuntimeException("Could not create rule");
        }
    }
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) AutomaticZenRule(android.app.AutomaticZenRule) ZenRule(android.service.notification.ZenModeConfig.ZenRule) AndroidRuntimeException(android.util.AndroidRuntimeException) ZenModeConfig(android.service.notification.ZenModeConfig)

Example 3 with AutomaticZenRule

use of android.app.AutomaticZenRule in project android_frameworks_base by crdroidandroid.

the class ZenModeHelper method addAutomaticZenRule.

public String addAutomaticZenRule(AutomaticZenRule automaticZenRule, String reason) {
    if (!isSystemRule(automaticZenRule)) {
        ServiceInfo owner = getServiceInfo(automaticZenRule.getOwner());
        if (owner == null) {
            throw new IllegalArgumentException("Owner is not a condition provider service");
        }
        int ruleInstanceLimit = -1;
        if (owner.metaData != null) {
            ruleInstanceLimit = owner.metaData.getInt(ConditionProviderService.META_DATA_RULE_INSTANCE_LIMIT, -1);
        }
        if (ruleInstanceLimit > 0 && ruleInstanceLimit < (getCurrentInstanceCount(automaticZenRule.getOwner()) + 1)) {
            throw new IllegalArgumentException("Rule instance limit exceeded");
        }
    }
    ZenModeConfig newConfig;
    synchronized (mConfig) {
        if (mConfig == null) {
            throw new AndroidRuntimeException("Could not create rule");
        }
        if (DEBUG) {
            Log.d(TAG, "addAutomaticZenRule rule= " + automaticZenRule + " reason=" + reason);
        }
        newConfig = mConfig.copy();
        ZenRule rule = new ZenRule();
        populateZenRule(automaticZenRule, rule, true);
        newConfig.automaticRules.put(rule.id, rule);
        if (setConfigLocked(newConfig, reason, true)) {
            return rule.id;
        } else {
            throw new AndroidRuntimeException("Could not create rule");
        }
    }
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) AutomaticZenRule(android.app.AutomaticZenRule) ZenRule(android.service.notification.ZenModeConfig.ZenRule) AndroidRuntimeException(android.util.AndroidRuntimeException) ZenModeConfig(android.service.notification.ZenModeConfig)

Example 4 with AutomaticZenRule

use of android.app.AutomaticZenRule in project android_frameworks_base by AOSPA.

the class ZenModeHelper method addAutomaticZenRule.

public String addAutomaticZenRule(AutomaticZenRule automaticZenRule, String reason) {
    if (!isSystemRule(automaticZenRule)) {
        ServiceInfo owner = getServiceInfo(automaticZenRule.getOwner());
        if (owner == null) {
            throw new IllegalArgumentException("Owner is not a condition provider service");
        }
        int ruleInstanceLimit = -1;
        if (owner.metaData != null) {
            ruleInstanceLimit = owner.metaData.getInt(ConditionProviderService.META_DATA_RULE_INSTANCE_LIMIT, -1);
        }
        if (ruleInstanceLimit > 0 && ruleInstanceLimit < (getCurrentInstanceCount(automaticZenRule.getOwner()) + 1)) {
            throw new IllegalArgumentException("Rule instance limit exceeded");
        }
    }
    ZenModeConfig newConfig;
    synchronized (mConfig) {
        if (mConfig == null) {
            throw new AndroidRuntimeException("Could not create rule");
        }
        if (DEBUG) {
            Log.d(TAG, "addAutomaticZenRule rule= " + automaticZenRule + " reason=" + reason);
        }
        newConfig = mConfig.copy();
        ZenRule rule = new ZenRule();
        populateZenRule(automaticZenRule, rule, true);
        newConfig.automaticRules.put(rule.id, rule);
        if (setConfigLocked(newConfig, reason, true)) {
            return rule.id;
        } else {
            throw new AndroidRuntimeException("Could not create rule");
        }
    }
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) AutomaticZenRule(android.app.AutomaticZenRule) ZenRule(android.service.notification.ZenModeConfig.ZenRule) AndroidRuntimeException(android.util.AndroidRuntimeException) ZenModeConfig(android.service.notification.ZenModeConfig)

Example 5 with AutomaticZenRule

use of android.app.AutomaticZenRule in project android_frameworks_base by DirtyUnicorns.

the class ZenModeHelper method addAutomaticZenRule.

public String addAutomaticZenRule(AutomaticZenRule automaticZenRule, String reason) {
    if (!isSystemRule(automaticZenRule)) {
        ServiceInfo owner = getServiceInfo(automaticZenRule.getOwner());
        if (owner == null) {
            throw new IllegalArgumentException("Owner is not a condition provider service");
        }
        int ruleInstanceLimit = -1;
        if (owner.metaData != null) {
            ruleInstanceLimit = owner.metaData.getInt(ConditionProviderService.META_DATA_RULE_INSTANCE_LIMIT, -1);
        }
        if (ruleInstanceLimit > 0 && ruleInstanceLimit < (getCurrentInstanceCount(automaticZenRule.getOwner()) + 1)) {
            throw new IllegalArgumentException("Rule instance limit exceeded");
        }
    }
    ZenModeConfig newConfig;
    synchronized (mConfig) {
        if (mConfig == null) {
            throw new AndroidRuntimeException("Could not create rule");
        }
        if (DEBUG) {
            Log.d(TAG, "addAutomaticZenRule rule= " + automaticZenRule + " reason=" + reason);
        }
        newConfig = mConfig.copy();
        ZenRule rule = new ZenRule();
        populateZenRule(automaticZenRule, rule, true);
        newConfig.automaticRules.put(rule.id, rule);
        if (setConfigLocked(newConfig, reason, true)) {
            return rule.id;
        } else {
            throw new AndroidRuntimeException("Could not create rule");
        }
    }
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) AutomaticZenRule(android.app.AutomaticZenRule) ZenRule(android.service.notification.ZenModeConfig.ZenRule) AndroidRuntimeException(android.util.AndroidRuntimeException) ZenModeConfig(android.service.notification.ZenModeConfig)

Aggregations

AutomaticZenRule (android.app.AutomaticZenRule)7 ServiceInfo (android.content.pm.ServiceInfo)5 ZenModeConfig (android.service.notification.ZenModeConfig)5 ZenRule (android.service.notification.ZenModeConfig.ZenRule)5 AndroidRuntimeException (android.util.AndroidRuntimeException)5 Preference (android.support.v7.preference.Preference)1 OnPreferenceClickListener (android.support.v7.preference.Preference.OnPreferenceClickListener)1 PreferenceScreen (android.support.v7.preference.PreferenceScreen)1 Map (java.util.Map)1