android.provider.Settings.Global#ZEN_MODE_IMPORTANT_INTERRUPTIONS源码实例Demo

下面列出了android.provider.Settings.Global#ZEN_MODE_IMPORTANT_INTERRUPTIONS 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: ZenModeFiltering.java
/**
 * @param extras extras of the notification with EXTRA_PEOPLE populated
 * @param contactsTimeoutMs timeout in milliseconds to wait for contacts response
 * @param timeoutAffinity affinity to return when the timeout specified via
 *                        <code>contactsTimeoutMs</code> is hit
 */
public static boolean matchesCallFilter(Context context, int zen, ZenModeConfig config,
        UserHandle userHandle, Bundle extras, ValidateNotificationPeople validator,
        int contactsTimeoutMs, float timeoutAffinity) {
    if (zen == Global.ZEN_MODE_NO_INTERRUPTIONS) return false; // nothing gets through
    if (zen == Global.ZEN_MODE_ALARMS) return false; // not an alarm
    if (zen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) {
        if (config.allowRepeatCallers && REPEAT_CALLERS.isRepeat(context, extras)) {
            return true;
        }
        if (!config.allowCalls) return false; // no other calls get through
        if (validator != null) {
            final float contactAffinity = validator.getContactAffinity(userHandle, extras,
                    contactsTimeoutMs, timeoutAffinity);
            return audienceMatches(config.allowCallsFrom, contactAffinity);
        }
    }
    return true;
}
 
源代码2 项目: android_9.0.0_r45   文件: ZenModeHelper.java
private void appendDefaultEveryNightRule(ZenModeConfig config) {
    if (config == null) return;

    final ScheduleInfo weeknights = new ScheduleInfo();
    weeknights.days = ZenModeConfig.ALL_DAYS;
    weeknights.startHour = 22;
    weeknights.endHour = 7;
    weeknights.exitAtAlarm = true;
    final ZenRule rule = new ZenRule();
    rule.enabled = false;
    rule.name = mDefaultRuleEveryNightName;
    rule.conditionId = ZenModeConfig.toScheduleConditionId(weeknights);
    rule.zenMode = Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS;
    rule.component = ScheduleConditionProvider.COMPONENT;
    rule.id = ZenModeConfig.EVERY_NIGHT_DEFAULT_RULE_ID;
    rule.creationTime = System.currentTimeMillis();
    config.automaticRules.put(rule.id, rule);
}
 
源代码3 项目: android_9.0.0_r45   文件: ZenModeHelper.java
private void appendDefaultEventRules(ZenModeConfig config) {
    if (config == null) return;

    final EventInfo events = new EventInfo();
    events.calendar = null; // any calendar
    events.reply = EventInfo.REPLY_YES_OR_MAYBE;
    final ZenRule rule = new ZenRule();
    rule.enabled = false;
    rule.name = mDefaultRuleEventsName;
    rule.conditionId = ZenModeConfig.toEventConditionId(events);
    rule.zenMode = Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS;
    rule.component = EventConditionProvider.COMPONENT;
    rule.id = ZenModeConfig.EVENTS_DEFAULT_RULE_ID;
    rule.creationTime = System.currentTimeMillis();
    config.automaticRules.put(rule.id, rule);
}
 
源代码4 项目: android_9.0.0_r45   文件: ZenModeConfig.java
public static ZenRule readRuleXml(XmlPullParser parser) {
    final ZenRule rt = new ZenRule();
    rt.enabled = safeBoolean(parser, RULE_ATT_ENABLED, true);
    rt.snoozing = safeBoolean(parser, RULE_ATT_SNOOZING, false);
    rt.name = parser.getAttributeValue(null, RULE_ATT_NAME);
    final String zen = parser.getAttributeValue(null, RULE_ATT_ZEN);
    rt.zenMode = tryParseZenMode(zen, -1);
    if (rt.zenMode == -1) {
        Slog.w(TAG, "Bad zen mode in rule xml:" + zen);
        return null;
    }
    rt.conditionId = safeUri(parser, RULE_ATT_CONDITION_ID);
    rt.component = safeComponentName(parser, RULE_ATT_COMPONENT);
    rt.creationTime = safeLong(parser, RULE_ATT_CREATION_TIME, 0);
    rt.enabler = parser.getAttributeValue(null, RULE_ATT_ENABLER);
    rt.condition = readConditionXml(parser);

    // all default rules and user created rules updated to zenMode important interruptions
    if (rt.zenMode != Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS
            && Condition.isValidId(rt.conditionId, SYSTEM_AUTHORITY)) {
        Slog.i(TAG, "Updating zenMode of automatic rule " + rt.name);
        rt.zenMode = Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS;
    }
    return rt;
}
 
源代码5 项目: android_9.0.0_r45   文件: ZenLog.java
private static String zenModeToString(int zenMode) {
    switch (zenMode) {
        case Global.ZEN_MODE_OFF: return "off";
        case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS: return "important_interruptions";
        case Global.ZEN_MODE_ALARMS: return "alarms";
        case Global.ZEN_MODE_NO_INTERRUPTIONS: return "no_interruptions";
        default: return "unknown";
    }
}
 
源代码6 项目: android_9.0.0_r45   文件: ZenModeHelper.java
@VisibleForTesting
protected void applyZenToRingerMode() {
    if (mAudioManager == null) return;
    // force the ringer mode into compliance
    final int ringerModeInternal = mAudioManager.getRingerModeInternal();
    int newRingerModeInternal = ringerModeInternal;
    switch (mZenMode) {
        case Global.ZEN_MODE_NO_INTERRUPTIONS:
        case Global.ZEN_MODE_ALARMS:
            if (ringerModeInternal != AudioManager.RINGER_MODE_SILENT) {
                setPreviousRingerModeSetting(ringerModeInternal);
                newRingerModeInternal = AudioManager.RINGER_MODE_SILENT;
            }
            break;
        case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS:
            // do not apply zen to ringer, streams zen muted in AudioService
            break;
        case Global.ZEN_MODE_OFF:
            if (ringerModeInternal == AudioManager.RINGER_MODE_SILENT) {
                newRingerModeInternal = getPreviousRingerModeSetting();
                setPreviousRingerModeSetting(null);
            }
            break;
    }
    if (newRingerModeInternal != -1) {
        mAudioManager.setRingerModeInternal(newRingerModeInternal, TAG);
    }
}
 
源代码7 项目: android_9.0.0_r45   文件: ZenModeHelper.java
private static int zenSeverity(int zen) {
    switch (zen) {
        case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS: return 1;
        case Global.ZEN_MODE_ALARMS: return 2;
        case Global.ZEN_MODE_NO_INTERRUPTIONS: return 3;
        default: return 0;
    }
}
 
源代码8 项目: android_9.0.0_r45   文件: ZenModeHelper.java
@Override
public int onSetRingerModeExternal(int ringerModeOld, int ringerModeNew, String caller,
        int ringerModeInternal, VolumePolicy policy) {
    int ringerModeInternalOut = ringerModeNew;
    final boolean isChange = ringerModeOld != ringerModeNew;
    final boolean isVibrate = ringerModeInternal == AudioManager.RINGER_MODE_VIBRATE;

    int newZen = -1;
    switch (ringerModeNew) {
        case AudioManager.RINGER_MODE_SILENT:
            if (isChange) {
                if (mZenMode == Global.ZEN_MODE_OFF) {
                    newZen = Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS;
                }
                ringerModeInternalOut = isVibrate ? AudioManager.RINGER_MODE_VIBRATE
                        : AudioManager.RINGER_MODE_SILENT;
            } else {
                ringerModeInternalOut = ringerModeInternal;
            }
            break;
        case AudioManager.RINGER_MODE_VIBRATE:
        case AudioManager.RINGER_MODE_NORMAL:
            if (mZenMode != Global.ZEN_MODE_OFF) {
                newZen = Global.ZEN_MODE_OFF;
            }
            break;
    }
    if (newZen != -1) {
        setManualZenMode(newZen, null, "ringerModeExternal", caller,
                false /*setRingerMode*/);
    }

    ZenLog.traceSetRingerModeExternal(ringerModeOld, ringerModeNew, caller,
            ringerModeInternal, ringerModeInternalOut);
    return ringerModeInternalOut;
}
 
源代码9 项目: android_9.0.0_r45   文件: ZenModeHelper.java
@Override
public int getRingerModeAffectedStreams(int streams) {
    // ringtone and notification streams are always affected by ringer mode
    // system stream is affected by ringer mode when not in priority-only
    streams |= (1 << AudioSystem.STREAM_RING) |
            (1 << AudioSystem.STREAM_NOTIFICATION) |
            (1 << AudioSystem.STREAM_SYSTEM);

    if (mZenMode == Global.ZEN_MODE_NO_INTERRUPTIONS) {
        // alarm and music streams affected by ringer mode when in total silence
        streams |= (1 << AudioSystem.STREAM_ALARM) |
                (1 << AudioSystem.STREAM_MUSIC);
    } else {
        streams &= ~((1 << AudioSystem.STREAM_ALARM) |
                (1 << AudioSystem.STREAM_MUSIC));
    }

    if (mZenMode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS
            && ZenModeConfig.areAllPriorityOnlyNotificationZenSoundsMuted(mConfig)) {
        // system stream is not affected by ringer mode in priority only when the ringer
        // is zen muted (all other notification categories are muted)
        streams &= ~(1 << AudioSystem.STREAM_SYSTEM);
    } else {
        streams |= (1 << AudioSystem.STREAM_SYSTEM);
    }
    return streams;
}
 
源代码10 项目: android_9.0.0_r45   文件: NotificationManager.java
/** @hide */
public static int zenModeToInterruptionFilter(int zen) {
    switch (zen) {
        case Global.ZEN_MODE_OFF: return INTERRUPTION_FILTER_ALL;
        case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS: return INTERRUPTION_FILTER_PRIORITY;
        case Global.ZEN_MODE_ALARMS: return INTERRUPTION_FILTER_ALARMS;
        case Global.ZEN_MODE_NO_INTERRUPTIONS: return INTERRUPTION_FILTER_NONE;
        default: return INTERRUPTION_FILTER_UNKNOWN;
    }
}
 
源代码11 项目: android_9.0.0_r45   文件: NotificationManager.java
/** @hide */
public static int zenModeFromInterruptionFilter(int interruptionFilter, int defValue) {
    switch (interruptionFilter) {
        case INTERRUPTION_FILTER_ALL: return Global.ZEN_MODE_OFF;
        case INTERRUPTION_FILTER_PRIORITY: return Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS;
        case INTERRUPTION_FILTER_ALARMS: return Global.ZEN_MODE_ALARMS;
        case INTERRUPTION_FILTER_NONE:  return Global.ZEN_MODE_NO_INTERRUPTIONS;
        default: return defValue;
    }
}
 
源代码12 项目: android_9.0.0_r45   文件: ZenModeConfig.java
/**
 * Determines if DND is currently overriding the ringer
 */
public static boolean isZenOverridingRinger(int zen, ZenModeConfig zenConfig) {
    return zen == Global.ZEN_MODE_NO_INTERRUPTIONS
            || zen == Global.ZEN_MODE_ALARMS
            || (zen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS
            && ZenModeConfig.areAllPriorityOnlyNotificationZenSoundsMuted(zenConfig));
}
 
源代码13 项目: android_9.0.0_r45   文件: SeekBarVolumizer.java
private boolean isZenMuted() {
    return mNotificationOrRing && mZenMode == Global.ZEN_MODE_ALARMS
            || mZenMode == Global.ZEN_MODE_NO_INTERRUPTIONS
            || (mZenMode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS
                && ((!mAllowAlarms && isAlarmsStream(mStreamType))
                    || (!mAllowMedia && isMediaStream(mStreamType))
                    || (!mAllowRinger && isNotificationOrRing(mStreamType))));
}
 
源代码14 项目: android_9.0.0_r45   文件: ZenModeFiltering.java
public boolean shouldIntercept(int zen, ZenModeConfig config, NotificationRecord record) {
    if (zen == ZEN_MODE_OFF) {
        return false;
    }
    // Make an exception to policy for the notification saying that policy has changed
    if (NotificationManager.Policy.areAllVisualEffectsSuppressed(config.suppressedVisualEffects)
            && "android".equals(record.sbn.getPackageName())
            && SystemMessageProto.SystemMessage.NOTE_ZEN_UPGRADE == record.sbn.getId()) {
        ZenLog.traceNotIntercepted(record, "systemDndChangedNotification");
        return false;
    }
    switch (zen) {
        case Global.ZEN_MODE_NO_INTERRUPTIONS:
            // #notevenalarms
            ZenLog.traceIntercepted(record, "none");
            return true;
        case Global.ZEN_MODE_ALARMS:
            if (isAlarm(record)) {
                // Alarms only
                return false;
            }
            ZenLog.traceIntercepted(record, "alarmsOnly");
            return true;
        case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS:
            // allow user-prioritized packages through in priority mode
            if (record.getPackagePriority() == Notification.PRIORITY_MAX) {
                ZenLog.traceNotIntercepted(record, "priorityApp");
                return false;
            }

            if (isAlarm(record)) {
                if (!config.allowAlarms) {
                    ZenLog.traceIntercepted(record, "!allowAlarms");
                    return true;
                }
                return false;
            }
            if (isCall(record)) {
                if (config.allowRepeatCallers
                        && REPEAT_CALLERS.isRepeat(mContext, extras(record))) {
                    ZenLog.traceNotIntercepted(record, "repeatCaller");
                    return false;
                }
                if (!config.allowCalls) {
                    ZenLog.traceIntercepted(record, "!allowCalls");
                    return true;
                }
                return shouldInterceptAudience(config.allowCallsFrom, record);
            }
            if (isMessage(record)) {
                if (!config.allowMessages) {
                    ZenLog.traceIntercepted(record, "!allowMessages");
                    return true;
                }
                return shouldInterceptAudience(config.allowMessagesFrom, record);
            }
            if (isEvent(record)) {
                if (!config.allowEvents) {
                    ZenLog.traceIntercepted(record, "!allowEvents");
                    return true;
                }
                return false;
            }
            if (isReminder(record)) {
                if (!config.allowReminders) {
                    ZenLog.traceIntercepted(record, "!allowReminders");
                    return true;
                }
                return false;
            }
            if (isMedia(record)) {
                if (!config.allowMedia) {
                    ZenLog.traceIntercepted(record, "!allowMedia");
                    return true;
                }
                return false;
            }
            if (isSystem(record)) {
                if (!config.allowSystem) {
                    ZenLog.traceIntercepted(record, "!allowSystem");
                    return true;
                }
                return false;
            }
            ZenLog.traceIntercepted(record, "!priority");
            return true;
        default:
            return false;
    }
}
 
源代码15 项目: android_9.0.0_r45   文件: ZenModeHelper.java
@VisibleForTesting
protected void applyRestrictions() {
    final boolean zenPriorityOnly = mZenMode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS;
    final boolean zenSilence = mZenMode == Global.ZEN_MODE_NO_INTERRUPTIONS;
    final boolean zenAlarmsOnly = mZenMode == Global.ZEN_MODE_ALARMS;

    // notification restrictions
    final boolean muteNotifications =
            (mSuppressedEffects & SUPPRESSED_EFFECT_NOTIFICATIONS) != 0;
    // call restrictions
    final boolean muteCalls = zenAlarmsOnly
            || (zenPriorityOnly && !mConfig.allowCalls && !mConfig.allowRepeatCallers)
            || (mSuppressedEffects & SUPPRESSED_EFFECT_CALLS) != 0;
    // alarm restrictions
    final boolean muteAlarms = zenPriorityOnly && !mConfig.allowAlarms;
    // media restrictions
    final boolean muteMedia = zenPriorityOnly && !mConfig.allowMedia;
    // system restrictions
    final boolean muteSystem = zenAlarmsOnly || (zenPriorityOnly && !mConfig.allowSystem);
    // total silence restrictions
    final boolean muteEverything = zenSilence
            || (zenPriorityOnly && ZenModeConfig.areAllZenBehaviorSoundsMuted(mConfig));

    for (int usage : AudioAttributes.SDK_USAGES) {
        final int suppressionBehavior = AudioAttributes.SUPPRESSIBLE_USAGES.get(usage);
        if (suppressionBehavior == AudioAttributes.SUPPRESSIBLE_NEVER) {
            applyRestrictions(false /*mute*/, usage);
        } else if (suppressionBehavior == AudioAttributes.SUPPRESSIBLE_NOTIFICATION) {
            applyRestrictions(muteNotifications || muteEverything, usage);
        } else if (suppressionBehavior == AudioAttributes.SUPPRESSIBLE_CALL) {
            applyRestrictions(muteCalls || muteEverything, usage);
        } else if (suppressionBehavior == AudioAttributes.SUPPRESSIBLE_ALARM) {
            applyRestrictions(muteAlarms || muteEverything, usage);
        } else if (suppressionBehavior == AudioAttributes.SUPPRESSIBLE_MEDIA) {
            applyRestrictions(muteMedia || muteEverything, usage);
        } else if (suppressionBehavior == AudioAttributes.SUPPRESSIBLE_SYSTEM) {
            if (usage == AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) {
                // normally DND will only restrict touch sounds, not haptic feedback/vibrations
                applyRestrictions(muteSystem || muteEverything, usage,
                        AppOpsManager.OP_PLAY_AUDIO);
                applyRestrictions(false, usage, AppOpsManager.OP_VIBRATE);
            } else {
                applyRestrictions(muteSystem || muteEverything, usage);
            }
        } else {
            applyRestrictions(muteEverything, usage);
        }
    }
}
 
源代码16 项目: android_9.0.0_r45   文件: ZenModeHelper.java
@Override
public int onSetRingerModeInternal(int ringerModeOld, int ringerModeNew, String caller,
        int ringerModeExternal, VolumePolicy policy) {
    final boolean isChange = ringerModeOld != ringerModeNew;

    int ringerModeExternalOut = ringerModeNew;

    if (mZenMode == Global.ZEN_MODE_OFF
            || (mZenMode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS
            && !ZenModeConfig.areAllPriorityOnlyNotificationZenSoundsMuted(mConfig))) {
        // in priority only with ringer not muted, save ringer mode changes
        // in dnd off, save ringer mode changes
        setPreviousRingerModeSetting(ringerModeNew);
    }
    int newZen = -1;
    switch (ringerModeNew) {
        case AudioManager.RINGER_MODE_SILENT:
            if (isChange && policy.doNotDisturbWhenSilent) {
                if (mZenMode == Global.ZEN_MODE_OFF) {
                    newZen = Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS;
                }
                setPreviousRingerModeSetting(ringerModeOld);
            }
            break;
        case AudioManager.RINGER_MODE_VIBRATE:
        case AudioManager.RINGER_MODE_NORMAL:
            if (isChange && ringerModeOld == AudioManager.RINGER_MODE_SILENT
                    && (mZenMode == Global.ZEN_MODE_NO_INTERRUPTIONS
                    || mZenMode == Global.ZEN_MODE_ALARMS
                    || (mZenMode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS
                    && ZenModeConfig.areAllPriorityOnlyNotificationZenSoundsMuted(
                    mConfig)))) {
                newZen = Global.ZEN_MODE_OFF;
            } else if (mZenMode != Global.ZEN_MODE_OFF) {
                ringerModeExternalOut = AudioManager.RINGER_MODE_SILENT;
            }
            break;
    }

    if (newZen != -1) {
        setManualZenMode(newZen, null, "ringerModeInternal", null,
                false /*setRingerMode*/);
    }
    if (isChange || newZen != -1 || ringerModeExternal != ringerModeExternalOut) {
        ZenLog.traceSetRingerModeInternal(ringerModeOld, ringerModeNew, caller,
                ringerModeExternal, ringerModeExternalOut);
    }
    return ringerModeExternalOut;
}