The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.app; |
| 18 | |
Julia Reynolds | 0edb50c | 2016-02-26 14:08:25 -0500 | [diff] [blame] | 19 | import android.annotation.IntDef; |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 20 | import android.annotation.NonNull; |
Julia Reynolds | a7ba45a | 2018-08-29 09:07:52 -0400 | [diff] [blame] | 21 | import android.annotation.Nullable; |
John Spurlock | b478252 | 2014-08-22 14:54:46 -0400 | [diff] [blame] | 22 | import android.annotation.SdkConstant; |
Julia Reynolds | 12ad7ca | 2019-01-28 09:29:16 -0500 | [diff] [blame] | 23 | import android.annotation.SystemApi; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 24 | import android.annotation.SystemService; |
Julia Reynolds | b6c1f99 | 2016-11-22 09:26:46 -0500 | [diff] [blame] | 25 | import android.annotation.TestApi; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 26 | import android.app.Notification.Builder; |
Artur Satayev | c895b1b | 2019-12-10 17:47:51 +0000 | [diff] [blame] | 27 | import android.compat.annotation.UnsupportedAppUsage; |
John Spurlock | b478252 | 2014-08-22 14:54:46 -0400 | [diff] [blame] | 28 | import android.content.ComponentName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.content.Context; |
Julia Reynolds | e0d711f | 2017-09-01 08:50:47 -0400 | [diff] [blame] | 30 | import android.content.Intent; |
Dan Sandler | 994349c | 2015-04-15 11:02:54 -0400 | [diff] [blame] | 31 | import android.content.pm.ParceledListSlice; |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 32 | import android.graphics.drawable.Icon; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 33 | import android.net.Uri; |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 34 | import android.os.Build; |
John Spurlock | 2b122f4 | 2014-08-27 16:29:47 -0400 | [diff] [blame] | 35 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.os.Handler; |
| 37 | import android.os.IBinder; |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 38 | import android.os.Parcel; |
| 39 | import android.os.Parcelable; |
Jeff Sharkey | 69ddab4 | 2012-08-25 00:05:46 -0700 | [diff] [blame] | 40 | import android.os.RemoteException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.os.ServiceManager; |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 42 | import android.os.StrictMode; |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 43 | import android.os.UserHandle; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 44 | import android.provider.Settings.Global; |
Julia Reynolds | ad6dd35 | 2019-03-07 16:46:22 -0500 | [diff] [blame] | 45 | import android.service.notification.Adjustment; |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 46 | import android.service.notification.Condition; |
Dan Sandler | 994349c | 2015-04-15 11:02:54 -0400 | [diff] [blame] | 47 | import android.service.notification.StatusBarNotification; |
John Spurlock | cdb57ae | 2015-02-11 19:04:11 -0500 | [diff] [blame] | 48 | import android.service.notification.ZenModeConfig; |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 49 | import android.service.notification.ZenPolicy; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | import android.util.Log; |
Kweku Adams | 5ec78cd | 2017-09-25 16:29:54 -0700 | [diff] [blame] | 51 | import android.util.proto.ProtoOutputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | |
Julia Reynolds | 0edb50c | 2016-02-26 14:08:25 -0500 | [diff] [blame] | 53 | import java.lang.annotation.Retention; |
| 54 | import java.lang.annotation.RetentionPolicy; |
Beverly | c629ee4 | 2018-10-02 16:14:07 -0400 | [diff] [blame] | 55 | import java.util.ArrayList; |
Geoffrey Pitsch | 0353371 | 2017-01-05 10:30:07 -0500 | [diff] [blame] | 56 | import java.util.Arrays; |
Julia Reynolds | 361e82d3 | 2016-02-26 18:19:49 -0500 | [diff] [blame] | 57 | import java.util.HashMap; |
Chris Wren | 5ab5c74 | 2016-05-10 15:32:23 -0400 | [diff] [blame] | 58 | import java.util.List; |
Julia Reynolds | 361e82d3 | 2016-02-26 18:19:49 -0500 | [diff] [blame] | 59 | import java.util.Map; |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 60 | import java.util.Objects; |
| 61 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | /** |
| 63 | * Class to notify the user of events that happen. This is how you tell |
| 64 | * the user that something has happened in the background. {@more} |
| 65 | * |
| 66 | * Notifications can take different forms: |
| 67 | * <ul> |
| 68 | * <li>A persistent icon that goes in the status bar and is accessible |
| 69 | * through the launcher, (when the user selects it, a designated Intent |
| 70 | * can be launched),</li> |
| 71 | * <li>Turning on or flashing LEDs on the device, or</li> |
| 72 | * <li>Alerting the user by flashing the backlight, playing a sound, |
| 73 | * or vibrating.</li> |
| 74 | * </ul> |
| 75 | * |
| 76 | * <p> |
Peter Collingbourne | b97c349 | 2010-10-13 20:04:52 +0100 | [diff] [blame] | 77 | * Each of the notify methods takes an int id parameter and optionally a |
| 78 | * {@link String} tag parameter, which may be {@code null}. These parameters |
| 79 | * are used to form a pair (tag, id), or ({@code null}, id) if tag is |
| 80 | * unspecified. This pair identifies this notification from your app to the |
| 81 | * system, so that pair should be unique within your app. If you call one |
| 82 | * of the notify methods with a (tag, id) pair that is currently active and |
| 83 | * a new set of notification parameters, it will be updated. For example, |
| 84 | * if you pass a new status bar icon, the old icon in the status bar will |
| 85 | * be replaced with the new one. This is also the same tag and id you pass |
| 86 | * to the {@link #cancel(int)} or {@link #cancel(String, int)} method to clear |
| 87 | * this notification. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | * |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 89 | * <div class="special reference"> |
| 90 | * <h3>Developer Guides</h3> |
| 91 | * <p>For a guide to creating notifications, read the |
| 92 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a> |
| 93 | * developer guide.</p> |
| 94 | * </div> |
| 95 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | * @see android.app.Notification |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | */ |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 98 | @SystemService(Context.NOTIFICATION_SERVICE) |
| 99 | public class NotificationManager { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | private static String TAG = "NotificationManager"; |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 101 | private static boolean localLOGV = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | |
John Spurlock | b478252 | 2014-08-22 14:54:46 -0400 | [diff] [blame] | 103 | /** |
Julia Reynolds | fc9767b | 2018-01-22 17:45:16 -0500 | [diff] [blame] | 104 | * Intent that is broadcast when an application is blocked or unblocked. |
| 105 | * |
| 106 | * This broadcast is only sent to the app whose block state has changed. |
| 107 | * |
| 108 | * Input: nothing |
Julia Reynolds | 44ff7c9 | 2018-02-05 10:02:30 -0500 | [diff] [blame] | 109 | * Output: {@link #EXTRA_BLOCKED_STATE} |
Julia Reynolds | fc9767b | 2018-01-22 17:45:16 -0500 | [diff] [blame] | 110 | */ |
| 111 | @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 112 | public static final String ACTION_APP_BLOCK_STATE_CHANGED = |
| 113 | "android.app.action.APP_BLOCK_STATE_CHANGED"; |
| 114 | |
| 115 | /** |
Julia Reynolds | 3eb3ffd | 2017-11-16 10:11:32 -0500 | [diff] [blame] | 116 | * Intent that is broadcast when a {@link NotificationChannel} is blocked |
| 117 | * (when {@link NotificationChannel#getImportance()} is {@link #IMPORTANCE_NONE}) or unblocked |
| 118 | * (when {@link NotificationChannel#getImportance()} is anything other than |
| 119 | * {@link #IMPORTANCE_NONE}). |
| 120 | * |
| 121 | * This broadcast is only sent to the app that owns the channel that has changed. |
| 122 | * |
| 123 | * Input: nothing |
Julia Reynolds | 44ff7c9 | 2018-02-05 10:02:30 -0500 | [diff] [blame] | 124 | * Output: {@link #EXTRA_NOTIFICATION_CHANNEL_ID} |
| 125 | * Output: {@link #EXTRA_BLOCKED_STATE} |
Julia Reynolds | 3eb3ffd | 2017-11-16 10:11:32 -0500 | [diff] [blame] | 126 | */ |
| 127 | @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 128 | public static final String ACTION_NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED = |
| 129 | "android.app.action.NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED"; |
| 130 | |
| 131 | /** |
Julia Reynolds | 44ff7c9 | 2018-02-05 10:02:30 -0500 | [diff] [blame] | 132 | * Extra for {@link #ACTION_NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED} containing the id of the |
| 133 | * {@link NotificationChannel} which has a new blocked state. |
Julia Reynolds | 3eb3ffd | 2017-11-16 10:11:32 -0500 | [diff] [blame] | 134 | * |
Julia Reynolds | 44ff7c9 | 2018-02-05 10:02:30 -0500 | [diff] [blame] | 135 | * The value will be the {@link NotificationChannel#getId()} of the channel. |
Julia Reynolds | 3eb3ffd | 2017-11-16 10:11:32 -0500 | [diff] [blame] | 136 | */ |
Julia Reynolds | 44ff7c9 | 2018-02-05 10:02:30 -0500 | [diff] [blame] | 137 | public static final String EXTRA_NOTIFICATION_CHANNEL_ID = |
| 138 | "android.app.extra.NOTIFICATION_CHANNEL_ID"; |
| 139 | |
| 140 | /** |
| 141 | * Extra for {@link #ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED} containing the id |
| 142 | * of the {@link NotificationChannelGroup} which has a new blocked state. |
| 143 | * |
| 144 | * The value will be the {@link NotificationChannelGroup#getId()} of the group. |
| 145 | */ |
| 146 | public static final String EXTRA_NOTIFICATION_CHANNEL_GROUP_ID = |
| 147 | "android.app.extra.NOTIFICATION_CHANNEL_GROUP_ID"; |
| 148 | |
Julia Reynolds | 3eb3ffd | 2017-11-16 10:11:32 -0500 | [diff] [blame] | 149 | |
| 150 | /** |
| 151 | * Extra for {@link #ACTION_NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED} or |
| 152 | * {@link #ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED} containing the new blocked |
| 153 | * state as a boolean. |
| 154 | * |
| 155 | * The value will be {@code true} if this channel or group is now blocked and {@code false} if |
| 156 | * this channel or group is now unblocked. |
| 157 | */ |
| 158 | public static final String EXTRA_BLOCKED_STATE = "android.app.extra.BLOCKED_STATE"; |
| 159 | |
Julia Reynolds | 3eb3ffd | 2017-11-16 10:11:32 -0500 | [diff] [blame] | 160 | /** |
| 161 | * Intent that is broadcast when a {@link NotificationChannelGroup} is |
| 162 | * {@link NotificationChannelGroup#isBlocked() blocked} or unblocked. |
| 163 | * |
| 164 | * This broadcast is only sent to the app that owns the channel group that has changed. |
| 165 | * |
| 166 | * Input: nothing |
Julia Reynolds | 44ff7c9 | 2018-02-05 10:02:30 -0500 | [diff] [blame] | 167 | * Output: {@link #EXTRA_NOTIFICATION_CHANNEL_GROUP_ID} |
| 168 | * Output: {@link #EXTRA_BLOCKED_STATE} |
Julia Reynolds | 3eb3ffd | 2017-11-16 10:11:32 -0500 | [diff] [blame] | 169 | */ |
| 170 | @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 171 | public static final String ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED = |
| 172 | "android.app.action.NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED"; |
| 173 | |
| 174 | /** |
Julia Reynolds | 3ec9330 | 2019-07-11 15:27:31 -0400 | [diff] [blame] | 175 | * Intent that is broadcast when the status of an {@link AutomaticZenRule} has changed. |
| 176 | * |
| 177 | * <p>Use this to know whether you need to continue monitor to device state in order to |
| 178 | * provide up-to-date states (with {@link #setAutomaticZenRuleState(String, Condition)}) for |
| 179 | * this rule.</p> |
| 180 | * |
| 181 | * Input: nothing |
| 182 | * Output: {@link #EXTRA_AUTOMATIC_ZEN_RULE_ID} |
| 183 | * Output: {@link #EXTRA_AUTOMATIC_ZEN_RULE_STATUS} |
| 184 | */ |
| 185 | @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 186 | public static final String ACTION_AUTOMATIC_ZEN_RULE_STATUS_CHANGED = |
| 187 | "android.app.action.AUTOMATIC_ZEN_RULE_STATUS_CHANGED"; |
| 188 | |
| 189 | /** |
| 190 | * Integer extra for {@link #ACTION_AUTOMATIC_ZEN_RULE_STATUS_CHANGED} containing the state of |
| 191 | * the {@link AutomaticZenRule}. |
| 192 | * |
| 193 | * <p> |
| 194 | * The value will be one of {@link #AUTOMATIC_RULE_STATUS_ENABLED}, |
| 195 | * {@link #AUTOMATIC_RULE_STATUS_DISABLED}, {@link #AUTOMATIC_RULE_STATUS_REMOVED}, |
| 196 | * {@link #AUTOMATIC_RULE_STATUS_UNKNOWN}. |
| 197 | * </p> |
| 198 | */ |
| 199 | public static final String EXTRA_AUTOMATIC_ZEN_RULE_STATUS = |
| 200 | "android.app.extra.AUTOMATIC_ZEN_RULE_STATUS"; |
| 201 | |
| 202 | /** |
| 203 | * String extra for {@link #ACTION_AUTOMATIC_ZEN_RULE_STATUS_CHANGED} containing the id of the |
| 204 | * {@link AutomaticZenRule} (see {@link #addAutomaticZenRule(AutomaticZenRule)}) that has |
| 205 | * changed. |
| 206 | */ |
| 207 | public static final String EXTRA_AUTOMATIC_ZEN_RULE_ID = |
| 208 | "android.app.extra.AUTOMATIC_ZEN_RULE_ID"; |
| 209 | |
| 210 | /** @hide */ |
| 211 | @IntDef(prefix = { "AUTOMATIC_RULE_STATUS" }, value = { |
| 212 | AUTOMATIC_RULE_STATUS_ENABLED, AUTOMATIC_RULE_STATUS_DISABLED, |
| 213 | AUTOMATIC_RULE_STATUS_REMOVED, AUTOMATIC_RULE_STATUS_UNKNOWN |
| 214 | }) |
| 215 | @Retention(RetentionPolicy.SOURCE) |
| 216 | public @interface AutomaticZenRuleStatus {} |
| 217 | |
| 218 | /** |
| 219 | * Constant value for {@link #EXTRA_AUTOMATIC_ZEN_RULE_STATUS} - the current status of the |
| 220 | * rule is unknown at your target sdk version, and you should continue to provide state changes |
| 221 | * via {@link #setAutomaticZenRuleState(String, Condition)}. |
| 222 | */ |
| 223 | public static final int AUTOMATIC_RULE_STATUS_UNKNOWN = -1; |
| 224 | |
| 225 | /** |
| 226 | * Constant value for {@link #EXTRA_AUTOMATIC_ZEN_RULE_STATUS} - the given rule currently |
| 227 | * exists and is enabled. You should continue to provide state changes via |
| 228 | * {@link #setAutomaticZenRuleState(String, Condition)}. |
| 229 | */ |
| 230 | public static final int AUTOMATIC_RULE_STATUS_ENABLED = 1; |
| 231 | |
| 232 | /** |
| 233 | * Constant value for {@link #EXTRA_AUTOMATIC_ZEN_RULE_STATUS} - the given rule currently |
| 234 | * exists but is disabled. You do not need to continue to provide state changes via |
| 235 | * {@link #setAutomaticZenRuleState(String, Condition)} until the rule is reenabled. |
| 236 | */ |
| 237 | public static final int AUTOMATIC_RULE_STATUS_DISABLED = 2; |
| 238 | |
| 239 | /** |
| 240 | * Constant value for {@link #EXTRA_AUTOMATIC_ZEN_RULE_STATUS} - the given rule has been |
| 241 | * deleted. Further calls to {@link #setAutomaticZenRuleState(String, Condition)} will be |
| 242 | * ignored. |
| 243 | */ |
| 244 | public static final int AUTOMATIC_RULE_STATUS_REMOVED = 3; |
| 245 | |
| 246 | /** |
John Spurlock | b478252 | 2014-08-22 14:54:46 -0400 | [diff] [blame] | 247 | * Intent that is broadcast when the state of {@link #getEffectsSuppressor()} changes. |
| 248 | * This broadcast is only sent to registered receivers. |
| 249 | * |
| 250 | * @hide |
| 251 | */ |
| 252 | @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 253 | public static final String ACTION_EFFECTS_SUPPRESSOR_CHANGED |
| 254 | = "android.os.action.ACTION_EFFECTS_SUPPRESSOR_CHANGED"; |
| 255 | |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 256 | /** |
John Spurlock | 7c74f78 | 2015-06-04 13:01:42 -0400 | [diff] [blame] | 257 | * Intent that is broadcast when the state of {@link #isNotificationPolicyAccessGranted()} |
| 258 | * changes. |
| 259 | * |
| 260 | * This broadcast is only sent to registered receivers, and only to the apps that have changed. |
| 261 | */ |
| 262 | @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 263 | public static final String ACTION_NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED |
| 264 | = "android.app.action.NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED"; |
| 265 | |
| 266 | /** |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 267 | * Intent that is broadcast when the state of getNotificationPolicy() changes. |
| 268 | * This broadcast is only sent to registered receivers. |
| 269 | */ |
| 270 | @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 271 | public static final String ACTION_NOTIFICATION_POLICY_CHANGED |
| 272 | = "android.app.action.NOTIFICATION_POLICY_CHANGED"; |
| 273 | |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 274 | /** |
| 275 | * Intent that is broadcast when the state of getCurrentInterruptionFilter() changes. |
| 276 | * This broadcast is only sent to registered receivers. |
| 277 | */ |
| 278 | @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 279 | public static final String ACTION_INTERRUPTION_FILTER_CHANGED |
| 280 | = "android.app.action.INTERRUPTION_FILTER_CHANGED"; |
| 281 | |
| 282 | /** |
Jason Monk | a992732 | 2015-12-13 16:22:37 -0500 | [diff] [blame] | 283 | * Intent that is broadcast when the state of getCurrentInterruptionFilter() changes. |
| 284 | * @hide |
| 285 | */ |
| 286 | @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 287 | public static final String ACTION_INTERRUPTION_FILTER_CHANGED_INTERNAL |
| 288 | = "android.app.action.INTERRUPTION_FILTER_CHANGED_INTERNAL"; |
| 289 | |
Julia Reynolds | 0edb50c | 2016-02-26 14:08:25 -0500 | [diff] [blame] | 290 | /** @hide */ |
Jeff Sharkey | 6503bd8 | 2017-04-19 23:24:18 -0600 | [diff] [blame] | 291 | @IntDef(prefix = { "INTERRUPTION_FILTER_" }, value = { |
| 292 | INTERRUPTION_FILTER_NONE, INTERRUPTION_FILTER_PRIORITY, INTERRUPTION_FILTER_ALARMS, |
| 293 | INTERRUPTION_FILTER_ALL, INTERRUPTION_FILTER_UNKNOWN |
| 294 | }) |
Julia Reynolds | 0edb50c | 2016-02-26 14:08:25 -0500 | [diff] [blame] | 295 | @Retention(RetentionPolicy.SOURCE) |
| 296 | public @interface InterruptionFilter {} |
| 297 | |
Jason Monk | a992732 | 2015-12-13 16:22:37 -0500 | [diff] [blame] | 298 | /** |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 299 | * {@link #getCurrentInterruptionFilter() Interruption filter} constant - |
Julia Reynolds | dd0605b | 2016-04-06 10:26:54 -0400 | [diff] [blame] | 300 | * Normal interruption filter - no notifications are suppressed. |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 301 | */ |
| 302 | public static final int INTERRUPTION_FILTER_ALL = 1; |
| 303 | |
| 304 | /** |
| 305 | * {@link #getCurrentInterruptionFilter() Interruption filter} constant - |
Julia Reynolds | dd0605b | 2016-04-06 10:26:54 -0400 | [diff] [blame] | 306 | * Priority interruption filter - all notifications are suppressed except those that match |
| 307 | * the priority criteria. Some audio streams are muted. See |
| 308 | * {@link Policy#priorityCallSenders}, {@link Policy#priorityCategories}, |
| 309 | * {@link Policy#priorityMessageSenders} to define or query this criteria. Users can |
| 310 | * additionally specify packages that can bypass this interruption filter. |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 311 | */ |
| 312 | public static final int INTERRUPTION_FILTER_PRIORITY = 2; |
| 313 | |
| 314 | /** |
| 315 | * {@link #getCurrentInterruptionFilter() Interruption filter} constant - |
Julia Reynolds | dd0605b | 2016-04-06 10:26:54 -0400 | [diff] [blame] | 316 | * No interruptions filter - all notifications are suppressed and all audio streams (except |
| 317 | * those used for phone calls) and vibrations are muted. |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 318 | */ |
| 319 | public static final int INTERRUPTION_FILTER_NONE = 3; |
| 320 | |
| 321 | /** |
| 322 | * {@link #getCurrentInterruptionFilter() Interruption filter} constant - |
Julia Reynolds | dd0605b | 2016-04-06 10:26:54 -0400 | [diff] [blame] | 323 | * Alarms only interruption filter - all notifications except those of category |
| 324 | * {@link Notification#CATEGORY_ALARM} are suppressed. Some audio streams are muted. |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 325 | */ |
| 326 | public static final int INTERRUPTION_FILTER_ALARMS = 4; |
| 327 | |
| 328 | /** {@link #getCurrentInterruptionFilter() Interruption filter} constant - returned when |
| 329 | * the value is unavailable for any reason. |
| 330 | */ |
| 331 | public static final int INTERRUPTION_FILTER_UNKNOWN = 0; |
| 332 | |
Chris Wren | 5ab5c74 | 2016-05-10 15:32:23 -0400 | [diff] [blame] | 333 | /** @hide */ |
Jeff Sharkey | 6503bd8 | 2017-04-19 23:24:18 -0600 | [diff] [blame] | 334 | @IntDef(prefix = { "IMPORTANCE_" }, value = { |
| 335 | IMPORTANCE_UNSPECIFIED, IMPORTANCE_NONE, |
| 336 | IMPORTANCE_MIN, IMPORTANCE_LOW, IMPORTANCE_DEFAULT, IMPORTANCE_HIGH |
| 337 | }) |
Chris Wren | 5ab5c74 | 2016-05-10 15:32:23 -0400 | [diff] [blame] | 338 | @Retention(RetentionPolicy.SOURCE) |
| 339 | public @interface Importance {} |
| 340 | |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 341 | /** |
| 342 | * Activity Action: Launch an Automatic Zen Rule configuration screen |
| 343 | * <p> |
| 344 | * Input: Optionally, {@link #EXTRA_AUTOMATIC_RULE_ID}, if the configuration screen for an |
| 345 | * existing rule should be displayed. If the rule id is missing or null, apps should display |
| 346 | * a configuration screen where users can create a new instance of the rule. |
| 347 | * <p> |
| 348 | * Output: Nothing |
| 349 | * <p> |
| 350 | * You can have multiple activities handling this intent, if you support multiple |
| 351 | * {@link AutomaticZenRule rules}. In order for the system to properly display all of your |
| 352 | * rule types so that users can create new instances or configure existing ones, you need |
| 353 | * to add some extra metadata ({@link #META_DATA_AUTOMATIC_RULE_TYPE}) |
| 354 | * to your activity tag in your manifest. If you'd like to limit the number of rules a user |
| 355 | * can create from this flow, you can additionally optionally include |
| 356 | * {@link #META_DATA_RULE_INSTANCE_LIMIT}. |
| 357 | * |
| 358 | * For example, |
| 359 | * <meta-data |
| 360 | * android:name="android.app.zen.automatic.ruleType" |
| 361 | * android:value="@string/my_condition_rule"> |
| 362 | * </meta-data> |
| 363 | * <meta-data |
| 364 | * android:name="android.app.zen.automatic.ruleInstanceLimit" |
| 365 | * android:value="1"> |
| 366 | * </meta-data> |
| 367 | * </p> |
| 368 | * </p> |
| 369 | * |
| 370 | * @see {@link #addAutomaticZenRule(AutomaticZenRule)} |
| 371 | */ |
| 372 | @SdkConstant(SdkConstant.SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 373 | public static final String ACTION_AUTOMATIC_ZEN_RULE = |
| 374 | "android.app.action.AUTOMATIC_ZEN_RULE"; |
| 375 | |
| 376 | /** |
| 377 | * Used as an optional string extra on {@link #ACTION_AUTOMATIC_ZEN_RULE} intents. If |
| 378 | * provided, contains the id of the {@link AutomaticZenRule} (as returned from |
| 379 | * {@link NotificationManager#addAutomaticZenRule(AutomaticZenRule)}) for which configuration |
| 380 | * settings should be displayed. |
| 381 | */ |
| 382 | public static final String EXTRA_AUTOMATIC_RULE_ID = "android.app.extra.AUTOMATIC_RULE_ID"; |
| 383 | |
| 384 | /** |
| 385 | * A required {@code meta-data} tag for activities that handle |
| 386 | * {@link #ACTION_AUTOMATIC_ZEN_RULE}. |
| 387 | * |
| 388 | * This tag should contain a localized name of the type of the zen rule provided by the |
| 389 | * activity. |
| 390 | */ |
Julia Reynolds | 395bf705 | 2019-03-21 11:41:17 -0400 | [diff] [blame] | 391 | public static final String META_DATA_AUTOMATIC_RULE_TYPE = |
| 392 | "android.service.zen.automatic.ruleType"; |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 393 | |
| 394 | /** |
| 395 | * An optional {@code meta-data} tag for activities that handle |
| 396 | * {@link #ACTION_AUTOMATIC_ZEN_RULE}. |
| 397 | * |
| 398 | * This tag should contain the maximum number of rule instances that |
| 399 | * can be created for this rule type. Omit or enter a value <= 0 to allow unlimited instances. |
| 400 | */ |
| 401 | public static final String META_DATA_RULE_INSTANCE_LIMIT = |
Julia Reynolds | 395bf705 | 2019-03-21 11:41:17 -0400 | [diff] [blame] | 402 | "android.service.zen.automatic.ruleInstanceLimit"; |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 403 | |
Chris Wren | 5ab5c74 | 2016-05-10 15:32:23 -0400 | [diff] [blame] | 404 | /** Value signifying that the user has not expressed a per-app visibility override value. |
| 405 | * @hide */ |
| 406 | public static final int VISIBILITY_NO_OVERRIDE = -1000; |
Julia Reynolds | 8576991 | 2016-10-25 09:08:57 -0400 | [diff] [blame] | 407 | |
Chris Wren | 5ab5c74 | 2016-05-10 15:32:23 -0400 | [diff] [blame] | 408 | /** |
| 409 | * Value signifying that the user has not expressed an importance. |
| 410 | * |
| 411 | * This value is for persisting preferences, and should never be associated with |
| 412 | * an actual notification. |
| 413 | */ |
| 414 | public static final int IMPORTANCE_UNSPECIFIED = -1000; |
| 415 | |
| 416 | /** |
Julia Reynolds | baff400 | 2016-12-15 11:34:26 -0500 | [diff] [blame] | 417 | * A notification with no importance: does not show in the shade. |
Chris Wren | 5ab5c74 | 2016-05-10 15:32:23 -0400 | [diff] [blame] | 418 | */ |
| 419 | public static final int IMPORTANCE_NONE = 0; |
| 420 | |
| 421 | /** |
Dianne Hackborn | 6e5bd3f | 2017-07-31 14:22:04 -0700 | [diff] [blame] | 422 | * Min notification importance: only shows in the shade, below the fold. This should |
| 423 | * not be used with {@link Service#startForeground(int, Notification) Service.startForeground} |
| 424 | * since a foreground service is supposed to be something the user cares about so it does |
| 425 | * not make semantic sense to mark its notification as minimum importance. If you do this |
| 426 | * as of Android version {@link android.os.Build.VERSION_CODES#O}, the system will show |
| 427 | * a higher-priority notification about your app running in the background. |
Chris Wren | 5ab5c74 | 2016-05-10 15:32:23 -0400 | [diff] [blame] | 428 | */ |
| 429 | public static final int IMPORTANCE_MIN = 1; |
| 430 | |
| 431 | /** |
Julia Reynolds | 12ad7ca | 2019-01-28 09:29:16 -0500 | [diff] [blame] | 432 | * Low notification importance: Shows in the shade, and potentially in the status bar |
| 433 | * (see {@link #shouldHideSilentStatusBarIcons()}), but is not audibly intrusive. |
Chris Wren | 5ab5c74 | 2016-05-10 15:32:23 -0400 | [diff] [blame] | 434 | */ |
| 435 | public static final int IMPORTANCE_LOW = 2; |
| 436 | |
| 437 | /** |
Julia Reynolds | 8576991 | 2016-10-25 09:08:57 -0400 | [diff] [blame] | 438 | * Default notification importance: shows everywhere, makes noise, but does not visually |
| 439 | * intrude. |
Chris Wren | 5ab5c74 | 2016-05-10 15:32:23 -0400 | [diff] [blame] | 440 | */ |
| 441 | public static final int IMPORTANCE_DEFAULT = 3; |
| 442 | |
| 443 | /** |
Julia Reynolds | 8576991 | 2016-10-25 09:08:57 -0400 | [diff] [blame] | 444 | * Higher notification importance: shows everywhere, makes noise and peeks. May use full screen |
| 445 | * intents. |
Chris Wren | 5ab5c74 | 2016-05-10 15:32:23 -0400 | [diff] [blame] | 446 | */ |
| 447 | public static final int IMPORTANCE_HIGH = 4; |
| 448 | |
| 449 | /** |
Julia Reynolds | 8576991 | 2016-10-25 09:08:57 -0400 | [diff] [blame] | 450 | * Unused. |
Chris Wren | 5ab5c74 | 2016-05-10 15:32:23 -0400 | [diff] [blame] | 451 | */ |
| 452 | public static final int IMPORTANCE_MAX = 5; |
| 453 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 454 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | private static INotificationManager sService; |
| 456 | |
Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 457 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 458 | @UnsupportedAppUsage |
Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 459 | static public INotificationManager getService() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | { |
| 461 | if (sService != null) { |
| 462 | return sService; |
| 463 | } |
| 464 | IBinder b = ServiceManager.getService("notification"); |
| 465 | sService = INotificationManager.Stub.asInterface(b); |
| 466 | return sService; |
| 467 | } |
| 468 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 469 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 470 | /*package*/ NotificationManager(Context context, Handler handler) |
| 471 | { |
| 472 | mContext = context; |
| 473 | } |
| 474 | |
Jeff Sharkey | 69ddab4 | 2012-08-25 00:05:46 -0700 | [diff] [blame] | 475 | /** {@hide} */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 476 | @UnsupportedAppUsage |
Jeff Sharkey | 69ddab4 | 2012-08-25 00:05:46 -0700 | [diff] [blame] | 477 | public static NotificationManager from(Context context) { |
| 478 | return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); |
| 479 | } |
| 480 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 481 | /** |
Daniel Sandler | e97a3bc | 2011-02-07 16:47:07 -0500 | [diff] [blame] | 482 | * Post a notification to be shown in the status bar. If a notification with |
| 483 | * the same id has already been posted by your application and has not yet been canceled, it |
| 484 | * will be replaced by the updated information. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 485 | * |
| 486 | * @param id An identifier for this notification unique within your |
| 487 | * application. |
Daniel Sandler | e97a3bc | 2011-02-07 16:47:07 -0500 | [diff] [blame] | 488 | * @param notification A {@link Notification} object describing what to show the user. Must not |
| 489 | * be null. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 490 | */ |
| 491 | public void notify(int id, Notification notification) |
| 492 | { |
Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 493 | notify(null, id, notification); |
| 494 | } |
| 495 | |
| 496 | /** |
Julia Reynolds | a7ba45a | 2018-08-29 09:07:52 -0400 | [diff] [blame] | 497 | * Posts a notification to be shown in the status bar. If a notification with |
Daniel Sandler | e97a3bc | 2011-02-07 16:47:07 -0500 | [diff] [blame] | 498 | * the same tag and id has already been posted by your application and has not yet been |
| 499 | * canceled, it will be replaced by the updated information. |
Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 500 | * |
Julia Reynolds | e0d711f | 2017-09-01 08:50:47 -0400 | [diff] [blame] | 501 | * All {@link android.service.notification.NotificationListenerService listener services} will |
| 502 | * be granted {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} access to any {@link Uri uris} |
| 503 | * provided on this notification or the |
| 504 | * {@link NotificationChannel} this notification is posted to using |
| 505 | * {@link Context#grantUriPermission(String, Uri, int)}. Permission will be revoked when the |
| 506 | * notification is canceled, or you can revoke permissions with |
| 507 | * {@link Context#revokeUriPermission(Uri, int)}. |
| 508 | * |
Peter Collingbourne | b97c349 | 2010-10-13 20:04:52 +0100 | [diff] [blame] | 509 | * @param tag A string identifier for this notification. May be {@code null}. |
| 510 | * @param id An identifier for this notification. The pair (tag, id) must be unique |
| 511 | * within your application. |
Daniel Sandler | e97a3bc | 2011-02-07 16:47:07 -0500 | [diff] [blame] | 512 | * @param notification A {@link Notification} object describing what to |
| 513 | * show the user. Must not be null. |
Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 514 | */ |
| 515 | public void notify(String tag, int id, Notification notification) |
| 516 | { |
Jeff Sharkey | ad357d1 | 2018-02-02 13:25:31 -0700 | [diff] [blame] | 517 | notifyAsUser(tag, id, notification, mContext.getUser()); |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | /** |
Julia Reynolds | a7ba45a | 2018-08-29 09:07:52 -0400 | [diff] [blame] | 521 | * Posts a notification as a specified package to be shown in the status bar. If a notification |
| 522 | * with the same tag and id has already been posted for that package and has not yet been |
| 523 | * canceled, it will be replaced by the updated information. |
| 524 | * |
| 525 | * All {@link android.service.notification.NotificationListenerService listener services} will |
| 526 | * be granted {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} access to any {@link Uri uris} |
| 527 | * provided on this notification or the |
| 528 | * {@link NotificationChannel} this notification is posted to using |
| 529 | * {@link Context#grantUriPermission(String, Uri, int)}. Permission will be revoked when the |
| 530 | * notification is canceled, or you can revoke permissions with |
| 531 | * {@link Context#revokeUriPermission(Uri, int)}. |
| 532 | * |
| 533 | * @param targetPackage The package to post the notification as. The package must have granted |
| 534 | * you access to post notifications on their behalf with |
| 535 | * {@link #setNotificationDelegate(String)}. |
| 536 | * @param tag A string identifier for this notification. May be {@code null}. |
| 537 | * @param id An identifier for this notification. The pair (tag, id) must be unique |
| 538 | * within your application. |
| 539 | * @param notification A {@link Notification} object describing what to |
| 540 | * show the user. Must not be null. |
| 541 | */ |
Julia Reynolds | e4a47dd | 2019-06-07 13:40:59 -0400 | [diff] [blame] | 542 | public void notifyAsPackage(@NonNull String targetPackage, @Nullable String tag, int id, |
Fabian Kozynski | 867550e | 2019-02-28 12:59:57 -0500 | [diff] [blame] | 543 | @NonNull Notification notification) { |
Julia Reynolds | a7ba45a | 2018-08-29 09:07:52 -0400 | [diff] [blame] | 544 | INotificationManager service = getService(); |
| 545 | String sender = mContext.getPackageName(); |
| 546 | |
| 547 | try { |
| 548 | if (localLOGV) Log.v(TAG, sender + ": notify(" + id + ", " + notification + ")"); |
| 549 | service.enqueueNotificationWithTag(targetPackage, sender, tag, id, |
| 550 | fixNotification(notification), mContext.getUser().getIdentifier()); |
| 551 | } catch (RemoteException e) { |
| 552 | throw e.rethrowFromSystemServer(); |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | /** |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 557 | * @hide |
| 558 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 559 | @UnsupportedAppUsage |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 560 | public void notifyAsUser(String tag, int id, Notification notification, UserHandle user) |
| 561 | { |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 562 | INotificationManager service = getService(); |
| 563 | String pkg = mContext.getPackageName(); |
Julia Reynolds | a7ba45a | 2018-08-29 09:07:52 -0400 | [diff] [blame] | 564 | |
| 565 | try { |
| 566 | if (localLOGV) Log.v(TAG, pkg + ": notify(" + id + ", " + notification + ")"); |
| 567 | service.enqueueNotificationWithTag(pkg, mContext.getOpPackageName(), tag, id, |
| 568 | fixNotification(notification), user.getIdentifier()); |
| 569 | } catch (RemoteException e) { |
| 570 | throw e.rethrowFromSystemServer(); |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | private Notification fixNotification(Notification notification) { |
| 575 | String pkg = mContext.getPackageName(); |
Julia Reynolds | da30354 | 2015-11-23 14:00:20 -0500 | [diff] [blame] | 576 | // Fix the notification as best we can. |
| 577 | Notification.addFieldsFromContext(mContext, notification); |
Julia Reynolds | e0d711f | 2017-09-01 08:50:47 -0400 | [diff] [blame] | 578 | |
Jeff Sharkey | 65c4a2b | 2012-09-25 17:22:27 -0700 | [diff] [blame] | 579 | if (notification.sound != null) { |
| 580 | notification.sound = notification.sound.getCanonicalUri(); |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 581 | if (StrictMode.vmFileUriExposureEnabled()) { |
Jeff Sharkey | ac3be9a | 2016-02-01 10:39:30 -0700 | [diff] [blame] | 582 | notification.sound.checkFileUriExposed("Notification.sound"); |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 583 | } |
Julia Reynolds | e0d711f | 2017-09-01 08:50:47 -0400 | [diff] [blame] | 584 | |
Jeff Sharkey | 65c4a2b | 2012-09-25 17:22:27 -0700 | [diff] [blame] | 585 | } |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 586 | fixLegacySmallIcon(notification, pkg); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 587 | if (mContext.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1) { |
| 588 | if (notification.getSmallIcon() == null) { |
| 589 | throw new IllegalArgumentException("Invalid notification (no valid small icon): " |
| 590 | + notification); |
| 591 | } |
| 592 | } |
Julia Reynolds | a7ba45a | 2018-08-29 09:07:52 -0400 | [diff] [blame] | 593 | |
Selim Cinek | d042662 | 2017-07-11 13:19:59 +0200 | [diff] [blame] | 594 | notification.reduceImageSizes(mContext); |
Rajeev Kumar | bc79dcd | 2020-02-04 19:54:30 -0800 | [diff] [blame] | 595 | return Builder.maybeCloneStrippedForDelivery(notification); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 596 | } |
| 597 | |
Dan Sandler | d63f932 | 2015-05-06 15:18:49 -0400 | [diff] [blame] | 598 | private void fixLegacySmallIcon(Notification n, String pkg) { |
| 599 | if (n.getSmallIcon() == null && n.icon != 0) { |
| 600 | n.setSmallIcon(Icon.createWithResource(pkg, n.icon)); |
| 601 | } |
| 602 | } |
| 603 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 604 | /** |
Julia Reynolds | e4a47dd | 2019-06-07 13:40:59 -0400 | [diff] [blame] | 605 | * Cancels a previously posted notification. |
| 606 | * |
| 607 | * <p>If the notification does not currently represent a |
| 608 | * {@link Service#startForeground(int, Notification) foreground service}, it will be |
| 609 | * removed from the UI and live |
| 610 | * {@link android.service.notification.NotificationListenerService notification listeners} |
| 611 | * will be informed so they can remove the notification from their UIs.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 612 | */ |
| 613 | public void cancel(int id) |
| 614 | { |
Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 615 | cancel(null, id); |
| 616 | } |
| 617 | |
| 618 | /** |
Julia Reynolds | e4a47dd | 2019-06-07 13:40:59 -0400 | [diff] [blame] | 619 | * Cancels a previously posted notification. |
| 620 | * |
| 621 | * <p>If the notification does not currently represent a |
| 622 | * {@link Service#startForeground(int, Notification) foreground service}, it will be |
| 623 | * removed from the UI and live |
| 624 | * {@link android.service.notification.NotificationListenerService notification listeners} |
| 625 | * will be informed so they can remove the notification from their UIs.</p> |
Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 626 | */ |
Julia Reynolds | e4a47dd | 2019-06-07 13:40:59 -0400 | [diff] [blame] | 627 | public void cancel(@Nullable String tag, int id) |
Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 628 | { |
Jeff Sharkey | ad357d1 | 2018-02-02 13:25:31 -0700 | [diff] [blame] | 629 | cancelAsUser(tag, id, mContext.getUser()); |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | /** |
Julia Reynolds | e4a47dd | 2019-06-07 13:40:59 -0400 | [diff] [blame] | 633 | * Cancels a previously posted notification. |
| 634 | * |
| 635 | * <p>If the notification does not currently represent a |
| 636 | * {@link Service#startForeground(int, Notification) foreground service}, it will be |
| 637 | * removed from the UI and live |
| 638 | * {@link android.service.notification.NotificationListenerService notification listeners} |
| 639 | * will be informed so they can remove the notification from their UIs.</p> |
| 640 | * |
| 641 | * <p>This method may be used by {@link #getNotificationDelegate() a notification delegate} to |
| 642 | * cancel notifications that they have posted via {@link #notifyAsPackage(String, String, int, |
| 643 | * Notification)}.</p> |
| 644 | * |
| 645 | * @param targetPackage The package to cancel the notification as. If this package is not your |
| 646 | * package, you can only cancel notifications you posted with |
| 647 | * {@link #notifyAsPackage(String, String, int, Notification). |
| 648 | * @param tag A string identifier for this notification. May be {@code null}. |
| 649 | * @param id An identifier for this notification. |
| 650 | */ |
| 651 | public void cancelAsPackage(@NonNull String targetPackage, @Nullable String tag, int id) { |
| 652 | INotificationManager service = getService(); |
| 653 | try { |
| 654 | service.cancelNotificationWithTag(targetPackage, mContext.getOpPackageName(), |
| 655 | tag, id, mContext.getUser().getIdentifier()); |
| 656 | } catch (RemoteException e) { |
| 657 | throw e.rethrowFromSystemServer(); |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | /** |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 662 | * @hide |
| 663 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 664 | @UnsupportedAppUsage |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 665 | public void cancelAsUser(String tag, int id, UserHandle user) |
| 666 | { |
| 667 | INotificationManager service = getService(); |
| 668 | String pkg = mContext.getPackageName(); |
| 669 | if (localLOGV) Log.v(TAG, pkg + ": cancel(" + id + ")"); |
| 670 | try { |
Julia Reynolds | e4a47dd | 2019-06-07 13:40:59 -0400 | [diff] [blame] | 671 | service.cancelNotificationWithTag( |
| 672 | pkg, mContext.getOpPackageName(), tag, id, user.getIdentifier()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 673 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 674 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 675 | } |
| 676 | } |
| 677 | |
| 678 | /** |
| 679 | * Cancel all previously shown notifications. See {@link #cancel} for the |
| 680 | * detailed behavior. |
| 681 | */ |
| 682 | public void cancelAll() |
| 683 | { |
| 684 | INotificationManager service = getService(); |
| 685 | String pkg = mContext.getPackageName(); |
| 686 | if (localLOGV) Log.v(TAG, pkg + ": cancelAll()"); |
| 687 | try { |
Jeff Sharkey | ad357d1 | 2018-02-02 13:25:31 -0700 | [diff] [blame] | 688 | service.cancelAllNotifications(pkg, mContext.getUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 689 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 690 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 691 | } |
| 692 | } |
| 693 | |
John Spurlock | b478252 | 2014-08-22 14:54:46 -0400 | [diff] [blame] | 694 | /** |
Julia Reynolds | a7ba45a | 2018-08-29 09:07:52 -0400 | [diff] [blame] | 695 | * Allows a package to post notifications on your behalf using |
| 696 | * {@link #notifyAsPackage(String, String, int, Notification)}. |
| 697 | * |
| 698 | * This can be used to allow persistent processes to post notifications based on messages |
| 699 | * received on your behalf from the cloud, without your process having to wake up. |
| 700 | * |
| 701 | * You can check if you have an allowed delegate with {@link #getNotificationDelegate()} and |
Julia Reynolds | cbc45e7 | 2019-03-07 12:31:52 -0500 | [diff] [blame] | 702 | * revoke your delegate by passing null to this method. |
Julia Reynolds | a7ba45a | 2018-08-29 09:07:52 -0400 | [diff] [blame] | 703 | * |
| 704 | * @param delegate Package name of the app which can send notifications on your behalf. |
| 705 | */ |
Julia Reynolds | cbc45e7 | 2019-03-07 12:31:52 -0500 | [diff] [blame] | 706 | public void setNotificationDelegate(@Nullable String delegate) { |
Julia Reynolds | a7ba45a | 2018-08-29 09:07:52 -0400 | [diff] [blame] | 707 | INotificationManager service = getService(); |
| 708 | String pkg = mContext.getPackageName(); |
| 709 | if (localLOGV) Log.v(TAG, pkg + ": cancelAll()"); |
| 710 | try { |
| 711 | service.setNotificationDelegate(pkg, delegate); |
| 712 | } catch (RemoteException e) { |
| 713 | throw e.rethrowFromSystemServer(); |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | /** |
Julia Reynolds | a7ba45a | 2018-08-29 09:07:52 -0400 | [diff] [blame] | 718 | * Returns the {@link #setNotificationDelegate(String) delegate} that can post notifications on |
| 719 | * your behalf, if there currently is one. |
| 720 | */ |
| 721 | public @Nullable String getNotificationDelegate() { |
| 722 | INotificationManager service = getService(); |
| 723 | String pkg = mContext.getPackageName(); |
| 724 | try { |
| 725 | return service.getNotificationDelegate(pkg); |
| 726 | } catch (RemoteException e) { |
| 727 | throw e.rethrowFromSystemServer(); |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | /** |
| 732 | * Returns whether you are allowed to post notifications on behalf of a given package, with |
| 733 | * {@link #notifyAsPackage(String, String, int, Notification)}. |
| 734 | * |
| 735 | * See {@link #setNotificationDelegate(String)}. |
| 736 | */ |
Fabian Kozynski | 867550e | 2019-02-28 12:59:57 -0500 | [diff] [blame] | 737 | public boolean canNotifyAsPackage(@NonNull String pkg) { |
Julia Reynolds | a7ba45a | 2018-08-29 09:07:52 -0400 | [diff] [blame] | 738 | INotificationManager service = getService(); |
| 739 | try { |
Julia Reynolds | 7a6d07a | 2019-03-18 11:31:56 -0400 | [diff] [blame] | 740 | return service.canNotifyAsPackage(mContext.getPackageName(), pkg, mContext.getUserId()); |
Julia Reynolds | a7ba45a | 2018-08-29 09:07:52 -0400 | [diff] [blame] | 741 | } catch (RemoteException e) { |
| 742 | throw e.rethrowFromSystemServer(); |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | /** |
Julia Reynolds | 59e152e | 2017-01-25 17:42:53 -0500 | [diff] [blame] | 747 | * Creates a group container for {@link NotificationChannel} objects. |
| 748 | * |
Julia Reynolds | 1d97e6a | 2017-03-13 15:05:40 -0400 | [diff] [blame] | 749 | * This can be used to rename an existing group. |
Julia Reynolds | 59e152e | 2017-01-25 17:42:53 -0500 | [diff] [blame] | 750 | * <p> |
| 751 | * Group information is only used for presentation, not for behavior. Groups are optional |
| 752 | * for channels, and you can have a mix of channels that belong to groups and channels |
| 753 | * that do not. |
| 754 | * </p> |
| 755 | * <p> |
| 756 | * For example, if your application supports multiple accounts, and those accounts will |
| 757 | * have similar channels, you can create a group for each account with account specific |
| 758 | * labels instead of appending account information to each channel's label. |
| 759 | * </p> |
| 760 | * |
| 761 | * @param group The group to create |
| 762 | */ |
| 763 | public void createNotificationChannelGroup(@NonNull NotificationChannelGroup group) { |
| 764 | createNotificationChannelGroups(Arrays.asList(group)); |
| 765 | } |
| 766 | |
| 767 | /** |
| 768 | * Creates multiple notification channel groups. |
| 769 | * |
| 770 | * @param groups The list of groups to create |
| 771 | */ |
| 772 | public void createNotificationChannelGroups(@NonNull List<NotificationChannelGroup> groups) { |
| 773 | INotificationManager service = getService(); |
| 774 | try { |
| 775 | service.createNotificationChannelGroups(mContext.getPackageName(), |
| 776 | new ParceledListSlice(groups)); |
| 777 | } catch (RemoteException e) { |
| 778 | throw e.rethrowFromSystemServer(); |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | /** |
Geoffrey Pitsch | 0353371 | 2017-01-05 10:30:07 -0500 | [diff] [blame] | 783 | * Creates a notification channel that notifications can be posted to. |
| 784 | * |
Julia Reynolds | 2c891c9 | 2017-03-17 14:23:47 -0400 | [diff] [blame] | 785 | * This can also be used to restore a deleted channel and to update an existing channel's |
Julia Reynolds | 005c8b9 | 2017-08-24 10:35:53 -0400 | [diff] [blame] | 786 | * name, description, group, and/or importance. |
Julia Reynolds | 0ffc13b | 2017-04-27 13:54:36 -0400 | [diff] [blame] | 787 | * |
| 788 | * <p>The name and description should only be changed if the locale changes |
Julia Reynolds | 2c891c9 | 2017-03-17 14:23:47 -0400 | [diff] [blame] | 789 | * or in response to the user renaming this channel. For example, if a user has a channel |
| 790 | * named 'John Doe' that represents messages from a 'John Doe', and 'John Doe' changes his name |
| 791 | * to 'John Smith,' the channel can be renamed to match. |
Geoffrey Pitsch | 07532c3 | 2017-07-18 11:44:06 -0400 | [diff] [blame] | 792 | * |
| 793 | * <p>The importance of an existing channel will only be changed if the new importance is lower |
| 794 | * than the current value and the user has not altered any settings on this channel. |
| 795 | * |
Julia Reynolds | 005c8b9 | 2017-08-24 10:35:53 -0400 | [diff] [blame] | 796 | * <p>The group an existing channel will only be changed if the channel does not already |
| 797 | * belong to a group. |
| 798 | * |
Julia Reynolds | 2c891c9 | 2017-03-17 14:23:47 -0400 | [diff] [blame] | 799 | * All other fields are ignored for channels that already exist. |
Julia Reynolds | 59e152e | 2017-01-25 17:42:53 -0500 | [diff] [blame] | 800 | * |
Geoffrey Pitsch | 0353371 | 2017-01-05 10:30:07 -0500 | [diff] [blame] | 801 | * @param channel the channel to create. Note that the created channel may differ from this |
Julia Reynolds | e866533 | 2017-03-13 13:00:41 -0400 | [diff] [blame] | 802 | * value. If the provided channel is malformed, a RemoteException will be |
Julia Reynolds | 1d97e6a | 2017-03-13 15:05:40 -0400 | [diff] [blame] | 803 | * thrown. |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 804 | */ |
Geoffrey Pitsch | 0353371 | 2017-01-05 10:30:07 -0500 | [diff] [blame] | 805 | public void createNotificationChannel(@NonNull NotificationChannel channel) { |
| 806 | createNotificationChannels(Arrays.asList(channel)); |
Geoffrey Pitsch | e75a66e | 2016-11-22 11:12:11 -0500 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | /** |
Julia Reynolds | 1d97e6a | 2017-03-13 15:05:40 -0400 | [diff] [blame] | 810 | * Creates multiple notification channels that different notifications can be posted to. See |
| 811 | * {@link #createNotificationChannel(NotificationChannel)}. |
Geoffrey Pitsch | e75a66e | 2016-11-22 11:12:11 -0500 | [diff] [blame] | 812 | * |
Julia Reynolds | 1d97e6a | 2017-03-13 15:05:40 -0400 | [diff] [blame] | 813 | * @param channels the list of channels to attempt to create. |
Geoffrey Pitsch | e75a66e | 2016-11-22 11:12:11 -0500 | [diff] [blame] | 814 | */ |
Geoffrey Pitsch | 0353371 | 2017-01-05 10:30:07 -0500 | [diff] [blame] | 815 | public void createNotificationChannels(@NonNull List<NotificationChannel> channels) { |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 816 | INotificationManager service = getService(); |
| 817 | try { |
Geoffrey Pitsch | 0353371 | 2017-01-05 10:30:07 -0500 | [diff] [blame] | 818 | service.createNotificationChannels(mContext.getPackageName(), |
| 819 | new ParceledListSlice(channels)); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 820 | } catch (RemoteException e) { |
| 821 | throw e.rethrowFromSystemServer(); |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | /** |
| 826 | * Returns the notification channel settings for a given channel id. |
Julia Reynolds | 0ffc13b | 2017-04-27 13:54:36 -0400 | [diff] [blame] | 827 | * |
Julia Reynolds | b4a9e9c | 2019-03-20 15:46:08 -0400 | [diff] [blame] | 828 | * <p>The channel must belong to your package, or to a package you are an approved notification |
| 829 | * delegate for (see {@link #canNotifyAsPackage(String)}), or it will not be returned. To query |
| 830 | * a channel as a notification delegate, call this method from a context created for that |
| 831 | * package (see {@link Context#createPackageContext(String, int)}).</p> |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 832 | */ |
| 833 | public NotificationChannel getNotificationChannel(String channelId) { |
| 834 | INotificationManager service = getService(); |
| 835 | try { |
Julia Reynolds | b4a9e9c | 2019-03-20 15:46:08 -0400 | [diff] [blame] | 836 | return service.getNotificationChannel(mContext.getOpPackageName(), |
| 837 | mContext.getUserId(), mContext.getPackageName(), channelId); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 838 | } catch (RemoteException e) { |
| 839 | throw e.rethrowFromSystemServer(); |
| 840 | } |
| 841 | } |
| 842 | |
| 843 | /** |
Julia Reynolds | 0f76734 | 2019-12-18 09:11:55 -0500 | [diff] [blame] | 844 | * Returns the notification channel settings for a given channel and conversation id. |
| 845 | * |
| 846 | * <p>The channel must belong to your package, or to a package you are an approved notification |
| 847 | * delegate for (see {@link #canNotifyAsPackage(String)}), or it will not be returned. To query |
| 848 | * a channel as a notification delegate, call this method from a context created for that |
| 849 | * package (see {@link Context#createPackageContext(String, int)}).</p> |
| 850 | */ |
| 851 | public @Nullable NotificationChannel getNotificationChannel(@NonNull String channelId, |
| 852 | @NonNull String conversationId) { |
| 853 | INotificationManager service = getService(); |
| 854 | try { |
| 855 | return service.getConversationNotificationChannel(mContext.getOpPackageName(), |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 856 | mContext.getUserId(), mContext.getPackageName(), channelId, true, |
| 857 | conversationId); |
Julia Reynolds | 0f76734 | 2019-12-18 09:11:55 -0500 | [diff] [blame] | 858 | } catch (RemoteException e) { |
| 859 | throw e.rethrowFromSystemServer(); |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | /** |
Julia Reynolds | 0ffc13b | 2017-04-27 13:54:36 -0400 | [diff] [blame] | 864 | * Returns all notification channels belonging to the calling package. |
Julia Reynolds | b4a9e9c | 2019-03-20 15:46:08 -0400 | [diff] [blame] | 865 | * |
| 866 | * <p>Approved notification delegates (see {@link #canNotifyAsPackage(String)}) can query |
| 867 | * notification channels belonging to packages they are the delegate for. To do so, call this |
| 868 | * method from a context created for that package (see |
| 869 | * {@link Context#createPackageContext(String, int)}).</p> |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 870 | */ |
| 871 | public List<NotificationChannel> getNotificationChannels() { |
| 872 | INotificationManager service = getService(); |
| 873 | try { |
Julia Reynolds | b4a9e9c | 2019-03-20 15:46:08 -0400 | [diff] [blame] | 874 | return service.getNotificationChannels(mContext.getOpPackageName(), |
| 875 | mContext.getPackageName(), mContext.getUserId()).getList(); |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 876 | } catch (RemoteException e) { |
| 877 | throw e.rethrowFromSystemServer(); |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | /** |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 882 | * Deletes the given notification channel. |
Julia Reynolds | 0ffc13b | 2017-04-27 13:54:36 -0400 | [diff] [blame] | 883 | * |
| 884 | * <p>If you {@link #createNotificationChannel(NotificationChannel) create} a new channel with |
| 885 | * this same id, the deleted channel will be un-deleted with all of the same settings it |
| 886 | * had before it was deleted. |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 887 | */ |
| 888 | public void deleteNotificationChannel(String channelId) { |
| 889 | INotificationManager service = getService(); |
| 890 | try { |
| 891 | service.deleteNotificationChannel(mContext.getPackageName(), channelId); |
| 892 | } catch (RemoteException e) { |
| 893 | throw e.rethrowFromSystemServer(); |
| 894 | } |
| 895 | } |
| 896 | |
| 897 | /** |
Julia Reynolds | 3eb3ffd | 2017-11-16 10:11:32 -0500 | [diff] [blame] | 898 | * Returns the notification channel group settings for a given channel group id. |
| 899 | * |
| 900 | * The channel group must belong to your package, or null will be returned. |
| 901 | */ |
| 902 | public NotificationChannelGroup getNotificationChannelGroup(String channelGroupId) { |
| 903 | INotificationManager service = getService(); |
| 904 | try { |
| 905 | return service.getNotificationChannelGroup(mContext.getPackageName(), channelGroupId); |
| 906 | } catch (RemoteException e) { |
| 907 | throw e.rethrowFromSystemServer(); |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | /** |
Julia Reynolds | 9bfba59 | 2017-03-15 14:03:55 -0400 | [diff] [blame] | 912 | * Returns all notification channel groups belonging to the calling app. |
| 913 | */ |
| 914 | public List<NotificationChannelGroup> getNotificationChannelGroups() { |
| 915 | INotificationManager service = getService(); |
| 916 | try { |
Beverly | c629ee4 | 2018-10-02 16:14:07 -0400 | [diff] [blame] | 917 | final ParceledListSlice<NotificationChannelGroup> parceledList = |
| 918 | service.getNotificationChannelGroups(mContext.getPackageName()); |
| 919 | if (parceledList != null) { |
| 920 | return parceledList.getList(); |
| 921 | } |
Julia Reynolds | 9bfba59 | 2017-03-15 14:03:55 -0400 | [diff] [blame] | 922 | } catch (RemoteException e) { |
| 923 | throw e.rethrowFromSystemServer(); |
| 924 | } |
Beverly | c629ee4 | 2018-10-02 16:14:07 -0400 | [diff] [blame] | 925 | return new ArrayList<>(); |
Julia Reynolds | 9bfba59 | 2017-03-15 14:03:55 -0400 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | /** |
Julia Reynolds | 0ffc13b | 2017-04-27 13:54:36 -0400 | [diff] [blame] | 929 | * Deletes the given notification channel group, and all notification channels that |
| 930 | * belong to it. |
Julia Reynolds | 9bfba59 | 2017-03-15 14:03:55 -0400 | [diff] [blame] | 931 | */ |
| 932 | public void deleteNotificationChannelGroup(String groupId) { |
| 933 | INotificationManager service = getService(); |
| 934 | try { |
| 935 | service.deleteNotificationChannelGroup(mContext.getPackageName(), groupId); |
| 936 | } catch (RemoteException e) { |
| 937 | throw e.rethrowFromSystemServer(); |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | /** |
John Spurlock | b478252 | 2014-08-22 14:54:46 -0400 | [diff] [blame] | 942 | * @hide |
| 943 | */ |
Julia Reynolds | b6c1f99 | 2016-11-22 09:26:46 -0500 | [diff] [blame] | 944 | @TestApi |
John Spurlock | b478252 | 2014-08-22 14:54:46 -0400 | [diff] [blame] | 945 | public ComponentName getEffectsSuppressor() { |
| 946 | INotificationManager service = getService(); |
| 947 | try { |
| 948 | return service.getEffectsSuppressor(); |
| 949 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 950 | throw e.rethrowFromSystemServer(); |
John Spurlock | b478252 | 2014-08-22 14:54:46 -0400 | [diff] [blame] | 951 | } |
| 952 | } |
| 953 | |
John Spurlock | 2b122f4 | 2014-08-27 16:29:47 -0400 | [diff] [blame] | 954 | /** |
| 955 | * @hide |
| 956 | */ |
Julia Reynolds | 8762194 | 2019-01-29 16:19:36 -0500 | [diff] [blame] | 957 | @TestApi |
John Spurlock | 2b122f4 | 2014-08-27 16:29:47 -0400 | [diff] [blame] | 958 | public boolean matchesCallFilter(Bundle extras) { |
| 959 | INotificationManager service = getService(); |
| 960 | try { |
| 961 | return service.matchesCallFilter(extras); |
| 962 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 963 | throw e.rethrowFromSystemServer(); |
John Spurlock | 2b122f4 | 2014-08-27 16:29:47 -0400 | [diff] [blame] | 964 | } |
| 965 | } |
| 966 | |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 967 | /** |
| 968 | * @hide |
| 969 | */ |
| 970 | public boolean isSystemConditionProviderEnabled(String path) { |
| 971 | INotificationManager service = getService(); |
| 972 | try { |
| 973 | return service.isSystemConditionProviderEnabled(path); |
| 974 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 975 | throw e.rethrowFromSystemServer(); |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 976 | } |
| 977 | } |
| 978 | |
John Spurlock | cdb57ae | 2015-02-11 19:04:11 -0500 | [diff] [blame] | 979 | /** |
| 980 | * @hide |
| 981 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 982 | @UnsupportedAppUsage |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 983 | public void setZenMode(int mode, Uri conditionId, String reason) { |
John Spurlock | cdb57ae | 2015-02-11 19:04:11 -0500 | [diff] [blame] | 984 | INotificationManager service = getService(); |
| 985 | try { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 986 | service.setZenMode(mode, conditionId, reason); |
John Spurlock | cdb57ae | 2015-02-11 19:04:11 -0500 | [diff] [blame] | 987 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 988 | throw e.rethrowFromSystemServer(); |
John Spurlock | cdb57ae | 2015-02-11 19:04:11 -0500 | [diff] [blame] | 989 | } |
| 990 | } |
| 991 | |
| 992 | /** |
| 993 | * @hide |
| 994 | */ |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 995 | public int getZenMode() { |
John Spurlock | cdb57ae | 2015-02-11 19:04:11 -0500 | [diff] [blame] | 996 | INotificationManager service = getService(); |
| 997 | try { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 998 | return service.getZenMode(); |
John Spurlock | cdb57ae | 2015-02-11 19:04:11 -0500 | [diff] [blame] | 999 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1000 | throw e.rethrowFromSystemServer(); |
John Spurlock | cdb57ae | 2015-02-11 19:04:11 -0500 | [diff] [blame] | 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | /** |
| 1005 | * @hide |
| 1006 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1007 | @UnsupportedAppUsage |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1008 | public ZenModeConfig getZenModeConfig() { |
John Spurlock | cdb57ae | 2015-02-11 19:04:11 -0500 | [diff] [blame] | 1009 | INotificationManager service = getService(); |
| 1010 | try { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1011 | return service.getZenModeConfig(); |
John Spurlock | cdb57ae | 2015-02-11 19:04:11 -0500 | [diff] [blame] | 1012 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1013 | throw e.rethrowFromSystemServer(); |
John Spurlock | cdb57ae | 2015-02-11 19:04:11 -0500 | [diff] [blame] | 1014 | } |
John Spurlock | cdb57ae | 2015-02-11 19:04:11 -0500 | [diff] [blame] | 1015 | } |
| 1016 | |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1017 | /** |
Beverly | 430b71a | 2020-03-16 14:17:31 -0400 | [diff] [blame] | 1018 | * Returns the currently applied notification policy. |
| 1019 | * |
Beverly | d994e2e | 2019-10-11 14:36:37 -0400 | [diff] [blame] | 1020 | * <p> |
Beverly | 430b71a | 2020-03-16 14:17:31 -0400 | [diff] [blame] | 1021 | * If {@link #getCurrentInterruptionFilter} is equal to {@link #INTERRUPTION_FILTER_ALL}, |
| 1022 | * then the consolidated notification policy will match the default notification policy |
| 1023 | * returned by {@link #getNotificationPolicy}. |
Beverly | d994e2e | 2019-10-11 14:36:37 -0400 | [diff] [blame] | 1024 | * </p> |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 1025 | */ |
Beverly | 430b71a | 2020-03-16 14:17:31 -0400 | [diff] [blame] | 1026 | public @NonNull NotificationManager.Policy getConsolidatedNotificationPolicy() { |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 1027 | INotificationManager service = getService(); |
| 1028 | try { |
| 1029 | return service.getConsolidatedNotificationPolicy(); |
| 1030 | } catch (RemoteException e) { |
| 1031 | throw e.rethrowFromSystemServer(); |
| 1032 | } |
| 1033 | } |
| 1034 | |
| 1035 | /** |
| 1036 | * @hide |
| 1037 | */ |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 1038 | public int getRuleInstanceCount(ComponentName owner) { |
| 1039 | INotificationManager service = getService(); |
| 1040 | try { |
| 1041 | return service.getRuleInstanceCount(owner); |
| 1042 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1043 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 1044 | } |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | /** |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1048 | * Returns AutomaticZenRules owned by the caller. |
| 1049 | * |
| 1050 | * <p> |
Jay Aliomer | 8e3aac5 | 2019-10-16 13:48:39 -0400 | [diff] [blame] | 1051 | * Throws a SecurityException if policy access is not granted to this package. |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1052 | * See {@link #isNotificationPolicyAccessGranted}. |
| 1053 | */ |
Julia Reynolds | 361e82d3 | 2016-02-26 18:19:49 -0500 | [diff] [blame] | 1054 | public Map<String, AutomaticZenRule> getAutomaticZenRules() { |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1055 | INotificationManager service = getService(); |
| 1056 | try { |
Julia Reynolds | 361e82d3 | 2016-02-26 18:19:49 -0500 | [diff] [blame] | 1057 | List<ZenModeConfig.ZenRule> rules = service.getZenRules(); |
| 1058 | Map<String, AutomaticZenRule> ruleMap = new HashMap<>(); |
| 1059 | for (ZenModeConfig.ZenRule rule : rules) { |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 1060 | ruleMap.put(rule.id, new AutomaticZenRule(rule.name, rule.component, |
| 1061 | rule.configurationActivity, rule.conditionId, rule.zenPolicy, |
| 1062 | zenModeToInterruptionFilter(rule.zenMode), rule.enabled, |
| 1063 | rule.creationTime)); |
Julia Reynolds | 361e82d3 | 2016-02-26 18:19:49 -0500 | [diff] [blame] | 1064 | } |
| 1065 | return ruleMap; |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1066 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1067 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1068 | } |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | /** |
Julia Reynolds | 4fe98d6 | 2015-10-06 16:23:41 -0400 | [diff] [blame] | 1072 | * Returns the AutomaticZenRule with the given id, if it exists and the caller has access. |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1073 | * |
| 1074 | * <p> |
Jay Aliomer | 8e3aac5 | 2019-10-16 13:48:39 -0400 | [diff] [blame] | 1075 | * Throws a SecurityException if policy access is not granted to this package. |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1076 | * See {@link #isNotificationPolicyAccessGranted}. |
| 1077 | * |
| 1078 | * <p> |
Julia Reynolds | 4fe98d6 | 2015-10-06 16:23:41 -0400 | [diff] [blame] | 1079 | * Returns null if there are no zen rules that match the given id, or if the calling package |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1080 | * doesn't own the matching rule. See {@link AutomaticZenRule#getOwner}. |
| 1081 | */ |
Julia Reynolds | 4fe98d6 | 2015-10-06 16:23:41 -0400 | [diff] [blame] | 1082 | public AutomaticZenRule getAutomaticZenRule(String id) { |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1083 | INotificationManager service = getService(); |
| 1084 | try { |
Julia Reynolds | 4fe98d6 | 2015-10-06 16:23:41 -0400 | [diff] [blame] | 1085 | return service.getAutomaticZenRule(id); |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1086 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1087 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1088 | } |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | /** |
Julia Reynolds | 4fe98d6 | 2015-10-06 16:23:41 -0400 | [diff] [blame] | 1092 | * Creates the given zen rule. |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1093 | * |
| 1094 | * <p> |
Jay Aliomer | 8e3aac5 | 2019-10-16 13:48:39 -0400 | [diff] [blame] | 1095 | * Throws a SecurityException if policy access is not granted to this package. |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1096 | * See {@link #isNotificationPolicyAccessGranted}. |
| 1097 | * |
Julia Reynolds | 4fe98d6 | 2015-10-06 16:23:41 -0400 | [diff] [blame] | 1098 | * @param automaticZenRule the rule to create. |
Julia Reynolds | 361e82d3 | 2016-02-26 18:19:49 -0500 | [diff] [blame] | 1099 | * @return The id of the newly created rule; null if the rule could not be created. |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1100 | */ |
Julia Reynolds | 361e82d3 | 2016-02-26 18:19:49 -0500 | [diff] [blame] | 1101 | public String addAutomaticZenRule(AutomaticZenRule automaticZenRule) { |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1102 | INotificationManager service = getService(); |
| 1103 | try { |
Julia Reynolds | 4fe98d6 | 2015-10-06 16:23:41 -0400 | [diff] [blame] | 1104 | return service.addAutomaticZenRule(automaticZenRule); |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1105 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1106 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1107 | } |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | /** |
Julia Reynolds | 4fe98d6 | 2015-10-06 16:23:41 -0400 | [diff] [blame] | 1111 | * Updates the given zen rule. |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1112 | * |
| 1113 | * <p> |
Jay Aliomer | 8e3aac5 | 2019-10-16 13:48:39 -0400 | [diff] [blame] | 1114 | * Throws a SecurityException if policy access is not granted to this package. |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1115 | * See {@link #isNotificationPolicyAccessGranted}. |
| 1116 | * |
| 1117 | * <p> |
| 1118 | * Callers can only update rules that they own. See {@link AutomaticZenRule#getOwner}. |
Julia Reynolds | 361e82d3 | 2016-02-26 18:19:49 -0500 | [diff] [blame] | 1119 | * @param id The id of the rule to update |
Geoffrey Pitsch | e75a66e | 2016-11-22 11:12:11 -0500 | [diff] [blame] | 1120 | * @param automaticZenRule the rule to update. |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1121 | * @return Whether the rule was successfully updated. |
| 1122 | */ |
Julia Reynolds | 361e82d3 | 2016-02-26 18:19:49 -0500 | [diff] [blame] | 1123 | public boolean updateAutomaticZenRule(String id, AutomaticZenRule automaticZenRule) { |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1124 | INotificationManager service = getService(); |
| 1125 | try { |
Julia Reynolds | 361e82d3 | 2016-02-26 18:19:49 -0500 | [diff] [blame] | 1126 | return service.updateAutomaticZenRule(id, automaticZenRule); |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1127 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1128 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1129 | } |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | /** |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 1133 | * Informs the notification manager that the state of an {@link AutomaticZenRule} has changed. |
| 1134 | * Use this method to put the system into Do Not Disturb mode or request that it exits Do Not |
| 1135 | * Disturb mode. The calling app must own the provided {@link android.app.AutomaticZenRule}. |
| 1136 | * <p> |
| 1137 | * This method can be used in conjunction with or as a replacement to |
| 1138 | * {@link android.service.notification.ConditionProviderService#notifyCondition(Condition)}. |
| 1139 | * </p> |
| 1140 | * @param id The id of the rule whose state should change |
| 1141 | * @param condition The new state of this rule |
| 1142 | */ |
Fabian Kozynski | 867550e | 2019-02-28 12:59:57 -0500 | [diff] [blame] | 1143 | public void setAutomaticZenRuleState(@NonNull String id, @NonNull Condition condition) { |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 1144 | INotificationManager service = getService(); |
| 1145 | try { |
| 1146 | service.setAutomaticZenRuleState(id, condition); |
| 1147 | } catch (RemoteException e) { |
| 1148 | throw e.rethrowFromSystemServer(); |
| 1149 | } |
| 1150 | } |
| 1151 | |
| 1152 | /** |
Julia Reynolds | 4fe98d6 | 2015-10-06 16:23:41 -0400 | [diff] [blame] | 1153 | * Deletes the automatic zen rule with the given id. |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1154 | * |
| 1155 | * <p> |
Jay Aliomer | 8e3aac5 | 2019-10-16 13:48:39 -0400 | [diff] [blame] | 1156 | * Throws a SecurityException if policy access is not granted to this package. |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1157 | * See {@link #isNotificationPolicyAccessGranted}. |
| 1158 | * |
| 1159 | * <p> |
| 1160 | * Callers can only delete rules that they own. See {@link AutomaticZenRule#getOwner}. |
Julia Reynolds | 4fe98d6 | 2015-10-06 16:23:41 -0400 | [diff] [blame] | 1161 | * @param id the id of the rule to delete. |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1162 | * @return Whether the rule was successfully deleted. |
| 1163 | */ |
Julia Reynolds | 4fe98d6 | 2015-10-06 16:23:41 -0400 | [diff] [blame] | 1164 | public boolean removeAutomaticZenRule(String id) { |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1165 | INotificationManager service = getService(); |
| 1166 | try { |
Julia Reynolds | 4fe98d6 | 2015-10-06 16:23:41 -0400 | [diff] [blame] | 1167 | return service.removeAutomaticZenRule(id); |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1168 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1169 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1170 | } |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | /** |
Julia Reynolds | c8e54e8 | 2015-11-30 16:43:05 -0500 | [diff] [blame] | 1174 | * Deletes all automatic zen rules owned by the given package. |
| 1175 | * |
| 1176 | * @hide |
| 1177 | */ |
| 1178 | public boolean removeAutomaticZenRules(String packageName) { |
| 1179 | INotificationManager service = getService(); |
| 1180 | try { |
| 1181 | return service.removeAutomaticZenRules(packageName); |
| 1182 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1183 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | c8e54e8 | 2015-11-30 16:43:05 -0500 | [diff] [blame] | 1184 | } |
Julia Reynolds | c8e54e8 | 2015-11-30 16:43:05 -0500 | [diff] [blame] | 1185 | } |
| 1186 | |
Julia Reynolds | 0edb50c | 2016-02-26 14:08:25 -0500 | [diff] [blame] | 1187 | /** |
Jeff Sharkey | 6503bd8 | 2017-04-19 23:24:18 -0600 | [diff] [blame] | 1188 | * Returns the user specified importance for notifications from the calling |
| 1189 | * package. |
Julia Reynolds | 0edb50c | 2016-02-26 14:08:25 -0500 | [diff] [blame] | 1190 | */ |
Chris Wren | 5ab5c74 | 2016-05-10 15:32:23 -0400 | [diff] [blame] | 1191 | public @Importance int getImportance() { |
Julia Reynolds | 81afbcd | 2016-02-09 14:54:08 -0500 | [diff] [blame] | 1192 | INotificationManager service = getService(); |
| 1193 | try { |
Julia Reynolds | ef37f28 | 2016-02-12 09:11:27 -0500 | [diff] [blame] | 1194 | return service.getPackageImportance(mContext.getPackageName()); |
Julia Reynolds | 81afbcd | 2016-02-09 14:54:08 -0500 | [diff] [blame] | 1195 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1196 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 81afbcd | 2016-02-09 14:54:08 -0500 | [diff] [blame] | 1197 | } |
Julia Reynolds | 81afbcd | 2016-02-09 14:54:08 -0500 | [diff] [blame] | 1198 | } |
| 1199 | |
Julia Reynolds | 0edb50c | 2016-02-26 14:08:25 -0500 | [diff] [blame] | 1200 | /** |
| 1201 | * Returns whether notifications from the calling package are blocked. |
| 1202 | */ |
Julia Reynolds | 81afbcd | 2016-02-09 14:54:08 -0500 | [diff] [blame] | 1203 | public boolean areNotificationsEnabled() { |
| 1204 | INotificationManager service = getService(); |
| 1205 | try { |
| 1206 | return service.areNotificationsEnabled(mContext.getPackageName()); |
| 1207 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1208 | throw e.rethrowFromSystemServer(); |
Julia Reynolds | 81afbcd | 2016-02-09 14:54:08 -0500 | [diff] [blame] | 1209 | } |
Julia Reynolds | 81afbcd | 2016-02-09 14:54:08 -0500 | [diff] [blame] | 1210 | } |
| 1211 | |
Julia Reynolds | 33ab8a0 | 2018-12-17 16:19:52 -0500 | [diff] [blame] | 1212 | |
| 1213 | /** |
| 1214 | * Sets whether notifications posted by this app can appear outside of the |
| 1215 | * notification shade, floating over other apps' content. |
| 1216 | * |
| 1217 | * <p>This value will be ignored for notifications that are posted to channels that do not |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 1218 | * allow bubbles ({@link NotificationChannel#canBubble()}. |
Julia Reynolds | 33ab8a0 | 2018-12-17 16:19:52 -0500 | [diff] [blame] | 1219 | * |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 1220 | * @see Notification#getBubbleMetadata() |
Julia Reynolds | 33ab8a0 | 2018-12-17 16:19:52 -0500 | [diff] [blame] | 1221 | */ |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 1222 | public boolean areBubblesAllowed() { |
Julia Reynolds | 33ab8a0 | 2018-12-17 16:19:52 -0500 | [diff] [blame] | 1223 | INotificationManager service = getService(); |
| 1224 | try { |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 1225 | return service.areBubblesAllowed(mContext.getPackageName()); |
Julia Reynolds | 33ab8a0 | 2018-12-17 16:19:52 -0500 | [diff] [blame] | 1226 | } catch (RemoteException e) { |
| 1227 | throw e.rethrowFromSystemServer(); |
| 1228 | } |
| 1229 | } |
| 1230 | |
Julia Reynolds | c8e54e8 | 2015-11-30 16:43:05 -0500 | [diff] [blame] | 1231 | /** |
Julia Reynolds | deb2d0b | 2019-06-17 15:34:26 -0400 | [diff] [blame] | 1232 | * Silences the current notification sound, if ones currently playing. |
| 1233 | * <p> |
| 1234 | * It is intended to handle use-cases such as silencing a ringing call |
| 1235 | * when the user presses the volume button during ringing. |
| 1236 | * <p> |
| 1237 | * If this method is called prior to when the notification begins playing, the sound will not be |
| 1238 | * silenced. As such it is not intended as a means to avoid playing of a sound. |
| 1239 | * @hide |
| 1240 | */ |
| 1241 | public void silenceNotificationSound() { |
| 1242 | INotificationManager service = getService(); |
| 1243 | try { |
| 1244 | service.silenceNotificationSound(); |
| 1245 | } catch (RemoteException e) { |
| 1246 | throw e.rethrowFromSystemServer(); |
| 1247 | } |
| 1248 | } |
| 1249 | |
| 1250 | /** |
Julia Reynolds | b40cd09 | 2019-01-25 09:35:02 -0500 | [diff] [blame] | 1251 | * Returns whether notifications from this package are temporarily hidden. This |
| 1252 | * could be done because the package was marked as distracting to the user via |
| 1253 | * {@code PackageManager#setDistractingPackageRestrictions(String[], int)} or because the |
| 1254 | * package is {@code PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle, |
| 1255 | * PersistableBundle, SuspendDialogInfo) suspended}. |
| 1256 | */ |
| 1257 | public boolean areNotificationsPaused() { |
| 1258 | INotificationManager service = getService(); |
| 1259 | try { |
| 1260 | return service.isPackagePaused(mContext.getPackageName()); |
| 1261 | } catch (RemoteException e) { |
| 1262 | throw e.rethrowFromSystemServer(); |
| 1263 | } |
| 1264 | } |
| 1265 | |
| 1266 | /** |
Beverly | 312ef3e | 2017-11-15 11:12:51 -0500 | [diff] [blame] | 1267 | * Checks the ability to modify notification do not disturb policy for the calling package. |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1268 | * |
John Spurlock | 7c74f78 | 2015-06-04 13:01:42 -0400 | [diff] [blame] | 1269 | * <p> |
Beverly | 312ef3e | 2017-11-15 11:12:51 -0500 | [diff] [blame] | 1270 | * Returns true if the calling package can modify notification policy. |
John Spurlock | 7c74f78 | 2015-06-04 13:01:42 -0400 | [diff] [blame] | 1271 | * |
| 1272 | * <p> |
Julia Reynolds | b852e56 | 2017-06-06 16:14:18 -0400 | [diff] [blame] | 1273 | * Apps can request policy access by sending the user to the activity that matches the system |
| 1274 | * intent action {@link android.provider.Settings#ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS}. |
John Spurlock | 7c74f78 | 2015-06-04 13:01:42 -0400 | [diff] [blame] | 1275 | * |
| 1276 | * <p> |
| 1277 | * Use {@link #ACTION_NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED} to listen for |
| 1278 | * user grant or denial of this access. |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1279 | */ |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1280 | public boolean isNotificationPolicyAccessGranted() { |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1281 | INotificationManager service = getService(); |
| 1282 | try { |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1283 | return service.isNotificationPolicyAccessGranted(mContext.getOpPackageName()); |
| 1284 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1285 | throw e.rethrowFromSystemServer(); |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1286 | } |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1287 | } |
| 1288 | |
Julia Reynolds | b852e56 | 2017-06-06 16:14:18 -0400 | [diff] [blame] | 1289 | /** |
| 1290 | * Checks whether the user has approved a given |
| 1291 | * {@link android.service.notification.NotificationListenerService}. |
| 1292 | * |
| 1293 | * <p> |
| 1294 | * The listener service must belong to the calling app. |
| 1295 | * |
| 1296 | * <p> |
| 1297 | * Apps can request notification listener access by sending the user to the activity that |
| 1298 | * matches the system intent action |
| 1299 | * {@link android.provider.Settings#ACTION_NOTIFICATION_LISTENER_SETTINGS}. |
| 1300 | */ |
| 1301 | public boolean isNotificationListenerAccessGranted(ComponentName listener) { |
| 1302 | INotificationManager service = getService(); |
| 1303 | try { |
| 1304 | return service.isNotificationListenerAccessGranted(listener); |
| 1305 | } catch (RemoteException e) { |
| 1306 | throw e.rethrowFromSystemServer(); |
| 1307 | } |
| 1308 | } |
| 1309 | |
Fabian Kozynski | d942566 | 2019-01-29 13:08:30 -0500 | [diff] [blame] | 1310 | /** |
| 1311 | * Checks whether the user has approved a given |
| 1312 | * {@link android.service.notification.NotificationAssistantService}. |
| 1313 | * |
| 1314 | * <p> |
| 1315 | * The assistant service must belong to the calling app. |
| 1316 | * |
| 1317 | * <p> |
| 1318 | * Apps can request notification assistant access by sending the user to the activity that |
| 1319 | * matches the system intent action |
| 1320 | * TODO: STOPSHIP: Add correct intent |
| 1321 | * {@link android.provider.Settings#ACTION_MANAGE_DEFAULT_APPS_SETTINGS}. |
Julia Reynolds | d0ceefa | 2019-03-03 16:10:52 -0500 | [diff] [blame] | 1322 | * @hide |
Fabian Kozynski | d942566 | 2019-01-29 13:08:30 -0500 | [diff] [blame] | 1323 | */ |
Julia Reynolds | d0ceefa | 2019-03-03 16:10:52 -0500 | [diff] [blame] | 1324 | @SystemApi |
Julia Reynolds | dc6adc6 | 2019-04-08 10:35:40 -0400 | [diff] [blame] | 1325 | @TestApi |
Fabian Kozynski | 867550e | 2019-02-28 12:59:57 -0500 | [diff] [blame] | 1326 | public boolean isNotificationAssistantAccessGranted(@NonNull ComponentName assistant) { |
Julia Reynolds | b852e56 | 2017-06-06 16:14:18 -0400 | [diff] [blame] | 1327 | INotificationManager service = getService(); |
| 1328 | try { |
| 1329 | return service.isNotificationAssistantAccessGranted(assistant); |
| 1330 | } catch (RemoteException e) { |
| 1331 | throw e.rethrowFromSystemServer(); |
| 1332 | } |
| 1333 | } |
| 1334 | |
Julia Reynolds | 12ad7ca | 2019-01-28 09:29:16 -0500 | [diff] [blame] | 1335 | /** |
| 1336 | * Returns whether the user wants silent notifications (see {@link #IMPORTANCE_LOW} to appear |
| 1337 | * in the status bar. |
| 1338 | * |
| 1339 | * <p>Only available for {@link #isNotificationListenerAccessGranted(ComponentName) notification |
| 1340 | * listeners}. |
| 1341 | */ |
| 1342 | public boolean shouldHideSilentStatusBarIcons() { |
| 1343 | INotificationManager service = getService(); |
| 1344 | try { |
| 1345 | return service.shouldHideSilentStatusIcons(mContext.getOpPackageName()); |
| 1346 | } catch (RemoteException e) { |
| 1347 | throw e.rethrowFromSystemServer(); |
| 1348 | } |
| 1349 | } |
| 1350 | |
Julia Reynolds | ad6dd35 | 2019-03-07 16:46:22 -0500 | [diff] [blame] | 1351 | /** |
| 1352 | * Returns the list of {@link android.service.notification.Adjustment adjustment keys} that can |
| 1353 | * be modified by the current {@link android.service.notification.NotificationAssistantService}. |
| 1354 | * |
| 1355 | * <p>Only callable by the current |
| 1356 | * {@link android.service.notification.NotificationAssistantService}. |
| 1357 | * See {@link #isNotificationAssistantAccessGranted(ComponentName)}</p> |
| 1358 | * @hide |
| 1359 | */ |
| 1360 | @SystemApi |
Julia Reynolds | dc6adc6 | 2019-04-08 10:35:40 -0400 | [diff] [blame] | 1361 | @TestApi |
Julia Reynolds | 088c448 | 2019-04-10 12:43:27 -0400 | [diff] [blame] | 1362 | public @NonNull @Adjustment.Keys List<String> getAllowedAssistantAdjustments() { |
Julia Reynolds | ad6dd35 | 2019-03-07 16:46:22 -0500 | [diff] [blame] | 1363 | INotificationManager service = getService(); |
| 1364 | try { |
Julia Reynolds | 088c448 | 2019-04-10 12:43:27 -0400 | [diff] [blame] | 1365 | return service.getAllowedAssistantAdjustments(mContext.getOpPackageName()); |
Julia Reynolds | ad6dd35 | 2019-03-07 16:46:22 -0500 | [diff] [blame] | 1366 | } catch (RemoteException e) { |
| 1367 | throw e.rethrowFromSystemServer(); |
| 1368 | } |
| 1369 | } |
| 1370 | |
Julia Reynolds | dc6adc6 | 2019-04-08 10:35:40 -0400 | [diff] [blame] | 1371 | /** |
| 1372 | * @hide |
| 1373 | */ |
| 1374 | @TestApi |
Julia Reynolds | 088c448 | 2019-04-10 12:43:27 -0400 | [diff] [blame] | 1375 | public void allowAssistantAdjustment(String capability) { |
Julia Reynolds | dc6adc6 | 2019-04-08 10:35:40 -0400 | [diff] [blame] | 1376 | INotificationManager service = getService(); |
| 1377 | try { |
Julia Reynolds | 088c448 | 2019-04-10 12:43:27 -0400 | [diff] [blame] | 1378 | service.allowAssistantAdjustment(capability); |
Julia Reynolds | dc6adc6 | 2019-04-08 10:35:40 -0400 | [diff] [blame] | 1379 | } catch (RemoteException e) { |
| 1380 | throw e.rethrowFromSystemServer(); |
| 1381 | } |
| 1382 | } |
| 1383 | |
| 1384 | /** |
| 1385 | * @hide |
| 1386 | */ |
| 1387 | @TestApi |
Julia Reynolds | 088c448 | 2019-04-10 12:43:27 -0400 | [diff] [blame] | 1388 | public void disallowAssistantAdjustment(String capability) { |
Julia Reynolds | dc6adc6 | 2019-04-08 10:35:40 -0400 | [diff] [blame] | 1389 | INotificationManager service = getService(); |
| 1390 | try { |
Julia Reynolds | 088c448 | 2019-04-10 12:43:27 -0400 | [diff] [blame] | 1391 | service.disallowAssistantAdjustment(capability); |
Julia Reynolds | dc6adc6 | 2019-04-08 10:35:40 -0400 | [diff] [blame] | 1392 | } catch (RemoteException e) { |
| 1393 | throw e.rethrowFromSystemServer(); |
| 1394 | } |
| 1395 | } |
| 1396 | |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1397 | /** @hide */ |
| 1398 | public boolean isNotificationPolicyAccessGrantedForPackage(String pkg) { |
| 1399 | INotificationManager service = getService(); |
| 1400 | try { |
| 1401 | return service.isNotificationPolicyAccessGrantedForPackage(pkg); |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1402 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1403 | throw e.rethrowFromSystemServer(); |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1404 | } |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | /** |
Julia Reynolds | b852e56 | 2017-06-06 16:14:18 -0400 | [diff] [blame] | 1408 | * @hide |
| 1409 | */ |
| 1410 | public List<String> getEnabledNotificationListenerPackages() { |
| 1411 | INotificationManager service = getService(); |
| 1412 | try { |
| 1413 | return service.getEnabledNotificationListenerPackages(); |
| 1414 | } catch (RemoteException e) { |
| 1415 | throw e.rethrowFromSystemServer(); |
| 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | /** |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 1420 | * Gets the current user-specified default notification policy. |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1421 | * |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1422 | * <p> |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1423 | */ |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1424 | public Policy getNotificationPolicy() { |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1425 | INotificationManager service = getService(); |
| 1426 | try { |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1427 | return service.getNotificationPolicy(mContext.getOpPackageName()); |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1428 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1429 | throw e.rethrowFromSystemServer(); |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1430 | } |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | /** |
| 1434 | * Sets the current notification policy. |
| 1435 | * |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1436 | * <p> |
John Spurlock | 7c74f78 | 2015-06-04 13:01:42 -0400 | [diff] [blame] | 1437 | * Only available if policy access is granted to this package. |
| 1438 | * See {@link #isNotificationPolicyAccessGranted}. |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1439 | * |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1440 | * @param policy The new desired policy. |
| 1441 | */ |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1442 | public void setNotificationPolicy(@NonNull Policy policy) { |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1443 | checkRequired("policy", policy); |
| 1444 | INotificationManager service = getService(); |
| 1445 | try { |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1446 | service.setNotificationPolicy(mContext.getOpPackageName(), policy); |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1447 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1448 | throw e.rethrowFromSystemServer(); |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1449 | } |
| 1450 | } |
| 1451 | |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1452 | /** @hide */ |
| 1453 | public void setNotificationPolicyAccessGranted(String pkg, boolean granted) { |
| 1454 | INotificationManager service = getService(); |
| 1455 | try { |
| 1456 | service.setNotificationPolicyAccessGranted(pkg, granted); |
| 1457 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1458 | throw e.rethrowFromSystemServer(); |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | /** @hide */ |
Julia Reynolds | b852e56 | 2017-06-06 16:14:18 -0400 | [diff] [blame] | 1463 | public void setNotificationListenerAccessGranted(ComponentName listener, boolean granted) { |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1464 | INotificationManager service = getService(); |
| 1465 | try { |
Julia Reynolds | b852e56 | 2017-06-06 16:14:18 -0400 | [diff] [blame] | 1466 | service.setNotificationListenerAccessGranted(listener, granted); |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1467 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1468 | throw e.rethrowFromSystemServer(); |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1469 | } |
Julia Reynolds | b852e56 | 2017-06-06 16:14:18 -0400 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | /** @hide */ |
| 1473 | public void setNotificationListenerAccessGrantedForUser(ComponentName listener, int userId, |
| 1474 | boolean granted) { |
| 1475 | INotificationManager service = getService(); |
| 1476 | try { |
| 1477 | service.setNotificationListenerAccessGrantedForUser(listener, userId, granted); |
| 1478 | } catch (RemoteException e) { |
| 1479 | throw e.rethrowFromSystemServer(); |
| 1480 | } |
| 1481 | } |
| 1482 | |
Fabian Kozynski | d942566 | 2019-01-29 13:08:30 -0500 | [diff] [blame] | 1483 | /** |
| 1484 | * Grants/revokes Notification Assistant access to {@code assistant} for current user. |
Fabian Kozynski | cbfbb1d | 2019-03-15 09:51:39 -0400 | [diff] [blame] | 1485 | * To grant access for a particular user, obtain this service by using the {@link Context} |
| 1486 | * provided by {@link Context#createPackageContextAsUser} |
Fabian Kozynski | d942566 | 2019-01-29 13:08:30 -0500 | [diff] [blame] | 1487 | * |
| 1488 | * @param assistant Name of component to grant/revoke access or {@code null} to revoke access to |
| 1489 | * current assistant |
| 1490 | * @param granted Grant/revoke access |
| 1491 | * @hide |
| 1492 | */ |
| 1493 | @SystemApi |
Julia Reynolds | dc6adc6 | 2019-04-08 10:35:40 -0400 | [diff] [blame] | 1494 | @TestApi |
Fabian Kozynski | 5747d63 | 2019-03-11 14:23:23 -0400 | [diff] [blame] | 1495 | public void setNotificationAssistantAccessGranted(@Nullable ComponentName assistant, |
| 1496 | boolean granted) { |
Fabian Kozynski | d942566 | 2019-01-29 13:08:30 -0500 | [diff] [blame] | 1497 | INotificationManager service = getService(); |
| 1498 | try { |
| 1499 | service.setNotificationAssistantAccessGranted(assistant, granted); |
| 1500 | } catch (RemoteException e) { |
| 1501 | throw e.rethrowFromSystemServer(); |
| 1502 | } |
| 1503 | } |
| 1504 | |
Julia Reynolds | b852e56 | 2017-06-06 16:14:18 -0400 | [diff] [blame] | 1505 | /** @hide */ |
| 1506 | public List<ComponentName> getEnabledNotificationListeners(int userId) { |
| 1507 | INotificationManager service = getService(); |
| 1508 | try { |
| 1509 | return service.getEnabledNotificationListeners(userId); |
| 1510 | } catch (RemoteException e) { |
| 1511 | throw e.rethrowFromSystemServer(); |
| 1512 | } |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1513 | } |
| 1514 | |
Fabian Kozynski | d942566 | 2019-01-29 13:08:30 -0500 | [diff] [blame] | 1515 | /** @hide */ |
| 1516 | @SystemApi |
Julia Reynolds | dc6adc6 | 2019-04-08 10:35:40 -0400 | [diff] [blame] | 1517 | @TestApi |
Fabian Kozynski | d942566 | 2019-01-29 13:08:30 -0500 | [diff] [blame] | 1518 | public @Nullable ComponentName getAllowedNotificationAssistant() { |
| 1519 | INotificationManager service = getService(); |
| 1520 | try { |
| 1521 | return service.getAllowedNotificationAssistant(); |
| 1522 | } catch (RemoteException e) { |
| 1523 | throw e.rethrowFromSystemServer(); |
| 1524 | } |
| 1525 | } |
| 1526 | |
| 1527 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1528 | private Context mContext; |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1529 | |
| 1530 | private static void checkRequired(String name, Object value) { |
| 1531 | if (value == null) { |
| 1532 | throw new IllegalArgumentException(name + " is required"); |
| 1533 | } |
| 1534 | } |
| 1535 | |
| 1536 | /** |
| 1537 | * Notification policy configuration. Represents user-preferences for notification |
Julia Reynolds | cedacef | 2016-03-04 08:18:47 -0500 | [diff] [blame] | 1538 | * filtering. |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1539 | */ |
| 1540 | public static class Policy implements android.os.Parcelable { |
| 1541 | /** Reminder notifications are prioritized. */ |
| 1542 | public static final int PRIORITY_CATEGORY_REMINDERS = 1 << 0; |
| 1543 | /** Event notifications are prioritized. */ |
| 1544 | public static final int PRIORITY_CATEGORY_EVENTS = 1 << 1; |
| 1545 | /** Message notifications are prioritized. */ |
| 1546 | public static final int PRIORITY_CATEGORY_MESSAGES = 1 << 2; |
| 1547 | /** Calls are prioritized. */ |
| 1548 | public static final int PRIORITY_CATEGORY_CALLS = 1 << 3; |
| 1549 | /** Calls from repeat callers are prioritized. */ |
| 1550 | public static final int PRIORITY_CATEGORY_REPEAT_CALLERS = 1 << 4; |
Beverly | 0421687 | 2017-09-28 10:55:32 -0400 | [diff] [blame] | 1551 | /** Alarms are prioritized */ |
| 1552 | public static final int PRIORITY_CATEGORY_ALARMS = 1 << 5; |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 1553 | /** Media, game, voice navigation are prioritized */ |
| 1554 | public static final int PRIORITY_CATEGORY_MEDIA = 1 << 6; |
| 1555 | /**System (catch-all for non-never suppressible sounds) are prioritized */ |
| 1556 | public static final int PRIORITY_CATEGORY_SYSTEM = 1 << 7; |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 1557 | /** |
| 1558 | * Conversations are allowed through DND. |
| 1559 | */ |
| 1560 | public static final int PRIORITY_CATEGORY_CONVERSATIONS = 1 << 8; |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1561 | |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 1562 | /** |
| 1563 | * @hide |
| 1564 | */ |
| 1565 | public static final int[] ALL_PRIORITY_CATEGORIES = { |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 1566 | PRIORITY_CATEGORY_ALARMS, |
| 1567 | PRIORITY_CATEGORY_MEDIA, |
| 1568 | PRIORITY_CATEGORY_SYSTEM, |
| 1569 | PRIORITY_CATEGORY_REMINDERS, |
| 1570 | PRIORITY_CATEGORY_EVENTS, |
| 1571 | PRIORITY_CATEGORY_MESSAGES, |
| 1572 | PRIORITY_CATEGORY_CALLS, |
| 1573 | PRIORITY_CATEGORY_REPEAT_CALLERS, |
| 1574 | PRIORITY_CATEGORY_CONVERSATIONS, |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1575 | }; |
| 1576 | |
Julia Reynolds | 229684b | 2020-02-23 20:39:04 -0500 | [diff] [blame] | 1577 | /** @hide */ |
| 1578 | @IntDef(prefix = { "PRIORITY_SENDERS_" }, value = { |
| 1579 | PRIORITY_SENDERS_ANY, |
| 1580 | PRIORITY_SENDERS_CONTACTS, |
| 1581 | PRIORITY_SENDERS_STARRED, |
| 1582 | }) |
| 1583 | @Retention(RetentionPolicy.SOURCE) |
| 1584 | public @interface PrioritySenders {} |
| 1585 | |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1586 | /** Any sender is prioritized. */ |
| 1587 | public static final int PRIORITY_SENDERS_ANY = 0; |
| 1588 | /** Saved contacts are prioritized. */ |
| 1589 | public static final int PRIORITY_SENDERS_CONTACTS = 1; |
| 1590 | /** Only starred contacts are prioritized. */ |
| 1591 | public static final int PRIORITY_SENDERS_STARRED = 2; |
| 1592 | |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 1593 | |
| 1594 | /** @hide */ |
| 1595 | @IntDef(prefix = { "CONVERSATION_SENDERS_" }, value = { |
| 1596 | CONVERSATION_SENDERS_ANYONE, |
| 1597 | CONVERSATION_SENDERS_IMPORTANT, |
| 1598 | CONVERSATION_SENDERS_NONE, |
| 1599 | }) |
| 1600 | @Retention(RetentionPolicy.SOURCE) |
| 1601 | public @interface ConversationSenders {} |
| 1602 | /** |
| 1603 | * Used to indicate all conversations can bypass dnd. |
| 1604 | */ |
| 1605 | public static final int CONVERSATION_SENDERS_ANYONE = ZenPolicy.CONVERSATION_SENDERS_ANYONE; |
| 1606 | |
| 1607 | /** |
| 1608 | * Used to indicate important conversations can bypass dnd. |
| 1609 | */ |
| 1610 | public static final int CONVERSATION_SENDERS_IMPORTANT = |
| 1611 | ZenPolicy.CONVERSATION_SENDERS_IMPORTANT; |
| 1612 | |
| 1613 | /** |
| 1614 | * Used to indicate no conversations can bypass dnd. |
| 1615 | */ |
| 1616 | public static final int CONVERSATION_SENDERS_NONE = ZenPolicy.CONVERSATION_SENDERS_NONE; |
| 1617 | |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1618 | /** Notification categories to prioritize. Bitmask of PRIORITY_CATEGORY_* constants. */ |
| 1619 | public final int priorityCategories; |
| 1620 | |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1621 | /** Notification senders to prioritize for calls. One of: |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1622 | * PRIORITY_SENDERS_ANY, PRIORITY_SENDERS_CONTACTS, PRIORITY_SENDERS_STARRED */ |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1623 | public final int priorityCallSenders; |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1624 | |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1625 | /** Notification senders to prioritize for messages. One of: |
| 1626 | * PRIORITY_SENDERS_ANY, PRIORITY_SENDERS_CONTACTS, PRIORITY_SENDERS_STARRED */ |
| 1627 | public final int priorityMessageSenders; |
| 1628 | |
Julia Reynolds | d560729 | 2016-02-05 15:25:58 -0500 | [diff] [blame] | 1629 | /** |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 1630 | * Notification senders to prioritize for conversations. One of: |
| 1631 | * {@link #CONVERSATION_SENDERS_NONE}, {@link #CONVERSATION_SENDERS_IMPORTANT}, |
| 1632 | * {@link #CONVERSATION_SENDERS_ANYONE}. |
| 1633 | */ |
| 1634 | public final int priorityConversationSenders; |
| 1635 | |
| 1636 | /** |
| 1637 | * @hide |
| 1638 | */ |
| 1639 | public static final int CONVERSATION_SENDERS_UNSET = -1; |
| 1640 | |
| 1641 | /** |
Julia Reynolds | d560729 | 2016-02-05 15:25:58 -0500 | [diff] [blame] | 1642 | * @hide |
| 1643 | */ |
Julia Reynolds | f612869ae | 2015-11-05 16:48:55 -0500 | [diff] [blame] | 1644 | public static final int SUPPRESSED_EFFECTS_UNSET = -1; |
Julia Reynolds | ccc6ae6 | 2018-03-01 16:24:49 -0500 | [diff] [blame] | 1645 | |
Julia Reynolds | d560729 | 2016-02-05 15:25:58 -0500 | [diff] [blame] | 1646 | /** |
Julia Reynolds | cedacef | 2016-03-04 08:18:47 -0500 | [diff] [blame] | 1647 | * Whether notifications suppressed by DND should not interrupt visually (e.g. with |
| 1648 | * notification lights or by turning the screen on) when the screen is off. |
Julia Reynolds | ccc6ae6 | 2018-03-01 16:24:49 -0500 | [diff] [blame] | 1649 | * |
| 1650 | * @deprecated use {@link #SUPPRESSED_EFFECT_FULL_SCREEN_INTENT} and |
| 1651 | * {@link #SUPPRESSED_EFFECT_AMBIENT} and {@link #SUPPRESSED_EFFECT_LIGHTS} individually. |
Julia Reynolds | d560729 | 2016-02-05 15:25:58 -0500 | [diff] [blame] | 1652 | */ |
Julia Reynolds | ccc6ae6 | 2018-03-01 16:24:49 -0500 | [diff] [blame] | 1653 | @Deprecated |
Julia Reynolds | d560729 | 2016-02-05 15:25:58 -0500 | [diff] [blame] | 1654 | public static final int SUPPRESSED_EFFECT_SCREEN_OFF = 1 << 0; |
| 1655 | /** |
Julia Reynolds | cedacef | 2016-03-04 08:18:47 -0500 | [diff] [blame] | 1656 | * Whether notifications suppressed by DND should not interrupt visually when the screen |
| 1657 | * is on (e.g. by peeking onto the screen). |
Julia Reynolds | ccc6ae6 | 2018-03-01 16:24:49 -0500 | [diff] [blame] | 1658 | * |
| 1659 | * @deprecated use {@link #SUPPRESSED_EFFECT_PEEK}. |
Julia Reynolds | d560729 | 2016-02-05 15:25:58 -0500 | [diff] [blame] | 1660 | */ |
Julia Reynolds | ccc6ae6 | 2018-03-01 16:24:49 -0500 | [diff] [blame] | 1661 | @Deprecated |
Julia Reynolds | d560729 | 2016-02-05 15:25:58 -0500 | [diff] [blame] | 1662 | public static final int SUPPRESSED_EFFECT_SCREEN_ON = 1 << 1; |
Julia Reynolds | f612869ae | 2015-11-05 16:48:55 -0500 | [diff] [blame] | 1663 | |
Julia Reynolds | ccc6ae6 | 2018-03-01 16:24:49 -0500 | [diff] [blame] | 1664 | /** |
| 1665 | * Whether {@link Notification#fullScreenIntent full screen intents} from |
| 1666 | * notifications intercepted by DND are blocked. |
| 1667 | */ |
| 1668 | public static final int SUPPRESSED_EFFECT_FULL_SCREEN_INTENT = 1 << 2; |
| 1669 | |
| 1670 | /** |
| 1671 | * Whether {@link NotificationChannel#shouldShowLights() notification lights} from |
| 1672 | * notifications intercepted by DND are blocked. |
| 1673 | */ |
| 1674 | public static final int SUPPRESSED_EFFECT_LIGHTS = 1 << 3; |
| 1675 | |
| 1676 | /** |
| 1677 | * Whether notifications intercepted by DND are prevented from peeking. |
| 1678 | */ |
| 1679 | public static final int SUPPRESSED_EFFECT_PEEK = 1 << 4; |
| 1680 | |
| 1681 | /** |
| 1682 | * Whether notifications intercepted by DND are prevented from appearing in the status bar, |
| 1683 | * on devices that support status bars. |
| 1684 | */ |
| 1685 | public static final int SUPPRESSED_EFFECT_STATUS_BAR = 1 << 5; |
| 1686 | |
| 1687 | /** |
| 1688 | * Whether {@link NotificationChannel#canShowBadge() badges} from |
| 1689 | * notifications intercepted by DND are blocked on devices that support badging. |
| 1690 | */ |
| 1691 | public static final int SUPPRESSED_EFFECT_BADGE = 1 << 6; |
| 1692 | |
| 1693 | /** |
| 1694 | * Whether notification intercepted by DND are prevented from appearing on ambient displays |
| 1695 | * on devices that support ambient display. |
| 1696 | */ |
| 1697 | public static final int SUPPRESSED_EFFECT_AMBIENT = 1 << 7; |
| 1698 | |
| 1699 | /** |
| 1700 | * Whether notification intercepted by DND are prevented from appearing in notification |
| 1701 | * list views like the notification shade or lockscreen on devices that support those |
| 1702 | * views. |
| 1703 | */ |
| 1704 | public static final int SUPPRESSED_EFFECT_NOTIFICATION_LIST = 1 << 8; |
| 1705 | |
Julia Reynolds | f612869ae | 2015-11-05 16:48:55 -0500 | [diff] [blame] | 1706 | private static final int[] ALL_SUPPRESSED_EFFECTS = { |
Julia Reynolds | d560729 | 2016-02-05 15:25:58 -0500 | [diff] [blame] | 1707 | SUPPRESSED_EFFECT_SCREEN_OFF, |
Julia Reynolds | 6172158 | 2016-01-05 08:35:25 -0500 | [diff] [blame] | 1708 | SUPPRESSED_EFFECT_SCREEN_ON, |
Julia Reynolds | ccc6ae6 | 2018-03-01 16:24:49 -0500 | [diff] [blame] | 1709 | SUPPRESSED_EFFECT_FULL_SCREEN_INTENT, |
| 1710 | SUPPRESSED_EFFECT_LIGHTS, |
| 1711 | SUPPRESSED_EFFECT_PEEK, |
| 1712 | SUPPRESSED_EFFECT_STATUS_BAR, |
| 1713 | SUPPRESSED_EFFECT_BADGE, |
| 1714 | SUPPRESSED_EFFECT_AMBIENT, |
| 1715 | SUPPRESSED_EFFECT_NOTIFICATION_LIST |
Julia Reynolds | f612869ae | 2015-11-05 16:48:55 -0500 | [diff] [blame] | 1716 | }; |
| 1717 | |
| 1718 | /** |
| 1719 | * Visual effects to suppress for a notification that is filtered by Do Not Disturb mode. |
| 1720 | * Bitmask of SUPPRESSED_EFFECT_* constants. |
| 1721 | */ |
| 1722 | public final int suppressedVisualEffects; |
| 1723 | |
Julia Reynolds | cedacef | 2016-03-04 08:18:47 -0500 | [diff] [blame] | 1724 | /** |
Beverly | 86d076f | 2018-04-17 14:44:52 -0400 | [diff] [blame] | 1725 | * @hide |
| 1726 | */ |
| 1727 | public static final int STATE_CHANNELS_BYPASSING_DND = 1 << 0; |
| 1728 | |
| 1729 | /** |
| 1730 | * @hide |
| 1731 | */ |
| 1732 | public static final int STATE_UNSET = -1; |
| 1733 | |
| 1734 | /** |
| 1735 | * Notification state information that is necessary to determine Do Not Disturb behavior. |
| 1736 | * Bitmask of STATE_* constants. |
| 1737 | * @hide |
| 1738 | */ |
| 1739 | public final int state; |
| 1740 | |
| 1741 | /** |
Julia Reynolds | cedacef | 2016-03-04 08:18:47 -0500 | [diff] [blame] | 1742 | * Constructs a policy for Do Not Disturb priority mode behavior. |
| 1743 | * |
Julia Reynolds | ccc6ae6 | 2018-03-01 16:24:49 -0500 | [diff] [blame] | 1744 | * <p> |
| 1745 | * Apps that target API levels below {@link Build.VERSION_CODES#P} cannot |
| 1746 | * change user-designated values to allow or disallow |
| 1747 | * {@link Policy#PRIORITY_CATEGORY_ALARMS}, {@link Policy#PRIORITY_CATEGORY_SYSTEM}, and |
| 1748 | * {@link Policy#PRIORITY_CATEGORY_MEDIA} from bypassing dnd. |
| 1749 | * |
Julia Reynolds | cedacef | 2016-03-04 08:18:47 -0500 | [diff] [blame] | 1750 | * @param priorityCategories bitmask of categories of notifications that can bypass DND. |
| 1751 | * @param priorityCallSenders which callers can bypass DND. |
| 1752 | * @param priorityMessageSenders which message senders can bypass DND. |
| 1753 | */ |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1754 | public Policy(int priorityCategories, int priorityCallSenders, int priorityMessageSenders) { |
Julia Reynolds | f612869ae | 2015-11-05 16:48:55 -0500 | [diff] [blame] | 1755 | this(priorityCategories, priorityCallSenders, priorityMessageSenders, |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 1756 | SUPPRESSED_EFFECTS_UNSET, STATE_UNSET, CONVERSATION_SENDERS_UNSET); |
Julia Reynolds | f612869ae | 2015-11-05 16:48:55 -0500 | [diff] [blame] | 1757 | } |
| 1758 | |
Julia Reynolds | cedacef | 2016-03-04 08:18:47 -0500 | [diff] [blame] | 1759 | /** |
| 1760 | * Constructs a policy for Do Not Disturb priority mode behavior. |
| 1761 | * |
Julia Reynolds | ccc6ae6 | 2018-03-01 16:24:49 -0500 | [diff] [blame] | 1762 | * <p> |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 1763 | * Apps that target API levels below {@link Build.VERSION_CODES#R} cannot |
Julia Reynolds | ccc6ae6 | 2018-03-01 16:24:49 -0500 | [diff] [blame] | 1764 | * change user-designated values to allow or disallow |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 1765 | * {@link Policy#PRIORITY_CATEGORY_CONVERSATIONS}, from bypassing dnd. |
Julia Reynolds | ccc6ae6 | 2018-03-01 16:24:49 -0500 | [diff] [blame] | 1766 | * <p> |
| 1767 | * Additionally, apps that target API levels below {@link Build.VERSION_CODES#P} can |
| 1768 | * only modify the {@link #SUPPRESSED_EFFECT_SCREEN_ON} and |
| 1769 | * {@link #SUPPRESSED_EFFECT_SCREEN_OFF} bits of the suppressed visual effects field. |
| 1770 | * All other suppressed effects will be ignored and reconstituted from the screen on |
| 1771 | * and screen off values. |
| 1772 | * <p> |
| 1773 | * Apps that target {@link Build.VERSION_CODES#P} or above can set any |
| 1774 | * suppressed visual effects. However, if any suppressed effects > |
| 1775 | * {@link #SUPPRESSED_EFFECT_SCREEN_ON} are set, {@link #SUPPRESSED_EFFECT_SCREEN_ON} |
| 1776 | * and {@link #SUPPRESSED_EFFECT_SCREEN_OFF} will be ignored and reconstituted from |
| 1777 | * the more specific suppressed visual effect bits. Apps should migrate to targeting |
| 1778 | * specific effects instead of the deprecated {@link #SUPPRESSED_EFFECT_SCREEN_ON} and |
| 1779 | * {@link #SUPPRESSED_EFFECT_SCREEN_OFF} effects. |
| 1780 | * |
Julia Reynolds | cedacef | 2016-03-04 08:18:47 -0500 | [diff] [blame] | 1781 | * @param priorityCategories bitmask of categories of notifications that can bypass DND. |
| 1782 | * @param priorityCallSenders which callers can bypass DND. |
| 1783 | * @param priorityMessageSenders which message senders can bypass DND. |
| 1784 | * @param suppressedVisualEffects which visual interruptions should be suppressed from |
| 1785 | * notifications that are filtered by DND. |
| 1786 | */ |
Julia Reynolds | f612869ae | 2015-11-05 16:48:55 -0500 | [diff] [blame] | 1787 | public Policy(int priorityCategories, int priorityCallSenders, int priorityMessageSenders, |
| 1788 | int suppressedVisualEffects) { |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 1789 | this(priorityCategories, priorityCallSenders, priorityMessageSenders, |
| 1790 | suppressedVisualEffects, STATE_UNSET, CONVERSATION_SENDERS_UNSET); |
| 1791 | } |
| 1792 | |
| 1793 | /** |
| 1794 | * Constructs a policy for Do Not Disturb priority mode behavior. |
| 1795 | * |
| 1796 | * <p> |
| 1797 | * Apps that target API levels below {@link Build.VERSION_CODES#P} cannot |
| 1798 | * change user-designated values to allow or disallow |
| 1799 | * {@link Policy#PRIORITY_CATEGORY_CONVERSATIONS} from bypassing dnd. If you do need |
| 1800 | * to change them, use a {@link ZenPolicy} associated with an {@link AutomaticZenRule} |
| 1801 | * instead of changing the global setting. |
| 1802 | * <p> |
| 1803 | * Apps that target API levels below {@link Build.VERSION_CODES#P} cannot |
| 1804 | * change user-designated values to allow or disallow |
| 1805 | * {@link Policy#PRIORITY_CATEGORY_ALARMS}, |
| 1806 | * {@link Policy#PRIORITY_CATEGORY_SYSTEM}, and |
| 1807 | * {@link Policy#PRIORITY_CATEGORY_MEDIA} from bypassing dnd. |
| 1808 | * <p> |
| 1809 | * Additionally, apps that target API levels below {@link Build.VERSION_CODES#P} can |
| 1810 | * only modify the {@link #SUPPRESSED_EFFECT_SCREEN_ON} and |
| 1811 | * {@link #SUPPRESSED_EFFECT_SCREEN_OFF} bits of the suppressed visual effects field. |
| 1812 | * All other suppressed effects will be ignored and reconstituted from the screen on |
| 1813 | * and screen off values. |
| 1814 | * <p> |
| 1815 | * Apps that target {@link Build.VERSION_CODES#P} or above can set any |
| 1816 | * suppressed visual effects. However, if any suppressed effects > |
| 1817 | * {@link #SUPPRESSED_EFFECT_SCREEN_ON} are set, {@link #SUPPRESSED_EFFECT_SCREEN_ON} |
| 1818 | * and {@link #SUPPRESSED_EFFECT_SCREEN_OFF} will be ignored and reconstituted from |
| 1819 | * the more specific suppressed visual effect bits. Apps should migrate to targeting |
| 1820 | * specific effects instead of the deprecated {@link #SUPPRESSED_EFFECT_SCREEN_ON} and |
| 1821 | * {@link #SUPPRESSED_EFFECT_SCREEN_OFF} effects. |
| 1822 | * |
| 1823 | * @param priorityCategories bitmask of categories of notifications that can bypass DND. |
| 1824 | * @param priorityCallSenders which callers can bypass DND. |
| 1825 | * @param priorityMessageSenders which message senders can bypass DND. |
| 1826 | * @param suppressedVisualEffects which visual interruptions should be suppressed from |
| 1827 | * notifications that are filtered by DND. |
| 1828 | */ |
Julia Reynolds | 229684b | 2020-02-23 20:39:04 -0500 | [diff] [blame] | 1829 | public Policy(int priorityCategories, @PrioritySenders int priorityCallSenders, |
| 1830 | @PrioritySenders int priorityMessageSenders, |
| 1831 | int suppressedVisualEffects, @ConversationSenders int priorityConversationSenders) { |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 1832 | this(priorityCategories, priorityCallSenders, priorityMessageSenders, |
| 1833 | suppressedVisualEffects, STATE_UNSET, priorityConversationSenders); |
Beverly | 86d076f | 2018-04-17 14:44:52 -0400 | [diff] [blame] | 1834 | } |
| 1835 | |
| 1836 | /** @hide */ |
| 1837 | public Policy(int priorityCategories, int priorityCallSenders, int priorityMessageSenders, |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 1838 | int suppressedVisualEffects, int state, int priorityConversationSenders) { |
Beverly | 86d076f | 2018-04-17 14:44:52 -0400 | [diff] [blame] | 1839 | this.priorityCategories = priorityCategories; |
| 1840 | this.priorityCallSenders = priorityCallSenders; |
| 1841 | this.priorityMessageSenders = priorityMessageSenders; |
| 1842 | this.suppressedVisualEffects = suppressedVisualEffects; |
| 1843 | this.state = state; |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 1844 | this.priorityConversationSenders = priorityConversationSenders; |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1845 | } |
| 1846 | |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 1847 | |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1848 | /** @hide */ |
| 1849 | public Policy(Parcel source) { |
Beverly | 86d076f | 2018-04-17 14:44:52 -0400 | [diff] [blame] | 1850 | this(source.readInt(), source.readInt(), source.readInt(), source.readInt(), |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 1851 | source.readInt(), source.readInt()); |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1852 | } |
| 1853 | |
| 1854 | @Override |
| 1855 | public void writeToParcel(Parcel dest, int flags) { |
| 1856 | dest.writeInt(priorityCategories); |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1857 | dest.writeInt(priorityCallSenders); |
| 1858 | dest.writeInt(priorityMessageSenders); |
Julia Reynolds | f612869ae | 2015-11-05 16:48:55 -0500 | [diff] [blame] | 1859 | dest.writeInt(suppressedVisualEffects); |
Beverly | 86d076f | 2018-04-17 14:44:52 -0400 | [diff] [blame] | 1860 | dest.writeInt(state); |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 1861 | dest.writeInt(priorityConversationSenders); |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1862 | } |
| 1863 | |
| 1864 | @Override |
| 1865 | public int describeContents() { |
| 1866 | return 0; |
| 1867 | } |
| 1868 | |
| 1869 | @Override |
| 1870 | public int hashCode() { |
Julia Reynolds | f612869ae | 2015-11-05 16:48:55 -0500 | [diff] [blame] | 1871 | return Objects.hash(priorityCategories, priorityCallSenders, priorityMessageSenders, |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 1872 | suppressedVisualEffects, state, priorityConversationSenders); |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1873 | } |
| 1874 | |
| 1875 | @Override |
| 1876 | public boolean equals(Object o) { |
| 1877 | if (!(o instanceof Policy)) return false; |
| 1878 | if (o == this) return true; |
| 1879 | final Policy other = (Policy) o; |
| 1880 | return other.priorityCategories == priorityCategories |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1881 | && other.priorityCallSenders == priorityCallSenders |
Julia Reynolds | f612869ae | 2015-11-05 16:48:55 -0500 | [diff] [blame] | 1882 | && other.priorityMessageSenders == priorityMessageSenders |
Beverly | 9cb05c9 | 2018-11-28 10:03:23 -0500 | [diff] [blame] | 1883 | && suppressedVisualEffectsEqual(suppressedVisualEffects, |
Beverly | 4f8b022 | 2019-10-24 13:35:03 -0400 | [diff] [blame] | 1884 | other.suppressedVisualEffects) |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 1885 | && other.state == this.state |
| 1886 | && other.priorityConversationSenders == this.priorityConversationSenders; |
Beverly | 9cb05c9 | 2018-11-28 10:03:23 -0500 | [diff] [blame] | 1887 | } |
| 1888 | |
Beverly | 9cb05c9 | 2018-11-28 10:03:23 -0500 | [diff] [blame] | 1889 | private boolean suppressedVisualEffectsEqual(int suppressedEffects, |
| 1890 | int otherSuppressedVisualEffects) { |
| 1891 | if (suppressedEffects == otherSuppressedVisualEffects) { |
| 1892 | return true; |
| 1893 | } |
| 1894 | |
| 1895 | if ((suppressedEffects & SUPPRESSED_EFFECT_SCREEN_ON) != 0) { |
| 1896 | suppressedEffects |= SUPPRESSED_EFFECT_PEEK; |
| 1897 | } |
| 1898 | if ((suppressedEffects & SUPPRESSED_EFFECT_SCREEN_OFF) != 0) { |
| 1899 | suppressedEffects |= SUPPRESSED_EFFECT_FULL_SCREEN_INTENT; |
| 1900 | suppressedEffects |= SUPPRESSED_EFFECT_LIGHTS; |
| 1901 | suppressedEffects |= SUPPRESSED_EFFECT_AMBIENT; |
| 1902 | } |
| 1903 | |
| 1904 | if ((otherSuppressedVisualEffects & SUPPRESSED_EFFECT_SCREEN_ON) != 0) { |
| 1905 | otherSuppressedVisualEffects |= SUPPRESSED_EFFECT_PEEK; |
| 1906 | } |
| 1907 | if ((otherSuppressedVisualEffects & SUPPRESSED_EFFECT_SCREEN_OFF) != 0) { |
| 1908 | otherSuppressedVisualEffects |= SUPPRESSED_EFFECT_FULL_SCREEN_INTENT; |
| 1909 | otherSuppressedVisualEffects |= SUPPRESSED_EFFECT_LIGHTS; |
| 1910 | otherSuppressedVisualEffects |= SUPPRESSED_EFFECT_AMBIENT; |
| 1911 | } |
| 1912 | |
| 1913 | if ((suppressedEffects & SUPPRESSED_EFFECT_SCREEN_ON) |
| 1914 | != (otherSuppressedVisualEffects & SUPPRESSED_EFFECT_SCREEN_ON)) { |
| 1915 | int currSuppressedEffects = (suppressedEffects & SUPPRESSED_EFFECT_SCREEN_ON) != 0 |
| 1916 | ? otherSuppressedVisualEffects : suppressedEffects; |
| 1917 | if ((currSuppressedEffects & SUPPRESSED_EFFECT_PEEK) == 0) { |
| 1918 | return false; |
| 1919 | } |
| 1920 | } |
| 1921 | |
| 1922 | if ((suppressedEffects & SUPPRESSED_EFFECT_SCREEN_OFF) |
| 1923 | != (otherSuppressedVisualEffects & SUPPRESSED_EFFECT_SCREEN_OFF)) { |
| 1924 | int currSuppressedEffects = (suppressedEffects & SUPPRESSED_EFFECT_SCREEN_OFF) != 0 |
| 1925 | ? otherSuppressedVisualEffects : suppressedEffects; |
| 1926 | if ((currSuppressedEffects & SUPPRESSED_EFFECT_FULL_SCREEN_INTENT) == 0 |
| 1927 | || (currSuppressedEffects & SUPPRESSED_EFFECT_LIGHTS) == 0 |
| 1928 | || (currSuppressedEffects & SUPPRESSED_EFFECT_AMBIENT) == 0) { |
| 1929 | return false; |
| 1930 | } |
| 1931 | } |
| 1932 | |
| 1933 | int thisWithoutOldEffects = suppressedEffects |
| 1934 | & ~SUPPRESSED_EFFECT_SCREEN_ON |
| 1935 | & ~SUPPRESSED_EFFECT_SCREEN_OFF; |
| 1936 | int otherWithoutOldEffects = otherSuppressedVisualEffects |
| 1937 | & ~SUPPRESSED_EFFECT_SCREEN_ON |
| 1938 | & ~SUPPRESSED_EFFECT_SCREEN_OFF; |
| 1939 | return thisWithoutOldEffects == otherWithoutOldEffects; |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1940 | } |
| 1941 | |
| 1942 | @Override |
| 1943 | public String toString() { |
| 1944 | return "NotificationManager.Policy[" |
| 1945 | + "priorityCategories=" + priorityCategoriesToString(priorityCategories) |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 1946 | + ",priorityCallSenders=" + prioritySendersToString(priorityCallSenders) |
| 1947 | + ",priorityMessageSenders=" + prioritySendersToString(priorityMessageSenders) |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 1948 | + ",priorityConvSenders=" |
| 1949 | + conversationSendersToString(priorityConversationSenders) |
Julia Reynolds | f612869ae | 2015-11-05 16:48:55 -0500 | [diff] [blame] | 1950 | + ",suppressedVisualEffects=" |
| 1951 | + suppressedEffectsToString(suppressedVisualEffects) |
Beverly | 86d076f | 2018-04-17 14:44:52 -0400 | [diff] [blame] | 1952 | + ",areChannelsBypassingDnd=" + (((state & STATE_CHANNELS_BYPASSING_DND) != 0) |
| 1953 | ? "true" : "false") |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1954 | + "]"; |
| 1955 | } |
| 1956 | |
Kweku Adams | 5ec78cd | 2017-09-25 16:29:54 -0700 | [diff] [blame] | 1957 | /** @hide */ |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 1958 | public void dumpDebug(ProtoOutputStream proto, long fieldId) { |
Kweku Adams | 5ec78cd | 2017-09-25 16:29:54 -0700 | [diff] [blame] | 1959 | final long pToken = proto.start(fieldId); |
| 1960 | |
| 1961 | bitwiseToProtoEnum(proto, PolicyProto.PRIORITY_CATEGORIES, priorityCategories); |
| 1962 | proto.write(PolicyProto.PRIORITY_CALL_SENDER, priorityCallSenders); |
| 1963 | proto.write(PolicyProto.PRIORITY_MESSAGE_SENDER, priorityMessageSenders); |
| 1964 | bitwiseToProtoEnum( |
| 1965 | proto, PolicyProto.SUPPRESSED_VISUAL_EFFECTS, suppressedVisualEffects); |
| 1966 | |
| 1967 | proto.end(pToken); |
| 1968 | } |
| 1969 | |
| 1970 | private static void bitwiseToProtoEnum(ProtoOutputStream proto, long fieldId, int data) { |
| 1971 | for (int i = 1; data > 0; ++i, data >>>= 1) { |
| 1972 | if ((data & 1) == 1) { |
| 1973 | proto.write(fieldId, i); |
| 1974 | } |
| 1975 | } |
| 1976 | } |
| 1977 | |
Julia Reynolds | ccc6ae6 | 2018-03-01 16:24:49 -0500 | [diff] [blame] | 1978 | /** |
| 1979 | * @hide |
| 1980 | */ |
| 1981 | public static int getAllSuppressedVisualEffects() { |
| 1982 | int effects = 0; |
| 1983 | for (int i = 0; i < ALL_SUPPRESSED_EFFECTS.length; i++) { |
| 1984 | effects |= ALL_SUPPRESSED_EFFECTS[i]; |
| 1985 | } |
| 1986 | return effects; |
| 1987 | } |
| 1988 | |
| 1989 | /** |
| 1990 | * @hide |
| 1991 | */ |
| 1992 | public static boolean areAllVisualEffectsSuppressed(int effects) { |
| 1993 | for (int i = 0; i < ALL_SUPPRESSED_EFFECTS.length; i++) { |
| 1994 | final int effect = ALL_SUPPRESSED_EFFECTS[i]; |
| 1995 | if ((effects & effect) == 0) { |
| 1996 | return false; |
| 1997 | } |
| 1998 | } |
| 1999 | return true; |
| 2000 | } |
| 2001 | |
Julia Reynolds | 9aa1c9e | 2018-04-09 11:31:15 -0400 | [diff] [blame] | 2002 | private static int toggleEffects(int currentEffects, int[] effects, boolean suppress) { |
| 2003 | for (int i = 0; i < effects.length; i++) { |
| 2004 | final int effect = effects[i]; |
| 2005 | if (suppress) { |
| 2006 | currentEffects |= effect; |
| 2007 | } else { |
| 2008 | currentEffects &= ~effect; |
| 2009 | } |
| 2010 | } |
| 2011 | return currentEffects; |
| 2012 | } |
| 2013 | |
Julia Reynolds | f612869ae | 2015-11-05 16:48:55 -0500 | [diff] [blame] | 2014 | public static String suppressedEffectsToString(int effects) { |
| 2015 | if (effects <= 0) return ""; |
| 2016 | final StringBuilder sb = new StringBuilder(); |
| 2017 | for (int i = 0; i < ALL_SUPPRESSED_EFFECTS.length; i++) { |
| 2018 | final int effect = ALL_SUPPRESSED_EFFECTS[i]; |
| 2019 | if ((effects & effect) != 0) { |
| 2020 | if (sb.length() > 0) sb.append(','); |
| 2021 | sb.append(effectToString(effect)); |
| 2022 | } |
| 2023 | effects &= ~effect; |
| 2024 | } |
| 2025 | if (effects != 0) { |
| 2026 | if (sb.length() > 0) sb.append(','); |
| 2027 | sb.append("UNKNOWN_").append(effects); |
| 2028 | } |
| 2029 | return sb.toString(); |
| 2030 | } |
| 2031 | |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 2032 | public static String priorityCategoriesToString(int priorityCategories) { |
| 2033 | if (priorityCategories == 0) return ""; |
| 2034 | final StringBuilder sb = new StringBuilder(); |
| 2035 | for (int i = 0; i < ALL_PRIORITY_CATEGORIES.length; i++) { |
| 2036 | final int priorityCategory = ALL_PRIORITY_CATEGORIES[i]; |
| 2037 | if ((priorityCategories & priorityCategory) != 0) { |
| 2038 | if (sb.length() > 0) sb.append(','); |
| 2039 | sb.append(priorityCategoryToString(priorityCategory)); |
| 2040 | } |
| 2041 | priorityCategories &= ~priorityCategory; |
| 2042 | } |
| 2043 | if (priorityCategories != 0) { |
| 2044 | if (sb.length() > 0) sb.append(','); |
| 2045 | sb.append("PRIORITY_CATEGORY_UNKNOWN_").append(priorityCategories); |
| 2046 | } |
| 2047 | return sb.toString(); |
| 2048 | } |
| 2049 | |
Julia Reynolds | f612869ae | 2015-11-05 16:48:55 -0500 | [diff] [blame] | 2050 | private static String effectToString(int effect) { |
| 2051 | switch (effect) { |
Julia Reynolds | ccc6ae6 | 2018-03-01 16:24:49 -0500 | [diff] [blame] | 2052 | case SUPPRESSED_EFFECT_FULL_SCREEN_INTENT: |
| 2053 | return "SUPPRESSED_EFFECT_FULL_SCREEN_INTENT"; |
| 2054 | case SUPPRESSED_EFFECT_LIGHTS: |
| 2055 | return "SUPPRESSED_EFFECT_LIGHTS"; |
| 2056 | case SUPPRESSED_EFFECT_PEEK: |
| 2057 | return "SUPPRESSED_EFFECT_PEEK"; |
| 2058 | case SUPPRESSED_EFFECT_STATUS_BAR: |
| 2059 | return "SUPPRESSED_EFFECT_STATUS_BAR"; |
| 2060 | case SUPPRESSED_EFFECT_BADGE: |
| 2061 | return "SUPPRESSED_EFFECT_BADGE"; |
| 2062 | case SUPPRESSED_EFFECT_AMBIENT: |
| 2063 | return "SUPPRESSED_EFFECT_AMBIENT"; |
| 2064 | case SUPPRESSED_EFFECT_NOTIFICATION_LIST: |
| 2065 | return "SUPPRESSED_EFFECT_NOTIFICATION_LIST"; |
| 2066 | case SUPPRESSED_EFFECT_SCREEN_OFF: |
| 2067 | return "SUPPRESSED_EFFECT_SCREEN_OFF"; |
| 2068 | case SUPPRESSED_EFFECT_SCREEN_ON: |
| 2069 | return "SUPPRESSED_EFFECT_SCREEN_ON"; |
| 2070 | case SUPPRESSED_EFFECTS_UNSET: |
| 2071 | return "SUPPRESSED_EFFECTS_UNSET"; |
Julia Reynolds | f612869ae | 2015-11-05 16:48:55 -0500 | [diff] [blame] | 2072 | default: return "UNKNOWN_" + effect; |
| 2073 | } |
| 2074 | } |
| 2075 | |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 2076 | private static String priorityCategoryToString(int priorityCategory) { |
| 2077 | switch (priorityCategory) { |
| 2078 | case PRIORITY_CATEGORY_REMINDERS: return "PRIORITY_CATEGORY_REMINDERS"; |
| 2079 | case PRIORITY_CATEGORY_EVENTS: return "PRIORITY_CATEGORY_EVENTS"; |
| 2080 | case PRIORITY_CATEGORY_MESSAGES: return "PRIORITY_CATEGORY_MESSAGES"; |
| 2081 | case PRIORITY_CATEGORY_CALLS: return "PRIORITY_CATEGORY_CALLS"; |
| 2082 | case PRIORITY_CATEGORY_REPEAT_CALLERS: return "PRIORITY_CATEGORY_REPEAT_CALLERS"; |
Beverly | 0421687 | 2017-09-28 10:55:32 -0400 | [diff] [blame] | 2083 | case PRIORITY_CATEGORY_ALARMS: return "PRIORITY_CATEGORY_ALARMS"; |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 2084 | case PRIORITY_CATEGORY_MEDIA: return "PRIORITY_CATEGORY_MEDIA"; |
| 2085 | case PRIORITY_CATEGORY_SYSTEM: return "PRIORITY_CATEGORY_SYSTEM"; |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 2086 | case PRIORITY_CATEGORY_CONVERSATIONS: return "PRIORITY_CATEGORY_CONVERSATIONS"; |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 2087 | default: return "PRIORITY_CATEGORY_UNKNOWN_" + priorityCategory; |
| 2088 | } |
| 2089 | } |
| 2090 | |
| 2091 | public static String prioritySendersToString(int prioritySenders) { |
| 2092 | switch (prioritySenders) { |
| 2093 | case PRIORITY_SENDERS_ANY: return "PRIORITY_SENDERS_ANY"; |
| 2094 | case PRIORITY_SENDERS_CONTACTS: return "PRIORITY_SENDERS_CONTACTS"; |
| 2095 | case PRIORITY_SENDERS_STARRED: return "PRIORITY_SENDERS_STARRED"; |
| 2096 | default: return "PRIORITY_SENDERS_UNKNOWN_" + prioritySenders; |
| 2097 | } |
| 2098 | } |
| 2099 | |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 2100 | /** |
| 2101 | * @hide |
| 2102 | */ |
| 2103 | public static @NonNull String conversationSendersToString(int priorityConversationSenders) { |
| 2104 | switch (priorityConversationSenders) { |
| 2105 | case CONVERSATION_SENDERS_ANYONE: |
| 2106 | return "anyone"; |
| 2107 | case CONVERSATION_SENDERS_IMPORTANT: |
| 2108 | return "important"; |
| 2109 | case CONVERSATION_SENDERS_NONE: |
| 2110 | return "none"; |
| 2111 | case CONVERSATION_SENDERS_UNSET: |
| 2112 | return "unset"; |
| 2113 | } |
| 2114 | return "invalidConversationType{" + priorityConversationSenders + "}"; |
| 2115 | } |
| 2116 | |
| 2117 | public static final @android.annotation.NonNull Parcelable.Creator<Policy> CREATOR |
| 2118 | = new Parcelable.Creator<Policy>() { |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 2119 | @Override |
| 2120 | public Policy createFromParcel(Parcel in) { |
| 2121 | return new Policy(in); |
| 2122 | } |
| 2123 | |
| 2124 | @Override |
| 2125 | public Policy[] newArray(int size) { |
| 2126 | return new Policy[size]; |
| 2127 | } |
| 2128 | }; |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 2129 | |
| 2130 | /** @hide **/ |
| 2131 | public boolean allowAlarms() { |
| 2132 | return (priorityCategories & PRIORITY_CATEGORY_ALARMS) != 0; |
| 2133 | } |
| 2134 | |
| 2135 | /** @hide **/ |
| 2136 | public boolean allowMedia() { |
| 2137 | return (priorityCategories & PRIORITY_CATEGORY_MEDIA) != 0; |
| 2138 | } |
| 2139 | |
| 2140 | /** @hide **/ |
| 2141 | public boolean allowSystem() { |
| 2142 | return (priorityCategories & PRIORITY_CATEGORY_SYSTEM) != 0; |
| 2143 | } |
| 2144 | |
| 2145 | /** @hide **/ |
| 2146 | public boolean allowRepeatCallers() { |
| 2147 | return (priorityCategories & PRIORITY_CATEGORY_REPEAT_CALLERS) != 0; |
| 2148 | } |
| 2149 | |
| 2150 | /** @hide **/ |
| 2151 | public boolean allowCalls() { |
| 2152 | return (priorityCategories & PRIORITY_CATEGORY_CALLS) != 0; |
| 2153 | } |
| 2154 | |
| 2155 | /** @hide **/ |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 2156 | public boolean allowConversations() { |
| 2157 | return (priorityCategories & PRIORITY_CATEGORY_CONVERSATIONS) != 0; |
| 2158 | } |
| 2159 | |
| 2160 | /** @hide **/ |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 2161 | public boolean allowMessages() { |
| 2162 | return (priorityCategories & PRIORITY_CATEGORY_MESSAGES) != 0; |
| 2163 | } |
| 2164 | |
| 2165 | /** @hide **/ |
| 2166 | public boolean allowEvents() { |
| 2167 | return (priorityCategories & PRIORITY_CATEGORY_EVENTS) != 0; |
| 2168 | } |
| 2169 | |
| 2170 | /** @hide **/ |
| 2171 | public boolean allowReminders() { |
| 2172 | return (priorityCategories & PRIORITY_CATEGORY_REMINDERS) != 0; |
| 2173 | } |
| 2174 | |
| 2175 | /** @hide **/ |
| 2176 | public int allowCallsFrom() { |
| 2177 | return priorityCallSenders; |
| 2178 | } |
| 2179 | |
| 2180 | /** @hide **/ |
| 2181 | public int allowMessagesFrom() { |
| 2182 | return priorityMessageSenders; |
| 2183 | } |
| 2184 | |
Beverly | 1219670 | 2018-12-12 15:05:51 -0500 | [diff] [blame] | 2185 | /** @hide **/ |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 2186 | public int allowConversationsFrom() { |
| 2187 | return priorityConversationSenders; |
| 2188 | } |
| 2189 | |
| 2190 | /** @hide **/ |
Beverly | 1219670 | 2018-12-12 15:05:51 -0500 | [diff] [blame] | 2191 | public boolean showFullScreenIntents() { |
| 2192 | return (suppressedVisualEffects & SUPPRESSED_EFFECT_FULL_SCREEN_INTENT) == 0; |
| 2193 | } |
| 2194 | |
| 2195 | /** @hide **/ |
| 2196 | public boolean showLights() { |
| 2197 | return (suppressedVisualEffects & SUPPRESSED_EFFECT_LIGHTS) == 0; |
| 2198 | } |
| 2199 | |
| 2200 | /** @hide **/ |
| 2201 | public boolean showPeeking() { |
| 2202 | return (suppressedVisualEffects & SUPPRESSED_EFFECT_PEEK) == 0; |
| 2203 | } |
| 2204 | |
| 2205 | /** @hide **/ |
| 2206 | public boolean showStatusBarIcons() { |
| 2207 | return (suppressedVisualEffects & SUPPRESSED_EFFECT_STATUS_BAR) == 0; |
| 2208 | } |
| 2209 | |
| 2210 | /** @hide **/ |
| 2211 | public boolean showAmbient() { |
| 2212 | return (suppressedVisualEffects & SUPPRESSED_EFFECT_AMBIENT) == 0; |
| 2213 | } |
| 2214 | |
| 2215 | /** @hide **/ |
| 2216 | public boolean showBadges() { |
| 2217 | return (suppressedVisualEffects & SUPPRESSED_EFFECT_BADGE) == 0; |
| 2218 | } |
| 2219 | |
| 2220 | /** @hide **/ |
| 2221 | public boolean showInNotificationList() { |
| 2222 | return (suppressedVisualEffects & SUPPRESSED_EFFECT_NOTIFICATION_LIST) == 0; |
| 2223 | } |
| 2224 | |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 2225 | /** |
| 2226 | * returns a deep copy of this policy |
| 2227 | * @hide |
| 2228 | */ |
| 2229 | public Policy copy() { |
| 2230 | final Parcel parcel = Parcel.obtain(); |
| 2231 | try { |
| 2232 | writeToParcel(parcel, 0); |
| 2233 | parcel.setDataPosition(0); |
| 2234 | return new Policy(parcel); |
| 2235 | } finally { |
| 2236 | parcel.recycle(); |
| 2237 | } |
| 2238 | } |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 2239 | } |
| 2240 | |
Dan Sandler | 994349c | 2015-04-15 11:02:54 -0400 | [diff] [blame] | 2241 | /** |
| 2242 | * Recover a list of active notifications: ones that have been posted by the calling app that |
| 2243 | * have not yet been dismissed by the user or {@link #cancel(String, int)}ed by the app. |
| 2244 | * |
Julia Reynolds | d12392c | 2018-12-17 14:06:04 -0500 | [diff] [blame] | 2245 | * <p><Each notification is embedded in a {@link StatusBarNotification} object, including the |
Dan Sandler | 994349c | 2015-04-15 11:02:54 -0400 | [diff] [blame] | 2246 | * original <code>tag</code> and <code>id</code> supplied to |
| 2247 | * {@link #notify(String, int, Notification) notify()} |
| 2248 | * (via {@link StatusBarNotification#getTag() getTag()} and |
| 2249 | * {@link StatusBarNotification#getId() getId()}) as well as a copy of the original |
| 2250 | * {@link Notification} object (via {@link StatusBarNotification#getNotification()}). |
Julia Reynolds | d12392c | 2018-12-17 14:06:04 -0500 | [diff] [blame] | 2251 | * </p> |
| 2252 | * <p>From {@link Build.VERSION_CODES#Q}, will also return notifications you've posted as an |
| 2253 | * app's notification delegate via |
| 2254 | * {@link NotificationManager#notifyAsPackage(String, String, int, Notification)}. |
| 2255 | * </p> |
Dan Sandler | 994349c | 2015-04-15 11:02:54 -0400 | [diff] [blame] | 2256 | * |
| 2257 | * @return An array of {@link StatusBarNotification}. |
| 2258 | */ |
| 2259 | public StatusBarNotification[] getActiveNotifications() { |
| 2260 | final INotificationManager service = getService(); |
| 2261 | final String pkg = mContext.getPackageName(); |
| 2262 | try { |
| 2263 | final ParceledListSlice<StatusBarNotification> parceledList |
Jeff Sharkey | ad357d1 | 2018-02-02 13:25:31 -0700 | [diff] [blame] | 2264 | = service.getAppActiveNotifications(pkg, mContext.getUserId()); |
Julia Reynolds | 34a8084 | 2018-09-21 13:01:00 -0400 | [diff] [blame] | 2265 | if (parceledList != null) { |
| 2266 | final List<StatusBarNotification> list = parceledList.getList(); |
| 2267 | return list.toArray(new StatusBarNotification[list.size()]); |
| 2268 | } |
Dan Sandler | 994349c | 2015-04-15 11:02:54 -0400 | [diff] [blame] | 2269 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 2270 | throw e.rethrowFromSystemServer(); |
Dan Sandler | 994349c | 2015-04-15 11:02:54 -0400 | [diff] [blame] | 2271 | } |
Julia Reynolds | 34a8084 | 2018-09-21 13:01:00 -0400 | [diff] [blame] | 2272 | return new StatusBarNotification[0]; |
Dan Sandler | 994349c | 2015-04-15 11:02:54 -0400 | [diff] [blame] | 2273 | } |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 2274 | |
| 2275 | /** |
| 2276 | * Gets the current notification interruption filter. |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 2277 | * <p> |
Jeff Sharkey | 6503bd8 | 2017-04-19 23:24:18 -0600 | [diff] [blame] | 2278 | * The interruption filter defines which notifications are allowed to |
| 2279 | * interrupt the user (e.g. via sound & vibration) and is applied |
| 2280 | * globally. |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 2281 | */ |
Julia Reynolds | 0edb50c | 2016-02-26 14:08:25 -0500 | [diff] [blame] | 2282 | public final @InterruptionFilter int getCurrentInterruptionFilter() { |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 2283 | final INotificationManager service = getService(); |
| 2284 | try { |
| 2285 | return zenModeToInterruptionFilter(service.getZenMode()); |
| 2286 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 2287 | throw e.rethrowFromSystemServer(); |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 2288 | } |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 2289 | } |
| 2290 | |
| 2291 | /** |
| 2292 | * Sets the current notification interruption filter. |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 2293 | * <p> |
Jeff Sharkey | 6503bd8 | 2017-04-19 23:24:18 -0600 | [diff] [blame] | 2294 | * The interruption filter defines which notifications are allowed to |
| 2295 | * interrupt the user (e.g. via sound & vibration) and is applied |
| 2296 | * globally. |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 2297 | * <p> |
Jeff Sharkey | 6503bd8 | 2017-04-19 23:24:18 -0600 | [diff] [blame] | 2298 | * Only available if policy access is granted to this package. See |
| 2299 | * {@link #isNotificationPolicyAccessGranted}. |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 2300 | */ |
Jeff Sharkey | 6503bd8 | 2017-04-19 23:24:18 -0600 | [diff] [blame] | 2301 | public final void setInterruptionFilter(@InterruptionFilter int interruptionFilter) { |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 2302 | final INotificationManager service = getService(); |
| 2303 | try { |
| 2304 | service.setInterruptionFilter(mContext.getOpPackageName(), interruptionFilter); |
| 2305 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 2306 | throw e.rethrowFromSystemServer(); |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 2307 | } |
| 2308 | } |
| 2309 | |
| 2310 | /** @hide */ |
| 2311 | public static int zenModeToInterruptionFilter(int zen) { |
| 2312 | switch (zen) { |
| 2313 | case Global.ZEN_MODE_OFF: return INTERRUPTION_FILTER_ALL; |
| 2314 | case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS: return INTERRUPTION_FILTER_PRIORITY; |
| 2315 | case Global.ZEN_MODE_ALARMS: return INTERRUPTION_FILTER_ALARMS; |
| 2316 | case Global.ZEN_MODE_NO_INTERRUPTIONS: return INTERRUPTION_FILTER_NONE; |
| 2317 | default: return INTERRUPTION_FILTER_UNKNOWN; |
| 2318 | } |
| 2319 | } |
| 2320 | |
| 2321 | /** @hide */ |
| 2322 | public static int zenModeFromInterruptionFilter(int interruptionFilter, int defValue) { |
| 2323 | switch (interruptionFilter) { |
| 2324 | case INTERRUPTION_FILTER_ALL: return Global.ZEN_MODE_OFF; |
| 2325 | case INTERRUPTION_FILTER_PRIORITY: return Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS; |
| 2326 | case INTERRUPTION_FILTER_ALARMS: return Global.ZEN_MODE_ALARMS; |
| 2327 | case INTERRUPTION_FILTER_NONE: return Global.ZEN_MODE_NO_INTERRUPTIONS; |
| 2328 | default: return defValue; |
| 2329 | } |
| 2330 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2331 | } |