Search in sources :

Example 46 with ZenRule

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

the class ZenModeConditions method onConditionChanged.

@Override
public void onConditionChanged(Uri id, Condition condition) {
    if (DEBUG)
        Log.d(TAG, "onConditionChanged " + id + " " + condition);
    ZenModeConfig config = mHelper.getConfig();
    if (config == null)
        return;
    boolean updated = updateCondition(id, condition, config.manualRule);
    for (ZenRule automaticRule : config.automaticRules.values()) {
        updated |= updateCondition(id, condition, automaticRule);
        updated |= updateSnoozing(automaticRule);
    }
    if (updated) {
        mHelper.setConfig(config, "conditionChanged");
    }
}
Also used : ZenRule(android.service.notification.ZenModeConfig.ZenRule) ZenModeConfig(android.service.notification.ZenModeConfig)

Example 47 with ZenRule

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

the class ZenModeHelper method removeAutomaticZenRule.

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)) {
            newConfig.automaticRules.remove(id);
            if (DEBUG)
                Log.d(TAG, "removeZenRule zenRule=" + id + " reason=" + reason);
        } else {
            throw new SecurityException("Cannot delete rules not owned by your condition provider");
        }
        return setConfigLocked(newConfig, reason, true);
    }
}
Also used : AutomaticZenRule(android.app.AutomaticZenRule) ZenRule(android.service.notification.ZenModeConfig.ZenRule) ZenModeConfig(android.service.notification.ZenModeConfig)

Example 48 with ZenRule

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

the class ZenModeHelper method setManualZenMode.

private void setManualZenMode(int zenMode, Uri conditionId, String reason, String caller, boolean setRingerMode) {
    ZenModeConfig newConfig;
    synchronized (mConfig) {
        if (mConfig == null)
            return;
        if (!Global.isValidZenMode(zenMode))
            return;
        if (DEBUG)
            Log.d(TAG, "setManualZenMode " + Global.zenModeToString(zenMode) + " conditionId=" + conditionId + " reason=" + reason + " setRingerMode=" + setRingerMode);
        newConfig = mConfig.copy();
        if (zenMode == Global.ZEN_MODE_OFF) {
            newConfig.manualRule = null;
            for (ZenRule automaticRule : newConfig.automaticRules.values()) {
                if (automaticRule.isAutomaticActive()) {
                    automaticRule.snoozing = true;
                }
            }
        } else {
            final ZenRule newRule = new ZenRule();
            newRule.enabled = true;
            newRule.zenMode = zenMode;
            newRule.conditionId = conditionId;
            newRule.enabler = caller;
            newConfig.manualRule = newRule;
        }
        setConfigLocked(newConfig, reason, setRingerMode);
    }
}
Also used : AutomaticZenRule(android.app.AutomaticZenRule) ZenRule(android.service.notification.ZenModeConfig.ZenRule) ZenModeConfig(android.service.notification.ZenModeConfig)

Example 49 with ZenRule

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

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 50 with ZenRule

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

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