John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (c) 2015, 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 com.android.server.notification; |
| 18 | |
Julia Reynolds | ccc6ae6 | 2018-03-01 16:24:49 -0500 | [diff] [blame] | 19 | import static android.provider.Settings.Global.ZEN_MODE_OFF; |
| 20 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 21 | import android.app.Notification; |
Julia Reynolds | ccc6ae6 | 2018-03-01 16:24:49 -0500 | [diff] [blame] | 22 | import android.app.NotificationManager; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 23 | import android.content.ComponentName; |
| 24 | import android.content.Context; |
| 25 | import android.media.AudioAttributes; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 26 | import android.os.Bundle; |
| 27 | import android.os.UserHandle; |
| 28 | import android.provider.Settings.Global; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 29 | import android.service.notification.ZenModeConfig; |
| 30 | import android.telecom.TelecomManager; |
John Spurlock | 1d7d224 | 2015-04-10 08:10:22 -0400 | [diff] [blame] | 31 | import android.util.ArrayMap; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 32 | import android.util.Slog; |
| 33 | |
Julia Reynolds | ccc6ae6 | 2018-03-01 16:24:49 -0500 | [diff] [blame] | 34 | import com.android.internal.messages.nano.SystemMessageProto; |
Julia Reynolds | 51eb78f8 | 2018-03-07 07:35:21 -0500 | [diff] [blame] | 35 | import com.android.internal.util.NotificationMessagingUtil; |
Julia Reynolds | ccc6ae6 | 2018-03-01 16:24:49 -0500 | [diff] [blame] | 36 | |
John Spurlock | 1d7d224 | 2015-04-10 08:10:22 -0400 | [diff] [blame] | 37 | import java.io.PrintWriter; |
| 38 | import java.util.Date; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 39 | |
| 40 | public class ZenModeFiltering { |
| 41 | private static final String TAG = ZenModeHelper.TAG; |
| 42 | private static final boolean DEBUG = ZenModeHelper.DEBUG; |
| 43 | |
John Spurlock | 1d7d224 | 2015-04-10 08:10:22 -0400 | [diff] [blame] | 44 | static final RepeatCallers REPEAT_CALLERS = new RepeatCallers(); |
| 45 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 46 | private final Context mContext; |
| 47 | |
| 48 | private ComponentName mDefaultPhoneApp; |
Julia Reynolds | 51eb78f8 | 2018-03-07 07:35:21 -0500 | [diff] [blame] | 49 | private final NotificationMessagingUtil mMessagingUtil; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 50 | |
| 51 | public ZenModeFiltering(Context context) { |
| 52 | mContext = context; |
Julia Reynolds | 51eb78f8 | 2018-03-07 07:35:21 -0500 | [diff] [blame] | 53 | mMessagingUtil = new NotificationMessagingUtil(mContext); |
| 54 | } |
| 55 | |
| 56 | public ZenModeFiltering(Context context, NotificationMessagingUtil messagingUtil) { |
| 57 | mContext = context; |
| 58 | mMessagingUtil = messagingUtil; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 59 | } |
| 60 | |
John Spurlock | 1d7d224 | 2015-04-10 08:10:22 -0400 | [diff] [blame] | 61 | public void dump(PrintWriter pw, String prefix) { |
| 62 | pw.print(prefix); pw.print("mDefaultPhoneApp="); pw.println(mDefaultPhoneApp); |
| 63 | pw.print(prefix); pw.print("RepeatCallers.mThresholdMinutes="); |
| 64 | pw.println(REPEAT_CALLERS.mThresholdMinutes); |
| 65 | synchronized (REPEAT_CALLERS) { |
| 66 | if (!REPEAT_CALLERS.mCalls.isEmpty()) { |
| 67 | pw.print(prefix); pw.println("RepeatCallers.mCalls="); |
| 68 | for (int i = 0; i < REPEAT_CALLERS.mCalls.size(); i++) { |
| 69 | pw.print(prefix); pw.print(" "); |
| 70 | pw.print(REPEAT_CALLERS.mCalls.keyAt(i)); |
| 71 | pw.print(" at "); |
| 72 | pw.println(ts(REPEAT_CALLERS.mCalls.valueAt(i))); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | private static String ts(long time) { |
| 79 | return new Date(time) + " (" + time + ")"; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /** |
| 83 | * @param extras extras of the notification with EXTRA_PEOPLE populated |
| 84 | * @param contactsTimeoutMs timeout in milliseconds to wait for contacts response |
| 85 | * @param timeoutAffinity affinity to return when the timeout specified via |
| 86 | * <code>contactsTimeoutMs</code> is hit |
| 87 | */ |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 88 | public static boolean matchesCallFilter(Context context, int zen, NotificationManager.Policy |
| 89 | consolidatedPolicy, UserHandle userHandle, Bundle extras, |
| 90 | ValidateNotificationPeople validator, int contactsTimeoutMs, float timeoutAffinity) { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 91 | if (zen == Global.ZEN_MODE_NO_INTERRUPTIONS) return false; // nothing gets through |
| 92 | if (zen == Global.ZEN_MODE_ALARMS) return false; // not an alarm |
| 93 | if (zen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) { |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 94 | if (consolidatedPolicy.allowRepeatCallers() |
| 95 | && REPEAT_CALLERS.isRepeat(context, extras)) { |
Julia Reynolds | c6b371b | 2016-06-14 08:31:03 -0400 | [diff] [blame] | 96 | return true; |
| 97 | } |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 98 | if (!consolidatedPolicy.allowCalls()) return false; // no other calls get through |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 99 | if (validator != null) { |
| 100 | final float contactAffinity = validator.getContactAffinity(userHandle, extras, |
| 101 | contactsTimeoutMs, timeoutAffinity); |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 102 | return audienceMatches(consolidatedPolicy.allowCallsFrom(), contactAffinity); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | return true; |
| 106 | } |
| 107 | |
John Spurlock | 1d7d224 | 2015-04-10 08:10:22 -0400 | [diff] [blame] | 108 | private static Bundle extras(NotificationRecord record) { |
| 109 | return record != null && record.sbn != null && record.sbn.getNotification() != null |
| 110 | ? record.sbn.getNotification().extras : null; |
| 111 | } |
| 112 | |
Julia Reynolds | c6b371b | 2016-06-14 08:31:03 -0400 | [diff] [blame] | 113 | protected void recordCall(NotificationRecord record) { |
| 114 | REPEAT_CALLERS.recordCall(mContext, extras(record)); |
| 115 | } |
| 116 | |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 117 | /** |
| 118 | * Whether to intercept the notification based on the policy |
| 119 | */ |
| 120 | public boolean shouldIntercept(int zen, NotificationManager.Policy policy, |
| 121 | NotificationRecord record) { |
Brad Stenning | 1e14f9f | 2018-08-10 14:39:26 -0700 | [diff] [blame] | 122 | // Zen mode is ignored for critical notifications. |
| 123 | if (zen == ZEN_MODE_OFF || isCritical(record)) { |
Julia Reynolds | ccc6ae6 | 2018-03-01 16:24:49 -0500 | [diff] [blame] | 124 | return false; |
| 125 | } |
| 126 | // Make an exception to policy for the notification saying that policy has changed |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 127 | if (NotificationManager.Policy.areAllVisualEffectsSuppressed(policy.suppressedVisualEffects) |
Julia Reynolds | ccc6ae6 | 2018-03-01 16:24:49 -0500 | [diff] [blame] | 128 | && "android".equals(record.sbn.getPackageName()) |
| 129 | && SystemMessageProto.SystemMessage.NOTE_ZEN_UPGRADE == record.sbn.getId()) { |
| 130 | ZenLog.traceNotIntercepted(record, "systemDndChangedNotification"); |
| 131 | return false; |
| 132 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 133 | switch (zen) { |
| 134 | case Global.ZEN_MODE_NO_INTERRUPTIONS: |
| 135 | // #notevenalarms |
| 136 | ZenLog.traceIntercepted(record, "none"); |
| 137 | return true; |
| 138 | case Global.ZEN_MODE_ALARMS: |
| 139 | if (isAlarm(record)) { |
| 140 | // Alarms only |
| 141 | return false; |
| 142 | } |
| 143 | ZenLog.traceIntercepted(record, "alarmsOnly"); |
| 144 | return true; |
| 145 | case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS: |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 146 | // allow user-prioritized packages through in priority mode |
| 147 | if (record.getPackagePriority() == Notification.PRIORITY_MAX) { |
| 148 | ZenLog.traceNotIntercepted(record, "priorityApp"); |
| 149 | return false; |
| 150 | } |
Beverly | 0421687 | 2017-09-28 10:55:32 -0400 | [diff] [blame] | 151 | |
| 152 | if (isAlarm(record)) { |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 153 | if (!policy.allowAlarms()) { |
Beverly | 0421687 | 2017-09-28 10:55:32 -0400 | [diff] [blame] | 154 | ZenLog.traceIntercepted(record, "!allowAlarms"); |
| 155 | return true; |
| 156 | } |
| 157 | return false; |
| 158 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 159 | if (isCall(record)) { |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 160 | if (policy.allowRepeatCallers() |
John Spurlock | 1d7d224 | 2015-04-10 08:10:22 -0400 | [diff] [blame] | 161 | && REPEAT_CALLERS.isRepeat(mContext, extras(record))) { |
| 162 | ZenLog.traceNotIntercepted(record, "repeatCaller"); |
| 163 | return false; |
| 164 | } |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 165 | if (!policy.allowCalls()) { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 166 | ZenLog.traceIntercepted(record, "!allowCalls"); |
| 167 | return true; |
| 168 | } |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 169 | return shouldInterceptAudience(policy.allowCallsFrom(), record); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 170 | } |
| 171 | if (isMessage(record)) { |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 172 | if (!policy.allowMessages()) { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 173 | ZenLog.traceIntercepted(record, "!allowMessages"); |
| 174 | return true; |
| 175 | } |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 176 | return shouldInterceptAudience(policy.allowMessagesFrom(), record); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 177 | } |
| 178 | if (isEvent(record)) { |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 179 | if (!policy.allowEvents()) { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 180 | ZenLog.traceIntercepted(record, "!allowEvents"); |
| 181 | return true; |
| 182 | } |
| 183 | return false; |
| 184 | } |
| 185 | if (isReminder(record)) { |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 186 | if (!policy.allowReminders()) { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 187 | ZenLog.traceIntercepted(record, "!allowReminders"); |
| 188 | return true; |
| 189 | } |
| 190 | return false; |
| 191 | } |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 192 | if (isMedia(record)) { |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 193 | if (!policy.allowMedia()) { |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 194 | ZenLog.traceIntercepted(record, "!allowMedia"); |
| 195 | return true; |
| 196 | } |
| 197 | return false; |
| 198 | } |
| 199 | if (isSystem(record)) { |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 200 | if (!policy.allowSystem()) { |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 201 | ZenLog.traceIntercepted(record, "!allowSystem"); |
Beverly | 0421687 | 2017-09-28 10:55:32 -0400 | [diff] [blame] | 202 | return true; |
| 203 | } |
| 204 | return false; |
| 205 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 206 | ZenLog.traceIntercepted(record, "!priority"); |
| 207 | return true; |
| 208 | default: |
| 209 | return false; |
| 210 | } |
| 211 | } |
| 212 | |
Brad Stenning | 1e14f9f | 2018-08-10 14:39:26 -0700 | [diff] [blame] | 213 | /** |
| 214 | * Check if the notification is too critical to be suppressed. |
| 215 | * |
| 216 | * @param record the record to test for criticality |
| 217 | * @return {@code true} if notification is considered critical |
| 218 | * |
| 219 | * @see CriticalNotificationExtractor for criteria |
| 220 | */ |
| 221 | private boolean isCritical(NotificationRecord record) { |
| 222 | // 0 is the most critical |
| 223 | return record.getCriticality() < CriticalNotificationExtractor.NORMAL; |
| 224 | } |
| 225 | |
John Spurlock | a492d1d | 2015-05-05 18:30:28 -0400 | [diff] [blame] | 226 | private static boolean shouldInterceptAudience(int source, NotificationRecord record) { |
| 227 | if (!audienceMatches(source, record.getContactAffinity())) { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 228 | ZenLog.traceIntercepted(record, "!audienceMatches"); |
| 229 | return true; |
| 230 | } |
| 231 | return false; |
| 232 | } |
| 233 | |
Julia Reynolds | 51eb78f8 | 2018-03-07 07:35:21 -0500 | [diff] [blame] | 234 | protected static boolean isAlarm(NotificationRecord record) { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 235 | return record.isCategory(Notification.CATEGORY_ALARM) |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 236 | || record.isAudioAttributesUsage(AudioAttributes.USAGE_ALARM); |
| 237 | } |
| 238 | |
| 239 | private static boolean isEvent(NotificationRecord record) { |
| 240 | return record.isCategory(Notification.CATEGORY_EVENT); |
| 241 | } |
| 242 | |
| 243 | private static boolean isReminder(NotificationRecord record) { |
| 244 | return record.isCategory(Notification.CATEGORY_REMINDER); |
| 245 | } |
| 246 | |
| 247 | public boolean isCall(NotificationRecord record) { |
| 248 | return record != null && (isDefaultPhoneApp(record.sbn.getPackageName()) |
| 249 | || record.isCategory(Notification.CATEGORY_CALL)); |
| 250 | } |
| 251 | |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 252 | public boolean isMedia(NotificationRecord record) { |
| 253 | AudioAttributes aa = record.getAudioAttributes(); |
| 254 | return aa != null && AudioAttributes.SUPPRESSIBLE_USAGES.get(aa.getUsage()) == |
| 255 | AudioAttributes.SUPPRESSIBLE_MEDIA; |
| 256 | } |
| 257 | |
| 258 | public boolean isSystem(NotificationRecord record) { |
| 259 | AudioAttributes aa = record.getAudioAttributes(); |
| 260 | return aa != null && AudioAttributes.SUPPRESSIBLE_USAGES.get(aa.getUsage()) == |
| 261 | AudioAttributes.SUPPRESSIBLE_SYSTEM; |
| 262 | } |
| 263 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 264 | private boolean isDefaultPhoneApp(String pkg) { |
| 265 | if (mDefaultPhoneApp == null) { |
| 266 | final TelecomManager telecomm = |
| 267 | (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
| 268 | mDefaultPhoneApp = telecomm != null ? telecomm.getDefaultPhoneApp() : null; |
| 269 | if (DEBUG) Slog.d(TAG, "Default phone app: " + mDefaultPhoneApp); |
| 270 | } |
| 271 | return pkg != null && mDefaultPhoneApp != null |
| 272 | && pkg.equals(mDefaultPhoneApp.getPackageName()); |
| 273 | } |
| 274 | |
Julia Reynolds | 51eb78f8 | 2018-03-07 07:35:21 -0500 | [diff] [blame] | 275 | protected boolean isMessage(NotificationRecord record) { |
| 276 | return mMessagingUtil.isMessaging(record.sbn); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 277 | } |
| 278 | |
John Spurlock | a492d1d | 2015-05-05 18:30:28 -0400 | [diff] [blame] | 279 | private static boolean audienceMatches(int source, float contactAffinity) { |
| 280 | switch (source) { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 281 | case ZenModeConfig.SOURCE_ANYONE: |
| 282 | return true; |
| 283 | case ZenModeConfig.SOURCE_CONTACT: |
| 284 | return contactAffinity >= ValidateNotificationPeople.VALID_CONTACT; |
| 285 | case ZenModeConfig.SOURCE_STAR: |
| 286 | return contactAffinity >= ValidateNotificationPeople.STARRED_CONTACT; |
| 287 | default: |
John Spurlock | a492d1d | 2015-05-05 18:30:28 -0400 | [diff] [blame] | 288 | Slog.w(TAG, "Encountered unknown source: " + source); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 289 | return true; |
| 290 | } |
| 291 | } |
John Spurlock | 1d7d224 | 2015-04-10 08:10:22 -0400 | [diff] [blame] | 292 | |
| 293 | private static class RepeatCallers { |
Julia Reynolds | c6b371b | 2016-06-14 08:31:03 -0400 | [diff] [blame] | 294 | // Person : time |
John Spurlock | 1d7d224 | 2015-04-10 08:10:22 -0400 | [diff] [blame] | 295 | private final ArrayMap<String, Long> mCalls = new ArrayMap<>(); |
| 296 | private int mThresholdMinutes; |
| 297 | |
Julia Reynolds | c6b371b | 2016-06-14 08:31:03 -0400 | [diff] [blame] | 298 | private synchronized void recordCall(Context context, Bundle extras) { |
| 299 | setThresholdMinutes(context); |
| 300 | if (mThresholdMinutes <= 0 || extras == null) return; |
| 301 | final String peopleString = peopleString(extras); |
| 302 | if (peopleString == null) return; |
| 303 | final long now = System.currentTimeMillis(); |
| 304 | cleanUp(mCalls, now); |
| 305 | mCalls.put(peopleString, now); |
| 306 | } |
| 307 | |
John Spurlock | 1d7d224 | 2015-04-10 08:10:22 -0400 | [diff] [blame] | 308 | private synchronized boolean isRepeat(Context context, Bundle extras) { |
Julia Reynolds | c6b371b | 2016-06-14 08:31:03 -0400 | [diff] [blame] | 309 | setThresholdMinutes(context); |
John Spurlock | 1d7d224 | 2015-04-10 08:10:22 -0400 | [diff] [blame] | 310 | if (mThresholdMinutes <= 0 || extras == null) return false; |
| 311 | final String peopleString = peopleString(extras); |
| 312 | if (peopleString == null) return false; |
| 313 | final long now = System.currentTimeMillis(); |
Julia Reynolds | c6b371b | 2016-06-14 08:31:03 -0400 | [diff] [blame] | 314 | cleanUp(mCalls, now); |
| 315 | return mCalls.containsKey(peopleString); |
| 316 | } |
| 317 | |
| 318 | private synchronized void cleanUp(ArrayMap<String, Long> calls, long now) { |
| 319 | final int N = calls.size(); |
John Spurlock | 1d7d224 | 2015-04-10 08:10:22 -0400 | [diff] [blame] | 320 | for (int i = N - 1; i >= 0; i--) { |
| 321 | final long time = mCalls.valueAt(i); |
| 322 | if (time > now || (now - time) > mThresholdMinutes * 1000 * 60) { |
Julia Reynolds | c6b371b | 2016-06-14 08:31:03 -0400 | [diff] [blame] | 323 | calls.removeAt(i); |
John Spurlock | 1d7d224 | 2015-04-10 08:10:22 -0400 | [diff] [blame] | 324 | } |
| 325 | } |
Julia Reynolds | c6b371b | 2016-06-14 08:31:03 -0400 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | private void setThresholdMinutes(Context context) { |
| 329 | if (mThresholdMinutes <= 0) { |
| 330 | mThresholdMinutes = context.getResources().getInteger(com.android.internal.R.integer |
| 331 | .config_zen_repeat_callers_threshold); |
| 332 | } |
John Spurlock | 1d7d224 | 2015-04-10 08:10:22 -0400 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | private static String peopleString(Bundle extras) { |
| 336 | final String[] extraPeople = ValidateNotificationPeople.getExtraPeople(extras); |
| 337 | if (extraPeople == null || extraPeople.length == 0) return null; |
| 338 | final StringBuilder sb = new StringBuilder(); |
| 339 | for (int i = 0; i < extraPeople.length; i++) { |
| 340 | String extraPerson = extraPeople[i]; |
| 341 | if (extraPerson == null) continue; |
| 342 | extraPerson = extraPerson.trim(); |
| 343 | if (extraPerson.isEmpty()) continue; |
| 344 | if (sb.length() > 0) { |
| 345 | sb.append('|'); |
| 346 | } |
| 347 | sb.append(extraPerson); |
| 348 | } |
| 349 | return sb.length() == 0 ? null : sb.toString(); |
| 350 | } |
| 351 | } |
| 352 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 353 | } |