Search in sources :

Example 36 with ZenModeConfig

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

use of android.service.notification.ZenModeConfig 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 38 with ZenModeConfig

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

the class ZenModeHelper method readXml.

public void readXml(XmlPullParser parser, boolean forRestore) throws XmlPullParserException, IOException {
    final ZenModeConfig config = ZenModeConfig.readXml(parser, mConfigMigration);
    if (config != null) {
        if (forRestore) {
            //TODO: http://b/22388012
            if (config.user != UserHandle.USER_SYSTEM) {
                return;
            }
            // don't restore the manual rule
            config.manualRule = null;
            long time = System.currentTimeMillis();
            if (config.automaticRules != null) {
                for (ZenRule automaticRule : config.automaticRules.values()) {
                    // don't restore transient state from restored automatic rules
                    automaticRule.snoozing = false;
                    automaticRule.condition = null;
                    automaticRule.creationTime = time;
                }
            }
        }
        if (DEBUG)
            Log.d(TAG, "readXml");
        synchronized (mConfig) {
            setConfigLocked(config, "readXml");
        }
    }
}
Also used : AutomaticZenRule(android.app.AutomaticZenRule) ZenRule(android.service.notification.ZenModeConfig.ZenRule) ZenModeConfig(android.service.notification.ZenModeConfig)

Example 39 with ZenModeConfig

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

the class ZenModeHelper method loadConfigForUser.

private void loadConfigForUser(int user, String reason) {
    if (mUser == user || user < UserHandle.USER_SYSTEM)
        return;
    mUser = user;
    if (DEBUG)
        Log.d(TAG, reason + " u=" + user);
    ZenModeConfig config = mConfigs.get(user);
    if (config == null) {
        if (DEBUG)
            Log.d(TAG, reason + " generating default config for user " + user);
        config = mDefaultConfig.copy();
        config.user = user;
    }
    synchronized (mConfig) {
        setConfigLocked(config, reason);
    }
    cleanUpZenRules();
}
Also used : ZenModeConfig(android.service.notification.ZenModeConfig)

Example 40 with ZenModeConfig

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

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)

Aggregations

ZenModeConfig (android.service.notification.ZenModeConfig)50 ZenRule (android.service.notification.ZenModeConfig.ZenRule)40 AutomaticZenRule (android.app.AutomaticZenRule)25 PackageManager (android.content.pm.PackageManager)5 ServiceInfo (android.content.pm.ServiceInfo)5 AndroidRuntimeException (android.util.AndroidRuntimeException)5