blob: 9f2685bbb6bb631ff2f2cb8d5a2e4f8f63be0b64 [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;
Daniel Sandler09a247e2013-02-14 10:24:17 -050029import android.app.INotificationListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.app.ITransientNotification;
31import android.app.Notification;
32import android.app.PendingIntent;
33import android.app.StatusBarManager;
34import android.content.BroadcastReceiver;
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;
Dianne Hackbornd8a43f62009-08-17 23:33:56 -070039import android.content.pm.ApplicationInfo;
Daniel Sandler4a900acd2013-01-30 14:04:10 -050040import android.content.pm.PackageInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.content.pm.PackageManager;
42import android.content.pm.PackageManager.NameNotFoundException;
43import android.content.res.Resources;
Dianne Hackborn1dac2772009-06-26 18:16:48 -070044import android.database.ContentObserver;
svetoslavganov75986cf2009-05-14 22:28:01 -070045import android.media.AudioManager;
Jeff Sharkey098d5802012-04-26 17:30:34 -070046import android.media.IAudioService;
47import android.media.IRingtonePlayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import android.net.Uri;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049import android.os.Binder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import android.os.IBinder;
52import android.os.Message;
Daniel Sandlerfde19b12013-01-17 00:21:05 -050053import android.os.Parcel;
54import android.os.Parcelable;
Dianne Hackbornd8a43f62009-08-17 23:33:56 -070055import android.os.Process;
svetoslavganov75986cf2009-05-14 22:28:01 -070056import android.os.RemoteException;
Jeff Sharkey098d5802012-04-26 17:30:34 -070057import android.os.ServiceManager;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070058import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059import android.os.Vibrator;
60import android.provider.Settings;
Daniel Sandlere96ffb12010-03-11 13:38:06 -050061import android.telephony.TelephonyManager;
svetoslavganov75986cf2009-05-14 22:28:01 -070062import android.text.TextUtils;
Dianne Hackborn39606a02012-07-31 17:54:35 -070063import android.util.AtomicFile;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import android.util.EventLog;
65import android.util.Log;
Andy Stadler110988c2010-12-03 14:29:16 -080066import android.util.Slog;
Daniel Sandler0da673f2012-04-11 12:33:16 -040067import android.util.Xml;
svetoslavganov75986cf2009-05-14 22:28:01 -070068import android.view.accessibility.AccessibilityEvent;
69import android.view.accessibility.AccessibilityManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070import android.widget.Toast;
71
Jeff Sharkey098d5802012-04-26 17:30:34 -070072import com.android.internal.statusbar.StatusBarNotification;
Jeff Sharkey098d5802012-04-26 17:30:34 -070073
74import org.xmlpull.v1.XmlPullParser;
75import org.xmlpull.v1.XmlPullParserException;
Jeff Sharkey098d5802012-04-26 17:30:34 -070076
Daniel Sandler0da673f2012-04-11 12:33:16 -040077import java.io.File;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078import java.io.FileDescriptor;
Daniel Sandler0da673f2012-04-11 12:33:16 -040079import java.io.FileInputStream;
80import java.io.FileNotFoundException;
Daniel Sandler0da673f2012-04-11 12:33:16 -040081import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082import java.io.PrintWriter;
Daniel Sandlerfde19b12013-01-17 00:21:05 -050083import java.util.ArrayDeque;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084import java.util.ArrayList;
85import java.util.Arrays;
Daniel Sandler0da673f2012-04-11 12:33:16 -040086import java.util.HashSet;
Daniel Sandlerfde19b12013-01-17 00:21:05 -050087import java.util.Iterator;
88import java.util.NoSuchElementException;
Daniel Sandler0da673f2012-04-11 12:33:16 -040089
90import libcore.io.IoUtils;
91
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092
Daniel Sandlerd0a2f862010-08-03 15:29:31 -040093/** {@hide} */
94public class NotificationManagerService extends INotificationManager.Stub
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095{
96 private static final String TAG = "NotificationService";
97 private static final boolean DBG = false;
98
Joe Onoratobd73d012010-06-04 11:44:54 -070099 private static final int MAX_PACKAGE_NOTIFICATIONS = 50;
100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101 // message codes
102 private static final int MESSAGE_TIMEOUT = 2;
103
104 private static final int LONG_DELAY = 3500; // 3.5 seconds
105 private static final int SHORT_DELAY = 2000; // 2 seconds
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800106
107 private static final long[] DEFAULT_VIBRATE_PATTERN = {0, 250, 250, 250};
Daniel Sandleredbb3802012-11-13 20:49:47 -0800108 private static final int VIBRATE_PATTERN_MAXLEN = 8 * 2 + 1; // up to eight bumps
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109
110 private static final int DEFAULT_STREAM_TYPE = AudioManager.STREAM_NOTIFICATION;
Daniel Sandler49a2ad12012-03-28 15:46:39 -0400111 private static final boolean SCORE_ONGOING_HIGHER = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112
Daniel Sandler0da673f2012-04-11 12:33:16 -0400113 private static final int JUNK_SCORE = -1000;
114 private static final int NOTIFICATION_PRIORITY_MULTIPLIER = 10;
115 private static final int SCORE_DISPLAY_THRESHOLD = Notification.PRIORITY_MIN * NOTIFICATION_PRIORITY_MULTIPLIER;
116
Daniel Sandler526fa0e2012-12-04 14:51:50 -0500117 // Notifications with scores below this will not interrupt the user, either via LED or
118 // sound or vibration
119 private static final int SCORE_INTERRUPTION_THRESHOLD =
120 Notification.PRIORITY_LOW * NOTIFICATION_PRIORITY_MULTIPLIER;
121
Daniel Sandler0da673f2012-04-11 12:33:16 -0400122 private static final boolean ENABLE_BLOCKED_NOTIFICATIONS = true;
123 private static final boolean ENABLE_BLOCKED_TOASTS = true;
124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 final Context mContext;
126 final IActivityManager mAm;
127 final IBinder mForegroundToken = new Binder();
128
129 private WorkerHandler mHandler;
Joe Onorato089de882010-04-12 08:18:45 -0700130 private StatusBarManagerService mStatusBar;
Mike Lockwood3cb67a32009-11-27 14:25:58 -0500131 private LightsService.Light mNotificationLight;
132 private LightsService.Light mAttentionLight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133
Mike Lockwood670f9322010-01-20 12:13:36 -0500134 private int mDefaultNotificationColor;
135 private int mDefaultNotificationLedOn;
136 private int mDefaultNotificationLedOff;
137
Daniel Sandleredbb3802012-11-13 20:49:47 -0800138 private long[] mDefaultVibrationPattern;
139 private long[] mFallbackVibrationPattern;
140
Joe Onorato30275482009-07-08 17:09:14 -0700141 private boolean mSystemReady;
Joe Onorato39f5b6a2009-07-23 12:29:19 -0400142 private int mDisabledNotifications;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143
Jeff Sharkey098d5802012-04-26 17:30:34 -0700144 private NotificationRecord mSoundNotification;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 private NotificationRecord mVibrateNotification;
Jeff Sharkey098d5802012-04-26 17:30:34 -0700146
147 private IAudioService mAudioService;
Jeff Brownc2346132012-04-13 01:55:38 -0700148 private Vibrator mVibrator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149
Mike Lockwoodc22404a2009-12-02 11:15:02 -0500150 // for enabling and disabling notification pulse behavior
Mike Lockwood63b5ad92011-08-30 09:55:30 -0400151 private boolean mScreenOn = true;
Daniel Sandlere96ffb12010-03-11 13:38:06 -0500152 private boolean mInCall = false;
Mike Lockwoodc22404a2009-12-02 11:15:02 -0500153 private boolean mNotificationPulseEnabled;
154
Daniel Sandler09a247e2013-02-14 10:24:17 -0500155 // used as a mutex for access to all active notifications & listeners
Fred Quintana6ecaff12009-09-25 14:23:13 -0700156 private final ArrayList<NotificationRecord> mNotificationList =
157 new ArrayList<NotificationRecord>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158
159 private ArrayList<ToastRecord> mToastQueue;
160
161 private ArrayList<NotificationRecord> mLights = new ArrayList<NotificationRecord>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 private NotificationRecord mLedNotification;
svetoslavganov75986cf2009-05-14 22:28:01 -0700163
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500164 private final AppOpsManager mAppOps;
165
Daniel Sandler09a247e2013-02-14 10:24:17 -0500166 private ArrayList<NotificationListenerInfo> mListeners = new ArrayList<NotificationListenerInfo>();
167
Daniel Sandler0da673f2012-04-11 12:33:16 -0400168 // Notification control database. For now just contains disabled packages.
169 private AtomicFile mPolicyFile;
170 private HashSet<String> mBlockedPackages = new HashSet<String>();
171
172 private static final int DB_VERSION = 1;
173
174 private static final String TAG_BODY = "notification-policy";
175 private static final String ATTR_VERSION = "version";
176
177 private static final String TAG_BLOCKED_PKGS = "blocked-packages";
178 private static final String TAG_PACKAGE = "package";
179 private static final String ATTR_NAME = "name";
180
Daniel Sandler09a247e2013-02-14 10:24:17 -0500181 private class NotificationListenerInfo implements DeathRecipient {
182 INotificationListener listener;
183 int userid;
184 public NotificationListenerInfo(INotificationListener listener, int userid) {
185 this.listener = listener;
186 this.userid = userid;
187 }
188
189 public void notifyPostedIfUserMatch(StatusBarNotification sbn) {
190 if (this.userid != sbn.getUserId()) return;
191 try {
192 listener.onNotificationPosted(sbn);
193 } catch (RemoteException ex) {
194 // not there?
195 }
196 }
197
198 public void notifyRemovedIfUserMatch(StatusBarNotification sbn) {
199 if (this.userid != sbn.getUserId()) return;
200 try {
201 listener.onNotificationRemoved(sbn);
202 } catch (RemoteException ex) {
203 // not there?
204 }
205 }
206
207 @Override
208 public void binderDied() {
209 unregisterListener(this.listener, this.userid);
210 }
211 }
212
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500213 private static class Archive {
214 static final int BUFFER_SIZE = 1000;
215 ArrayDeque<StatusBarNotification> mBuffer = new ArrayDeque<StatusBarNotification>(BUFFER_SIZE);
216
217 public Archive() {
218
219 }
220 public void record(StatusBarNotification nr) {
221 if (mBuffer.size() == BUFFER_SIZE) {
222 mBuffer.removeFirst();
223 }
224 mBuffer.addLast(nr);
225 }
226
227 public void clear() {
228 mBuffer.clear();
229 }
230
231 public Iterator<StatusBarNotification> descendingIterator() {
232 return mBuffer.descendingIterator();
233 }
234 public Iterator<StatusBarNotification> ascendingIterator() {
235 return mBuffer.iterator();
236 }
237 public Iterator<StatusBarNotification> filter(
238 final Iterator<StatusBarNotification> iter, final String pkg, final int userId) {
239 return new Iterator<StatusBarNotification>() {
240 StatusBarNotification mNext = findNext();
241
242 private StatusBarNotification findNext() {
243 while (iter.hasNext()) {
244 StatusBarNotification nr = iter.next();
245 if ((pkg == null || nr.pkg == pkg)
246 && (userId == UserHandle.USER_ALL || nr.getUserId() == userId)) {
247 return nr;
248 }
249 }
250 return null;
251 }
252
253 @Override
254 public boolean hasNext() {
255 return mNext == null;
256 }
257
258 @Override
259 public StatusBarNotification next() {
260 StatusBarNotification next = mNext;
261 if (next == null) {
262 throw new NoSuchElementException();
263 }
264 mNext = findNext();
265 return next;
266 }
267
268 @Override
269 public void remove() {
270 iter.remove();
271 }
272 };
273 }
Daniel Sandler78d0d252013-02-12 08:14:52 -0500274
275 public StatusBarNotification[] getArray(int count) {
276 if (count == 0) count = Archive.BUFFER_SIZE;
277 final StatusBarNotification[] a
278 = new StatusBarNotification[Math.min(count, mBuffer.size())];
279 Iterator<StatusBarNotification> iter = descendingIterator();
280 int i=0;
281 while (iter.hasNext() && i < count) {
282 a[i++] = iter.next();
283 }
284 return a;
285 }
286
287 public StatusBarNotification[] getArray(int count, String pkg, int userId) {
288 if (count == 0) count = Archive.BUFFER_SIZE;
289 final StatusBarNotification[] a
290 = new StatusBarNotification[Math.min(count, mBuffer.size())];
291 Iterator<StatusBarNotification> iter = filter(descendingIterator(), pkg, userId);
292 int i=0;
293 while (iter.hasNext() && i < count) {
294 a[i++] = iter.next();
295 }
296 return a;
297 }
298
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500299 }
300
301 Archive mArchive = new Archive();
302
Daniel Sandler0da673f2012-04-11 12:33:16 -0400303 private void loadBlockDb() {
304 synchronized(mBlockedPackages) {
305 if (mPolicyFile == null) {
306 File dir = new File("/data/system");
307 mPolicyFile = new AtomicFile(new File(dir, "notification_policy.xml"));
308
309 mBlockedPackages.clear();
310
311 FileInputStream infile = null;
312 try {
313 infile = mPolicyFile.openRead();
314 final XmlPullParser parser = Xml.newPullParser();
315 parser.setInput(infile, null);
316
317 int type;
318 String tag;
319 int version = DB_VERSION;
320 while ((type = parser.next()) != END_DOCUMENT) {
321 tag = parser.getName();
322 if (type == START_TAG) {
323 if (TAG_BODY.equals(tag)) {
324 version = Integer.parseInt(parser.getAttributeValue(null, ATTR_VERSION));
325 } else if (TAG_BLOCKED_PKGS.equals(tag)) {
326 while ((type = parser.next()) != END_DOCUMENT) {
327 tag = parser.getName();
328 if (TAG_PACKAGE.equals(tag)) {
329 mBlockedPackages.add(parser.getAttributeValue(null, ATTR_NAME));
330 } else if (TAG_BLOCKED_PKGS.equals(tag) && type == END_TAG) {
331 break;
332 }
333 }
334 }
335 }
336 }
337 } catch (FileNotFoundException e) {
338 // No data yet
339 } catch (IOException e) {
340 Log.wtf(TAG, "Unable to read blocked notifications database", e);
341 } catch (NumberFormatException e) {
342 Log.wtf(TAG, "Unable to parse blocked notifications database", e);
343 } catch (XmlPullParserException e) {
344 Log.wtf(TAG, "Unable to parse blocked notifications database", e);
345 } finally {
346 IoUtils.closeQuietly(infile);
347 }
348 }
349 }
350 }
351
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500352 /**
353 * Use this when you just want to know if notifications are OK for this package.
354 */
355 public boolean areNotificationsEnabledForPackage(String pkg, int uid) {
Daniel Sandler0da673f2012-04-11 12:33:16 -0400356 checkCallerIsSystem();
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500357 return (mAppOps.checkOpNoThrow(AppOpsManager.OP_POST_NOTIFICATION, uid, pkg)
358 == AppOpsManager.MODE_ALLOWED);
Daniel Sandler0da673f2012-04-11 12:33:16 -0400359 }
360
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500361 /** Use this when you actually want to post a notification or toast.
362 *
363 * Unchecked. Not exposed via Binder, but can be called in the course of enqueue*().
364 */
365 private boolean noteNotificationOp(String pkg, int uid) {
366 if (mAppOps.noteOpNoThrow(AppOpsManager.OP_POST_NOTIFICATION, uid, pkg)
367 != AppOpsManager.MODE_ALLOWED) {
368 Slog.v(TAG, "notifications are disabled by AppOps for " + pkg);
369 return false;
Daniel Sandler0da673f2012-04-11 12:33:16 -0400370 }
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500371 return true;
Daniel Sandler0da673f2012-04-11 12:33:16 -0400372 }
373
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500374 public void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled) {
Daniel Sandler0da673f2012-04-11 12:33:16 -0400375 checkCallerIsSystem();
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500376 if (true||DBG) {
Daniel Sandler0da673f2012-04-11 12:33:16 -0400377 Slog.v(TAG, (enabled?"en":"dis") + "abling notifications for " + pkg);
378 }
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500379 mAppOps.setMode(AppOpsManager.OP_POST_NOTIFICATION, uid, pkg,
380 enabled ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_IGNORED);
Daniel Sandler0da673f2012-04-11 12:33:16 -0400381 }
382
383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 private static String idDebugString(Context baseContext, String packageName, int id) {
385 Context c = null;
386
387 if (packageName != null) {
388 try {
389 c = baseContext.createPackageContext(packageName, 0);
390 } catch (NameNotFoundException e) {
391 c = baseContext;
392 }
393 } else {
394 c = baseContext;
395 }
396
397 String pkg;
398 String type;
399 String name;
400
401 Resources r = c.getResources();
402 try {
403 return r.getResourceName(id);
404 } catch (Resources.NotFoundException e) {
405 return "<name unknown>";
406 }
407 }
408
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500409 public StatusBarNotification[] getActiveNotifications(String callingPkg) {
410 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NOTIFICATIONS,
Daniel Sandler78d0d252013-02-12 08:14:52 -0500411 "NotificationManagerService.getActiveNotifications");
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500412
413 StatusBarNotification[] tmp = null;
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500414 int uid = Binder.getCallingUid();
415
416 if (mAppOps.noteOpNoThrow(AppOpsManager.OP_ACCESS_NOTIFICATIONS, uid, callingPkg)
417 == AppOpsManager.MODE_ALLOWED) {
418 synchronized (mNotificationList) {
419 tmp = new StatusBarNotification[mNotificationList.size()];
420 final int N = mNotificationList.size();
421 for (int i=0; i<N; i++) {
422 tmp[i] = mNotificationList.get(i).sbn;
423 }
424 }
425 }
426 return tmp;
427 }
428
Daniel Sandler78d0d252013-02-12 08:14:52 -0500429 public StatusBarNotification[] getHistoricalNotifications(String callingPkg, int count) {
430 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NOTIFICATIONS,
431 "NotificationManagerService.getHistoricalNotifications");
432
433 StatusBarNotification[] tmp = null;
434 int uid = Binder.getCallingUid();
435
436 if (mAppOps.noteOpNoThrow(AppOpsManager.OP_ACCESS_NOTIFICATIONS, uid, callingPkg)
437 == AppOpsManager.MODE_ALLOWED) {
438 synchronized (mArchive) {
439 tmp = mArchive.getArray(count);
440 }
441 }
442 return tmp;
443 }
444
Daniel Sandler09a247e2013-02-14 10:24:17 -0500445 @Override
446 public void registerListener(final INotificationListener listener, final int userid) {
447 checkCallerIsSystem();
448 synchronized (mNotificationList) {
449 try {
450 NotificationListenerInfo info = new NotificationListenerInfo(listener, userid);
451 listener.asBinder().linkToDeath(info, 0);
452 mListeners.add(info);
453 } catch (RemoteException e) {
454 // already dead
455 }
456 }
457 }
458
459 @Override
460 public void unregisterListener(INotificationListener listener, int userid) {
461 checkCallerIsSystem();
462 synchronized (mNotificationList) {
463 final int N = mListeners.size();
464 for (int i=N-1; i>=0; i--) {
465 final NotificationListenerInfo info = mListeners.get(i);
466 if (info.listener == listener && info.userid == userid) {
467 mListeners.remove(listener);
468 }
469 }
470 }
471 }
472
473 private void notifyPostedLocked(NotificationRecord n) {
474 final StatusBarNotification sbn = n.sbn;
475 for (final NotificationListenerInfo info : mListeners) {
476 mHandler.post(new Runnable() {
477 @Override
478 public void run() {
479 info.notifyPostedIfUserMatch(sbn);
480 }});
481 }
482 }
483
484 private void notifyRemovedLocked(NotificationRecord n) {
485 final StatusBarNotification sbn = n.sbn;
486 for (final NotificationListenerInfo info : mListeners) {
487 mHandler.post(new Runnable() {
488 @Override
489 public void run() {
490 info.notifyRemovedIfUserMatch(sbn);
491 }});
492 }
493 }
494
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500495 public static final class NotificationRecord
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 {
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500497 final StatusBarNotification sbn;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 IBinder statusBarKey;
499
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500500 NotificationRecord(StatusBarNotification sbn)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 {
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500502 this.sbn = sbn;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 }
Fred Quintana6ecaff12009-09-25 14:23:13 -0700504
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500505 public Notification getNotification() { return sbn.notification; }
506 public int getFlags() { return sbn.notification.flags; }
507 public int getUserId() { return sbn.getUserId(); }
508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509 void dump(PrintWriter pw, String prefix, Context baseContext) {
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500510 final Notification notification = sbn.notification;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 pw.println(prefix + this);
512 pw.println(prefix + " icon=0x" + Integer.toHexString(notification.icon)
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500513 + " / " + idDebugString(baseContext, this.sbn.pkg, notification.icon));
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500514 pw.println(prefix + " pri=" + notification.priority);
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500515 pw.println(prefix + " score=" + this.sbn.score);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 pw.println(prefix + " contentIntent=" + notification.contentIntent);
517 pw.println(prefix + " deleteIntent=" + notification.deleteIntent);
518 pw.println(prefix + " tickerText=" + notification.tickerText);
519 pw.println(prefix + " contentView=" + notification.contentView);
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500520 pw.println(prefix + " uid=" + this.sbn.uid + " userId=" + this.sbn.getUserId());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800521 pw.println(prefix + " defaults=0x" + Integer.toHexString(notification.defaults));
522 pw.println(prefix + " flags=0x" + Integer.toHexString(notification.flags));
523 pw.println(prefix + " sound=" + notification.sound);
524 pw.println(prefix + " vibrate=" + Arrays.toString(notification.vibrate));
525 pw.println(prefix + " ledARGB=0x" + Integer.toHexString(notification.ledARGB)
526 + " ledOnMS=" + notification.ledOnMS
527 + " ledOffMS=" + notification.ledOffMS);
528 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 @Override
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500531 public final String toString() {
532 return String.format(
533 "NotificationRecord(0x%08x: pkg=%s user=%s id=%d tag=%s score=%d: %s)",
534 System.identityHashCode(this),
535 this.sbn.pkg, this.sbn.user, this.sbn.id, this.sbn.tag,
536 this.sbn.score, this.sbn.notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800537 }
538 }
539
540 private static final class ToastRecord
541 {
542 final int pid;
543 final String pkg;
544 final ITransientNotification callback;
545 int duration;
546
547 ToastRecord(int pid, String pkg, ITransientNotification callback, int duration)
548 {
549 this.pid = pid;
550 this.pkg = pkg;
551 this.callback = callback;
552 this.duration = duration;
553 }
554
555 void update(int duration) {
556 this.duration = duration;
557 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800559 void dump(PrintWriter pw, String prefix) {
560 pw.println(prefix + this);
561 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 @Override
564 public final String toString()
565 {
566 return "ToastRecord{"
567 + Integer.toHexString(System.identityHashCode(this))
568 + " pkg=" + pkg
569 + " callback=" + callback
570 + " duration=" + duration;
571 }
572 }
573
Joe Onorato089de882010-04-12 08:18:45 -0700574 private StatusBarManagerService.NotificationCallbacks mNotificationCallbacks
575 = new StatusBarManagerService.NotificationCallbacks() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576
577 public void onSetDisabled(int status) {
578 synchronized (mNotificationList) {
579 mDisabledNotifications = status;
580 if ((mDisabledNotifications & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0) {
581 // cancel whatever's going on
582 long identity = Binder.clearCallingIdentity();
583 try {
Jeff Sharkey098d5802012-04-26 17:30:34 -0700584 final IRingtonePlayer player = mAudioService.getRingtonePlayer();
585 if (player != null) {
586 player.stopAsync();
587 }
588 } catch (RemoteException e) {
589 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 Binder.restoreCallingIdentity(identity);
591 }
592
593 identity = Binder.clearCallingIdentity();
594 try {
595 mVibrator.cancel();
Jeff Sharkey098d5802012-04-26 17:30:34 -0700596 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800597 Binder.restoreCallingIdentity(identity);
598 }
599 }
600 }
601 }
602
603 public void onClearAll() {
Dianne Hackborn41203752012-08-31 14:05:51 -0700604 // XXX to be totally correct, the caller should tell us which user
605 // this is for.
606 cancelAll(ActivityManager.getCurrentUser());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800607 }
608
Fred Quintana6ecaff12009-09-25 14:23:13 -0700609 public void onNotificationClick(String pkg, String tag, int id) {
Dianne Hackborn41203752012-08-31 14:05:51 -0700610 // XXX to be totally correct, the caller should tell us which user
611 // this is for.
Fred Quintana6ecaff12009-09-25 14:23:13 -0700612 cancelNotification(pkg, tag, id, Notification.FLAG_AUTO_CANCEL,
Dianne Hackborn41203752012-08-31 14:05:51 -0700613 Notification.FLAG_FOREGROUND_SERVICE, false,
614 ActivityManager.getCurrentUser());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800615 }
616
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400617 public void onNotificationClear(String pkg, String tag, int id) {
Dianne Hackborn41203752012-08-31 14:05:51 -0700618 // XXX to be totally correct, the caller should tell us which user
619 // this is for.
Joe Onorato46439ce2010-11-19 13:56:21 -0800620 cancelNotification(pkg, tag, id, 0,
621 Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE,
Dianne Hackborn41203752012-08-31 14:05:51 -0700622 true, ActivityManager.getCurrentUser());
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400623 }
624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800625 public void onPanelRevealed() {
626 synchronized (mNotificationList) {
627 // sound
628 mSoundNotification = null;
Jeff Sharkey098d5802012-04-26 17:30:34 -0700629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800630 long identity = Binder.clearCallingIdentity();
631 try {
Jeff Sharkey098d5802012-04-26 17:30:34 -0700632 final IRingtonePlayer player = mAudioService.getRingtonePlayer();
633 if (player != null) {
634 player.stopAsync();
635 }
636 } catch (RemoteException e) {
637 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638 Binder.restoreCallingIdentity(identity);
639 }
640
641 // vibrate
642 mVibrateNotification = null;
643 identity = Binder.clearCallingIdentity();
644 try {
645 mVibrator.cancel();
Jeff Sharkey098d5802012-04-26 17:30:34 -0700646 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800647 Binder.restoreCallingIdentity(identity);
648 }
649
650 // light
651 mLights.clear();
652 mLedNotification = null;
653 updateLightsLocked();
654 }
655 }
Joe Onorato005847b2010-06-04 16:08:02 -0400656
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700657 public void onNotificationError(String pkg, String tag, int id,
658 int uid, int initialPid, String message) {
Daniel Sandlerd0a2f862010-08-03 15:29:31 -0400659 Slog.d(TAG, "onNotification error pkg=" + pkg + " tag=" + tag + " id=" + id
660 + "; will crashApplication(uid=" + uid + ", pid=" + initialPid + ")");
Dianne Hackborn41203752012-08-31 14:05:51 -0700661 // XXX to be totally correct, the caller should tell us which user
662 // this is for.
663 cancelNotification(pkg, tag, id, 0, 0, false, UserHandle.getUserId(uid));
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700664 long ident = Binder.clearCallingIdentity();
665 try {
666 ActivityManagerNative.getDefault().crashApplication(uid, initialPid, pkg,
667 "Bad notification posted from package " + pkg
668 + ": " + message);
669 } catch (RemoteException e) {
670 }
671 Binder.restoreCallingIdentity(ident);
Joe Onorato005847b2010-06-04 16:08:02 -0400672 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 };
674
675 private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
676 @Override
677 public void onReceive(Context context, Intent intent) {
678 String action = intent.getAction();
679
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800680 boolean queryRestart = false;
Daniel Sandler26ece572012-06-01 15:38:46 -0400681 boolean packageChanged = false;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800682
Mike Lockwood541c9942011-06-12 19:35:45 -0400683 if (action.equals(Intent.ACTION_PACKAGE_REMOVED)
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800684 || action.equals(Intent.ACTION_PACKAGE_RESTARTED)
Daniel Sandler26ece572012-06-01 15:38:46 -0400685 || (packageChanged=action.equals(Intent.ACTION_PACKAGE_CHANGED))
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800686 || (queryRestart=action.equals(Intent.ACTION_QUERY_PACKAGE_RESTART))
Suchi Amalapurapub56ae202010-02-04 22:51:07 -0800687 || action.equals(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)) {
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800688 String pkgList[] = null;
Suchi Amalapurapub56ae202010-02-04 22:51:07 -0800689 if (action.equals(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)) {
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800690 pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800691 } else if (queryRestart) {
692 pkgList = intent.getStringArrayExtra(Intent.EXTRA_PACKAGES);
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800693 } else {
694 Uri uri = intent.getData();
695 if (uri == null) {
696 return;
697 }
698 String pkgName = uri.getSchemeSpecificPart();
699 if (pkgName == null) {
700 return;
701 }
Daniel Sandler26ece572012-06-01 15:38:46 -0400702 if (packageChanged) {
703 // We cancel notifications for packages which have just been disabled
704 final int enabled = mContext.getPackageManager()
705 .getApplicationEnabledSetting(pkgName);
706 if (enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED
707 || enabled == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
708 return;
709 }
710 }
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800711 pkgList = new String[]{pkgName};
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800712 }
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800713 if (pkgList != null && (pkgList.length > 0)) {
714 for (String pkgName : pkgList) {
Dianne Hackborn41203752012-08-31 14:05:51 -0700715 cancelAllNotificationsInt(pkgName, 0, 0, !queryRestart,
716 UserHandle.USER_ALL);
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800717 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800718 }
Mike Lockwood63b5ad92011-08-30 09:55:30 -0400719 } else if (action.equals(Intent.ACTION_SCREEN_ON)) {
720 // Keep track of screen on/off state, but do not turn off the notification light
721 // until user passes through the lock screen or views the notification.
722 mScreenOn = true;
723 } else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
724 mScreenOn = false;
Daniel Sandlere96ffb12010-03-11 13:38:06 -0500725 } else if (action.equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
Mike Lockwood63b5ad92011-08-30 09:55:30 -0400726 mInCall = (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
727 TelephonyManager.EXTRA_STATE_OFFHOOK));
Daniel Sandlere96ffb12010-03-11 13:38:06 -0500728 updateNotificationPulse();
Dianne Hackborn80a4af22012-08-27 19:18:31 -0700729 } else if (action.equals(Intent.ACTION_USER_STOPPED)) {
730 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
731 if (userHandle >= 0) {
Dianne Hackborn41203752012-08-31 14:05:51 -0700732 cancelAllNotificationsInt(null, 0, 0, true, userHandle);
Dianne Hackborn80a4af22012-08-27 19:18:31 -0700733 }
Mike Lockwood63b5ad92011-08-30 09:55:30 -0400734 } else if (action.equals(Intent.ACTION_USER_PRESENT)) {
735 // turn off LED when user passes through lock screen
736 mNotificationLight.turnOff();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737 }
738 }
739 };
740
Dianne Hackborn1dac2772009-06-26 18:16:48 -0700741 class SettingsObserver extends ContentObserver {
742 SettingsObserver(Handler handler) {
743 super(handler);
744 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800745
Dianne Hackborn1dac2772009-06-26 18:16:48 -0700746 void observe() {
747 ContentResolver resolver = mContext.getContentResolver();
Mike Lockwoodc22404a2009-12-02 11:15:02 -0500748 resolver.registerContentObserver(Settings.System.getUriFor(
749 Settings.System.NOTIFICATION_LIGHT_PULSE), false, this);
Dianne Hackborn1dac2772009-06-26 18:16:48 -0700750 update();
751 }
752
753 @Override public void onChange(boolean selfChange) {
754 update();
755 }
756
757 public void update() {
758 ContentResolver resolver = mContext.getContentResolver();
Mike Lockwoodc22404a2009-12-02 11:15:02 -0500759 boolean pulseEnabled = Settings.System.getInt(resolver,
760 Settings.System.NOTIFICATION_LIGHT_PULSE, 0) != 0;
761 if (mNotificationPulseEnabled != pulseEnabled) {
762 mNotificationPulseEnabled = pulseEnabled;
763 updateNotificationPulse();
764 }
Dianne Hackborn1dac2772009-06-26 18:16:48 -0700765 }
766 }
Mike Lockwoodc22404a2009-12-02 11:15:02 -0500767
Daniel Sandleredbb3802012-11-13 20:49:47 -0800768 static long[] getLongArray(Resources r, int resid, int maxlen, long[] def) {
769 int[] ar = r.getIntArray(resid);
770 if (ar == null) {
771 return def;
772 }
773 final int len = ar.length > maxlen ? maxlen : ar.length;
774 long[] out = new long[len];
775 for (int i=0; i<len; i++) {
776 out[i] = ar[i];
777 }
778 return out;
779 }
780
Joe Onorato089de882010-04-12 08:18:45 -0700781 NotificationManagerService(Context context, StatusBarManagerService statusBar,
Mike Lockwood3a322132009-11-24 00:30:52 -0500782 LightsService lights)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800783 {
784 super();
785 mContext = context;
Jeff Brownc2346132012-04-13 01:55:38 -0700786 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800787 mAm = ActivityManagerNative.getDefault();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800788 mToastQueue = new ArrayList<ToastRecord>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800789 mHandler = new WorkerHandler();
San Mehat3ee13172010-02-04 20:54:43 -0800790
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500791 mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE);
792
793 importOldBlockDb();
Daniel Sandler0da673f2012-04-11 12:33:16 -0400794
Joe Onorato089de882010-04-12 08:18:45 -0700795 mStatusBar = statusBar;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800796 statusBar.setNotificationCallbacks(mNotificationCallbacks);
797
Mike Lockwood3cb67a32009-11-27 14:25:58 -0500798 mNotificationLight = lights.getLight(LightsService.LIGHT_ID_NOTIFICATIONS);
799 mAttentionLight = lights.getLight(LightsService.LIGHT_ID_ATTENTION);
800
Mike Lockwood670f9322010-01-20 12:13:36 -0500801 Resources resources = mContext.getResources();
802 mDefaultNotificationColor = resources.getColor(
803 com.android.internal.R.color.config_defaultNotificationColor);
804 mDefaultNotificationLedOn = resources.getInteger(
805 com.android.internal.R.integer.config_defaultNotificationLedOn);
806 mDefaultNotificationLedOff = resources.getInteger(
807 com.android.internal.R.integer.config_defaultNotificationLedOff);
808
Daniel Sandleredbb3802012-11-13 20:49:47 -0800809 mDefaultVibrationPattern = getLongArray(resources,
810 com.android.internal.R.array.config_defaultNotificationVibePattern,
811 VIBRATE_PATTERN_MAXLEN,
812 DEFAULT_VIBRATE_PATTERN);
813
814 mFallbackVibrationPattern = getLongArray(resources,
815 com.android.internal.R.array.config_notificationFallbackVibePattern,
816 VIBRATE_PATTERN_MAXLEN,
817 DEFAULT_VIBRATE_PATTERN);
818
Joe Onorato39f5b6a2009-07-23 12:29:19 -0400819 // Don't start allowing notifications until the setup wizard has run once.
820 // After that, including subsequent boots, init with notifications turned on.
821 // This works on the first boot because the setup wizard will toggle this
822 // flag at least once and we'll go back to 0 after that.
Jeff Brownbf6f6f92012-09-25 15:03:20 -0700823 if (0 == Settings.Global.getInt(mContext.getContentResolver(),
824 Settings.Global.DEVICE_PROVISIONED, 0)) {
Joe Onorato39f5b6a2009-07-23 12:29:19 -0400825 mDisabledNotifications = StatusBarManager.DISABLE_NOTIFICATION_ALERTS;
826 }
827
Mike Lockwood35e16bf2010-11-30 19:53:36 -0500828 // register for various Intents
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800829 IntentFilter filter = new IntentFilter();
Mike Lockwoodc22404a2009-12-02 11:15:02 -0500830 filter.addAction(Intent.ACTION_SCREEN_ON);
831 filter.addAction(Intent.ACTION_SCREEN_OFF);
Daniel Sandlere96ffb12010-03-11 13:38:06 -0500832 filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Mike Lockwood63b5ad92011-08-30 09:55:30 -0400833 filter.addAction(Intent.ACTION_USER_PRESENT);
Dianne Hackborn80a4af22012-08-27 19:18:31 -0700834 filter.addAction(Intent.ACTION_USER_STOPPED);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800835 mContext.registerReceiver(mIntentReceiver, filter);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800836 IntentFilter pkgFilter = new IntentFilter();
837 pkgFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
Daniel Sandleraac0eb02011-08-06 22:51:56 -0400838 pkgFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800839 pkgFilter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
840 pkgFilter.addAction(Intent.ACTION_QUERY_PACKAGE_RESTART);
841 pkgFilter.addDataScheme("package");
842 mContext.registerReceiver(mIntentReceiver, pkgFilter);
Suchi Amalapurapub56ae202010-02-04 22:51:07 -0800843 IntentFilter sdFilter = new IntentFilter(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800844 mContext.registerReceiver(mIntentReceiver, sdFilter);
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800845
Mike Lockwoodc22404a2009-12-02 11:15:02 -0500846 SettingsObserver observer = new SettingsObserver(mHandler);
847 observer.observe();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800848 }
849
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500850 /**
851 * Read the old XML-based app block database and import those blockages into the AppOps system.
852 */
853 private void importOldBlockDb() {
854 loadBlockDb();
855
856 PackageManager pm = mContext.getPackageManager();
857 for (String pkg : mBlockedPackages) {
858 PackageInfo info = null;
859 try {
860 info = pm.getPackageInfo(pkg, 0);
861 setNotificationsEnabledForPackage(pkg, info.applicationInfo.uid, false);
862 } catch (NameNotFoundException e) {
863 // forget you
864 }
865 }
866 mBlockedPackages.clear();
867 if (mPolicyFile != null) {
868 mPolicyFile.delete();
869 }
870 }
871
Joe Onorato30275482009-07-08 17:09:14 -0700872 void systemReady() {
Jeff Sharkey098d5802012-04-26 17:30:34 -0700873 mAudioService = IAudioService.Stub.asInterface(
874 ServiceManager.getService(Context.AUDIO_SERVICE));
875
Joe Onorato30275482009-07-08 17:09:14 -0700876 // no beeping until we're basically done booting
877 mSystemReady = true;
878 }
879
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800880 // Toasts
881 // ============================================================================
882 public void enqueueToast(String pkg, ITransientNotification callback, int duration)
883 {
Daniel Sandlera7035902010-03-30 15:45:31 -0400884 if (DBG) Slog.i(TAG, "enqueueToast pkg=" + pkg + " callback=" + callback + " duration=" + duration);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800885
886 if (pkg == null || callback == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800887 Slog.e(TAG, "Not doing toast. pkg=" + pkg + " callback=" + callback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800888 return ;
889 }
890
Daniel Sandler0da673f2012-04-11 12:33:16 -0400891 final boolean isSystemToast = ("android".equals(pkg));
892
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500893 if (ENABLE_BLOCKED_TOASTS && !noteNotificationOp(pkg, Binder.getCallingUid())) {
894 if (!isSystemToast) {
895 Slog.e(TAG, "Suppressing toast from package " + pkg + " by user request.");
896 return;
897 }
Daniel Sandler0da673f2012-04-11 12:33:16 -0400898 }
899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800900 synchronized (mToastQueue) {
901 int callingPid = Binder.getCallingPid();
902 long callingId = Binder.clearCallingIdentity();
903 try {
904 ToastRecord record;
905 int index = indexOfToastLocked(pkg, callback);
906 // If it's already in the queue, we update it in place, we don't
907 // move it to the end of the queue.
908 if (index >= 0) {
909 record = mToastQueue.get(index);
910 record.update(duration);
911 } else {
Vairavan Srinivasanf9eb06c2011-01-21 18:08:36 -0800912 // Limit the number of toasts that any given package except the android
913 // package can enqueue. Prevents DOS attacks and deals with leaks.
Daniel Sandler0da673f2012-04-11 12:33:16 -0400914 if (!isSystemToast) {
Vairavan Srinivasanf9eb06c2011-01-21 18:08:36 -0800915 int count = 0;
916 final int N = mToastQueue.size();
917 for (int i=0; i<N; i++) {
918 final ToastRecord r = mToastQueue.get(i);
919 if (r.pkg.equals(pkg)) {
920 count++;
921 if (count >= MAX_PACKAGE_NOTIFICATIONS) {
922 Slog.e(TAG, "Package has already posted " + count
923 + " toasts. Not showing more. Package=" + pkg);
924 return;
925 }
926 }
927 }
928 }
929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 record = new ToastRecord(callingPid, pkg, callback, duration);
931 mToastQueue.add(record);
932 index = mToastQueue.size() - 1;
933 keepProcessAliveLocked(callingPid);
934 }
935 // If it's at index 0, it's the current toast. It doesn't matter if it's
936 // new or just been updated. Call back and tell it to show itself.
937 // If the callback fails, this will remove it from the list, so don't
938 // assume that it's valid after this.
939 if (index == 0) {
940 showNextToastLocked();
941 }
942 } finally {
943 Binder.restoreCallingIdentity(callingId);
944 }
945 }
946 }
947
948 public void cancelToast(String pkg, ITransientNotification callback) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800949 Slog.i(TAG, "cancelToast pkg=" + pkg + " callback=" + callback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950
951 if (pkg == null || callback == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800952 Slog.e(TAG, "Not cancelling notification. pkg=" + pkg + " callback=" + callback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800953 return ;
954 }
955
956 synchronized (mToastQueue) {
957 long callingId = Binder.clearCallingIdentity();
958 try {
959 int index = indexOfToastLocked(pkg, callback);
960 if (index >= 0) {
961 cancelToastLocked(index);
962 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800963 Slog.w(TAG, "Toast already cancelled. pkg=" + pkg + " callback=" + callback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800964 }
965 } finally {
966 Binder.restoreCallingIdentity(callingId);
967 }
968 }
969 }
970
971 private void showNextToastLocked() {
972 ToastRecord record = mToastQueue.get(0);
973 while (record != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800974 if (DBG) Slog.d(TAG, "Show pkg=" + record.pkg + " callback=" + record.callback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800975 try {
976 record.callback.show();
977 scheduleTimeoutLocked(record, false);
978 return;
979 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800980 Slog.w(TAG, "Object died trying to show notification " + record.callback
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800981 + " in package " + record.pkg);
982 // remove it from the list and let the process die
983 int index = mToastQueue.indexOf(record);
984 if (index >= 0) {
985 mToastQueue.remove(index);
986 }
987 keepProcessAliveLocked(record.pid);
988 if (mToastQueue.size() > 0) {
989 record = mToastQueue.get(0);
990 } else {
991 record = null;
992 }
993 }
994 }
995 }
996
997 private void cancelToastLocked(int index) {
998 ToastRecord record = mToastQueue.get(index);
999 try {
1000 record.callback.hide();
1001 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001002 Slog.w(TAG, "Object died trying to hide notification " + record.callback
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001003 + " in package " + record.pkg);
1004 // don't worry about this, we're about to remove it from
1005 // the list anyway
1006 }
1007 mToastQueue.remove(index);
1008 keepProcessAliveLocked(record.pid);
1009 if (mToastQueue.size() > 0) {
1010 // Show the next one. If the callback fails, this will remove
1011 // it from the list, so don't assume that the list hasn't changed
1012 // after this point.
1013 showNextToastLocked();
1014 }
1015 }
1016
1017 private void scheduleTimeoutLocked(ToastRecord r, boolean immediate)
1018 {
1019 Message m = Message.obtain(mHandler, MESSAGE_TIMEOUT, r);
1020 long delay = immediate ? 0 : (r.duration == Toast.LENGTH_LONG ? LONG_DELAY : SHORT_DELAY);
1021 mHandler.removeCallbacksAndMessages(r);
1022 mHandler.sendMessageDelayed(m, delay);
1023 }
1024
1025 private void handleTimeout(ToastRecord record)
1026 {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001027 if (DBG) Slog.d(TAG, "Timeout pkg=" + record.pkg + " callback=" + record.callback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001028 synchronized (mToastQueue) {
1029 int index = indexOfToastLocked(record.pkg, record.callback);
1030 if (index >= 0) {
1031 cancelToastLocked(index);
1032 }
1033 }
1034 }
1035
1036 // lock on mToastQueue
1037 private int indexOfToastLocked(String pkg, ITransientNotification callback)
1038 {
1039 IBinder cbak = callback.asBinder();
1040 ArrayList<ToastRecord> list = mToastQueue;
1041 int len = list.size();
1042 for (int i=0; i<len; i++) {
1043 ToastRecord r = list.get(i);
1044 if (r.pkg.equals(pkg) && r.callback.asBinder() == cbak) {
1045 return i;
1046 }
1047 }
1048 return -1;
1049 }
1050
1051 // lock on mToastQueue
1052 private void keepProcessAliveLocked(int pid)
1053 {
1054 int toastCount = 0; // toasts from this pid
1055 ArrayList<ToastRecord> list = mToastQueue;
1056 int N = list.size();
1057 for (int i=0; i<N; i++) {
1058 ToastRecord r = list.get(i);
1059 if (r.pid == pid) {
1060 toastCount++;
1061 }
1062 }
1063 try {
1064 mAm.setProcessForeground(mForegroundToken, pid, toastCount > 0);
1065 } catch (RemoteException e) {
1066 // Shouldn't happen.
1067 }
1068 }
1069
1070 private final class WorkerHandler extends Handler
1071 {
1072 @Override
1073 public void handleMessage(Message msg)
1074 {
1075 switch (msg.what)
1076 {
1077 case MESSAGE_TIMEOUT:
1078 handleTimeout((ToastRecord)msg.obj);
1079 break;
1080 }
1081 }
1082 }
1083
1084
1085 // Notifications
1086 // ============================================================================
Dianne Hackbornf265ea92013-01-31 15:00:51 -08001087 public void enqueueNotificationWithTag(String pkg, String basePkg, String tag, int id,
1088 Notification notification, int[] idOut, int userId)
Fred Quintana6ecaff12009-09-25 14:23:13 -07001089 {
Dianne Hackbornf265ea92013-01-31 15:00:51 -08001090 enqueueNotificationInternal(pkg, basePkg, Binder.getCallingUid(), Binder.getCallingPid(),
Dianne Hackborn41203752012-08-31 14:05:51 -07001091 tag, id, notification, idOut, userId);
Daniel Sandlerd0a2f862010-08-03 15:29:31 -04001092 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001093
1094 private final static int clamp(int x, int low, int high) {
1095 return (x < low) ? low : ((x > high) ? high : x);
Daniel Sandlere40451a2011-02-03 14:51:35 -05001096 }
1097
Daniel Sandlerd0a2f862010-08-03 15:29:31 -04001098 // Not exposed via Binder; for system use only (otherwise malicious apps could spoof the
1099 // uid/pid of another application)
Dianne Hackbornf265ea92013-01-31 15:00:51 -08001100 public void enqueueNotificationInternal(String pkg, String basePkg, int callingUid,
1101 int callingPid, String tag, int id, Notification notification, int[] idOut, int userId)
Daniel Sandlerd0a2f862010-08-03 15:29:31 -04001102 {
Daniel Sandler0da673f2012-04-11 12:33:16 -04001103 if (DBG) {
1104 Slog.v(TAG, "enqueueNotificationInternal: pkg=" + pkg + " id=" + id + " notification=" + notification);
1105 }
1106 checkCallerIsSystemOrSameApp(pkg);
1107 final boolean isSystemNotification = ("android".equals(pkg));
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001108
Dianne Hackborn41203752012-08-31 14:05:51 -07001109 userId = ActivityManager.handleIncomingUser(callingPid,
Amith Yamasani2c7ebea2012-10-30 15:28:27 -07001110 callingUid, userId, true, false, "enqueueNotification", pkg);
Jeff Sharkey65c4a2b2012-09-25 17:22:27 -07001111 final UserHandle user = new UserHandle(userId);
Dianne Hackborn41203752012-08-31 14:05:51 -07001112
Joe Onoratobd73d012010-06-04 11:44:54 -07001113 // Limit the number of notifications that any given package except the android
1114 // package can enqueue. Prevents DOS attacks and deals with leaks.
Daniel Sandler0da673f2012-04-11 12:33:16 -04001115 if (!isSystemNotification) {
Joe Onoratobd73d012010-06-04 11:44:54 -07001116 synchronized (mNotificationList) {
1117 int count = 0;
1118 final int N = mNotificationList.size();
1119 for (int i=0; i<N; i++) {
1120 final NotificationRecord r = mNotificationList.get(i);
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001121 if (r.sbn.pkg.equals(pkg) && r.sbn.getUserId() == userId) {
Joe Onoratobd73d012010-06-04 11:44:54 -07001122 count++;
1123 if (count >= MAX_PACKAGE_NOTIFICATIONS) {
1124 Slog.e(TAG, "Package has already posted " + count
1125 + " notifications. Not showing more. package=" + pkg);
1126 return;
1127 }
1128 }
1129 }
1130 }
1131 }
1132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001133 // This conditional is a dirty hack to limit the logging done on
1134 // behalf of the download manager without affecting other apps.
1135 if (!pkg.equals("com.android.providers.downloads")
1136 || Log.isLoggable("DownloadManager", Log.VERBOSE)) {
Daniel Sandler321e9c52012-10-12 10:59:26 -07001137 EventLog.writeEvent(EventLogTags.NOTIFICATION_ENQUEUE, pkg, id, tag, userId,
Daniel Sandlerb64cb882011-11-29 23:48:29 -05001138 notification.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001139 }
1140
1141 if (pkg == null || notification == null) {
1142 throw new IllegalArgumentException("null not allowed: pkg=" + pkg
1143 + " id=" + id + " notification=" + notification);
1144 }
1145 if (notification.icon != 0) {
1146 if (notification.contentView == null) {
1147 throw new IllegalArgumentException("contentView required: pkg=" + pkg
1148 + " id=" + id + " notification=" + notification);
1149 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001150 }
1151
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001152 // === Scoring ===
Daniel Sandler0da673f2012-04-11 12:33:16 -04001153
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001154 // 0. Sanitize inputs
1155 notification.priority = clamp(notification.priority, Notification.PRIORITY_MIN, Notification.PRIORITY_MAX);
1156 // Migrate notification flags to scores
1157 if (0 != (notification.flags & Notification.FLAG_HIGH_PRIORITY)) {
1158 if (notification.priority < Notification.PRIORITY_MAX) notification.priority = Notification.PRIORITY_MAX;
Daniel Sandler49a2ad12012-03-28 15:46:39 -04001159 } else if (SCORE_ONGOING_HIGHER && 0 != (notification.flags & Notification.FLAG_ONGOING_EVENT)) {
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001160 if (notification.priority < Notification.PRIORITY_HIGH) notification.priority = Notification.PRIORITY_HIGH;
1161 }
Daniel Sandler0da673f2012-04-11 12:33:16 -04001162
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001163 // 1. initial score: buckets of 10, around the app
Daniel Sandler0da673f2012-04-11 12:33:16 -04001164 int score = notification.priority * NOTIFICATION_PRIORITY_MULTIPLIER; //[-20..20]
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001165
Daniel Sandler0da673f2012-04-11 12:33:16 -04001166 // 2. Consult external heuristics (TBD)
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001167
Daniel Sandler0da673f2012-04-11 12:33:16 -04001168 // 3. Apply local rules
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001169
1170 // blocked apps
Daniel Sandler4a900acd2013-01-30 14:04:10 -05001171 if (ENABLE_BLOCKED_NOTIFICATIONS && !noteNotificationOp(pkg, callingUid)) {
1172 if (!isSystemNotification) {
1173 score = JUNK_SCORE;
1174 Slog.e(TAG, "Suppressing notification from package " + pkg + " by user request.");
1175 }
Daniel Sandler0da673f2012-04-11 12:33:16 -04001176 }
1177
1178 if (DBG) {
1179 Slog.v(TAG, "Assigned score=" + score + " to " + notification);
1180 }
1181
1182 if (score < SCORE_DISPLAY_THRESHOLD) {
1183 // Notification will be blocked because the score is too low.
1184 return;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001185 }
1186
Daniel Sandler526fa0e2012-12-04 14:51:50 -05001187 // Should this notification make noise, vibe, or use the LED?
1188 final boolean canInterrupt = (score >= SCORE_INTERRUPTION_THRESHOLD);
1189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001190 synchronized (mNotificationList) {
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001191 final StatusBarNotification n = new StatusBarNotification(
1192 pkg, id, tag, callingUid, callingPid, score, notification, user);
1193 NotificationRecord r = new NotificationRecord(n);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001194 NotificationRecord old = null;
1195
Dianne Hackborn41203752012-08-31 14:05:51 -07001196 int index = indexOfNotificationLocked(pkg, tag, id, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197 if (index < 0) {
1198 mNotificationList.add(r);
1199 } else {
1200 old = mNotificationList.remove(index);
1201 mNotificationList.add(index, r);
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001202 // Make sure we don't lose the foreground service state.
1203 if (old != null) {
1204 notification.flags |=
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001205 old.getNotification().flags&Notification.FLAG_FOREGROUND_SERVICE;
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001206 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001207 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001208
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001209 // Ensure if this is a foreground service that the proper additional
1210 // flags are set.
1211 if ((notification.flags&Notification.FLAG_FOREGROUND_SERVICE) != 0) {
1212 notification.flags |= Notification.FLAG_ONGOING_EVENT
1213 | Notification.FLAG_NO_CLEAR;
1214 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001215
Svetoslav Ganovc31ed392012-10-10 14:58:28 -07001216 final int currentUser;
1217 final long token = Binder.clearCallingIdentity();
1218 try {
1219 currentUser = ActivityManager.getCurrentUser();
1220 } finally {
1221 Binder.restoreCallingIdentity(token);
1222 }
1223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 if (notification.icon != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001225 if (old != null && old.statusBarKey != null) {
1226 r.statusBarKey = old.statusBarKey;
1227 long identity = Binder.clearCallingIdentity();
1228 try {
Joe Onorato18e69df2010-05-17 22:26:12 -07001229 mStatusBar.updateNotification(r.statusBarKey, n);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001230 }
1231 finally {
1232 Binder.restoreCallingIdentity(identity);
1233 }
1234 } else {
1235 long identity = Binder.clearCallingIdentity();
1236 try {
Joe Onorato18e69df2010-05-17 22:26:12 -07001237 r.statusBarKey = mStatusBar.addNotification(n);
Daniel Sandler526fa0e2012-12-04 14:51:50 -05001238 if ((n.notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0
1239 && canInterrupt) {
Mike Lockwoodece18ef2012-02-13 20:42:19 -08001240 mAttentionLight.pulse();
1241 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001242 }
1243 finally {
1244 Binder.restoreCallingIdentity(identity);
1245 }
1246 }
Svetoslav Ganovc31ed392012-10-10 14:58:28 -07001247 // Send accessibility events only for the current user.
1248 if (currentUser == userId) {
1249 sendAccessibilityEvent(notification, pkg);
1250 }
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001251
1252 // finally, keep some of this information around for later use
1253 mArchive.record(n);
Daniel Sandler09a247e2013-02-14 10:24:17 -05001254
1255 notifyPostedLocked(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256 } else {
Daniel Sandlere40451a2011-02-03 14:51:35 -05001257 Slog.e(TAG, "Ignoring notification with icon==0: " + notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001258 if (old != null && old.statusBarKey != null) {
1259 long identity = Binder.clearCallingIdentity();
1260 try {
Joe Onorato0cbda992010-05-02 16:28:15 -07001261 mStatusBar.removeNotification(old.statusBarKey);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001262 }
1263 finally {
1264 Binder.restoreCallingIdentity(identity);
1265 }
Daniel Sandler09a247e2013-02-14 10:24:17 -05001266
1267 notifyRemovedLocked(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001268 }
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001269 return; // do not play sounds, show lights, etc. for invalid notifications
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001270 }
1271
1272 // If we're not supposed to beep, vibrate, etc. then don't.
1273 if (((mDisabledNotifications & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) == 0)
1274 && (!(old != null
Joe Onorato30275482009-07-08 17:09:14 -07001275 && (notification.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0 ))
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001276 && (r.getUserId() == UserHandle.USER_ALL ||
1277 (r.getUserId() == userId && r.getUserId() == currentUser))
Daniel Sandler526fa0e2012-12-04 14:51:50 -05001278 && canInterrupt
Joe Onorato30275482009-07-08 17:09:14 -07001279 && mSystemReady) {
Eric Laurent524dc042009-11-27 05:07:55 -08001280
1281 final AudioManager audioManager = (AudioManager) mContext
1282 .getSystemService(Context.AUDIO_SERVICE);
Daniel Sandlerd4d2de22012-11-14 11:25:46 -08001283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001284 // sound
1285 final boolean useDefaultSound =
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001286 (notification.defaults & Notification.DEFAULT_SOUND) != 0;
Daniel Sandlerd4d2de22012-11-14 11:25:46 -08001287
1288 Uri soundUri = null;
1289 boolean hasValidSound = false;
1290
1291 if (useDefaultSound) {
1292 soundUri = Settings.System.DEFAULT_NOTIFICATION_URI;
1293
1294 // check to see if the default notification sound is silent
1295 ContentResolver resolver = mContext.getContentResolver();
1296 hasValidSound = Settings.System.getString(resolver,
1297 Settings.System.NOTIFICATION_SOUND) != null;
1298 } else if (notification.sound != null) {
1299 soundUri = notification.sound;
1300 hasValidSound = (soundUri != null);
1301 }
1302
1303 if (hasValidSound) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001304 boolean looping = (notification.flags & Notification.FLAG_INSISTENT) != 0;
1305 int audioStreamType;
1306 if (notification.audioStreamType >= 0) {
1307 audioStreamType = notification.audioStreamType;
1308 } else {
1309 audioStreamType = DEFAULT_STREAM_TYPE;
1310 }
1311 mSoundNotification = r;
Eric Laurent524dc042009-11-27 05:07:55 -08001312 // do not play notifications if stream volume is 0
Jean-Michel Trivid6770542012-10-10 12:03:41 -07001313 // (typically because ringer mode is silent) or if speech recognition is active.
1314 if ((audioManager.getStreamVolume(audioStreamType) != 0)
1315 && !audioManager.isSpeechRecognitionActive()) {
Jeff Sharkey098d5802012-04-26 17:30:34 -07001316 final long identity = Binder.clearCallingIdentity();
Eric Laurent524dc042009-11-27 05:07:55 -08001317 try {
Jeff Sharkey098d5802012-04-26 17:30:34 -07001318 final IRingtonePlayer player = mAudioService.getRingtonePlayer();
1319 if (player != null) {
Daniel Sandlerd4d2de22012-11-14 11:25:46 -08001320 player.playAsync(soundUri, user, looping, audioStreamType);
Jeff Sharkey098d5802012-04-26 17:30:34 -07001321 }
1322 } catch (RemoteException e) {
1323 } finally {
Eric Laurent524dc042009-11-27 05:07:55 -08001324 Binder.restoreCallingIdentity(identity);
1325 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001326 }
1327 }
1328
1329 // vibrate
Daniel Sandleredbb3802012-11-13 20:49:47 -08001330 // Does the notification want to specify its own vibration?
1331 final boolean hasCustomVibrate = notification.vibrate != null;
1332
David Agnew71789e12012-11-09 23:03:26 -05001333 // 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 -05001334 // and no other vibration is specified, we fall back to vibration
David Agnew71789e12012-11-09 23:03:26 -05001335 final boolean convertSoundToVibration =
Daniel Sandleredbb3802012-11-13 20:49:47 -08001336 !hasCustomVibrate
Daniel Sandlerd4d2de22012-11-14 11:25:46 -08001337 && hasValidSound
David Agnew71789e12012-11-09 23:03:26 -05001338 && (audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE);
1339
Daniel Sandler4a7a9b92012-11-20 12:59:41 -05001340 // The DEFAULT_VIBRATE flag trumps any custom vibration AND the fallback.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001341 final boolean useDefaultVibrate =
Daniel Sandleredbb3802012-11-13 20:49:47 -08001342 (notification.defaults & Notification.DEFAULT_VIBRATE) != 0;
David Agnew71789e12012-11-09 23:03:26 -05001343
Daniel Sandleredbb3802012-11-13 20:49:47 -08001344 if ((useDefaultVibrate || convertSoundToVibration || hasCustomVibrate)
Eric Laurentbffc3d12012-05-07 17:43:49 -07001345 && !(audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001346 mVibrateNotification = r;
1347
Daniel Sandleredbb3802012-11-13 20:49:47 -08001348 if (useDefaultVibrate || convertSoundToVibration) {
1349 // Escalate privileges so we can use the vibrator even if the notifying app
1350 // does not have the VIBRATE permission.
1351 long identity = Binder.clearCallingIdentity();
1352 try {
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001353 mVibrator.vibrate(r.sbn.uid, r.sbn.basePkg,
Dianne Hackbornf265ea92013-01-31 15:00:51 -08001354 useDefaultVibrate ? mDefaultVibrationPattern
1355 : mFallbackVibrationPattern,
Daniel Sandleredbb3802012-11-13 20:49:47 -08001356 ((notification.flags & Notification.FLAG_INSISTENT) != 0) ? 0: -1);
1357 } finally {
1358 Binder.restoreCallingIdentity(identity);
1359 }
1360 } else if (notification.vibrate.length > 1) {
1361 // If you want your own vibration pattern, you need the VIBRATE permission
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001362 mVibrator.vibrate(r.sbn.uid, r.sbn.basePkg, notification.vibrate,
Daniel Sandleredbb3802012-11-13 20:49:47 -08001363 ((notification.flags & Notification.FLAG_INSISTENT) != 0) ? 0: -1);
1364 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001365 }
1366 }
1367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001368 // light
1369 // the most recent thing gets the light
1370 mLights.remove(old);
1371 if (mLedNotification == old) {
1372 mLedNotification = null;
1373 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001374 //Slog.i(TAG, "notification.lights="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001375 // + ((old.notification.lights.flags & Notification.FLAG_SHOW_LIGHTS) != 0));
Daniel Sandler526fa0e2012-12-04 14:51:50 -05001376 if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0
1377 && canInterrupt) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001378 mLights.add(r);
1379 updateLightsLocked();
1380 } else {
1381 if (old != null
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001382 && ((old.getFlags() & Notification.FLAG_SHOW_LIGHTS) != 0)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001383 updateLightsLocked();
1384 }
1385 }
1386 }
1387
1388 idOut[0] = id;
1389 }
1390
Joe Onorato30275482009-07-08 17:09:14 -07001391 private void sendAccessibilityEvent(Notification notification, CharSequence packageName) {
svetoslavganov75986cf2009-05-14 22:28:01 -07001392 AccessibilityManager manager = AccessibilityManager.getInstance(mContext);
1393 if (!manager.isEnabled()) {
1394 return;
1395 }
1396
1397 AccessibilityEvent event =
1398 AccessibilityEvent.obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
1399 event.setPackageName(packageName);
1400 event.setClassName(Notification.class.getName());
1401 event.setParcelableData(notification);
1402 CharSequence tickerText = notification.tickerText;
1403 if (!TextUtils.isEmpty(tickerText)) {
1404 event.getText().add(tickerText);
1405 }
1406
1407 manager.sendAccessibilityEvent(event);
1408 }
1409
Joe Onorato46439ce2010-11-19 13:56:21 -08001410 private void cancelNotificationLocked(NotificationRecord r, boolean sendDelete) {
1411 // tell the app
1412 if (sendDelete) {
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001413 if (r.getNotification().deleteIntent != null) {
Joe Onorato46439ce2010-11-19 13:56:21 -08001414 try {
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001415 r.getNotification().deleteIntent.send();
Joe Onorato46439ce2010-11-19 13:56:21 -08001416 } catch (PendingIntent.CanceledException ex) {
1417 // do nothing - there's no relevant way to recover, and
1418 // no reason to let this propagate
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001419 Slog.w(TAG, "canceled PendingIntent for " + r.sbn.pkg, ex);
Joe Onorato46439ce2010-11-19 13:56:21 -08001420 }
1421 }
1422 }
1423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001424 // status bar
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001425 if (r.getNotification().icon != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001426 long identity = Binder.clearCallingIdentity();
1427 try {
Joe Onorato0cbda992010-05-02 16:28:15 -07001428 mStatusBar.removeNotification(r.statusBarKey);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001429 }
1430 finally {
1431 Binder.restoreCallingIdentity(identity);
1432 }
1433 r.statusBarKey = null;
Daniel Sandler09a247e2013-02-14 10:24:17 -05001434 notifyRemovedLocked(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001435 }
1436
1437 // sound
1438 if (mSoundNotification == r) {
1439 mSoundNotification = null;
Jeff Sharkey098d5802012-04-26 17:30:34 -07001440 final long identity = Binder.clearCallingIdentity();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001441 try {
Jeff Sharkey098d5802012-04-26 17:30:34 -07001442 final IRingtonePlayer player = mAudioService.getRingtonePlayer();
1443 if (player != null) {
1444 player.stopAsync();
1445 }
1446 } catch (RemoteException e) {
1447 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001448 Binder.restoreCallingIdentity(identity);
1449 }
1450 }
1451
1452 // vibrate
1453 if (mVibrateNotification == r) {
1454 mVibrateNotification = null;
1455 long identity = Binder.clearCallingIdentity();
1456 try {
1457 mVibrator.cancel();
1458 }
1459 finally {
1460 Binder.restoreCallingIdentity(identity);
1461 }
1462 }
1463
1464 // light
1465 mLights.remove(r);
1466 if (mLedNotification == r) {
1467 mLedNotification = null;
1468 }
1469 }
1470
1471 /**
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001472 * Cancels a notification ONLY if it has all of the {@code mustHaveFlags}
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001473 * and none of the {@code mustNotHaveFlags}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001474 */
Fred Quintana6ecaff12009-09-25 14:23:13 -07001475 private void cancelNotification(String pkg, String tag, int id, int mustHaveFlags,
Dianne Hackborn41203752012-08-31 14:05:51 -07001476 int mustNotHaveFlags, boolean sendDelete, int userId) {
Daniel Sandler321e9c52012-10-12 10:59:26 -07001477 EventLog.writeEvent(EventLogTags.NOTIFICATION_CANCEL, pkg, id, tag, userId,
Daniel Sandlerb64cb882011-11-29 23:48:29 -05001478 mustHaveFlags, mustNotHaveFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001479
1480 synchronized (mNotificationList) {
Dianne Hackborn41203752012-08-31 14:05:51 -07001481 int index = indexOfNotificationLocked(pkg, tag, id, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001482 if (index >= 0) {
Fred Quintana6ecaff12009-09-25 14:23:13 -07001483 NotificationRecord r = mNotificationList.get(index);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001484
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001485 if ((r.getNotification().flags & mustHaveFlags) != mustHaveFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001486 return;
1487 }
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001488 if ((r.getNotification().flags & mustNotHaveFlags) != 0) {
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001489 return;
1490 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001492 mNotificationList.remove(index);
1493
Joe Onorato46439ce2010-11-19 13:56:21 -08001494 cancelNotificationLocked(r, sendDelete);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001495 updateLightsLocked();
1496 }
1497 }
1498 }
1499
1500 /**
Daniel Sandler321e9c52012-10-12 10:59:26 -07001501 * Determine whether the userId applies to the notification in question, either because
1502 * they match exactly, or one of them is USER_ALL (which is treated as a wildcard).
1503 */
1504 private boolean notificationMatchesUserId(NotificationRecord r, int userId) {
1505 return
1506 // looking for USER_ALL notifications? match everything
1507 userId == UserHandle.USER_ALL
1508 // a notification sent to USER_ALL matches any query
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001509 || r.getUserId() == UserHandle.USER_ALL
Daniel Sandler321e9c52012-10-12 10:59:26 -07001510 // an exact user match
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001511 || r.getUserId() == userId;
Daniel Sandler321e9c52012-10-12 10:59:26 -07001512 }
1513
1514 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001515 * Cancels all notifications from a given package that have all of the
1516 * {@code mustHaveFlags}.
1517 */
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001518 boolean cancelAllNotificationsInt(String pkg, int mustHaveFlags,
Dianne Hackborn41203752012-08-31 14:05:51 -07001519 int mustNotHaveFlags, boolean doit, int userId) {
Daniel Sandler321e9c52012-10-12 10:59:26 -07001520 EventLog.writeEvent(EventLogTags.NOTIFICATION_CANCEL_ALL, pkg, userId,
1521 mustHaveFlags, mustNotHaveFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001522
1523 synchronized (mNotificationList) {
1524 final int N = mNotificationList.size();
1525 boolean canceledSomething = false;
1526 for (int i = N-1; i >= 0; --i) {
1527 NotificationRecord r = mNotificationList.get(i);
Daniel Sandler321e9c52012-10-12 10:59:26 -07001528 if (!notificationMatchesUserId(r, userId)) {
Dianne Hackborn41203752012-08-31 14:05:51 -07001529 continue;
1530 }
Amith Yamasani5ec00e92012-11-07 16:58:30 -08001531 // Don't remove notifications to all, if there's no package name specified
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001532 if (r.getUserId() == UserHandle.USER_ALL && pkg == null) {
Amith Yamasani5ec00e92012-11-07 16:58:30 -08001533 continue;
1534 }
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001535 if ((r.getFlags() & mustHaveFlags) != mustHaveFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001536 continue;
1537 }
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001538 if ((r.getFlags() & mustNotHaveFlags) != 0) {
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001539 continue;
1540 }
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001541 if (pkg != null && !r.sbn.pkg.equals(pkg)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001542 continue;
1543 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001544 canceledSomething = true;
1545 if (!doit) {
1546 return true;
1547 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001548 mNotificationList.remove(i);
Joe Onorato46439ce2010-11-19 13:56:21 -08001549 cancelNotificationLocked(r, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001550 }
1551 if (canceledSomething) {
1552 updateLightsLocked();
1553 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001554 return canceledSomething;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001555 }
1556 }
1557
Dianne Hackborn41203752012-08-31 14:05:51 -07001558 public void cancelNotificationWithTag(String pkg, String tag, int id, int userId) {
Daniel Sandler0da673f2012-04-11 12:33:16 -04001559 checkCallerIsSystemOrSameApp(pkg);
Dianne Hackborn41203752012-08-31 14:05:51 -07001560 userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
Amith Yamasani2c7ebea2012-10-30 15:28:27 -07001561 Binder.getCallingUid(), userId, true, false, "cancelNotificationWithTag", pkg);
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001562 // Don't allow client applications to cancel foreground service notis.
Fred Quintana6ecaff12009-09-25 14:23:13 -07001563 cancelNotification(pkg, tag, id, 0,
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001564 Binder.getCallingUid() == Process.SYSTEM_UID
Dianne Hackborn41203752012-08-31 14:05:51 -07001565 ? 0 : Notification.FLAG_FOREGROUND_SERVICE, false, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001566 }
1567
Dianne Hackborn41203752012-08-31 14:05:51 -07001568 public void cancelAllNotifications(String pkg, int userId) {
Daniel Sandler0da673f2012-04-11 12:33:16 -04001569 checkCallerIsSystemOrSameApp(pkg);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001570
Dianne Hackborn41203752012-08-31 14:05:51 -07001571 userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
Amith Yamasani2c7ebea2012-10-30 15:28:27 -07001572 Binder.getCallingUid(), userId, true, false, "cancelAllNotifications", pkg);
Dianne Hackborn41203752012-08-31 14:05:51 -07001573
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001574 // Calling from user space, don't allow the canceling of actively
1575 // running foreground services.
Dianne Hackborn41203752012-08-31 14:05:51 -07001576 cancelAllNotificationsInt(pkg, 0, Notification.FLAG_FOREGROUND_SERVICE, true, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001577 }
1578
Daniel Sandler0da673f2012-04-11 12:33:16 -04001579 void checkCallerIsSystem() {
1580 int uid = Binder.getCallingUid();
Dianne Hackborn0c380492012-08-20 17:23:30 -07001581 if (UserHandle.getAppId(uid) == Process.SYSTEM_UID || uid == 0) {
Daniel Sandler0da673f2012-04-11 12:33:16 -04001582 return;
1583 }
1584 throw new SecurityException("Disallowed call for uid " + uid);
1585 }
1586
1587 void checkCallerIsSystemOrSameApp(String pkg) {
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001588 int uid = Binder.getCallingUid();
Dianne Hackborn0c380492012-08-20 17:23:30 -07001589 if (UserHandle.getAppId(uid) == Process.SYSTEM_UID || uid == 0) {
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001590 return;
1591 }
1592 try {
Amith Yamasanif203aee2012-08-29 18:41:53 -07001593 ApplicationInfo ai = AppGlobals.getPackageManager().getApplicationInfo(
1594 pkg, 0, UserHandle.getCallingUserId());
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07001595 if (!UserHandle.isSameApp(ai.uid, uid)) {
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001596 throw new SecurityException("Calling uid " + uid + " gave package"
1597 + pkg + " which is owned by uid " + ai.uid);
1598 }
Amith Yamasanif203aee2012-08-29 18:41:53 -07001599 } catch (RemoteException re) {
1600 throw new SecurityException("Unknown package " + pkg + "\n" + re);
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001601 }
1602 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001603
Dianne Hackborn41203752012-08-31 14:05:51 -07001604 void cancelAll(int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001605 synchronized (mNotificationList) {
1606 final int N = mNotificationList.size();
1607 for (int i=N-1; i>=0; i--) {
1608 NotificationRecord r = mNotificationList.get(i);
1609
Daniel Sandler321e9c52012-10-12 10:59:26 -07001610 if (!notificationMatchesUserId(r, userId)) {
Dianne Hackborn41203752012-08-31 14:05:51 -07001611 continue;
1612 }
1613
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001614 if ((r.getFlags() & (Notification.FLAG_ONGOING_EVENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001615 | Notification.FLAG_NO_CLEAR)) == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001616 mNotificationList.remove(i);
Joe Onorato46439ce2010-11-19 13:56:21 -08001617 cancelNotificationLocked(r, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001618 }
1619 }
1620
1621 updateLightsLocked();
1622 }
1623 }
1624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001625 // lock on mNotificationList
1626 private void updateLightsLocked()
1627 {
The Android Open Source Project10592532009-03-18 17:39:46 -07001628 // handle notification lights
1629 if (mLedNotification == null) {
1630 // get next notification, if any
1631 int n = mLights.size();
1632 if (n > 0) {
1633 mLedNotification = mLights.get(n-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001634 }
1635 }
Mike Lockwoodc22404a2009-12-02 11:15:02 -05001636
Mike Lockwood63b5ad92011-08-30 09:55:30 -04001637 // Don't flash while we are in a call or screen is on
1638 if (mLedNotification == null || mInCall || mScreenOn) {
Mike Lockwood3cb67a32009-11-27 14:25:58 -05001639 mNotificationLight.turnOff();
The Android Open Source Project10592532009-03-18 17:39:46 -07001640 } else {
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001641 final Notification ledno = mLedNotification.sbn.notification;
1642 int ledARGB = ledno.ledARGB;
1643 int ledOnMS = ledno.ledOnMS;
1644 int ledOffMS = ledno.ledOffMS;
1645 if ((ledno.defaults & Notification.DEFAULT_LIGHTS) != 0) {
Mike Lockwood670f9322010-01-20 12:13:36 -05001646 ledARGB = mDefaultNotificationColor;
1647 ledOnMS = mDefaultNotificationLedOn;
1648 ledOffMS = mDefaultNotificationLedOff;
1649 }
1650 if (mNotificationPulseEnabled) {
1651 // pulse repeatedly
1652 mNotificationLight.setFlashing(ledARGB, LightsService.LIGHT_FLASH_TIMED,
1653 ledOnMS, ledOffMS);
Mike Lockwood670f9322010-01-20 12:13:36 -05001654 }
The Android Open Source Project10592532009-03-18 17:39:46 -07001655 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001656 }
1657
1658 // lock on mNotificationList
Dianne Hackborn41203752012-08-31 14:05:51 -07001659 private int indexOfNotificationLocked(String pkg, String tag, int id, int userId)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001660 {
1661 ArrayList<NotificationRecord> list = mNotificationList;
1662 final int len = list.size();
1663 for (int i=0; i<len; i++) {
1664 NotificationRecord r = list.get(i);
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001665 if (!notificationMatchesUserId(r, userId) || r.sbn.id != id) {
Dianne Hackborn41203752012-08-31 14:05:51 -07001666 continue;
1667 }
Fred Quintana6ecaff12009-09-25 14:23:13 -07001668 if (tag == null) {
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001669 if (r.sbn.tag != null) {
Fred Quintana6ecaff12009-09-25 14:23:13 -07001670 continue;
1671 }
1672 } else {
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001673 if (!tag.equals(r.sbn.tag)) {
Fred Quintana6ecaff12009-09-25 14:23:13 -07001674 continue;
1675 }
1676 }
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001677 if (r.sbn.pkg.equals(pkg)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001678 return i;
1679 }
1680 }
1681 return -1;
1682 }
1683
Mike Lockwoodc22404a2009-12-02 11:15:02 -05001684 private void updateNotificationPulse() {
1685 synchronized (mNotificationList) {
1686 updateLightsLocked();
1687 }
1688 }
1689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001690 // ======================================================================
1691 @Override
1692 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1693 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
1694 != PackageManager.PERMISSION_GRANTED) {
1695 pw.println("Permission Denial: can't dump NotificationManager from from pid="
1696 + Binder.getCallingPid()
1697 + ", uid=" + Binder.getCallingUid());
1698 return;
1699 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001701 pw.println("Current Notification Manager state:");
1702
1703 int N;
1704
1705 synchronized (mToastQueue) {
1706 N = mToastQueue.size();
1707 if (N > 0) {
1708 pw.println(" Toast Queue:");
1709 for (int i=0; i<N; i++) {
1710 mToastQueue.get(i).dump(pw, " ");
1711 }
1712 pw.println(" ");
1713 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001715 }
1716
1717 synchronized (mNotificationList) {
1718 N = mNotificationList.size();
1719 if (N > 0) {
1720 pw.println(" Notification List:");
1721 for (int i=0; i<N; i++) {
1722 mNotificationList.get(i).dump(pw, " ", mContext);
1723 }
1724 pw.println(" ");
1725 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001727 N = mLights.size();
1728 if (N > 0) {
1729 pw.println(" Lights List:");
1730 for (int i=0; i<N; i++) {
1731 mLights.get(i).dump(pw, " ", mContext);
1732 }
1733 pw.println(" ");
1734 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001735
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001736 pw.println(" mSoundNotification=" + mSoundNotification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001737 pw.println(" mVibrateNotification=" + mVibrateNotification);
Joe Onorato39f5b6a2009-07-23 12:29:19 -04001738 pw.println(" mDisabledNotifications=0x" + Integer.toHexString(mDisabledNotifications));
1739 pw.println(" mSystemReady=" + mSystemReady);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001740 }
1741 }
1742}