Java Code Examples for android.provider.Settings.Global#ZEN_MODE_OFF

The following examples show how to use android.provider.Settings.Global#ZEN_MODE_OFF . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZenModeHelper.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private int computeZenMode() {
    if (mConfig == null) return Global.ZEN_MODE_OFF;
    synchronized (mConfig) {
        if (mConfig.manualRule != null) return mConfig.manualRule.zenMode;
        int zen = Global.ZEN_MODE_OFF;
        for (ZenRule automaticRule : mConfig.automaticRules.values()) {
            if (automaticRule.isAutomaticActive()) {
                if (zenSeverity(automaticRule.zenMode) > zenSeverity(zen)) {
                    // automatic rule triggered dnd and user hasn't seen update dnd dialog
                    if (Settings.Global.getInt(mContext.getContentResolver(),
                            Global.ZEN_SETTINGS_SUGGESTION_VIEWED, 1) == 0) {
                        Settings.Global.putInt(mContext.getContentResolver(),
                                Global.SHOW_ZEN_SETTINGS_SUGGESTION, 1);
                    }
                    zen = automaticRule.zenMode;
                }
            }
        }
        return zen;
    }
}
 
Example 2
Source File: ZenLog.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
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";
    }
}
 
Example 3
Source File: ZenModeHelper.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
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, null, setRingerMode);
    }
}
 
Example 4
Source File: ZenModeHelper.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 5
Source File: ZenModeHelper.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 6
Source File: ZenModeHelper.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void showZenUpgradeNotification(int zen) {
    final boolean showNotification = mIsBootComplete
            && zen != Global.ZEN_MODE_OFF
            && Settings.Global.getInt(mContext.getContentResolver(),
            Settings.Global.SHOW_ZEN_UPGRADE_NOTIFICATION, 0) != 0;

    if (showNotification) {
        mNotificationManager.notify(TAG, SystemMessage.NOTE_ZEN_UPGRADE,
                createZenUpgradeNotification());
        Settings.Global.putInt(mContext.getContentResolver(),
                Global.SHOW_ZEN_UPGRADE_NOTIFICATION, 0);
    }
}
 
Example 7
Source File: NotificationManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** @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;
    }
}
 
Example 8
Source File: NotificationManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** @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;
    }
}
 
Example 9
Source File: ZenModeHelper.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example 10
Source File: ZenModeHelper.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public boolean canVolumeDownEnterSilent() {
    return mZenMode == Global.ZEN_MODE_OFF;
}