Search in sources :

Example 31 with ZenRule

use of android.service.notification.ZenModeConfig.ZenRule in project platform_frameworks_base by android.

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);
    }
    synchronized (mSubscriptions) {
        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 32 with ZenRule

use of android.service.notification.ZenModeConfig.ZenRule in project platform_frameworks_base by android.

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

use of android.service.notification.ZenModeConfig.ZenRule in project platform_frameworks_base by android.

the class ZenModeControllerImpl method updateZenModeConfig.

private void updateZenModeConfig() {
    final ZenModeConfig config = mNoMan.getZenModeConfig();
    if (Objects.equals(config, mConfig))
        return;
    final ZenRule oldRule = mConfig != null ? mConfig.manualRule : null;
    mConfig = config;
    fireConfigChanged(config);
    final ZenRule newRule = config != null ? config.manualRule : null;
    if (Objects.equals(oldRule, newRule))
        return;
    fireManualRuleChanged(newRule);
}
Also used : ZenRule(android.service.notification.ZenModeConfig.ZenRule) ZenModeConfig(android.service.notification.ZenModeConfig)

Example 34 with ZenRule

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

the class ZenModeControllerImpl method updateZenModeConfig.

private void updateZenModeConfig() {
    final ZenModeConfig config = mNoMan.getZenModeConfig();
    if (Objects.equals(config, mConfig))
        return;
    final ZenRule oldRule = mConfig != null ? mConfig.manualRule : null;
    mConfig = config;
    fireConfigChanged(config);
    final ZenRule newRule = config != null ? config.manualRule : null;
    if (Objects.equals(oldRule, newRule))
        return;
    fireManualRuleChanged(newRule);
}
Also used : ZenRule(android.service.notification.ZenModeConfig.ZenRule) ZenModeConfig(android.service.notification.ZenModeConfig)

Example 35 with ZenRule

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

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");
    }
}
Also used : AutomaticZenRule(android.app.AutomaticZenRule) ZenRule(android.service.notification.ZenModeConfig.ZenRule) PackageManager(android.content.pm.PackageManager) ZenModeConfig(android.service.notification.ZenModeConfig)

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