/* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.notification.modes; import static android.app.NotificationManager.INTERRUPTION_FILTER_ALL; import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY; import static java.util.Objects.requireNonNull; import android.annotation.SuppressLint; import android.app.AutomaticZenRule; import android.app.NotificationManager; import android.content.Context; import android.graphics.drawable.Drawable; import android.service.notification.ZenDeviceEffects; import android.service.notification.ZenPolicy; import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.android.settings.R; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import java.util.Objects; /** * Represents either an {@link AutomaticZenRule} or the manual DND rule in a unified way. * *
It also adapts other rule features that we don't want to expose in the UI, such as * interruption filters other than {@code PRIORITY}, rules without specific icons, etc. */ class ZenMode { private static final String TAG = "ZenMode"; /** * Additional value for the {@code @ZenPolicy.ChannelType} enumeration that indicates that all * channels can bypass DND when this policy is active. * *
This value shouldn't be used on "real" ZenPolicy objects sent to or returned from
* {@link android.app.NotificationManager}; it's a way of representing rules with interruption
* filter = {@link NotificationManager#INTERRUPTION_FILTER_ALL} in the UI.
*/
public static final int CHANNEL_POLICY_ALL = -1;
static final String MANUAL_DND_MODE_ID = "manual_dnd";
@SuppressLint("WrongConstant")
private static final ZenPolicy POLICY_INTERRUPTION_FILTER_ALL =
new ZenPolicy.Builder()
.allowChannels(CHANNEL_POLICY_ALL)
.allowAllSounds()
.showAllVisualEffects()
.build();
// Must match com.android.server.notification.ZenModeHelper#applyCustomPolicy.
private static final ZenPolicy POLICY_INTERRUPTION_FILTER_ALARMS =
new ZenPolicy.Builder()
.disallowAllSounds()
.allowAlarms(true)
.allowMedia(true)
.allowPriorityChannels(false)
.build();
// Must match com.android.server.notification.ZenModeHelper#applyCustomPolicy.
private static final ZenPolicy POLICY_INTERRUPTION_FILTER_NONE =
new ZenPolicy.Builder()
.disallowAllSounds()
.hideAllVisualEffects()
.allowPriorityChannels(false)
.build();
private final String mId;
private AutomaticZenRule mRule;
private final boolean mIsActive;
private final boolean mIsManualDnd;
ZenMode(String id, AutomaticZenRule rule, boolean isActive) {
this(id, rule, isActive, false);
}
private ZenMode(String id, AutomaticZenRule rule, boolean isActive, boolean isManualDnd) {
mId = id;
mRule = rule;
mIsActive = isActive;
mIsManualDnd = isManualDnd;
}
static ZenMode manualDndMode(AutomaticZenRule manualRule, boolean isActive) {
return new ZenMode(MANUAL_DND_MODE_ID, manualRule, isActive, true);
}
@NonNull
public String getId() {
return mId;
}
@NonNull
public AutomaticZenRule getRule() {
return mRule;
}
@NonNull
public ListenableFuture