blob: fa18e7601d091554a8033fccad3b5a721bd1007b [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package com.android.server;
18
Jeff Sharkey098d5802012-04-26 17:30:34 -070019import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
20import static org.xmlpull.v1.XmlPullParser.END_TAG;
21import static org.xmlpull.v1.XmlPullParser.START_TAG;
svetoslavganov75986cf2009-05-14 22:28:01 -070022
Dianne Hackborn41203752012-08-31 14:05:51 -070023import android.app.ActivityManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.app.ActivityManagerNative;
Amith Yamasanif203aee2012-08-29 18:41:53 -070025import android.app.AppGlobals;
Daniel Sandler4a900acd2013-01-30 14:04:10 -050026import android.app.AppOpsManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.app.IActivityManager;
28import android.app.INotificationManager;
29import android.app.ITransientNotification;
30import android.app.Notification;
31import android.app.PendingIntent;
32import android.app.StatusBarManager;
33import android.content.BroadcastReceiver;
Daniel Sandler5feceeb2013-03-22 18:29:23 -070034import android.content.ComponentName;
Dianne Hackborn1dac2772009-06-26 18:16:48 -070035import android.content.ContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.content.Context;
37import android.content.Intent;
38import android.content.IntentFilter;
Daniel Sandler5feceeb2013-03-22 18:29:23 -070039import android.content.ServiceConnection;
Dianne Hackbornd8a43f62009-08-17 23:33:56 -070040import android.content.pm.ApplicationInfo;
Daniel Sandler4a900acd2013-01-30 14:04:10 -050041import android.content.pm.PackageInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import android.content.pm.PackageManager;
43import android.content.pm.PackageManager.NameNotFoundException;
44import android.content.res.Resources;
Dianne Hackborn1dac2772009-06-26 18:16:48 -070045import android.database.ContentObserver;
Daniel Sandlerf45564e2013-04-15 15:05:08 -040046import android.graphics.Bitmap;
svetoslavganov75986cf2009-05-14 22:28:01 -070047import android.media.AudioManager;
Jeff Sharkey098d5802012-04-26 17:30:34 -070048import android.media.IAudioService;
49import android.media.IRingtonePlayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050import android.net.Uri;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import android.os.Binder;
Daniel Sandler5e62e3a2013-04-15 20:57:02 -040052import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import android.os.IBinder;
55import android.os.Message;
Dianne Hackbornd8a43f62009-08-17 23:33:56 -070056import android.os.Process;
svetoslavganov75986cf2009-05-14 22:28:01 -070057import android.os.RemoteException;
Jeff Sharkey098d5802012-04-26 17:30:34 -070058import android.os.ServiceManager;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070059import android.os.UserHandle;
Daniel Sandler4b749ef2013-03-18 21:53:04 -040060import android.os.UserManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.os.Vibrator;
62import android.provider.Settings;
Daniel Sandler5feceeb2013-03-22 18:29:23 -070063import android.service.notification.INotificationListener;
64import android.service.notification.NotificationListenerService;
65import android.service.notification.StatusBarNotification;
Daniel Sandlere96ffb12010-03-11 13:38:06 -050066import android.telephony.TelephonyManager;
svetoslavganov75986cf2009-05-14 22:28:01 -070067import android.text.TextUtils;
Dianne Hackborn39606a02012-07-31 17:54:35 -070068import android.util.AtomicFile;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069import android.util.EventLog;
70import android.util.Log;
Andy Stadler110988c2010-12-03 14:29:16 -080071import android.util.Slog;
Daniel Sandler0da673f2012-04-11 12:33:16 -040072import android.util.Xml;
svetoslavganov75986cf2009-05-14 22:28:01 -070073import android.view.accessibility.AccessibilityEvent;
74import android.view.accessibility.AccessibilityManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075import android.widget.Toast;
76
Jeff Sharkey098d5802012-04-26 17:30:34 -070077import org.xmlpull.v1.XmlPullParser;
78import org.xmlpull.v1.XmlPullParserException;
Jeff Sharkey098d5802012-04-26 17:30:34 -070079
Daniel Sandler0da673f2012-04-11 12:33:16 -040080import java.io.File;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081import java.io.FileDescriptor;
Daniel Sandler0da673f2012-04-11 12:33:16 -040082import java.io.FileInputStream;
83import java.io.FileNotFoundException;
Daniel Sandler0da673f2012-04-11 12:33:16 -040084import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085import java.io.PrintWriter;
Daniel Sandlerf45564e2013-04-15 15:05:08 -040086import java.lang.reflect.Array;
Daniel Sandlerfde19b12013-01-17 00:21:05 -050087import java.util.ArrayDeque;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088import java.util.ArrayList;
89import java.util.Arrays;
Daniel Sandler0da673f2012-04-11 12:33:16 -040090import java.util.HashSet;
Daniel Sandlerfde19b12013-01-17 00:21:05 -050091import java.util.Iterator;
92import java.util.NoSuchElementException;
Daniel Sandler0da673f2012-04-11 12:33:16 -040093
94import libcore.io.IoUtils;
95
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096
Daniel Sandlerd0a2f862010-08-03 15:29:31 -040097/** {@hide} */
98public class NotificationManagerService extends INotificationManager.Stub
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099{
100 private static final String TAG = "NotificationService";
101 private static final boolean DBG = false;
102
Joe Onoratobd73d012010-06-04 11:44:54 -0700103 private static final int MAX_PACKAGE_NOTIFICATIONS = 50;
104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 // message codes
106 private static final int MESSAGE_TIMEOUT = 2;
107
108 private static final int LONG_DELAY = 3500; // 3.5 seconds
109 private static final int SHORT_DELAY = 2000; // 2 seconds
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800110
111 private static final long[] DEFAULT_VIBRATE_PATTERN = {0, 250, 250, 250};
Daniel Sandleredbb3802012-11-13 20:49:47 -0800112 private static final int VIBRATE_PATTERN_MAXLEN = 8 * 2 + 1; // up to eight bumps
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113
114 private static final int DEFAULT_STREAM_TYPE = AudioManager.STREAM_NOTIFICATION;
Daniel Sandler49a2ad12012-03-28 15:46:39 -0400115 private static final boolean SCORE_ONGOING_HIGHER = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116
Daniel Sandler0da673f2012-04-11 12:33:16 -0400117 private static final int JUNK_SCORE = -1000;
118 private static final int NOTIFICATION_PRIORITY_MULTIPLIER = 10;
119 private static final int SCORE_DISPLAY_THRESHOLD = Notification.PRIORITY_MIN * NOTIFICATION_PRIORITY_MULTIPLIER;
120
Daniel Sandler526fa0e2012-12-04 14:51:50 -0500121 // Notifications with scores below this will not interrupt the user, either via LED or
122 // sound or vibration
123 private static final int SCORE_INTERRUPTION_THRESHOLD =
124 Notification.PRIORITY_LOW * NOTIFICATION_PRIORITY_MULTIPLIER;
125
Daniel Sandler0da673f2012-04-11 12:33:16 -0400126 private static final boolean ENABLE_BLOCKED_NOTIFICATIONS = true;
127 private static final boolean ENABLE_BLOCKED_TOASTS = true;
128
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700129 private static final String ENABLED_NOTIFICATION_LISTENERS_SEPARATOR = ":";
130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 final Context mContext;
132 final IActivityManager mAm;
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400133 final UserManager mUserManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 final IBinder mForegroundToken = new Binder();
135
136 private WorkerHandler mHandler;
Joe Onorato089de882010-04-12 08:18:45 -0700137 private StatusBarManagerService mStatusBar;
Mike Lockwood3cb67a32009-11-27 14:25:58 -0500138 private LightsService.Light mNotificationLight;
139 private LightsService.Light mAttentionLight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140
Mike Lockwood670f9322010-01-20 12:13:36 -0500141 private int mDefaultNotificationColor;
142 private int mDefaultNotificationLedOn;
143 private int mDefaultNotificationLedOff;
144
Daniel Sandleredbb3802012-11-13 20:49:47 -0800145 private long[] mDefaultVibrationPattern;
146 private long[] mFallbackVibrationPattern;
147
Joe Onorato30275482009-07-08 17:09:14 -0700148 private boolean mSystemReady;
Joe Onorato39f5b6a2009-07-23 12:29:19 -0400149 private int mDisabledNotifications;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150
Jeff Sharkey098d5802012-04-26 17:30:34 -0700151 private NotificationRecord mSoundNotification;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 private NotificationRecord mVibrateNotification;
Jeff Sharkey098d5802012-04-26 17:30:34 -0700153
154 private IAudioService mAudioService;
Jeff Brownc2346132012-04-13 01:55:38 -0700155 private Vibrator mVibrator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156
Mike Lockwoodc22404a2009-12-02 11:15:02 -0500157 // for enabling and disabling notification pulse behavior
Mike Lockwood63b5ad92011-08-30 09:55:30 -0400158 private boolean mScreenOn = true;
Daniel Sandlere96ffb12010-03-11 13:38:06 -0500159 private boolean mInCall = false;
Mike Lockwoodc22404a2009-12-02 11:15:02 -0500160 private boolean mNotificationPulseEnabled;
161
Daniel Sandler09a247e2013-02-14 10:24:17 -0500162 // used as a mutex for access to all active notifications & listeners
Fred Quintana6ecaff12009-09-25 14:23:13 -0700163 private final ArrayList<NotificationRecord> mNotificationList =
164 new ArrayList<NotificationRecord>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165
166 private ArrayList<ToastRecord> mToastQueue;
167
168 private ArrayList<NotificationRecord> mLights = new ArrayList<NotificationRecord>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 private NotificationRecord mLedNotification;
svetoslavganov75986cf2009-05-14 22:28:01 -0700170
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500171 private final AppOpsManager mAppOps;
172
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700173 // contains connections to all connected listeners, including app services
174 // and system listeners
175 private ArrayList<NotificationListenerInfo> mListeners
176 = new ArrayList<NotificationListenerInfo>();
177 // things that will be put into mListeners as soon as they're ready
178 private ArrayList<String> mServicesBinding = new ArrayList<String>();
179 // lists the component names of all enabled (and therefore connected) listener
180 // app services for the current user only
181 private HashSet<ComponentName> mEnabledListenersForCurrentUser
182 = new HashSet<ComponentName>();
183 // Just the packages from mEnabledListenersForCurrentUser
184 private HashSet<String> mEnabledListenerPackageNames = new HashSet<String>();
Daniel Sandler09a247e2013-02-14 10:24:17 -0500185
Daniel Sandler0da673f2012-04-11 12:33:16 -0400186 // Notification control database. For now just contains disabled packages.
187 private AtomicFile mPolicyFile;
188 private HashSet<String> mBlockedPackages = new HashSet<String>();
189
190 private static final int DB_VERSION = 1;
191
192 private static final String TAG_BODY = "notification-policy";
193 private static final String ATTR_VERSION = "version";
194
195 private static final String TAG_BLOCKED_PKGS = "blocked-packages";
196 private static final String TAG_PACKAGE = "package";
197 private static final String ATTR_NAME = "name";
198
Daniel Sandler09a247e2013-02-14 10:24:17 -0500199 private class NotificationListenerInfo implements DeathRecipient {
200 INotificationListener listener;
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700201 ComponentName component;
Daniel Sandler09a247e2013-02-14 10:24:17 -0500202 int userid;
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400203 boolean isSystem;
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700204 ServiceConnection connection;
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400205
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700206 public NotificationListenerInfo(INotificationListener listener, ComponentName component,
207 int userid, boolean isSystem) {
Daniel Sandler09a247e2013-02-14 10:24:17 -0500208 this.listener = listener;
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700209 this.component = component;
Daniel Sandler09a247e2013-02-14 10:24:17 -0500210 this.userid = userid;
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400211 this.isSystem = isSystem;
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700212 this.connection = null;
213 }
214
215 public NotificationListenerInfo(INotificationListener listener, ComponentName component,
216 int userid, ServiceConnection connection) {
217 this.listener = listener;
218 this.component = component;
219 this.userid = userid;
220 this.isSystem = false;
221 this.connection = connection;
Daniel Sandler09a247e2013-02-14 10:24:17 -0500222 }
223
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400224 boolean enabledAndUserMatches(StatusBarNotification sbn) {
225 final int nid = sbn.getUserId();
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700226 if (!isEnabledForCurrentUser()) {
227 return false;
228 }
Daniel Sandler21ca44d2013-03-07 13:58:00 -0500229 if (this.userid == UserHandle.USER_ALL) return true;
Daniel Sandler21ca44d2013-03-07 13:58:00 -0500230 return (nid == UserHandle.USER_ALL || nid == this.userid);
231 }
232
Daniel Sandler09a247e2013-02-14 10:24:17 -0500233 public void notifyPostedIfUserMatch(StatusBarNotification sbn) {
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700234 if (!enabledAndUserMatches(sbn)) {
235 return;
236 }
Daniel Sandler09a247e2013-02-14 10:24:17 -0500237 try {
238 listener.onNotificationPosted(sbn);
239 } catch (RemoteException ex) {
240 // not there?
241 }
242 }
243
244 public void notifyRemovedIfUserMatch(StatusBarNotification sbn) {
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400245 if (!enabledAndUserMatches(sbn)) return;
Daniel Sandler09a247e2013-02-14 10:24:17 -0500246 try {
247 listener.onNotificationRemoved(sbn);
248 } catch (RemoteException ex) {
249 // not there?
250 }
251 }
252
253 @Override
254 public void binderDied() {
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700255 if (connection == null) {
256 // This is not a service; it won't be recreated. We can give up this connection.
257 unregisterListener(this.listener, this.userid);
258 }
Daniel Sandler09a247e2013-02-14 10:24:17 -0500259 }
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400260
261 /** convenience method for looking in mEnabledListenersForCurrentUser */
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700262 public boolean isEnabledForCurrentUser() {
263 if (this.isSystem) return true;
264 if (this.connection == null) return false;
265 return mEnabledListenersForCurrentUser.contains(this.component);
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400266 }
Daniel Sandler09a247e2013-02-14 10:24:17 -0500267 }
268
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500269 private static class Archive {
Daniel Sandler5e62e3a2013-04-15 20:57:02 -0400270 static final int BUFFER_SIZE = 250;
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500271 ArrayDeque<StatusBarNotification> mBuffer = new ArrayDeque<StatusBarNotification>(BUFFER_SIZE);
272
273 public Archive() {
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500274 }
Jeff Sharkey0c1baf92013-04-03 13:08:52 -0700275
Daniel Sandler5e62e3a2013-04-15 20:57:02 -0400276 public String toString() {
277 final StringBuilder sb = new StringBuilder();
278 final int N = mBuffer.size();
279 sb.append("Archive (");
280 sb.append(N);
281 sb.append(" notification");
282 sb.append((N==1)?")":"s)");
283 return sb.toString();
284 }
285
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500286 public void record(StatusBarNotification nr) {
Jeff Sharkey0c1baf92013-04-03 13:08:52 -0700287 // Nuke heavy parts of notification before storing in archive
288 nr.notification.tickerView = null;
289 nr.notification.contentView = null;
290 nr.notification.bigContentView = null;
291 nr.notification.largeIcon = null;
Daniel Sandler5e62e3a2013-04-15 20:57:02 -0400292 final Bundle extras = nr.notification.extras;
293 extras.remove(Notification.EXTRA_LARGE_ICON);
294 extras.remove(Notification.EXTRA_LARGE_ICON_BIG);
295 extras.remove(Notification.EXTRA_PICTURE);
Jeff Sharkey0c1baf92013-04-03 13:08:52 -0700296
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500297 if (mBuffer.size() == BUFFER_SIZE) {
298 mBuffer.removeFirst();
299 }
300 mBuffer.addLast(nr);
301 }
302
Daniel Sandler5e62e3a2013-04-15 20:57:02 -0400303
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500304 public void clear() {
305 mBuffer.clear();
306 }
307
308 public Iterator<StatusBarNotification> descendingIterator() {
309 return mBuffer.descendingIterator();
310 }
311 public Iterator<StatusBarNotification> ascendingIterator() {
312 return mBuffer.iterator();
313 }
314 public Iterator<StatusBarNotification> filter(
315 final Iterator<StatusBarNotification> iter, final String pkg, final int userId) {
316 return new Iterator<StatusBarNotification>() {
317 StatusBarNotification mNext = findNext();
318
319 private StatusBarNotification findNext() {
320 while (iter.hasNext()) {
321 StatusBarNotification nr = iter.next();
322 if ((pkg == null || nr.pkg == pkg)
323 && (userId == UserHandle.USER_ALL || nr.getUserId() == userId)) {
324 return nr;
325 }
326 }
327 return null;
328 }
329
330 @Override
331 public boolean hasNext() {
332 return mNext == null;
333 }
334
335 @Override
336 public StatusBarNotification next() {
337 StatusBarNotification next = mNext;
338 if (next == null) {
339 throw new NoSuchElementException();
340 }
341 mNext = findNext();
342 return next;
343 }
344
345 @Override
346 public void remove() {
347 iter.remove();
348 }
349 };
350 }
Daniel Sandler78d0d252013-02-12 08:14:52 -0500351
352 public StatusBarNotification[] getArray(int count) {
353 if (count == 0) count = Archive.BUFFER_SIZE;
354 final StatusBarNotification[] a
355 = new StatusBarNotification[Math.min(count, mBuffer.size())];
356 Iterator<StatusBarNotification> iter = descendingIterator();
357 int i=0;
358 while (iter.hasNext() && i < count) {
359 a[i++] = iter.next();
360 }
361 return a;
362 }
363
364 public StatusBarNotification[] getArray(int count, String pkg, int userId) {
365 if (count == 0) count = Archive.BUFFER_SIZE;
366 final StatusBarNotification[] a
367 = new StatusBarNotification[Math.min(count, mBuffer.size())];
368 Iterator<StatusBarNotification> iter = filter(descendingIterator(), pkg, userId);
369 int i=0;
370 while (iter.hasNext() && i < count) {
371 a[i++] = iter.next();
372 }
373 return a;
374 }
375
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500376 }
377
378 Archive mArchive = new Archive();
379
Daniel Sandler0da673f2012-04-11 12:33:16 -0400380 private void loadBlockDb() {
381 synchronized(mBlockedPackages) {
382 if (mPolicyFile == null) {
383 File dir = new File("/data/system");
384 mPolicyFile = new AtomicFile(new File(dir, "notification_policy.xml"));
385
386 mBlockedPackages.clear();
387
388 FileInputStream infile = null;
389 try {
390 infile = mPolicyFile.openRead();
391 final XmlPullParser parser = Xml.newPullParser();
392 parser.setInput(infile, null);
393
394 int type;
395 String tag;
396 int version = DB_VERSION;
397 while ((type = parser.next()) != END_DOCUMENT) {
398 tag = parser.getName();
399 if (type == START_TAG) {
400 if (TAG_BODY.equals(tag)) {
401 version = Integer.parseInt(parser.getAttributeValue(null, ATTR_VERSION));
402 } else if (TAG_BLOCKED_PKGS.equals(tag)) {
403 while ((type = parser.next()) != END_DOCUMENT) {
404 tag = parser.getName();
405 if (TAG_PACKAGE.equals(tag)) {
406 mBlockedPackages.add(parser.getAttributeValue(null, ATTR_NAME));
407 } else if (TAG_BLOCKED_PKGS.equals(tag) && type == END_TAG) {
408 break;
409 }
410 }
411 }
412 }
413 }
414 } catch (FileNotFoundException e) {
415 // No data yet
416 } catch (IOException e) {
417 Log.wtf(TAG, "Unable to read blocked notifications database", e);
418 } catch (NumberFormatException e) {
419 Log.wtf(TAG, "Unable to parse blocked notifications database", e);
420 } catch (XmlPullParserException e) {
421 Log.wtf(TAG, "Unable to parse blocked notifications database", e);
422 } finally {
423 IoUtils.closeQuietly(infile);
424 }
425 }
426 }
427 }
428
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500429 /**
430 * Use this when you just want to know if notifications are OK for this package.
431 */
432 public boolean areNotificationsEnabledForPackage(String pkg, int uid) {
Daniel Sandler0da673f2012-04-11 12:33:16 -0400433 checkCallerIsSystem();
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500434 return (mAppOps.checkOpNoThrow(AppOpsManager.OP_POST_NOTIFICATION, uid, pkg)
435 == AppOpsManager.MODE_ALLOWED);
Daniel Sandler0da673f2012-04-11 12:33:16 -0400436 }
437
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500438 /** Use this when you actually want to post a notification or toast.
439 *
440 * Unchecked. Not exposed via Binder, but can be called in the course of enqueue*().
441 */
442 private boolean noteNotificationOp(String pkg, int uid) {
443 if (mAppOps.noteOpNoThrow(AppOpsManager.OP_POST_NOTIFICATION, uid, pkg)
444 != AppOpsManager.MODE_ALLOWED) {
445 Slog.v(TAG, "notifications are disabled by AppOps for " + pkg);
446 return false;
Daniel Sandler0da673f2012-04-11 12:33:16 -0400447 }
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500448 return true;
Daniel Sandler0da673f2012-04-11 12:33:16 -0400449 }
450
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500451 public void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled) {
Daniel Sandler0da673f2012-04-11 12:33:16 -0400452 checkCallerIsSystem();
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500453 if (true||DBG) {
Daniel Sandler0da673f2012-04-11 12:33:16 -0400454 Slog.v(TAG, (enabled?"en":"dis") + "abling notifications for " + pkg);
455 }
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500456 mAppOps.setMode(AppOpsManager.OP_POST_NOTIFICATION, uid, pkg,
457 enabled ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_IGNORED);
Daniel Sandler0da673f2012-04-11 12:33:16 -0400458 }
459
460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800461 private static String idDebugString(Context baseContext, String packageName, int id) {
462 Context c = null;
463
464 if (packageName != null) {
465 try {
466 c = baseContext.createPackageContext(packageName, 0);
467 } catch (NameNotFoundException e) {
468 c = baseContext;
469 }
470 } else {
471 c = baseContext;
472 }
473
474 String pkg;
475 String type;
476 String name;
477
478 Resources r = c.getResources();
479 try {
480 return r.getResourceName(id);
481 } catch (Resources.NotFoundException e) {
482 return "<name unknown>";
483 }
484 }
485
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700486 /**
487 * System-only API for getting a list of current (i.e. not cleared) notifications.
488 *
489 * Requires ACCESS_NOTIFICATIONS which is signature|system.
490 */
491 @Override
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500492 public StatusBarNotification[] getActiveNotifications(String callingPkg) {
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400493 // enforce() will ensure the calling uid has the correct permission
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500494 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NOTIFICATIONS,
Daniel Sandler78d0d252013-02-12 08:14:52 -0500495 "NotificationManagerService.getActiveNotifications");
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500496
497 StatusBarNotification[] tmp = null;
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500498 int uid = Binder.getCallingUid();
499
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400500 // noteOp will check to make sure the callingPkg matches the uid
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500501 if (mAppOps.noteOpNoThrow(AppOpsManager.OP_ACCESS_NOTIFICATIONS, uid, callingPkg)
502 == AppOpsManager.MODE_ALLOWED) {
503 synchronized (mNotificationList) {
504 tmp = new StatusBarNotification[mNotificationList.size()];
505 final int N = mNotificationList.size();
506 for (int i=0; i<N; i++) {
507 tmp[i] = mNotificationList.get(i).sbn;
508 }
509 }
510 }
511 return tmp;
512 }
513
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700514 /**
515 * System-only API for getting a list of recent (cleared, no longer shown) notifications.
516 *
517 * Requires ACCESS_NOTIFICATIONS which is signature|system.
518 */
519 @Override
Daniel Sandler78d0d252013-02-12 08:14:52 -0500520 public StatusBarNotification[] getHistoricalNotifications(String callingPkg, int count) {
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400521 // enforce() will ensure the calling uid has the correct permission
Daniel Sandler78d0d252013-02-12 08:14:52 -0500522 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NOTIFICATIONS,
523 "NotificationManagerService.getHistoricalNotifications");
524
525 StatusBarNotification[] tmp = null;
526 int uid = Binder.getCallingUid();
527
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400528 // noteOp will check to make sure the callingPkg matches the uid
Daniel Sandler78d0d252013-02-12 08:14:52 -0500529 if (mAppOps.noteOpNoThrow(AppOpsManager.OP_ACCESS_NOTIFICATIONS, uid, callingPkg)
530 == AppOpsManager.MODE_ALLOWED) {
531 synchronized (mArchive) {
532 tmp = mArchive.getArray(count);
533 }
534 }
535 return tmp;
536 }
537
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700538 /**
539 * Called whenever packages change, the user switches, or ENABLED_NOTIFICATION_LISTENERS
540 * is altered. (For example in response to USER_SWITCHED in our broadcast receiver)
541 */
542 void rebindListenerServices() {
543 String flat = Settings.Secure.getString(
544 mContext.getContentResolver(),
545 Settings.Secure.ENABLED_NOTIFICATION_LISTENERS);
546
547 NotificationListenerInfo[] toRemove = new NotificationListenerInfo[mListeners.size()];
548 final ArrayList<ComponentName> toAdd;
549 final int currentUser = ActivityManager.getCurrentUser();
550
551 synchronized (mNotificationList) {
552 // unbind and remove all existing listeners
553 toRemove = mListeners.toArray(toRemove);
554
555 toAdd = new ArrayList<ComponentName>();
556 final HashSet<ComponentName> newEnabled = new HashSet<ComponentName>();
557 final HashSet<String> newPackages = new HashSet<String>();
558
559 // decode the list of components
560 if (flat != null) {
561 String[] components = flat.split(ENABLED_NOTIFICATION_LISTENERS_SEPARATOR);
562 for (int i=0; i<components.length; i++) {
563 final ComponentName component
564 = ComponentName.unflattenFromString(components[i]);
565 if (component != null) {
566 newEnabled.add(component);
567 toAdd.add(component);
568 newPackages.add(component.getPackageName());
569 }
570 }
571
572 mEnabledListenersForCurrentUser = newEnabled;
573 mEnabledListenerPackageNames = newPackages;
574 }
575 }
576
577 for (NotificationListenerInfo info : toRemove) {
578 final ComponentName component = info.component;
579 final int oldUser = info.userid;
580 Slog.v(TAG, "disabling notification listener for user " + oldUser + ": " + component);
581 unregisterListenerService(component, info.userid);
582 }
583
584 final int N = toAdd.size();
585 for (int i=0; i<N; i++) {
586 final ComponentName component = toAdd.get(i);
587 Slog.v(TAG, "enabling notification listener for user " + currentUser + ": "
588 + component);
589 registerListenerService(component, currentUser);
590 }
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400591 }
592
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700593 /**
594 * Register a listener binder directly with the notification manager.
595 *
596 * Only works with system callers. Apps should extend
597 * {@link android.service.notification.NotificationListenerService}.
598 */
Daniel Sandler09a247e2013-02-14 10:24:17 -0500599 @Override
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400600 public void registerListener(final INotificationListener listener,
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700601 final ComponentName component, final int userid) {
602 checkCallerIsSystem();
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400603
Daniel Sandler09a247e2013-02-14 10:24:17 -0500604 synchronized (mNotificationList) {
605 try {
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400606 NotificationListenerInfo info
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700607 = new NotificationListenerInfo(listener, component, userid, true);
Daniel Sandler09a247e2013-02-14 10:24:17 -0500608 listener.asBinder().linkToDeath(info, 0);
609 mListeners.add(info);
610 } catch (RemoteException e) {
611 // already dead
612 }
613 }
614 }
615
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700616 /**
617 * Version of registerListener that takes the name of a
618 * {@link android.service.notification.NotificationListenerService} to bind to.
619 *
620 * This is the mechanism by which third parties may subscribe to notifications.
621 */
622 private void registerListenerService(final ComponentName name, final int userid) {
623 checkCallerIsSystem();
624
625 if (DBG) Slog.v(TAG, "registerListenerService: " + name + " u=" + userid);
626
627 synchronized (mNotificationList) {
628 final String servicesBindingTag = name.toString() + "/" + userid;
629 if (mServicesBinding.contains(servicesBindingTag)) {
630 // stop registering this thing already! we're working on it
631 return;
632 }
633 mServicesBinding.add(servicesBindingTag);
634
635 final int N = mListeners.size();
636 for (int i=N-1; i>=0; i--) {
637 final NotificationListenerInfo info = mListeners.get(i);
638 if (name.equals(info.component)
639 && info.userid == userid) {
640 // cut old connections
641 if (DBG) Slog.v(TAG, " disconnecting old listener: " + info.listener);
642 mListeners.remove(i);
643 if (info.connection != null) {
644 mContext.unbindService(info.connection);
645 }
646 }
647 }
648
649 Intent intent = new Intent(NotificationListenerService.SERVICE_INTERFACE);
650 intent.setComponent(name);
651
652 intent.putExtra(Intent.EXTRA_CLIENT_LABEL,
653 com.android.internal.R.string.notification_listener_binding_label);
654 intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity(
655 mContext, 0, new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS), 0));
656
657 try {
658 if (DBG) Slog.v(TAG, "binding: " + intent);
659 if (!mContext.bindServiceAsUser(intent,
660 new ServiceConnection() {
661 INotificationListener mListener;
662 @Override
663 public void onServiceConnected(ComponentName name, IBinder service) {
664 synchronized (mNotificationList) {
665 mServicesBinding.remove(servicesBindingTag);
666 try {
667 mListener = INotificationListener.Stub.asInterface(service);
668 NotificationListenerInfo info = new NotificationListenerInfo(
669 mListener, name, userid, this);
670 service.linkToDeath(info, 0);
671 mListeners.add(info);
672 } catch (RemoteException e) {
673 // already dead
674 }
675 }
676 }
677
678 @Override
679 public void onServiceDisconnected(ComponentName name) {
680 Slog.v(TAG, "notification listener connection lost: " + name);
681 }
682 },
683 Context.BIND_AUTO_CREATE,
684 new UserHandle(userid)))
685 {
686 mServicesBinding.remove(servicesBindingTag);
687 Slog.w(TAG, "Unable to bind listener service: " + intent);
688 return;
689 }
690 } catch (SecurityException ex) {
691 Slog.e(TAG, "Unable to bind listener service: " + intent, ex);
692 return;
693 }
694 }
695 }
696
697 /**
698 * Remove a listener binder directly
699 */
Daniel Sandler09a247e2013-02-14 10:24:17 -0500700 @Override
701 public void unregisterListener(INotificationListener listener, int userid) {
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400702 // no need to check permissions; if your listener binder is in the list,
703 // that's proof that you had permission to add it in the first place
704
Daniel Sandler09a247e2013-02-14 10:24:17 -0500705 synchronized (mNotificationList) {
706 final int N = mListeners.size();
707 for (int i=N-1; i>=0; i--) {
708 final NotificationListenerInfo info = mListeners.get(i);
709 if (info.listener == listener && info.userid == userid) {
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700710 mListeners.remove(i);
711 if (info.connection != null) {
712 mContext.unbindService(info.connection);
713 }
Daniel Sandler09a247e2013-02-14 10:24:17 -0500714 }
715 }
716 }
717 }
718
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700719 /**
720 * Remove a listener service for the given user by ComponentName
721 */
722 private void unregisterListenerService(ComponentName name, int userid) {
723 checkCallerIsSystem();
724
725 synchronized (mNotificationList) {
726 final int N = mListeners.size();
727 for (int i=N-1; i>=0; i--) {
728 final NotificationListenerInfo info = mListeners.get(i);
729 if (name.equals(info.component)
730 && info.userid == userid) {
731 mListeners.remove(i);
732 if (info.connection != null) {
733 mContext.unbindService(info.connection);
734 }
735 }
736 }
737 }
738 }
739
740 /**
741 * asynchronously notify all listeners about a new notification
742 */
Daniel Sandler09a247e2013-02-14 10:24:17 -0500743 private void notifyPostedLocked(NotificationRecord n) {
744 final StatusBarNotification sbn = n.sbn;
745 for (final NotificationListenerInfo info : mListeners) {
746 mHandler.post(new Runnable() {
747 @Override
748 public void run() {
749 info.notifyPostedIfUserMatch(sbn);
750 }});
751 }
752 }
753
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700754 /**
755 * asynchronously notify all listeners about a removed notification
756 */
Daniel Sandler09a247e2013-02-14 10:24:17 -0500757 private void notifyRemovedLocked(NotificationRecord n) {
758 final StatusBarNotification sbn = n.sbn;
759 for (final NotificationListenerInfo info : mListeners) {
760 mHandler.post(new Runnable() {
761 @Override
762 public void run() {
763 info.notifyRemovedIfUserMatch(sbn);
764 }});
765 }
766 }
767
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700768 // -- APIs to support listeners clicking/clearing notifications --
769
770 private NotificationListenerInfo checkListenerToken(INotificationListener listener) {
771 final IBinder token = listener.asBinder();
772 final int N = mListeners.size();
773 for (int i=0; i<N; i++) {
774 final NotificationListenerInfo info = mListeners.get(i);
775 if (info.listener.asBinder() == token) return info;
776 }
777 throw new SecurityException("Disallowed call from unknown listener: " + listener);
778 }
779
780 /**
781 * Allow an INotificationListener to simulate a "clear all" operation.
782 *
783 * {@see com.android.server.StatusBarManagerService.NotificationCallbacks#onClearAllNotifications}
784 *
785 * @param token The binder for the listener, to check that the caller is allowed
786 */
787 public void clearAllNotificationsFromListener(INotificationListener token) {
788 NotificationListenerInfo info = checkListenerToken(token);
789 long identity = Binder.clearCallingIdentity();
790 try {
791 cancelAll(info.userid);
792 } finally {
793 Binder.restoreCallingIdentity(identity);
794 }
795 }
796
797 /**
798 * Allow an INotificationListener to simulate clearing (dismissing) a single notification.
799 *
800 * {@see com.android.server.StatusBarManagerService.NotificationCallbacks#onNotificationClear}
801 *
802 * @param token The binder for the listener, to check that the caller is allowed
803 */
804 public void clearNotificationFromListener(INotificationListener token, String pkg, String tag, int id) {
805 NotificationListenerInfo info = checkListenerToken(token);
806 long identity = Binder.clearCallingIdentity();
807 try {
808 cancelNotification(pkg, tag, id, 0,
809 Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE,
810 true,
811 info.userid);
812 } finally {
813 Binder.restoreCallingIdentity(identity);
814 }
815 }
816
817 // -- end of listener APIs --
818
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500819 public static final class NotificationRecord
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800820 {
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500821 final StatusBarNotification sbn;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800822 IBinder statusBarKey;
823
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500824 NotificationRecord(StatusBarNotification sbn)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800825 {
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500826 this.sbn = sbn;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800827 }
Fred Quintana6ecaff12009-09-25 14:23:13 -0700828
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500829 public Notification getNotification() { return sbn.notification; }
830 public int getFlags() { return sbn.notification.flags; }
831 public int getUserId() { return sbn.getUserId(); }
832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800833 void dump(PrintWriter pw, String prefix, Context baseContext) {
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500834 final Notification notification = sbn.notification;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800835 pw.println(prefix + this);
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400836 pw.println(prefix + " uid=" + sbn.uid + " userId=" + sbn.getUserId());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800837 pw.println(prefix + " icon=0x" + Integer.toHexString(notification.icon)
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400838 + " / " + idDebugString(baseContext, sbn.pkg, notification.icon));
839 pw.println(prefix + " pri=" + notification.priority + " score=" + sbn.score);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800840 pw.println(prefix + " contentIntent=" + notification.contentIntent);
841 pw.println(prefix + " deleteIntent=" + notification.deleteIntent);
842 pw.println(prefix + " tickerText=" + notification.tickerText);
843 pw.println(prefix + " contentView=" + notification.contentView);
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400844 pw.println(prefix + String.format(" defaults=0x%08x flags=0x%08x",
845 notification.defaults, notification.flags));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800846 pw.println(prefix + " sound=" + notification.sound);
847 pw.println(prefix + " vibrate=" + Arrays.toString(notification.vibrate));
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400848 pw.println(prefix + String.format(" led=0x%08x onMs=%d offMs=%d",
849 notification.ledARGB, notification.ledOnMS, notification.ledOffMS));
850 if (notification.actions != null && notification.actions.length > 0) {
851 pw.println(prefix + " actions={");
852 final int N = notification.actions.length;
853 for (int i=0; i<N; i++) {
854 final Notification.Action action = notification.actions[i];
855 pw.println(String.format("%s [%d] \"%s\" -> %s",
856 prefix,
857 i,
858 action.title,
859 action.actionIntent.toString()
860 ));
861 }
862 pw.println(prefix + " }");
863 }
864 if (notification.extras != null && notification.extras.size() > 0) {
865 pw.println(prefix + " extras={");
866 for (String key : notification.extras.keySet()) {
867 pw.print(prefix + " " + key + "=");
868 Object val = notification.extras.get(key);
869 if (val == null) {
870 pw.println("null");
871 } else {
872 pw.print(val.toString());
873 if (val instanceof Bitmap) {
874 pw.print(String.format(" (%dx%d)",
875 ((Bitmap) val).getWidth(),
876 ((Bitmap) val).getHeight()));
877 } else if (val.getClass().isArray()) {
878 pw.println(" {");
879 final int N = Array.getLength(val);
880 for (int i=0; i<N; i++) {
881 if (i > 0) pw.println(",");
882 pw.print(prefix + " " + Array.get(val, i));
883 }
884 pw.print("\n" + prefix + " }");
885 }
886 pw.println();
887 }
888 }
889 pw.println(prefix + " }");
890 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800891 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800893 @Override
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500894 public final String toString() {
895 return String.format(
896 "NotificationRecord(0x%08x: pkg=%s user=%s id=%d tag=%s score=%d: %s)",
897 System.identityHashCode(this),
898 this.sbn.pkg, this.sbn.user, this.sbn.id, this.sbn.tag,
899 this.sbn.score, this.sbn.notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800900 }
901 }
902
903 private static final class ToastRecord
904 {
905 final int pid;
906 final String pkg;
907 final ITransientNotification callback;
908 int duration;
909
910 ToastRecord(int pid, String pkg, ITransientNotification callback, int duration)
911 {
912 this.pid = pid;
913 this.pkg = pkg;
914 this.callback = callback;
915 this.duration = duration;
916 }
917
918 void update(int duration) {
919 this.duration = duration;
920 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800922 void dump(PrintWriter pw, String prefix) {
923 pw.println(prefix + this);
924 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 @Override
927 public final String toString()
928 {
929 return "ToastRecord{"
930 + Integer.toHexString(System.identityHashCode(this))
931 + " pkg=" + pkg
932 + " callback=" + callback
933 + " duration=" + duration;
934 }
935 }
936
Joe Onorato089de882010-04-12 08:18:45 -0700937 private StatusBarManagerService.NotificationCallbacks mNotificationCallbacks
938 = new StatusBarManagerService.NotificationCallbacks() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800939
940 public void onSetDisabled(int status) {
941 synchronized (mNotificationList) {
942 mDisabledNotifications = status;
943 if ((mDisabledNotifications & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0) {
944 // cancel whatever's going on
945 long identity = Binder.clearCallingIdentity();
946 try {
Jeff Sharkey098d5802012-04-26 17:30:34 -0700947 final IRingtonePlayer player = mAudioService.getRingtonePlayer();
948 if (player != null) {
949 player.stopAsync();
950 }
951 } catch (RemoteException e) {
952 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800953 Binder.restoreCallingIdentity(identity);
954 }
955
956 identity = Binder.clearCallingIdentity();
957 try {
958 mVibrator.cancel();
Jeff Sharkey098d5802012-04-26 17:30:34 -0700959 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800960 Binder.restoreCallingIdentity(identity);
961 }
962 }
963 }
964 }
965
966 public void onClearAll() {
Dianne Hackborn41203752012-08-31 14:05:51 -0700967 // XXX to be totally correct, the caller should tell us which user
968 // this is for.
969 cancelAll(ActivityManager.getCurrentUser());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800970 }
971
Fred Quintana6ecaff12009-09-25 14:23:13 -0700972 public void onNotificationClick(String pkg, String tag, int id) {
Dianne Hackborn41203752012-08-31 14:05:51 -0700973 // XXX to be totally correct, the caller should tell us which user
974 // this is for.
Fred Quintana6ecaff12009-09-25 14:23:13 -0700975 cancelNotification(pkg, tag, id, Notification.FLAG_AUTO_CANCEL,
Dianne Hackborn41203752012-08-31 14:05:51 -0700976 Notification.FLAG_FOREGROUND_SERVICE, false,
977 ActivityManager.getCurrentUser());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800978 }
979
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400980 public void onNotificationClear(String pkg, String tag, int id) {
Dianne Hackborn41203752012-08-31 14:05:51 -0700981 // XXX to be totally correct, the caller should tell us which user
982 // this is for.
Joe Onorato46439ce2010-11-19 13:56:21 -0800983 cancelNotification(pkg, tag, id, 0,
984 Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE,
Dianne Hackborn41203752012-08-31 14:05:51 -0700985 true, ActivityManager.getCurrentUser());
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400986 }
987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800988 public void onPanelRevealed() {
989 synchronized (mNotificationList) {
990 // sound
991 mSoundNotification = null;
Jeff Sharkey098d5802012-04-26 17:30:34 -0700992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800993 long identity = Binder.clearCallingIdentity();
994 try {
Jeff Sharkey098d5802012-04-26 17:30:34 -0700995 final IRingtonePlayer player = mAudioService.getRingtonePlayer();
996 if (player != null) {
997 player.stopAsync();
998 }
999 } catch (RemoteException e) {
1000 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001001 Binder.restoreCallingIdentity(identity);
1002 }
1003
1004 // vibrate
1005 mVibrateNotification = null;
1006 identity = Binder.clearCallingIdentity();
1007 try {
1008 mVibrator.cancel();
Jeff Sharkey098d5802012-04-26 17:30:34 -07001009 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001010 Binder.restoreCallingIdentity(identity);
1011 }
1012
1013 // light
1014 mLights.clear();
1015 mLedNotification = null;
1016 updateLightsLocked();
1017 }
1018 }
Joe Onorato005847b2010-06-04 16:08:02 -04001019
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -07001020 public void onNotificationError(String pkg, String tag, int id,
1021 int uid, int initialPid, String message) {
Daniel Sandlerd0a2f862010-08-03 15:29:31 -04001022 Slog.d(TAG, "onNotification error pkg=" + pkg + " tag=" + tag + " id=" + id
1023 + "; will crashApplication(uid=" + uid + ", pid=" + initialPid + ")");
Dianne Hackborn41203752012-08-31 14:05:51 -07001024 // XXX to be totally correct, the caller should tell us which user
1025 // this is for.
1026 cancelNotification(pkg, tag, id, 0, 0, false, UserHandle.getUserId(uid));
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -07001027 long ident = Binder.clearCallingIdentity();
1028 try {
1029 ActivityManagerNative.getDefault().crashApplication(uid, initialPid, pkg,
1030 "Bad notification posted from package " + pkg
1031 + ": " + message);
1032 } catch (RemoteException e) {
1033 }
1034 Binder.restoreCallingIdentity(ident);
Joe Onorato005847b2010-06-04 16:08:02 -04001035 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001036 };
1037
1038 private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
1039 @Override
1040 public void onReceive(Context context, Intent intent) {
1041 String action = intent.getAction();
1042
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001043 boolean queryRestart = false;
Daniel Sandler26ece572012-06-01 15:38:46 -04001044 boolean packageChanged = false;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001045
Mike Lockwood541c9942011-06-12 19:35:45 -04001046 if (action.equals(Intent.ACTION_PACKAGE_REMOVED)
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001047 || action.equals(Intent.ACTION_PACKAGE_RESTARTED)
Daniel Sandler26ece572012-06-01 15:38:46 -04001048 || (packageChanged=action.equals(Intent.ACTION_PACKAGE_CHANGED))
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001049 || (queryRestart=action.equals(Intent.ACTION_QUERY_PACKAGE_RESTART))
Suchi Amalapurapub56ae202010-02-04 22:51:07 -08001050 || action.equals(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)) {
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001051 String pkgList[] = null;
Suchi Amalapurapub56ae202010-02-04 22:51:07 -08001052 if (action.equals(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)) {
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001053 pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001054 } else if (queryRestart) {
1055 pkgList = intent.getStringArrayExtra(Intent.EXTRA_PACKAGES);
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001056 } else {
1057 Uri uri = intent.getData();
1058 if (uri == null) {
1059 return;
1060 }
1061 String pkgName = uri.getSchemeSpecificPart();
1062 if (pkgName == null) {
1063 return;
1064 }
Daniel Sandler26ece572012-06-01 15:38:46 -04001065 if (packageChanged) {
1066 // We cancel notifications for packages which have just been disabled
1067 final int enabled = mContext.getPackageManager()
1068 .getApplicationEnabledSetting(pkgName);
1069 if (enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1070 || enabled == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
1071 return;
1072 }
1073 }
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001074 pkgList = new String[]{pkgName};
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001075 }
Daniel Sandler5feceeb2013-03-22 18:29:23 -07001076
1077 boolean anyListenersInvolved = false;
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001078 if (pkgList != null && (pkgList.length > 0)) {
1079 for (String pkgName : pkgList) {
Dianne Hackborn41203752012-08-31 14:05:51 -07001080 cancelAllNotificationsInt(pkgName, 0, 0, !queryRestart,
1081 UserHandle.USER_ALL);
Daniel Sandler5feceeb2013-03-22 18:29:23 -07001082 if (mEnabledListenerPackageNames.contains(pkgName)) {
1083 anyListenersInvolved = true;
1084 }
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001085 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 }
Daniel Sandler5feceeb2013-03-22 18:29:23 -07001087
1088 if (anyListenersInvolved) {
1089 // make sure we're still bound to any of our
1090 // listeners who may have just upgraded
1091 rebindListenerServices();
1092 }
Mike Lockwood63b5ad92011-08-30 09:55:30 -04001093 } else if (action.equals(Intent.ACTION_SCREEN_ON)) {
1094 // Keep track of screen on/off state, but do not turn off the notification light
1095 // until user passes through the lock screen or views the notification.
1096 mScreenOn = true;
1097 } else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
1098 mScreenOn = false;
Daniel Sandlere96ffb12010-03-11 13:38:06 -05001099 } else if (action.equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
Mike Lockwood63b5ad92011-08-30 09:55:30 -04001100 mInCall = (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
1101 TelephonyManager.EXTRA_STATE_OFFHOOK));
Daniel Sandlere96ffb12010-03-11 13:38:06 -05001102 updateNotificationPulse();
Dianne Hackborn80a4af22012-08-27 19:18:31 -07001103 } else if (action.equals(Intent.ACTION_USER_STOPPED)) {
1104 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
1105 if (userHandle >= 0) {
Dianne Hackborn41203752012-08-31 14:05:51 -07001106 cancelAllNotificationsInt(null, 0, 0, true, userHandle);
Dianne Hackborn80a4af22012-08-27 19:18:31 -07001107 }
Mike Lockwood63b5ad92011-08-30 09:55:30 -04001108 } else if (action.equals(Intent.ACTION_USER_PRESENT)) {
1109 // turn off LED when user passes through lock screen
1110 mNotificationLight.turnOff();
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001111 } else if (action.equals(Intent.ACTION_USER_SWITCHED)) {
1112 // reload per-user settings
1113 mSettingsObserver.update(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001114 }
1115 }
1116 };
1117
Dianne Hackborn1dac2772009-06-26 18:16:48 -07001118 class SettingsObserver extends ContentObserver {
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001119 private final Uri NOTIFICATION_LIGHT_PULSE_URI
1120 = Settings.System.getUriFor(Settings.System.NOTIFICATION_LIGHT_PULSE);
1121
1122 private final Uri ENABLED_NOTIFICATION_LISTENERS_URI
Daniel Sandler5feceeb2013-03-22 18:29:23 -07001123 = Settings.Secure.getUriFor(Settings.Secure.ENABLED_NOTIFICATION_LISTENERS);
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001124
Dianne Hackborn1dac2772009-06-26 18:16:48 -07001125 SettingsObserver(Handler handler) {
1126 super(handler);
1127 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001128
Dianne Hackborn1dac2772009-06-26 18:16:48 -07001129 void observe() {
1130 ContentResolver resolver = mContext.getContentResolver();
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001131 resolver.registerContentObserver(NOTIFICATION_LIGHT_PULSE_URI,
Daniel Sandler5feceeb2013-03-22 18:29:23 -07001132 false, this, UserHandle.USER_ALL);
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001133 resolver.registerContentObserver(ENABLED_NOTIFICATION_LISTENERS_URI,
Daniel Sandler5feceeb2013-03-22 18:29:23 -07001134 false, this, UserHandle.USER_ALL);
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001135 update(null);
Dianne Hackborn1dac2772009-06-26 18:16:48 -07001136 }
1137
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001138 @Override public void onChange(boolean selfChange, Uri uri) {
1139 update(uri);
Dianne Hackborn1dac2772009-06-26 18:16:48 -07001140 }
1141
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001142 public void update(Uri uri) {
Dianne Hackborn1dac2772009-06-26 18:16:48 -07001143 ContentResolver resolver = mContext.getContentResolver();
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001144 if (uri == null || NOTIFICATION_LIGHT_PULSE_URI.equals(uri)) {
1145 boolean pulseEnabled = Settings.System.getInt(resolver,
1146 Settings.System.NOTIFICATION_LIGHT_PULSE, 0) != 0;
1147 if (mNotificationPulseEnabled != pulseEnabled) {
1148 mNotificationPulseEnabled = pulseEnabled;
1149 updateNotificationPulse();
1150 }
1151 }
1152 if (uri == null || ENABLED_NOTIFICATION_LISTENERS_URI.equals(uri)) {
Daniel Sandler5feceeb2013-03-22 18:29:23 -07001153 rebindListenerServices();
Mike Lockwoodc22404a2009-12-02 11:15:02 -05001154 }
Dianne Hackborn1dac2772009-06-26 18:16:48 -07001155 }
1156 }
Mike Lockwoodc22404a2009-12-02 11:15:02 -05001157
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001158 private SettingsObserver mSettingsObserver;
1159
Daniel Sandleredbb3802012-11-13 20:49:47 -08001160 static long[] getLongArray(Resources r, int resid, int maxlen, long[] def) {
1161 int[] ar = r.getIntArray(resid);
1162 if (ar == null) {
1163 return def;
1164 }
1165 final int len = ar.length > maxlen ? maxlen : ar.length;
1166 long[] out = new long[len];
1167 for (int i=0; i<len; i++) {
1168 out[i] = ar[i];
1169 }
1170 return out;
1171 }
1172
Joe Onorato089de882010-04-12 08:18:45 -07001173 NotificationManagerService(Context context, StatusBarManagerService statusBar,
Mike Lockwood3a322132009-11-24 00:30:52 -05001174 LightsService lights)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 {
1176 super();
1177 mContext = context;
Jeff Brownc2346132012-04-13 01:55:38 -07001178 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001179 mAm = ActivityManagerNative.getDefault();
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001180 mUserManager = (UserManager)context.getSystemService(Context.USER_SERVICE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001181 mToastQueue = new ArrayList<ToastRecord>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001182 mHandler = new WorkerHandler();
San Mehat3ee13172010-02-04 20:54:43 -08001183
Daniel Sandler4a900acd2013-01-30 14:04:10 -05001184 mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE);
1185
1186 importOldBlockDb();
Daniel Sandler0da673f2012-04-11 12:33:16 -04001187
Joe Onorato089de882010-04-12 08:18:45 -07001188 mStatusBar = statusBar;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001189 statusBar.setNotificationCallbacks(mNotificationCallbacks);
1190
Mike Lockwood3cb67a32009-11-27 14:25:58 -05001191 mNotificationLight = lights.getLight(LightsService.LIGHT_ID_NOTIFICATIONS);
1192 mAttentionLight = lights.getLight(LightsService.LIGHT_ID_ATTENTION);
1193
Mike Lockwood670f9322010-01-20 12:13:36 -05001194 Resources resources = mContext.getResources();
1195 mDefaultNotificationColor = resources.getColor(
1196 com.android.internal.R.color.config_defaultNotificationColor);
1197 mDefaultNotificationLedOn = resources.getInteger(
1198 com.android.internal.R.integer.config_defaultNotificationLedOn);
1199 mDefaultNotificationLedOff = resources.getInteger(
1200 com.android.internal.R.integer.config_defaultNotificationLedOff);
1201
Daniel Sandleredbb3802012-11-13 20:49:47 -08001202 mDefaultVibrationPattern = getLongArray(resources,
1203 com.android.internal.R.array.config_defaultNotificationVibePattern,
1204 VIBRATE_PATTERN_MAXLEN,
1205 DEFAULT_VIBRATE_PATTERN);
1206
1207 mFallbackVibrationPattern = getLongArray(resources,
1208 com.android.internal.R.array.config_notificationFallbackVibePattern,
1209 VIBRATE_PATTERN_MAXLEN,
1210 DEFAULT_VIBRATE_PATTERN);
1211
Joe Onorato39f5b6a2009-07-23 12:29:19 -04001212 // Don't start allowing notifications until the setup wizard has run once.
1213 // After that, including subsequent boots, init with notifications turned on.
1214 // This works on the first boot because the setup wizard will toggle this
1215 // flag at least once and we'll go back to 0 after that.
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001216 if (0 == Settings.Global.getInt(mContext.getContentResolver(),
1217 Settings.Global.DEVICE_PROVISIONED, 0)) {
Joe Onorato39f5b6a2009-07-23 12:29:19 -04001218 mDisabledNotifications = StatusBarManager.DISABLE_NOTIFICATION_ALERTS;
1219 }
1220
Mike Lockwood35e16bf2010-11-30 19:53:36 -05001221 // register for various Intents
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001222 IntentFilter filter = new IntentFilter();
Mike Lockwoodc22404a2009-12-02 11:15:02 -05001223 filter.addAction(Intent.ACTION_SCREEN_ON);
1224 filter.addAction(Intent.ACTION_SCREEN_OFF);
Daniel Sandlere96ffb12010-03-11 13:38:06 -05001225 filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Mike Lockwood63b5ad92011-08-30 09:55:30 -04001226 filter.addAction(Intent.ACTION_USER_PRESENT);
Dianne Hackborn80a4af22012-08-27 19:18:31 -07001227 filter.addAction(Intent.ACTION_USER_STOPPED);
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001228 filter.addAction(Intent.ACTION_USER_SWITCHED);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001229 mContext.registerReceiver(mIntentReceiver, filter);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001230 IntentFilter pkgFilter = new IntentFilter();
1231 pkgFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
Daniel Sandleraac0eb02011-08-06 22:51:56 -04001232 pkgFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001233 pkgFilter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
1234 pkgFilter.addAction(Intent.ACTION_QUERY_PACKAGE_RESTART);
1235 pkgFilter.addDataScheme("package");
1236 mContext.registerReceiver(mIntentReceiver, pkgFilter);
Suchi Amalapurapub56ae202010-02-04 22:51:07 -08001237 IntentFilter sdFilter = new IntentFilter(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001238 mContext.registerReceiver(mIntentReceiver, sdFilter);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001239
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001240 mSettingsObserver = new SettingsObserver(mHandler);
1241 mSettingsObserver.observe();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001242 }
1243
Daniel Sandler4a900acd2013-01-30 14:04:10 -05001244 /**
1245 * Read the old XML-based app block database and import those blockages into the AppOps system.
1246 */
1247 private void importOldBlockDb() {
1248 loadBlockDb();
1249
1250 PackageManager pm = mContext.getPackageManager();
1251 for (String pkg : mBlockedPackages) {
1252 PackageInfo info = null;
1253 try {
1254 info = pm.getPackageInfo(pkg, 0);
1255 setNotificationsEnabledForPackage(pkg, info.applicationInfo.uid, false);
1256 } catch (NameNotFoundException e) {
1257 // forget you
1258 }
1259 }
1260 mBlockedPackages.clear();
1261 if (mPolicyFile != null) {
1262 mPolicyFile.delete();
1263 }
1264 }
1265
Joe Onorato30275482009-07-08 17:09:14 -07001266 void systemReady() {
Jeff Sharkey098d5802012-04-26 17:30:34 -07001267 mAudioService = IAudioService.Stub.asInterface(
1268 ServiceManager.getService(Context.AUDIO_SERVICE));
1269
Joe Onorato30275482009-07-08 17:09:14 -07001270 // no beeping until we're basically done booting
1271 mSystemReady = true;
Daniel Sandler5feceeb2013-03-22 18:29:23 -07001272
1273 // make sure our listener services are properly bound
1274 rebindListenerServices();
Joe Onorato30275482009-07-08 17:09:14 -07001275 }
1276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001277 // Toasts
1278 // ============================================================================
1279 public void enqueueToast(String pkg, ITransientNotification callback, int duration)
1280 {
Daniel Sandlera7035902010-03-30 15:45:31 -04001281 if (DBG) Slog.i(TAG, "enqueueToast pkg=" + pkg + " callback=" + callback + " duration=" + duration);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001282
1283 if (pkg == null || callback == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001284 Slog.e(TAG, "Not doing toast. pkg=" + pkg + " callback=" + callback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001285 return ;
1286 }
1287
Daniel Sandler0da673f2012-04-11 12:33:16 -04001288 final boolean isSystemToast = ("android".equals(pkg));
1289
Daniel Sandler4a900acd2013-01-30 14:04:10 -05001290 if (ENABLE_BLOCKED_TOASTS && !noteNotificationOp(pkg, Binder.getCallingUid())) {
1291 if (!isSystemToast) {
1292 Slog.e(TAG, "Suppressing toast from package " + pkg + " by user request.");
1293 return;
1294 }
Daniel Sandler0da673f2012-04-11 12:33:16 -04001295 }
1296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001297 synchronized (mToastQueue) {
1298 int callingPid = Binder.getCallingPid();
1299 long callingId = Binder.clearCallingIdentity();
1300 try {
1301 ToastRecord record;
1302 int index = indexOfToastLocked(pkg, callback);
1303 // If it's already in the queue, we update it in place, we don't
1304 // move it to the end of the queue.
1305 if (index >= 0) {
1306 record = mToastQueue.get(index);
1307 record.update(duration);
1308 } else {
Vairavan Srinivasanf9eb06c2011-01-21 18:08:36 -08001309 // Limit the number of toasts that any given package except the android
1310 // package can enqueue. Prevents DOS attacks and deals with leaks.
Daniel Sandler0da673f2012-04-11 12:33:16 -04001311 if (!isSystemToast) {
Vairavan Srinivasanf9eb06c2011-01-21 18:08:36 -08001312 int count = 0;
1313 final int N = mToastQueue.size();
1314 for (int i=0; i<N; i++) {
1315 final ToastRecord r = mToastQueue.get(i);
1316 if (r.pkg.equals(pkg)) {
1317 count++;
1318 if (count >= MAX_PACKAGE_NOTIFICATIONS) {
1319 Slog.e(TAG, "Package has already posted " + count
1320 + " toasts. Not showing more. Package=" + pkg);
1321 return;
1322 }
1323 }
1324 }
1325 }
1326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001327 record = new ToastRecord(callingPid, pkg, callback, duration);
1328 mToastQueue.add(record);
1329 index = mToastQueue.size() - 1;
1330 keepProcessAliveLocked(callingPid);
1331 }
1332 // If it's at index 0, it's the current toast. It doesn't matter if it's
1333 // new or just been updated. Call back and tell it to show itself.
1334 // If the callback fails, this will remove it from the list, so don't
1335 // assume that it's valid after this.
1336 if (index == 0) {
1337 showNextToastLocked();
1338 }
1339 } finally {
1340 Binder.restoreCallingIdentity(callingId);
1341 }
1342 }
1343 }
1344
1345 public void cancelToast(String pkg, ITransientNotification callback) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001346 Slog.i(TAG, "cancelToast pkg=" + pkg + " callback=" + callback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001347
1348 if (pkg == null || callback == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001349 Slog.e(TAG, "Not cancelling notification. pkg=" + pkg + " callback=" + callback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001350 return ;
1351 }
1352
1353 synchronized (mToastQueue) {
1354 long callingId = Binder.clearCallingIdentity();
1355 try {
1356 int index = indexOfToastLocked(pkg, callback);
1357 if (index >= 0) {
1358 cancelToastLocked(index);
1359 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001360 Slog.w(TAG, "Toast already cancelled. pkg=" + pkg + " callback=" + callback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001361 }
1362 } finally {
1363 Binder.restoreCallingIdentity(callingId);
1364 }
1365 }
1366 }
1367
1368 private void showNextToastLocked() {
1369 ToastRecord record = mToastQueue.get(0);
1370 while (record != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001371 if (DBG) Slog.d(TAG, "Show pkg=" + record.pkg + " callback=" + record.callback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001372 try {
1373 record.callback.show();
1374 scheduleTimeoutLocked(record, false);
1375 return;
1376 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001377 Slog.w(TAG, "Object died trying to show notification " + record.callback
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001378 + " in package " + record.pkg);
1379 // remove it from the list and let the process die
1380 int index = mToastQueue.indexOf(record);
1381 if (index >= 0) {
1382 mToastQueue.remove(index);
1383 }
1384 keepProcessAliveLocked(record.pid);
1385 if (mToastQueue.size() > 0) {
1386 record = mToastQueue.get(0);
1387 } else {
1388 record = null;
1389 }
1390 }
1391 }
1392 }
1393
1394 private void cancelToastLocked(int index) {
1395 ToastRecord record = mToastQueue.get(index);
1396 try {
1397 record.callback.hide();
1398 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001399 Slog.w(TAG, "Object died trying to hide notification " + record.callback
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001400 + " in package " + record.pkg);
1401 // don't worry about this, we're about to remove it from
1402 // the list anyway
1403 }
1404 mToastQueue.remove(index);
1405 keepProcessAliveLocked(record.pid);
1406 if (mToastQueue.size() > 0) {
1407 // Show the next one. If the callback fails, this will remove
1408 // it from the list, so don't assume that the list hasn't changed
1409 // after this point.
1410 showNextToastLocked();
1411 }
1412 }
1413
1414 private void scheduleTimeoutLocked(ToastRecord r, boolean immediate)
1415 {
1416 Message m = Message.obtain(mHandler, MESSAGE_TIMEOUT, r);
1417 long delay = immediate ? 0 : (r.duration == Toast.LENGTH_LONG ? LONG_DELAY : SHORT_DELAY);
1418 mHandler.removeCallbacksAndMessages(r);
1419 mHandler.sendMessageDelayed(m, delay);
1420 }
1421
1422 private void handleTimeout(ToastRecord record)
1423 {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001424 if (DBG) Slog.d(TAG, "Timeout pkg=" + record.pkg + " callback=" + record.callback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001425 synchronized (mToastQueue) {
1426 int index = indexOfToastLocked(record.pkg, record.callback);
1427 if (index >= 0) {
1428 cancelToastLocked(index);
1429 }
1430 }
1431 }
1432
1433 // lock on mToastQueue
1434 private int indexOfToastLocked(String pkg, ITransientNotification callback)
1435 {
1436 IBinder cbak = callback.asBinder();
1437 ArrayList<ToastRecord> list = mToastQueue;
1438 int len = list.size();
1439 for (int i=0; i<len; i++) {
1440 ToastRecord r = list.get(i);
1441 if (r.pkg.equals(pkg) && r.callback.asBinder() == cbak) {
1442 return i;
1443 }
1444 }
1445 return -1;
1446 }
1447
1448 // lock on mToastQueue
1449 private void keepProcessAliveLocked(int pid)
1450 {
1451 int toastCount = 0; // toasts from this pid
1452 ArrayList<ToastRecord> list = mToastQueue;
1453 int N = list.size();
1454 for (int i=0; i<N; i++) {
1455 ToastRecord r = list.get(i);
1456 if (r.pid == pid) {
1457 toastCount++;
1458 }
1459 }
1460 try {
1461 mAm.setProcessForeground(mForegroundToken, pid, toastCount > 0);
1462 } catch (RemoteException e) {
1463 // Shouldn't happen.
1464 }
1465 }
1466
1467 private final class WorkerHandler extends Handler
1468 {
1469 @Override
1470 public void handleMessage(Message msg)
1471 {
1472 switch (msg.what)
1473 {
1474 case MESSAGE_TIMEOUT:
1475 handleTimeout((ToastRecord)msg.obj);
1476 break;
1477 }
1478 }
1479 }
1480
1481
1482 // Notifications
1483 // ============================================================================
Dianne Hackbornf265ea92013-01-31 15:00:51 -08001484 public void enqueueNotificationWithTag(String pkg, String basePkg, String tag, int id,
1485 Notification notification, int[] idOut, int userId)
Fred Quintana6ecaff12009-09-25 14:23:13 -07001486 {
Dianne Hackbornf265ea92013-01-31 15:00:51 -08001487 enqueueNotificationInternal(pkg, basePkg, Binder.getCallingUid(), Binder.getCallingPid(),
Dianne Hackborn41203752012-08-31 14:05:51 -07001488 tag, id, notification, idOut, userId);
Daniel Sandlerd0a2f862010-08-03 15:29:31 -04001489 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001490
1491 private final static int clamp(int x, int low, int high) {
1492 return (x < low) ? low : ((x > high) ? high : x);
Daniel Sandlere40451a2011-02-03 14:51:35 -05001493 }
1494
Daniel Sandlerd0a2f862010-08-03 15:29:31 -04001495 // Not exposed via Binder; for system use only (otherwise malicious apps could spoof the
1496 // uid/pid of another application)
Dianne Hackbornf265ea92013-01-31 15:00:51 -08001497 public void enqueueNotificationInternal(String pkg, String basePkg, int callingUid,
1498 int callingPid, String tag, int id, Notification notification, int[] idOut, int userId)
Daniel Sandlerd0a2f862010-08-03 15:29:31 -04001499 {
Daniel Sandler0da673f2012-04-11 12:33:16 -04001500 if (DBG) {
1501 Slog.v(TAG, "enqueueNotificationInternal: pkg=" + pkg + " id=" + id + " notification=" + notification);
1502 }
1503 checkCallerIsSystemOrSameApp(pkg);
1504 final boolean isSystemNotification = ("android".equals(pkg));
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001505
Dianne Hackborn41203752012-08-31 14:05:51 -07001506 userId = ActivityManager.handleIncomingUser(callingPid,
Amith Yamasani2c7ebea2012-10-30 15:28:27 -07001507 callingUid, userId, true, false, "enqueueNotification", pkg);
Jeff Sharkey65c4a2b2012-09-25 17:22:27 -07001508 final UserHandle user = new UserHandle(userId);
Dianne Hackborn41203752012-08-31 14:05:51 -07001509
Joe Onoratobd73d012010-06-04 11:44:54 -07001510 // Limit the number of notifications that any given package except the android
1511 // package can enqueue. Prevents DOS attacks and deals with leaks.
Daniel Sandler0da673f2012-04-11 12:33:16 -04001512 if (!isSystemNotification) {
Joe Onoratobd73d012010-06-04 11:44:54 -07001513 synchronized (mNotificationList) {
1514 int count = 0;
1515 final int N = mNotificationList.size();
1516 for (int i=0; i<N; i++) {
1517 final NotificationRecord r = mNotificationList.get(i);
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001518 if (r.sbn.pkg.equals(pkg) && r.sbn.getUserId() == userId) {
Joe Onoratobd73d012010-06-04 11:44:54 -07001519 count++;
1520 if (count >= MAX_PACKAGE_NOTIFICATIONS) {
1521 Slog.e(TAG, "Package has already posted " + count
1522 + " notifications. Not showing more. package=" + pkg);
1523 return;
1524 }
1525 }
1526 }
1527 }
1528 }
1529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001530 // This conditional is a dirty hack to limit the logging done on
1531 // behalf of the download manager without affecting other apps.
1532 if (!pkg.equals("com.android.providers.downloads")
1533 || Log.isLoggable("DownloadManager", Log.VERBOSE)) {
Daniel Sandler321e9c52012-10-12 10:59:26 -07001534 EventLog.writeEvent(EventLogTags.NOTIFICATION_ENQUEUE, pkg, id, tag, userId,
Daniel Sandlerb64cb882011-11-29 23:48:29 -05001535 notification.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001536 }
1537
1538 if (pkg == null || notification == null) {
1539 throw new IllegalArgumentException("null not allowed: pkg=" + pkg
1540 + " id=" + id + " notification=" + notification);
1541 }
1542 if (notification.icon != 0) {
1543 if (notification.contentView == null) {
1544 throw new IllegalArgumentException("contentView required: pkg=" + pkg
1545 + " id=" + id + " notification=" + notification);
1546 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001547 }
1548
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001549 // === Scoring ===
Daniel Sandler0da673f2012-04-11 12:33:16 -04001550
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001551 // 0. Sanitize inputs
1552 notification.priority = clamp(notification.priority, Notification.PRIORITY_MIN, Notification.PRIORITY_MAX);
1553 // Migrate notification flags to scores
1554 if (0 != (notification.flags & Notification.FLAG_HIGH_PRIORITY)) {
1555 if (notification.priority < Notification.PRIORITY_MAX) notification.priority = Notification.PRIORITY_MAX;
Daniel Sandler49a2ad12012-03-28 15:46:39 -04001556 } else if (SCORE_ONGOING_HIGHER && 0 != (notification.flags & Notification.FLAG_ONGOING_EVENT)) {
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001557 if (notification.priority < Notification.PRIORITY_HIGH) notification.priority = Notification.PRIORITY_HIGH;
1558 }
Daniel Sandler0da673f2012-04-11 12:33:16 -04001559
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001560 // 1. initial score: buckets of 10, around the app
Daniel Sandler0da673f2012-04-11 12:33:16 -04001561 int score = notification.priority * NOTIFICATION_PRIORITY_MULTIPLIER; //[-20..20]
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001562
Daniel Sandler0da673f2012-04-11 12:33:16 -04001563 // 2. Consult external heuristics (TBD)
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001564
Daniel Sandler0da673f2012-04-11 12:33:16 -04001565 // 3. Apply local rules
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001566
1567 // blocked apps
Daniel Sandler4a900acd2013-01-30 14:04:10 -05001568 if (ENABLE_BLOCKED_NOTIFICATIONS && !noteNotificationOp(pkg, callingUid)) {
1569 if (!isSystemNotification) {
1570 score = JUNK_SCORE;
1571 Slog.e(TAG, "Suppressing notification from package " + pkg + " by user request.");
1572 }
Daniel Sandler0da673f2012-04-11 12:33:16 -04001573 }
1574
1575 if (DBG) {
1576 Slog.v(TAG, "Assigned score=" + score + " to " + notification);
1577 }
1578
1579 if (score < SCORE_DISPLAY_THRESHOLD) {
1580 // Notification will be blocked because the score is too low.
1581 return;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001582 }
1583
Daniel Sandler526fa0e2012-12-04 14:51:50 -05001584 // Should this notification make noise, vibe, or use the LED?
1585 final boolean canInterrupt = (score >= SCORE_INTERRUPTION_THRESHOLD);
1586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001587 synchronized (mNotificationList) {
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001588 final StatusBarNotification n = new StatusBarNotification(
1589 pkg, id, tag, callingUid, callingPid, score, notification, user);
1590 NotificationRecord r = new NotificationRecord(n);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001591 NotificationRecord old = null;
1592
Dianne Hackborn41203752012-08-31 14:05:51 -07001593 int index = indexOfNotificationLocked(pkg, tag, id, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001594 if (index < 0) {
1595 mNotificationList.add(r);
1596 } else {
1597 old = mNotificationList.remove(index);
1598 mNotificationList.add(index, r);
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001599 // Make sure we don't lose the foreground service state.
1600 if (old != null) {
1601 notification.flags |=
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001602 old.getNotification().flags&Notification.FLAG_FOREGROUND_SERVICE;
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001603 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001604 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001605
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001606 // Ensure if this is a foreground service that the proper additional
1607 // flags are set.
1608 if ((notification.flags&Notification.FLAG_FOREGROUND_SERVICE) != 0) {
1609 notification.flags |= Notification.FLAG_ONGOING_EVENT
1610 | Notification.FLAG_NO_CLEAR;
1611 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001612
Svetoslav Ganovc31ed392012-10-10 14:58:28 -07001613 final int currentUser;
1614 final long token = Binder.clearCallingIdentity();
1615 try {
1616 currentUser = ActivityManager.getCurrentUser();
1617 } finally {
1618 Binder.restoreCallingIdentity(token);
1619 }
1620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001621 if (notification.icon != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001622 if (old != null && old.statusBarKey != null) {
1623 r.statusBarKey = old.statusBarKey;
1624 long identity = Binder.clearCallingIdentity();
1625 try {
Joe Onorato18e69df2010-05-17 22:26:12 -07001626 mStatusBar.updateNotification(r.statusBarKey, n);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001627 }
1628 finally {
1629 Binder.restoreCallingIdentity(identity);
1630 }
1631 } else {
1632 long identity = Binder.clearCallingIdentity();
1633 try {
Joe Onorato18e69df2010-05-17 22:26:12 -07001634 r.statusBarKey = mStatusBar.addNotification(n);
Daniel Sandler526fa0e2012-12-04 14:51:50 -05001635 if ((n.notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0
1636 && canInterrupt) {
Mike Lockwoodece18ef2012-02-13 20:42:19 -08001637 mAttentionLight.pulse();
1638 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001639 }
1640 finally {
1641 Binder.restoreCallingIdentity(identity);
1642 }
1643 }
Svetoslav Ganovc31ed392012-10-10 14:58:28 -07001644 // Send accessibility events only for the current user.
1645 if (currentUser == userId) {
1646 sendAccessibilityEvent(notification, pkg);
1647 }
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001648
Daniel Sandler09a247e2013-02-14 10:24:17 -05001649 notifyPostedLocked(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001650 } else {
Daniel Sandlere40451a2011-02-03 14:51:35 -05001651 Slog.e(TAG, "Ignoring notification with icon==0: " + notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001652 if (old != null && old.statusBarKey != null) {
1653 long identity = Binder.clearCallingIdentity();
1654 try {
Joe Onorato0cbda992010-05-02 16:28:15 -07001655 mStatusBar.removeNotification(old.statusBarKey);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001656 }
1657 finally {
1658 Binder.restoreCallingIdentity(identity);
1659 }
Daniel Sandler09a247e2013-02-14 10:24:17 -05001660
1661 notifyRemovedLocked(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001662 }
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001663 return; // do not play sounds, show lights, etc. for invalid notifications
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001664 }
1665
1666 // If we're not supposed to beep, vibrate, etc. then don't.
1667 if (((mDisabledNotifications & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) == 0)
1668 && (!(old != null
Joe Onorato30275482009-07-08 17:09:14 -07001669 && (notification.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0 ))
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001670 && (r.getUserId() == UserHandle.USER_ALL ||
1671 (r.getUserId() == userId && r.getUserId() == currentUser))
Daniel Sandler526fa0e2012-12-04 14:51:50 -05001672 && canInterrupt
Joe Onorato30275482009-07-08 17:09:14 -07001673 && mSystemReady) {
Eric Laurent524dc042009-11-27 05:07:55 -08001674
1675 final AudioManager audioManager = (AudioManager) mContext
1676 .getSystemService(Context.AUDIO_SERVICE);
Daniel Sandlerd4d2de22012-11-14 11:25:46 -08001677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001678 // sound
1679 final boolean useDefaultSound =
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001680 (notification.defaults & Notification.DEFAULT_SOUND) != 0;
Daniel Sandlerd4d2de22012-11-14 11:25:46 -08001681
1682 Uri soundUri = null;
1683 boolean hasValidSound = false;
1684
1685 if (useDefaultSound) {
1686 soundUri = Settings.System.DEFAULT_NOTIFICATION_URI;
1687
1688 // check to see if the default notification sound is silent
1689 ContentResolver resolver = mContext.getContentResolver();
1690 hasValidSound = Settings.System.getString(resolver,
1691 Settings.System.NOTIFICATION_SOUND) != null;
1692 } else if (notification.sound != null) {
1693 soundUri = notification.sound;
1694 hasValidSound = (soundUri != null);
1695 }
1696
1697 if (hasValidSound) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001698 boolean looping = (notification.flags & Notification.FLAG_INSISTENT) != 0;
1699 int audioStreamType;
1700 if (notification.audioStreamType >= 0) {
1701 audioStreamType = notification.audioStreamType;
1702 } else {
1703 audioStreamType = DEFAULT_STREAM_TYPE;
1704 }
1705 mSoundNotification = r;
Eric Laurent524dc042009-11-27 05:07:55 -08001706 // do not play notifications if stream volume is 0
Jean-Michel Trivid6770542012-10-10 12:03:41 -07001707 // (typically because ringer mode is silent) or if speech recognition is active.
1708 if ((audioManager.getStreamVolume(audioStreamType) != 0)
1709 && !audioManager.isSpeechRecognitionActive()) {
Jeff Sharkey098d5802012-04-26 17:30:34 -07001710 final long identity = Binder.clearCallingIdentity();
Eric Laurent524dc042009-11-27 05:07:55 -08001711 try {
Jeff Sharkey098d5802012-04-26 17:30:34 -07001712 final IRingtonePlayer player = mAudioService.getRingtonePlayer();
1713 if (player != null) {
Daniel Sandlerd4d2de22012-11-14 11:25:46 -08001714 player.playAsync(soundUri, user, looping, audioStreamType);
Jeff Sharkey098d5802012-04-26 17:30:34 -07001715 }
1716 } catch (RemoteException e) {
1717 } finally {
Eric Laurent524dc042009-11-27 05:07:55 -08001718 Binder.restoreCallingIdentity(identity);
1719 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001720 }
1721 }
1722
1723 // vibrate
Daniel Sandleredbb3802012-11-13 20:49:47 -08001724 // Does the notification want to specify its own vibration?
1725 final boolean hasCustomVibrate = notification.vibrate != null;
1726
David Agnew71789e12012-11-09 23:03:26 -05001727 // new in 4.2: if there was supposed to be a sound and we're in vibrate mode,
Daniel Sandler4a7a9b92012-11-20 12:59:41 -05001728 // and no other vibration is specified, we fall back to vibration
David Agnew71789e12012-11-09 23:03:26 -05001729 final boolean convertSoundToVibration =
Daniel Sandleredbb3802012-11-13 20:49:47 -08001730 !hasCustomVibrate
Daniel Sandlerd4d2de22012-11-14 11:25:46 -08001731 && hasValidSound
David Agnew71789e12012-11-09 23:03:26 -05001732 && (audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE);
1733
Daniel Sandler4a7a9b92012-11-20 12:59:41 -05001734 // The DEFAULT_VIBRATE flag trumps any custom vibration AND the fallback.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001735 final boolean useDefaultVibrate =
Daniel Sandleredbb3802012-11-13 20:49:47 -08001736 (notification.defaults & Notification.DEFAULT_VIBRATE) != 0;
David Agnew71789e12012-11-09 23:03:26 -05001737
Daniel Sandleredbb3802012-11-13 20:49:47 -08001738 if ((useDefaultVibrate || convertSoundToVibration || hasCustomVibrate)
Eric Laurentbffc3d12012-05-07 17:43:49 -07001739 && !(audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001740 mVibrateNotification = r;
1741
Daniel Sandleredbb3802012-11-13 20:49:47 -08001742 if (useDefaultVibrate || convertSoundToVibration) {
1743 // Escalate privileges so we can use the vibrator even if the notifying app
1744 // does not have the VIBRATE permission.
1745 long identity = Binder.clearCallingIdentity();
1746 try {
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001747 mVibrator.vibrate(r.sbn.uid, r.sbn.basePkg,
Dianne Hackbornf265ea92013-01-31 15:00:51 -08001748 useDefaultVibrate ? mDefaultVibrationPattern
1749 : mFallbackVibrationPattern,
Daniel Sandleredbb3802012-11-13 20:49:47 -08001750 ((notification.flags & Notification.FLAG_INSISTENT) != 0) ? 0: -1);
1751 } finally {
1752 Binder.restoreCallingIdentity(identity);
1753 }
1754 } else if (notification.vibrate.length > 1) {
1755 // If you want your own vibration pattern, you need the VIBRATE permission
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001756 mVibrator.vibrate(r.sbn.uid, r.sbn.basePkg, notification.vibrate,
Daniel Sandleredbb3802012-11-13 20:49:47 -08001757 ((notification.flags & Notification.FLAG_INSISTENT) != 0) ? 0: -1);
1758 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001759 }
1760 }
1761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001762 // light
1763 // the most recent thing gets the light
1764 mLights.remove(old);
1765 if (mLedNotification == old) {
1766 mLedNotification = null;
1767 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001768 //Slog.i(TAG, "notification.lights="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001769 // + ((old.notification.lights.flags & Notification.FLAG_SHOW_LIGHTS) != 0));
Daniel Sandler526fa0e2012-12-04 14:51:50 -05001770 if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0
1771 && canInterrupt) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001772 mLights.add(r);
1773 updateLightsLocked();
1774 } else {
1775 if (old != null
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001776 && ((old.getFlags() & Notification.FLAG_SHOW_LIGHTS) != 0)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001777 updateLightsLocked();
1778 }
1779 }
1780 }
1781
1782 idOut[0] = id;
1783 }
1784
Joe Onorato30275482009-07-08 17:09:14 -07001785 private void sendAccessibilityEvent(Notification notification, CharSequence packageName) {
svetoslavganov75986cf2009-05-14 22:28:01 -07001786 AccessibilityManager manager = AccessibilityManager.getInstance(mContext);
1787 if (!manager.isEnabled()) {
1788 return;
1789 }
1790
1791 AccessibilityEvent event =
1792 AccessibilityEvent.obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
1793 event.setPackageName(packageName);
1794 event.setClassName(Notification.class.getName());
1795 event.setParcelableData(notification);
1796 CharSequence tickerText = notification.tickerText;
1797 if (!TextUtils.isEmpty(tickerText)) {
1798 event.getText().add(tickerText);
1799 }
1800
1801 manager.sendAccessibilityEvent(event);
1802 }
1803
Joe Onorato46439ce2010-11-19 13:56:21 -08001804 private void cancelNotificationLocked(NotificationRecord r, boolean sendDelete) {
1805 // tell the app
1806 if (sendDelete) {
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001807 if (r.getNotification().deleteIntent != null) {
Joe Onorato46439ce2010-11-19 13:56:21 -08001808 try {
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001809 r.getNotification().deleteIntent.send();
Joe Onorato46439ce2010-11-19 13:56:21 -08001810 } catch (PendingIntent.CanceledException ex) {
1811 // do nothing - there's no relevant way to recover, and
1812 // no reason to let this propagate
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001813 Slog.w(TAG, "canceled PendingIntent for " + r.sbn.pkg, ex);
Joe Onorato46439ce2010-11-19 13:56:21 -08001814 }
1815 }
1816 }
1817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001818 // status bar
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001819 if (r.getNotification().icon != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001820 long identity = Binder.clearCallingIdentity();
1821 try {
Joe Onorato0cbda992010-05-02 16:28:15 -07001822 mStatusBar.removeNotification(r.statusBarKey);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001823 }
1824 finally {
1825 Binder.restoreCallingIdentity(identity);
1826 }
1827 r.statusBarKey = null;
Daniel Sandler09a247e2013-02-14 10:24:17 -05001828 notifyRemovedLocked(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001829 }
1830
1831 // sound
1832 if (mSoundNotification == r) {
1833 mSoundNotification = null;
Jeff Sharkey098d5802012-04-26 17:30:34 -07001834 final long identity = Binder.clearCallingIdentity();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001835 try {
Jeff Sharkey098d5802012-04-26 17:30:34 -07001836 final IRingtonePlayer player = mAudioService.getRingtonePlayer();
1837 if (player != null) {
1838 player.stopAsync();
1839 }
1840 } catch (RemoteException e) {
1841 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001842 Binder.restoreCallingIdentity(identity);
1843 }
1844 }
1845
1846 // vibrate
1847 if (mVibrateNotification == r) {
1848 mVibrateNotification = null;
1849 long identity = Binder.clearCallingIdentity();
1850 try {
1851 mVibrator.cancel();
1852 }
1853 finally {
1854 Binder.restoreCallingIdentity(identity);
1855 }
1856 }
1857
1858 // light
1859 mLights.remove(r);
1860 if (mLedNotification == r) {
1861 mLedNotification = null;
1862 }
Daniel Sandler23d7c702013-03-07 16:32:06 -05001863
1864 // Save it for users of getHistoricalNotifications()
1865 mArchive.record(r.sbn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001866 }
1867
1868 /**
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001869 * Cancels a notification ONLY if it has all of the {@code mustHaveFlags}
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001870 * and none of the {@code mustNotHaveFlags}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001871 */
Fred Quintana6ecaff12009-09-25 14:23:13 -07001872 private void cancelNotification(String pkg, String tag, int id, int mustHaveFlags,
Dianne Hackborn41203752012-08-31 14:05:51 -07001873 int mustNotHaveFlags, boolean sendDelete, int userId) {
Daniel Sandler321e9c52012-10-12 10:59:26 -07001874 EventLog.writeEvent(EventLogTags.NOTIFICATION_CANCEL, pkg, id, tag, userId,
Daniel Sandlerb64cb882011-11-29 23:48:29 -05001875 mustHaveFlags, mustNotHaveFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001876
1877 synchronized (mNotificationList) {
Dianne Hackborn41203752012-08-31 14:05:51 -07001878 int index = indexOfNotificationLocked(pkg, tag, id, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001879 if (index >= 0) {
Fred Quintana6ecaff12009-09-25 14:23:13 -07001880 NotificationRecord r = mNotificationList.get(index);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001881
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001882 if ((r.getNotification().flags & mustHaveFlags) != mustHaveFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001883 return;
1884 }
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001885 if ((r.getNotification().flags & mustNotHaveFlags) != 0) {
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001886 return;
1887 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001889 mNotificationList.remove(index);
1890
Joe Onorato46439ce2010-11-19 13:56:21 -08001891 cancelNotificationLocked(r, sendDelete);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001892 updateLightsLocked();
1893 }
1894 }
1895 }
1896
1897 /**
Daniel Sandler321e9c52012-10-12 10:59:26 -07001898 * Determine whether the userId applies to the notification in question, either because
1899 * they match exactly, or one of them is USER_ALL (which is treated as a wildcard).
1900 */
1901 private boolean notificationMatchesUserId(NotificationRecord r, int userId) {
1902 return
1903 // looking for USER_ALL notifications? match everything
1904 userId == UserHandle.USER_ALL
1905 // a notification sent to USER_ALL matches any query
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001906 || r.getUserId() == UserHandle.USER_ALL
Daniel Sandler321e9c52012-10-12 10:59:26 -07001907 // an exact user match
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001908 || r.getUserId() == userId;
Daniel Sandler321e9c52012-10-12 10:59:26 -07001909 }
1910
1911 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001912 * Cancels all notifications from a given package that have all of the
1913 * {@code mustHaveFlags}.
1914 */
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001915 boolean cancelAllNotificationsInt(String pkg, int mustHaveFlags,
Dianne Hackborn41203752012-08-31 14:05:51 -07001916 int mustNotHaveFlags, boolean doit, int userId) {
Daniel Sandler321e9c52012-10-12 10:59:26 -07001917 EventLog.writeEvent(EventLogTags.NOTIFICATION_CANCEL_ALL, pkg, userId,
1918 mustHaveFlags, mustNotHaveFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001919
1920 synchronized (mNotificationList) {
1921 final int N = mNotificationList.size();
1922 boolean canceledSomething = false;
1923 for (int i = N-1; i >= 0; --i) {
1924 NotificationRecord r = mNotificationList.get(i);
Daniel Sandler321e9c52012-10-12 10:59:26 -07001925 if (!notificationMatchesUserId(r, userId)) {
Dianne Hackborn41203752012-08-31 14:05:51 -07001926 continue;
1927 }
Amith Yamasani5ec00e92012-11-07 16:58:30 -08001928 // Don't remove notifications to all, if there's no package name specified
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001929 if (r.getUserId() == UserHandle.USER_ALL && pkg == null) {
Amith Yamasani5ec00e92012-11-07 16:58:30 -08001930 continue;
1931 }
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001932 if ((r.getFlags() & mustHaveFlags) != mustHaveFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001933 continue;
1934 }
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001935 if ((r.getFlags() & mustNotHaveFlags) != 0) {
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001936 continue;
1937 }
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001938 if (pkg != null && !r.sbn.pkg.equals(pkg)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001939 continue;
1940 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001941 canceledSomething = true;
1942 if (!doit) {
1943 return true;
1944 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001945 mNotificationList.remove(i);
Joe Onorato46439ce2010-11-19 13:56:21 -08001946 cancelNotificationLocked(r, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001947 }
1948 if (canceledSomething) {
1949 updateLightsLocked();
1950 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001951 return canceledSomething;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001952 }
1953 }
1954
Dianne Hackborn41203752012-08-31 14:05:51 -07001955 public void cancelNotificationWithTag(String pkg, String tag, int id, int userId) {
Daniel Sandler0da673f2012-04-11 12:33:16 -04001956 checkCallerIsSystemOrSameApp(pkg);
Dianne Hackborn41203752012-08-31 14:05:51 -07001957 userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
Amith Yamasani2c7ebea2012-10-30 15:28:27 -07001958 Binder.getCallingUid(), userId, true, false, "cancelNotificationWithTag", pkg);
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001959 // Don't allow client applications to cancel foreground service notis.
Fred Quintana6ecaff12009-09-25 14:23:13 -07001960 cancelNotification(pkg, tag, id, 0,
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001961 Binder.getCallingUid() == Process.SYSTEM_UID
Dianne Hackborn41203752012-08-31 14:05:51 -07001962 ? 0 : Notification.FLAG_FOREGROUND_SERVICE, false, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001963 }
1964
Dianne Hackborn41203752012-08-31 14:05:51 -07001965 public void cancelAllNotifications(String pkg, int userId) {
Daniel Sandler0da673f2012-04-11 12:33:16 -04001966 checkCallerIsSystemOrSameApp(pkg);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001967
Dianne Hackborn41203752012-08-31 14:05:51 -07001968 userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
Amith Yamasani2c7ebea2012-10-30 15:28:27 -07001969 Binder.getCallingUid(), userId, true, false, "cancelAllNotifications", pkg);
Dianne Hackborn41203752012-08-31 14:05:51 -07001970
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001971 // Calling from user space, don't allow the canceling of actively
1972 // running foreground services.
Dianne Hackborn41203752012-08-31 14:05:51 -07001973 cancelAllNotificationsInt(pkg, 0, Notification.FLAG_FOREGROUND_SERVICE, true, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001974 }
1975
Daniel Sandler0da673f2012-04-11 12:33:16 -04001976 void checkCallerIsSystem() {
1977 int uid = Binder.getCallingUid();
Dianne Hackborn0c380492012-08-20 17:23:30 -07001978 if (UserHandle.getAppId(uid) == Process.SYSTEM_UID || uid == 0) {
Daniel Sandler0da673f2012-04-11 12:33:16 -04001979 return;
1980 }
1981 throw new SecurityException("Disallowed call for uid " + uid);
1982 }
1983
1984 void checkCallerIsSystemOrSameApp(String pkg) {
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001985 int uid = Binder.getCallingUid();
Dianne Hackborn0c380492012-08-20 17:23:30 -07001986 if (UserHandle.getAppId(uid) == Process.SYSTEM_UID || uid == 0) {
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001987 return;
1988 }
1989 try {
Amith Yamasanif203aee2012-08-29 18:41:53 -07001990 ApplicationInfo ai = AppGlobals.getPackageManager().getApplicationInfo(
1991 pkg, 0, UserHandle.getCallingUserId());
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07001992 if (!UserHandle.isSameApp(ai.uid, uid)) {
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001993 throw new SecurityException("Calling uid " + uid + " gave package"
1994 + pkg + " which is owned by uid " + ai.uid);
1995 }
Amith Yamasanif203aee2012-08-29 18:41:53 -07001996 } catch (RemoteException re) {
1997 throw new SecurityException("Unknown package " + pkg + "\n" + re);
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001998 }
1999 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002000
Dianne Hackborn41203752012-08-31 14:05:51 -07002001 void cancelAll(int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002002 synchronized (mNotificationList) {
2003 final int N = mNotificationList.size();
2004 for (int i=N-1; i>=0; i--) {
2005 NotificationRecord r = mNotificationList.get(i);
2006
Daniel Sandler321e9c52012-10-12 10:59:26 -07002007 if (!notificationMatchesUserId(r, userId)) {
Dianne Hackborn41203752012-08-31 14:05:51 -07002008 continue;
2009 }
2010
Daniel Sandlerfde19b12013-01-17 00:21:05 -05002011 if ((r.getFlags() & (Notification.FLAG_ONGOING_EVENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002012 | Notification.FLAG_NO_CLEAR)) == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002013 mNotificationList.remove(i);
Joe Onorato46439ce2010-11-19 13:56:21 -08002014 cancelNotificationLocked(r, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002015 }
2016 }
2017
2018 updateLightsLocked();
2019 }
2020 }
2021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002022 // lock on mNotificationList
2023 private void updateLightsLocked()
2024 {
The Android Open Source Project10592532009-03-18 17:39:46 -07002025 // handle notification lights
2026 if (mLedNotification == null) {
2027 // get next notification, if any
2028 int n = mLights.size();
2029 if (n > 0) {
2030 mLedNotification = mLights.get(n-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002031 }
2032 }
Mike Lockwoodc22404a2009-12-02 11:15:02 -05002033
Mike Lockwood63b5ad92011-08-30 09:55:30 -04002034 // Don't flash while we are in a call or screen is on
2035 if (mLedNotification == null || mInCall || mScreenOn) {
Mike Lockwood3cb67a32009-11-27 14:25:58 -05002036 mNotificationLight.turnOff();
The Android Open Source Project10592532009-03-18 17:39:46 -07002037 } else {
Daniel Sandlerfde19b12013-01-17 00:21:05 -05002038 final Notification ledno = mLedNotification.sbn.notification;
2039 int ledARGB = ledno.ledARGB;
2040 int ledOnMS = ledno.ledOnMS;
2041 int ledOffMS = ledno.ledOffMS;
2042 if ((ledno.defaults & Notification.DEFAULT_LIGHTS) != 0) {
Mike Lockwood670f9322010-01-20 12:13:36 -05002043 ledARGB = mDefaultNotificationColor;
2044 ledOnMS = mDefaultNotificationLedOn;
2045 ledOffMS = mDefaultNotificationLedOff;
2046 }
2047 if (mNotificationPulseEnabled) {
2048 // pulse repeatedly
2049 mNotificationLight.setFlashing(ledARGB, LightsService.LIGHT_FLASH_TIMED,
2050 ledOnMS, ledOffMS);
Mike Lockwood670f9322010-01-20 12:13:36 -05002051 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002052 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002053 }
2054
2055 // lock on mNotificationList
Dianne Hackborn41203752012-08-31 14:05:51 -07002056 private int indexOfNotificationLocked(String pkg, String tag, int id, int userId)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002057 {
2058 ArrayList<NotificationRecord> list = mNotificationList;
2059 final int len = list.size();
2060 for (int i=0; i<len; i++) {
2061 NotificationRecord r = list.get(i);
Daniel Sandlerfde19b12013-01-17 00:21:05 -05002062 if (!notificationMatchesUserId(r, userId) || r.sbn.id != id) {
Dianne Hackborn41203752012-08-31 14:05:51 -07002063 continue;
2064 }
Fred Quintana6ecaff12009-09-25 14:23:13 -07002065 if (tag == null) {
Daniel Sandlerfde19b12013-01-17 00:21:05 -05002066 if (r.sbn.tag != null) {
Fred Quintana6ecaff12009-09-25 14:23:13 -07002067 continue;
2068 }
2069 } else {
Daniel Sandlerfde19b12013-01-17 00:21:05 -05002070 if (!tag.equals(r.sbn.tag)) {
Fred Quintana6ecaff12009-09-25 14:23:13 -07002071 continue;
2072 }
2073 }
Daniel Sandlerfde19b12013-01-17 00:21:05 -05002074 if (r.sbn.pkg.equals(pkg)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002075 return i;
2076 }
2077 }
2078 return -1;
2079 }
2080
Mike Lockwoodc22404a2009-12-02 11:15:02 -05002081 private void updateNotificationPulse() {
2082 synchronized (mNotificationList) {
2083 updateLightsLocked();
2084 }
2085 }
2086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002087 // ======================================================================
2088 @Override
2089 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
2090 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
2091 != PackageManager.PERMISSION_GRANTED) {
2092 pw.println("Permission Denial: can't dump NotificationManager from from pid="
2093 + Binder.getCallingPid()
2094 + ", uid=" + Binder.getCallingUid());
2095 return;
2096 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002098 pw.println("Current Notification Manager state:");
2099
Daniel Sandler5feceeb2013-03-22 18:29:23 -07002100 pw.println(" Listeners (" + mEnabledListenersForCurrentUser.size()
2101 + ") enabled for current user:");
2102 for (ComponentName cmpt : mEnabledListenersForCurrentUser) {
2103 pw.println(" " + cmpt);
Daniel Sandler4b749ef2013-03-18 21:53:04 -04002104 }
Daniel Sandler4b749ef2013-03-18 21:53:04 -04002105
Daniel Sandler5feceeb2013-03-22 18:29:23 -07002106 pw.println(" Live listeners (" + mListeners.size() + "):");
Daniel Sandler4b749ef2013-03-18 21:53:04 -04002107 for (NotificationListenerInfo info : mListeners) {
Daniel Sandler5feceeb2013-03-22 18:29:23 -07002108 pw.println(" " + info.component
2109 + " (user " + info.userid + "): " + info.listener
2110 + (info.isSystem?" SYSTEM":""));
Daniel Sandler4b749ef2013-03-18 21:53:04 -04002111 }
2112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002113 int N;
2114
2115 synchronized (mToastQueue) {
2116 N = mToastQueue.size();
2117 if (N > 0) {
2118 pw.println(" Toast Queue:");
2119 for (int i=0; i<N; i++) {
2120 mToastQueue.get(i).dump(pw, " ");
2121 }
2122 pw.println(" ");
2123 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002125 }
2126
2127 synchronized (mNotificationList) {
2128 N = mNotificationList.size();
2129 if (N > 0) {
2130 pw.println(" Notification List:");
2131 for (int i=0; i<N; i++) {
2132 mNotificationList.get(i).dump(pw, " ", mContext);
2133 }
2134 pw.println(" ");
2135 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002137 N = mLights.size();
2138 if (N > 0) {
2139 pw.println(" Lights List:");
2140 for (int i=0; i<N; i++) {
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002141 pw.println(" " + mLights.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002142 }
2143 pw.println(" ");
2144 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002146 pw.println(" mSoundNotification=" + mSoundNotification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002147 pw.println(" mVibrateNotification=" + mVibrateNotification);
Joe Onorato39f5b6a2009-07-23 12:29:19 -04002148 pw.println(" mDisabledNotifications=0x" + Integer.toHexString(mDisabledNotifications));
2149 pw.println(" mSystemReady=" + mSystemReady);
Daniel Sandler5e62e3a2013-04-15 20:57:02 -04002150 pw.println(" mArchive=" + mArchive.toString());
2151 Iterator<StatusBarNotification> iter = mArchive.descendingIterator();
2152 int i=0;
2153 while (iter.hasNext()) {
2154 pw.println(" " + iter.next());
2155 if (++i >= 5) {
2156 if (iter.hasNext()) pw.println(" ...");
2157 break;
2158 }
2159 }
2160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002161 }
2162 }
2163}