Search in sources :

Example 21 with ZenRule

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

the class ZenModeHelper method appendDefaultScheduleRules.

private void appendDefaultScheduleRules(ZenModeConfig config) {
    if (config == null)
        return;
    final ScheduleInfo weeknights = new ScheduleInfo();
    weeknights.days = ZenModeConfig.WEEKNIGHT_DAYS;
    weeknights.startHour = 22;
    weeknights.endHour = 7;
    final ZenRule rule1 = new ZenRule();
    rule1.enabled = false;
    rule1.name = mContext.getResources().getString(R.string.zen_mode_default_weeknights_name);
    rule1.conditionId = ZenModeConfig.toScheduleConditionId(weeknights);
    rule1.zenMode = Global.ZEN_MODE_ALARMS;
    rule1.component = ScheduleConditionProvider.COMPONENT;
    rule1.id = ZenModeConfig.newRuleId();
    rule1.creationTime = System.currentTimeMillis();
    config.automaticRules.put(rule1.id, rule1);
    final ScheduleInfo weekends = new ScheduleInfo();
    weekends.days = ZenModeConfig.WEEKEND_DAYS;
    weekends.startHour = 23;
    weekends.startMinute = 30;
    weekends.endHour = 10;
    final ZenRule rule2 = new ZenRule();
    rule2.enabled = false;
    rule2.name = mContext.getResources().getString(R.string.zen_mode_default_weekends_name);
    rule2.conditionId = ZenModeConfig.toScheduleConditionId(weekends);
    rule2.zenMode = Global.ZEN_MODE_ALARMS;
    rule2.component = ScheduleConditionProvider.COMPONENT;
    rule2.id = ZenModeConfig.newRuleId();
    rule2.creationTime = System.currentTimeMillis();
    config.automaticRules.put(rule2.id, rule2);
}
Also used : AutomaticZenRule(android.app.AutomaticZenRule) ZenRule(android.service.notification.ZenModeConfig.ZenRule) ScheduleInfo(android.service.notification.ZenModeConfig.ScheduleInfo)

Example 22 with ZenRule

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

Example 23 with ZenRule

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

Example 24 with ZenRule

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

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

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

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