Search in sources :

Example 36 with ZenRule

use of android.service.notification.ZenModeConfig.ZenRule in project android_frameworks_base by DirtyUnicorns.

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);
    }
}
Also used : ZenModeConfig(android.service.notification.ZenModeConfig) ZenRule(android.service.notification.ZenModeConfig.ZenRule)

Example 37 with ZenRule

use of android.service.notification.ZenModeConfig.ZenRule in project android_frameworks_base by DirtyUnicorns.

the class ZenModeHelper method appendDefaultEventRules.

private void appendDefaultEventRules(ZenModeConfig config) {
    if (config == null)
        return;
    final EventInfo events = new EventInfo();
    // any calendar
    events.calendar = null;
    events.reply = EventInfo.REPLY_YES_OR_MAYBE;
    final ZenRule rule = new ZenRule();
    rule.enabled = false;
    rule.name = mContext.getResources().getString(R.string.zen_mode_default_events_name);
    rule.conditionId = ZenModeConfig.toEventConditionId(events);
    rule.zenMode = Global.ZEN_MODE_ALARMS;
    rule.component = EventConditionProvider.COMPONENT;
    rule.id = ZenModeConfig.newRuleId();
    rule.creationTime = System.currentTimeMillis();
    config.automaticRules.put(rule.id, rule);
}
Also used : AutomaticZenRule(android.app.AutomaticZenRule) ZenRule(android.service.notification.ZenModeConfig.ZenRule) EventInfo(android.service.notification.ZenModeConfig.EventInfo)

Example 38 with ZenRule

use of android.service.notification.ZenModeConfig.ZenRule 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)

Example 39 with ZenRule

use of android.service.notification.ZenModeConfig.ZenRule in project android_frameworks_base by DirtyUnicorns.

the class ZenModeConditions method evaluateConfig.

public void evaluateConfig(ZenModeConfig config, boolean processSubscriptions) {
    if (config == null)
        return;
    if (config.manualRule != null && config.manualRule.condition != null && !config.manualRule.isTrueOrUnknown()) {
        if (DEBUG)
            Log.d(TAG, "evaluateConfig: clearing manual rule");
        config.manualRule = null;
    }
    final ArraySet<Uri> current = new ArraySet<>();
    evaluateRule(config.manualRule, current, processSubscriptions);
    for (ZenRule automaticRule : config.automaticRules.values()) {
        evaluateRule(automaticRule, current, processSubscriptions);
        updateSnoozing(automaticRule);
    }
    final int N = mSubscriptions.size();
    for (int i = N - 1; i >= 0; i--) {
        final Uri id = mSubscriptions.keyAt(i);
        final ComponentName component = mSubscriptions.valueAt(i);
        if (processSubscriptions) {
            if (!current.contains(id)) {
                mConditionProviders.unsubscribeIfNecessary(component, id);
                mSubscriptions.removeAt(i);
            }
        }
    }
    mFirstEvaluation = false;
}
Also used : ZenRule(android.service.notification.ZenModeConfig.ZenRule) ArraySet(android.util.ArraySet) ComponentName(android.content.ComponentName) Uri(android.net.Uri)

Example 40 with ZenRule

use of android.service.notification.ZenModeConfig.ZenRule in project android_frameworks_base by AOSPA.

the class ZenModeConditions method evaluateConfig.

public void evaluateConfig(ZenModeConfig config, boolean processSubscriptions) {
    if (config == null)
        return;
    if (config.manualRule != null && config.manualRule.condition != null && !config.manualRule.isTrueOrUnknown()) {
        if (DEBUG)
            Log.d(TAG, "evaluateConfig: clearing manual rule");
        config.manualRule = null;
    }
    final ArraySet<Uri> current = new ArraySet<>();
    evaluateRule(config.manualRule, current, processSubscriptions);
    for (ZenRule automaticRule : config.automaticRules.values()) {
        evaluateRule(automaticRule, current, processSubscriptions);
        updateSnoozing(automaticRule);
    }
    final int N = mSubscriptions.size();
    for (int i = N - 1; i >= 0; i--) {
        final Uri id = mSubscriptions.keyAt(i);
        final ComponentName component = mSubscriptions.valueAt(i);
        if (processSubscriptions) {
            if (!current.contains(id)) {
                mConditionProviders.unsubscribeIfNecessary(component, id);
                mSubscriptions.removeAt(i);
            }
        }
    }
    mFirstEvaluation = false;
}
Also used : ZenRule(android.service.notification.ZenModeConfig.ZenRule) ArraySet(android.util.ArraySet) ComponentName(android.content.ComponentName) Uri(android.net.Uri)

Aggregations

ZenRule (android.service.notification.ZenModeConfig.ZenRule)55 ZenModeConfig (android.service.notification.ZenModeConfig)40 AutomaticZenRule (android.app.AutomaticZenRule)35 ComponentName (android.content.ComponentName)5 PackageManager (android.content.pm.PackageManager)5 ServiceInfo (android.content.pm.ServiceInfo)5 Uri (android.net.Uri)5 EventInfo (android.service.notification.ZenModeConfig.EventInfo)5 ScheduleInfo (android.service.notification.ZenModeConfig.ScheduleInfo)5 AndroidRuntimeException (android.util.AndroidRuntimeException)5 ArraySet (android.util.ArraySet)5