Search in sources :

Example 1 with ZenRule

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

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

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

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

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

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

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

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

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

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)

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