blob: 52ba665aea6149f20321cbe6819e807b39e957ee [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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.app.ActivityManagerNative;
24import android.app.IActivityManager;
25import android.app.INotificationManager;
26import android.app.ITransientNotification;
27import android.app.Notification;
28import android.app.PendingIntent;
29import android.app.StatusBarManager;
30import android.content.BroadcastReceiver;
Dianne Hackborn1dac2772009-06-26 18:16:48 -070031import android.content.ContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.content.Context;
33import android.content.Intent;
34import android.content.IntentFilter;
Dianne Hackbornd8a43f62009-08-17 23:33:56 -070035import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.content.pm.PackageManager;
37import android.content.pm.PackageManager.NameNotFoundException;
38import android.content.res.Resources;
Dianne Hackborn1dac2772009-06-26 18:16:48 -070039import android.database.ContentObserver;
svetoslavganov75986cf2009-05-14 22:28:01 -070040import android.media.AudioManager;
Jeff Sharkey098d5802012-04-26 17:30:34 -070041import android.media.IAudioService;
42import android.media.IRingtonePlayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043import android.net.Uri;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import android.os.Binder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import android.os.IBinder;
47import android.os.Message;
Dianne Hackbornd8a43f62009-08-17 23:33:56 -070048import android.os.Process;
svetoslavganov75986cf2009-05-14 22:28:01 -070049import android.os.RemoteException;
Jeff Sharkey098d5802012-04-26 17:30:34 -070050import android.os.ServiceManager;
Amith Yamasani742a6712011-05-04 14:49:28 -070051import android.os.UserId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052import android.os.Vibrator;
53import android.provider.Settings;
Daniel Sandlere96ffb12010-03-11 13:38:06 -050054import android.telephony.TelephonyManager;
svetoslavganov75986cf2009-05-14 22:28:01 -070055import android.text.TextUtils;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import android.util.EventLog;
57import android.util.Log;
Andy Stadler110988c2010-12-03 14:29:16 -080058import android.util.Slog;
Daniel Sandler0da673f2012-04-11 12:33:16 -040059import android.util.Xml;
svetoslavganov75986cf2009-05-14 22:28:01 -070060import android.view.accessibility.AccessibilityEvent;
61import android.view.accessibility.AccessibilityManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062import android.widget.Toast;
63
Jeff Sharkey098d5802012-04-26 17:30:34 -070064import com.android.internal.os.AtomicFile;
65import com.android.internal.statusbar.StatusBarNotification;
66import com.android.internal.util.FastXmlSerializer;
67
68import org.xmlpull.v1.XmlPullParser;
69import org.xmlpull.v1.XmlPullParserException;
70import org.xmlpull.v1.XmlSerializer;
71
Daniel Sandler0da673f2012-04-11 12:33:16 -040072import java.io.File;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073import java.io.FileDescriptor;
Daniel Sandler0da673f2012-04-11 12:33:16 -040074import java.io.FileInputStream;
75import java.io.FileNotFoundException;
76import java.io.FileOutputStream;
77import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078import java.io.PrintWriter;
79import java.util.ArrayList;
80import java.util.Arrays;
Daniel Sandler0da673f2012-04-11 12:33:16 -040081import java.util.HashSet;
82
83import libcore.io.IoUtils;
84
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085
Daniel Sandlerd0a2f862010-08-03 15:29:31 -040086/** {@hide} */
87public class NotificationManagerService extends INotificationManager.Stub
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088{
89 private static final String TAG = "NotificationService";
90 private static final boolean DBG = false;
91
Joe Onoratobd73d012010-06-04 11:44:54 -070092 private static final int MAX_PACKAGE_NOTIFICATIONS = 50;
93
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 // message codes
95 private static final int MESSAGE_TIMEOUT = 2;
96
97 private static final int LONG_DELAY = 3500; // 3.5 seconds
98 private static final int SHORT_DELAY = 2000; // 2 seconds
Doug Zongkerab5c49c2009-12-04 10:31:43 -080099
100 private static final long[] DEFAULT_VIBRATE_PATTERN = {0, 250, 250, 250};
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101
102 private static final int DEFAULT_STREAM_TYPE = AudioManager.STREAM_NOTIFICATION;
Daniel Sandler49a2ad12012-03-28 15:46:39 -0400103 private static final boolean SCORE_ONGOING_HIGHER = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104
Daniel Sandler0da673f2012-04-11 12:33:16 -0400105 private static final int JUNK_SCORE = -1000;
106 private static final int NOTIFICATION_PRIORITY_MULTIPLIER = 10;
107 private static final int SCORE_DISPLAY_THRESHOLD = Notification.PRIORITY_MIN * NOTIFICATION_PRIORITY_MULTIPLIER;
108
109 private static final boolean ENABLE_BLOCKED_NOTIFICATIONS = true;
110 private static final boolean ENABLE_BLOCKED_TOASTS = true;
111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112 final Context mContext;
113 final IActivityManager mAm;
114 final IBinder mForegroundToken = new Binder();
115
116 private WorkerHandler mHandler;
Joe Onorato089de882010-04-12 08:18:45 -0700117 private StatusBarManagerService mStatusBar;
Mike Lockwood3cb67a32009-11-27 14:25:58 -0500118 private LightsService.Light mNotificationLight;
119 private LightsService.Light mAttentionLight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120
Mike Lockwood670f9322010-01-20 12:13:36 -0500121 private int mDefaultNotificationColor;
122 private int mDefaultNotificationLedOn;
123 private int mDefaultNotificationLedOff;
124
Joe Onorato30275482009-07-08 17:09:14 -0700125 private boolean mSystemReady;
Joe Onorato39f5b6a2009-07-23 12:29:19 -0400126 private int mDisabledNotifications;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127
Jeff Sharkey098d5802012-04-26 17:30:34 -0700128 private NotificationRecord mSoundNotification;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 private NotificationRecord mVibrateNotification;
Jeff Sharkey098d5802012-04-26 17:30:34 -0700130
131 private IAudioService mAudioService;
Jeff Brownc2346132012-04-13 01:55:38 -0700132 private Vibrator mVibrator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133
Mike Lockwoodc22404a2009-12-02 11:15:02 -0500134 // for enabling and disabling notification pulse behavior
Mike Lockwood63b5ad92011-08-30 09:55:30 -0400135 private boolean mScreenOn = true;
Daniel Sandlere96ffb12010-03-11 13:38:06 -0500136 private boolean mInCall = false;
Mike Lockwoodc22404a2009-12-02 11:15:02 -0500137 private boolean mNotificationPulseEnabled;
138
Fred Quintana6ecaff12009-09-25 14:23:13 -0700139 private final ArrayList<NotificationRecord> mNotificationList =
140 new ArrayList<NotificationRecord>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141
142 private ArrayList<ToastRecord> mToastQueue;
143
144 private ArrayList<NotificationRecord> mLights = new ArrayList<NotificationRecord>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 private NotificationRecord mLedNotification;
svetoslavganov75986cf2009-05-14 22:28:01 -0700146
Daniel Sandler0da673f2012-04-11 12:33:16 -0400147 // Notification control database. For now just contains disabled packages.
148 private AtomicFile mPolicyFile;
149 private HashSet<String> mBlockedPackages = new HashSet<String>();
150
151 private static final int DB_VERSION = 1;
152
153 private static final String TAG_BODY = "notification-policy";
154 private static final String ATTR_VERSION = "version";
155
156 private static final String TAG_BLOCKED_PKGS = "blocked-packages";
157 private static final String TAG_PACKAGE = "package";
158 private static final String ATTR_NAME = "name";
159
160 private void loadBlockDb() {
161 synchronized(mBlockedPackages) {
162 if (mPolicyFile == null) {
163 File dir = new File("/data/system");
164 mPolicyFile = new AtomicFile(new File(dir, "notification_policy.xml"));
165
166 mBlockedPackages.clear();
167
168 FileInputStream infile = null;
169 try {
170 infile = mPolicyFile.openRead();
171 final XmlPullParser parser = Xml.newPullParser();
172 parser.setInput(infile, null);
173
174 int type;
175 String tag;
176 int version = DB_VERSION;
177 while ((type = parser.next()) != END_DOCUMENT) {
178 tag = parser.getName();
179 if (type == START_TAG) {
180 if (TAG_BODY.equals(tag)) {
181 version = Integer.parseInt(parser.getAttributeValue(null, ATTR_VERSION));
182 } else if (TAG_BLOCKED_PKGS.equals(tag)) {
183 while ((type = parser.next()) != END_DOCUMENT) {
184 tag = parser.getName();
185 if (TAG_PACKAGE.equals(tag)) {
186 mBlockedPackages.add(parser.getAttributeValue(null, ATTR_NAME));
187 } else if (TAG_BLOCKED_PKGS.equals(tag) && type == END_TAG) {
188 break;
189 }
190 }
191 }
192 }
193 }
194 } catch (FileNotFoundException e) {
195 // No data yet
196 } catch (IOException e) {
197 Log.wtf(TAG, "Unable to read blocked notifications database", e);
198 } catch (NumberFormatException e) {
199 Log.wtf(TAG, "Unable to parse blocked notifications database", e);
200 } catch (XmlPullParserException e) {
201 Log.wtf(TAG, "Unable to parse blocked notifications database", e);
202 } finally {
203 IoUtils.closeQuietly(infile);
204 }
205 }
206 }
207 }
208
209 private void writeBlockDb() {
210 synchronized(mBlockedPackages) {
211 FileOutputStream outfile = null;
212 try {
213 outfile = mPolicyFile.startWrite();
214
215 XmlSerializer out = new FastXmlSerializer();
216 out.setOutput(outfile, "utf-8");
217
218 out.startDocument(null, true);
219
220 out.startTag(null, TAG_BODY); {
221 out.attribute(null, ATTR_VERSION, String.valueOf(DB_VERSION));
222 out.startTag(null, TAG_BLOCKED_PKGS); {
223 // write all known network policies
224 for (String pkg : mBlockedPackages) {
225 out.startTag(null, TAG_PACKAGE); {
226 out.attribute(null, ATTR_NAME, pkg);
227 } out.endTag(null, TAG_PACKAGE);
228 }
229 } out.endTag(null, TAG_BLOCKED_PKGS);
230 } out.endTag(null, TAG_BODY);
231
232 out.endDocument();
233
234 mPolicyFile.finishWrite(outfile);
235 } catch (IOException e) {
236 if (outfile != null) {
237 mPolicyFile.failWrite(outfile);
238 }
239 }
240 }
241 }
242
243 public boolean areNotificationsEnabledForPackage(String pkg) {
244 checkCallerIsSystem();
245 return areNotificationsEnabledForPackageInt(pkg);
246 }
247
248 // Unchecked. Not exposed via Binder, but can be called in the course of enqueue*().
249 private boolean areNotificationsEnabledForPackageInt(String pkg) {
250 final boolean enabled = !mBlockedPackages.contains(pkg);
251 if (DBG) {
252 Slog.v(TAG, "notifications are " + (enabled?"en":"dis") + "abled for " + pkg);
253 }
254 return enabled;
255 }
256
257 public void setNotificationsEnabledForPackage(String pkg, boolean enabled) {
258 checkCallerIsSystem();
259 if (DBG) {
260 Slog.v(TAG, (enabled?"en":"dis") + "abling notifications for " + pkg);
261 }
262 if (enabled) {
263 mBlockedPackages.remove(pkg);
264 } else {
265 mBlockedPackages.add(pkg);
266
267 // Now, cancel any outstanding notifications that are part of a just-disabled app
268 if (ENABLE_BLOCKED_NOTIFICATIONS) {
269 synchronized (mNotificationList) {
270 final int N = mNotificationList.size();
271 for (int i=0; i<N; i++) {
272 final NotificationRecord r = mNotificationList.get(i);
273 if (r.pkg.equals(pkg)) {
274 cancelNotificationLocked(r, false);
275 }
276 }
277 }
278 }
279 // Don't bother canceling toasts, they'll go away soon enough.
280 }
281 writeBlockDb();
282 }
283
284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 private static String idDebugString(Context baseContext, String packageName, int id) {
286 Context c = null;
287
288 if (packageName != null) {
289 try {
290 c = baseContext.createPackageContext(packageName, 0);
291 } catch (NameNotFoundException e) {
292 c = baseContext;
293 }
294 } else {
295 c = baseContext;
296 }
297
298 String pkg;
299 String type;
300 String name;
301
302 Resources r = c.getResources();
303 try {
304 return r.getResourceName(id);
305 } catch (Resources.NotFoundException e) {
306 return "<name unknown>";
307 }
308 }
309
310 private static final class NotificationRecord
311 {
Fred Quintana6ecaff12009-09-25 14:23:13 -0700312 final String pkg;
313 final String tag;
314 final int id;
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700315 final int uid;
316 final int initialPid;
Fred Quintana6ecaff12009-09-25 14:23:13 -0700317 final Notification notification;
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500318 final int score;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319 IBinder statusBarKey;
320
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500321 NotificationRecord(String pkg, String tag, int id, int uid, int initialPid, int score, Notification notification)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800322 {
323 this.pkg = pkg;
Fred Quintana6ecaff12009-09-25 14:23:13 -0700324 this.tag = tag;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325 this.id = id;
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700326 this.uid = uid;
327 this.initialPid = initialPid;
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500328 this.score = score;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329 this.notification = notification;
330 }
Fred Quintana6ecaff12009-09-25 14:23:13 -0700331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332 void dump(PrintWriter pw, String prefix, Context baseContext) {
333 pw.println(prefix + this);
334 pw.println(prefix + " icon=0x" + Integer.toHexString(notification.icon)
335 + " / " + idDebugString(baseContext, this.pkg, notification.icon));
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500336 pw.println(prefix + " pri=" + notification.priority);
337 pw.println(prefix + " score=" + this.score);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800338 pw.println(prefix + " contentIntent=" + notification.contentIntent);
339 pw.println(prefix + " deleteIntent=" + notification.deleteIntent);
340 pw.println(prefix + " tickerText=" + notification.tickerText);
341 pw.println(prefix + " contentView=" + notification.contentView);
Amith Yamasani0dedffd2012-03-30 10:47:23 -0700342 pw.println(prefix + " uid=" + uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343 pw.println(prefix + " defaults=0x" + Integer.toHexString(notification.defaults));
344 pw.println(prefix + " flags=0x" + Integer.toHexString(notification.flags));
345 pw.println(prefix + " sound=" + notification.sound);
346 pw.println(prefix + " vibrate=" + Arrays.toString(notification.vibrate));
347 pw.println(prefix + " ledARGB=0x" + Integer.toHexString(notification.ledARGB)
348 + " ledOnMS=" + notification.ledOnMS
349 + " ledOffMS=" + notification.ledOffMS);
350 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 @Override
353 public final String toString()
354 {
355 return "NotificationRecord{"
356 + Integer.toHexString(System.identityHashCode(this))
357 + " pkg=" + pkg
Fred Quintana6ecaff12009-09-25 14:23:13 -0700358 + " id=" + Integer.toHexString(id)
Daniel Sandlere40451a2011-02-03 14:51:35 -0500359 + " tag=" + tag
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500360 + " score=" + score
Daniel Sandlere40451a2011-02-03 14:51:35 -0500361 + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800362 }
363 }
364
365 private static final class ToastRecord
366 {
367 final int pid;
368 final String pkg;
369 final ITransientNotification callback;
370 int duration;
371
372 ToastRecord(int pid, String pkg, ITransientNotification callback, int duration)
373 {
374 this.pid = pid;
375 this.pkg = pkg;
376 this.callback = callback;
377 this.duration = duration;
378 }
379
380 void update(int duration) {
381 this.duration = duration;
382 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 void dump(PrintWriter pw, String prefix) {
385 pw.println(prefix + this);
386 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 @Override
389 public final String toString()
390 {
391 return "ToastRecord{"
392 + Integer.toHexString(System.identityHashCode(this))
393 + " pkg=" + pkg
394 + " callback=" + callback
395 + " duration=" + duration;
396 }
397 }
398
Joe Onorato089de882010-04-12 08:18:45 -0700399 private StatusBarManagerService.NotificationCallbacks mNotificationCallbacks
400 = new StatusBarManagerService.NotificationCallbacks() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800401
402 public void onSetDisabled(int status) {
403 synchronized (mNotificationList) {
404 mDisabledNotifications = status;
405 if ((mDisabledNotifications & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0) {
406 // cancel whatever's going on
407 long identity = Binder.clearCallingIdentity();
408 try {
Jeff Sharkey098d5802012-04-26 17:30:34 -0700409 final IRingtonePlayer player = mAudioService.getRingtonePlayer();
410 if (player != null) {
411 player.stopAsync();
412 }
413 } catch (RemoteException e) {
414 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415 Binder.restoreCallingIdentity(identity);
416 }
417
418 identity = Binder.clearCallingIdentity();
419 try {
420 mVibrator.cancel();
Jeff Sharkey098d5802012-04-26 17:30:34 -0700421 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 Binder.restoreCallingIdentity(identity);
423 }
424 }
425 }
426 }
427
428 public void onClearAll() {
429 cancelAll();
430 }
431
Fred Quintana6ecaff12009-09-25 14:23:13 -0700432 public void onNotificationClick(String pkg, String tag, int id) {
433 cancelNotification(pkg, tag, id, Notification.FLAG_AUTO_CANCEL,
jhtop.kim2e448f72011-07-13 17:15:32 +0900434 Notification.FLAG_FOREGROUND_SERVICE, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 }
436
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400437 public void onNotificationClear(String pkg, String tag, int id) {
Joe Onorato46439ce2010-11-19 13:56:21 -0800438 cancelNotification(pkg, tag, id, 0,
439 Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE,
440 true);
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400441 }
442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 public void onPanelRevealed() {
444 synchronized (mNotificationList) {
445 // sound
446 mSoundNotification = null;
Jeff Sharkey098d5802012-04-26 17:30:34 -0700447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 long identity = Binder.clearCallingIdentity();
449 try {
Jeff Sharkey098d5802012-04-26 17:30:34 -0700450 final IRingtonePlayer player = mAudioService.getRingtonePlayer();
451 if (player != null) {
452 player.stopAsync();
453 }
454 } catch (RemoteException e) {
455 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800456 Binder.restoreCallingIdentity(identity);
457 }
458
459 // vibrate
460 mVibrateNotification = null;
461 identity = Binder.clearCallingIdentity();
462 try {
463 mVibrator.cancel();
Jeff Sharkey098d5802012-04-26 17:30:34 -0700464 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800465 Binder.restoreCallingIdentity(identity);
466 }
467
468 // light
469 mLights.clear();
470 mLedNotification = null;
471 updateLightsLocked();
472 }
473 }
Joe Onorato005847b2010-06-04 16:08:02 -0400474
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700475 public void onNotificationError(String pkg, String tag, int id,
476 int uid, int initialPid, String message) {
Daniel Sandlerd0a2f862010-08-03 15:29:31 -0400477 Slog.d(TAG, "onNotification error pkg=" + pkg + " tag=" + tag + " id=" + id
478 + "; will crashApplication(uid=" + uid + ", pid=" + initialPid + ")");
Joe Onorato46439ce2010-11-19 13:56:21 -0800479 cancelNotification(pkg, tag, id, 0, 0, false);
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700480 long ident = Binder.clearCallingIdentity();
481 try {
482 ActivityManagerNative.getDefault().crashApplication(uid, initialPid, pkg,
483 "Bad notification posted from package " + pkg
484 + ": " + message);
485 } catch (RemoteException e) {
486 }
487 Binder.restoreCallingIdentity(ident);
Joe Onorato005847b2010-06-04 16:08:02 -0400488 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800489 };
490
491 private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
492 @Override
493 public void onReceive(Context context, Intent intent) {
494 String action = intent.getAction();
495
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800496 boolean queryRestart = false;
497
Mike Lockwood541c9942011-06-12 19:35:45 -0400498 if (action.equals(Intent.ACTION_PACKAGE_REMOVED)
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800499 || action.equals(Intent.ACTION_PACKAGE_RESTARTED)
Daniel Sandleraac0eb02011-08-06 22:51:56 -0400500 || action.equals(Intent.ACTION_PACKAGE_CHANGED)
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800501 || (queryRestart=action.equals(Intent.ACTION_QUERY_PACKAGE_RESTART))
Suchi Amalapurapub56ae202010-02-04 22:51:07 -0800502 || action.equals(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)) {
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800503 String pkgList[] = null;
Suchi Amalapurapub56ae202010-02-04 22:51:07 -0800504 if (action.equals(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)) {
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800505 pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800506 } else if (queryRestart) {
507 pkgList = intent.getStringArrayExtra(Intent.EXTRA_PACKAGES);
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800508 } else {
509 Uri uri = intent.getData();
510 if (uri == null) {
511 return;
512 }
513 String pkgName = uri.getSchemeSpecificPart();
514 if (pkgName == null) {
515 return;
516 }
517 pkgList = new String[]{pkgName};
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800518 }
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800519 if (pkgList != null && (pkgList.length > 0)) {
520 for (String pkgName : pkgList) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800521 cancelAllNotificationsInt(pkgName, 0, 0, !queryRestart);
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800522 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800523 }
Mike Lockwood63b5ad92011-08-30 09:55:30 -0400524 } else if (action.equals(Intent.ACTION_SCREEN_ON)) {
525 // Keep track of screen on/off state, but do not turn off the notification light
526 // until user passes through the lock screen or views the notification.
527 mScreenOn = true;
528 } else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
529 mScreenOn = false;
Daniel Sandlere96ffb12010-03-11 13:38:06 -0500530 } else if (action.equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
Mike Lockwood63b5ad92011-08-30 09:55:30 -0400531 mInCall = (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
532 TelephonyManager.EXTRA_STATE_OFFHOOK));
Daniel Sandlere96ffb12010-03-11 13:38:06 -0500533 updateNotificationPulse();
Mike Lockwood63b5ad92011-08-30 09:55:30 -0400534 } else if (action.equals(Intent.ACTION_USER_PRESENT)) {
535 // turn off LED when user passes through lock screen
536 mNotificationLight.turnOff();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800537 }
538 }
539 };
540
Dianne Hackborn1dac2772009-06-26 18:16:48 -0700541 class SettingsObserver extends ContentObserver {
542 SettingsObserver(Handler handler) {
543 super(handler);
544 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800545
Dianne Hackborn1dac2772009-06-26 18:16:48 -0700546 void observe() {
547 ContentResolver resolver = mContext.getContentResolver();
Mike Lockwoodc22404a2009-12-02 11:15:02 -0500548 resolver.registerContentObserver(Settings.System.getUriFor(
549 Settings.System.NOTIFICATION_LIGHT_PULSE), false, this);
Dianne Hackborn1dac2772009-06-26 18:16:48 -0700550 update();
551 }
552
553 @Override public void onChange(boolean selfChange) {
554 update();
555 }
556
557 public void update() {
558 ContentResolver resolver = mContext.getContentResolver();
Mike Lockwoodc22404a2009-12-02 11:15:02 -0500559 boolean pulseEnabled = Settings.System.getInt(resolver,
560 Settings.System.NOTIFICATION_LIGHT_PULSE, 0) != 0;
561 if (mNotificationPulseEnabled != pulseEnabled) {
562 mNotificationPulseEnabled = pulseEnabled;
563 updateNotificationPulse();
564 }
Dianne Hackborn1dac2772009-06-26 18:16:48 -0700565 }
566 }
Mike Lockwoodc22404a2009-12-02 11:15:02 -0500567
Joe Onorato089de882010-04-12 08:18:45 -0700568 NotificationManagerService(Context context, StatusBarManagerService statusBar,
Mike Lockwood3a322132009-11-24 00:30:52 -0500569 LightsService lights)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570 {
571 super();
572 mContext = context;
Jeff Brownc2346132012-04-13 01:55:38 -0700573 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800574 mAm = ActivityManagerNative.getDefault();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 mToastQueue = new ArrayList<ToastRecord>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 mHandler = new WorkerHandler();
San Mehat3ee13172010-02-04 20:54:43 -0800577
Daniel Sandler0da673f2012-04-11 12:33:16 -0400578 loadBlockDb();
579
Joe Onorato089de882010-04-12 08:18:45 -0700580 mStatusBar = statusBar;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 statusBar.setNotificationCallbacks(mNotificationCallbacks);
582
Mike Lockwood3cb67a32009-11-27 14:25:58 -0500583 mNotificationLight = lights.getLight(LightsService.LIGHT_ID_NOTIFICATIONS);
584 mAttentionLight = lights.getLight(LightsService.LIGHT_ID_ATTENTION);
585
Mike Lockwood670f9322010-01-20 12:13:36 -0500586 Resources resources = mContext.getResources();
587 mDefaultNotificationColor = resources.getColor(
588 com.android.internal.R.color.config_defaultNotificationColor);
589 mDefaultNotificationLedOn = resources.getInteger(
590 com.android.internal.R.integer.config_defaultNotificationLedOn);
591 mDefaultNotificationLedOff = resources.getInteger(
592 com.android.internal.R.integer.config_defaultNotificationLedOff);
593
Joe Onorato39f5b6a2009-07-23 12:29:19 -0400594 // Don't start allowing notifications until the setup wizard has run once.
595 // After that, including subsequent boots, init with notifications turned on.
596 // This works on the first boot because the setup wizard will toggle this
597 // flag at least once and we'll go back to 0 after that.
598 if (0 == Settings.Secure.getInt(mContext.getContentResolver(),
599 Settings.Secure.DEVICE_PROVISIONED, 0)) {
600 mDisabledNotifications = StatusBarManager.DISABLE_NOTIFICATION_ALERTS;
601 }
602
Mike Lockwood35e16bf2010-11-30 19:53:36 -0500603 // register for various Intents
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604 IntentFilter filter = new IntentFilter();
Mike Lockwoodc22404a2009-12-02 11:15:02 -0500605 filter.addAction(Intent.ACTION_SCREEN_ON);
606 filter.addAction(Intent.ACTION_SCREEN_OFF);
Daniel Sandlere96ffb12010-03-11 13:38:06 -0500607 filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Mike Lockwood63b5ad92011-08-30 09:55:30 -0400608 filter.addAction(Intent.ACTION_USER_PRESENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800609 mContext.registerReceiver(mIntentReceiver, filter);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800610 IntentFilter pkgFilter = new IntentFilter();
611 pkgFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
Daniel Sandleraac0eb02011-08-06 22:51:56 -0400612 pkgFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800613 pkgFilter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
614 pkgFilter.addAction(Intent.ACTION_QUERY_PACKAGE_RESTART);
615 pkgFilter.addDataScheme("package");
616 mContext.registerReceiver(mIntentReceiver, pkgFilter);
Suchi Amalapurapub56ae202010-02-04 22:51:07 -0800617 IntentFilter sdFilter = new IntentFilter(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800618 mContext.registerReceiver(mIntentReceiver, sdFilter);
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800619
Mike Lockwoodc22404a2009-12-02 11:15:02 -0500620 SettingsObserver observer = new SettingsObserver(mHandler);
621 observer.observe();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800622 }
623
Joe Onorato30275482009-07-08 17:09:14 -0700624 void systemReady() {
Jeff Sharkey098d5802012-04-26 17:30:34 -0700625 mAudioService = IAudioService.Stub.asInterface(
626 ServiceManager.getService(Context.AUDIO_SERVICE));
627
Joe Onorato30275482009-07-08 17:09:14 -0700628 // no beeping until we're basically done booting
629 mSystemReady = true;
630 }
631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632 // Toasts
633 // ============================================================================
634 public void enqueueToast(String pkg, ITransientNotification callback, int duration)
635 {
Daniel Sandlera7035902010-03-30 15:45:31 -0400636 if (DBG) Slog.i(TAG, "enqueueToast pkg=" + pkg + " callback=" + callback + " duration=" + duration);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800637
638 if (pkg == null || callback == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800639 Slog.e(TAG, "Not doing toast. pkg=" + pkg + " callback=" + callback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 return ;
641 }
642
Daniel Sandler0da673f2012-04-11 12:33:16 -0400643 final boolean isSystemToast = ("android".equals(pkg));
644
645 if (ENABLE_BLOCKED_TOASTS && !isSystemToast && !areNotificationsEnabledForPackageInt(pkg)) {
646 Slog.e(TAG, "Suppressing toast from package " + pkg + " by user request.");
647 return;
648 }
649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800650 synchronized (mToastQueue) {
651 int callingPid = Binder.getCallingPid();
652 long callingId = Binder.clearCallingIdentity();
653 try {
654 ToastRecord record;
655 int index = indexOfToastLocked(pkg, callback);
656 // If it's already in the queue, we update it in place, we don't
657 // move it to the end of the queue.
658 if (index >= 0) {
659 record = mToastQueue.get(index);
660 record.update(duration);
661 } else {
Vairavan Srinivasanf9eb06c2011-01-21 18:08:36 -0800662 // Limit the number of toasts that any given package except the android
663 // package can enqueue. Prevents DOS attacks and deals with leaks.
Daniel Sandler0da673f2012-04-11 12:33:16 -0400664 if (!isSystemToast) {
Vairavan Srinivasanf9eb06c2011-01-21 18:08:36 -0800665 int count = 0;
666 final int N = mToastQueue.size();
667 for (int i=0; i<N; i++) {
668 final ToastRecord r = mToastQueue.get(i);
669 if (r.pkg.equals(pkg)) {
670 count++;
671 if (count >= MAX_PACKAGE_NOTIFICATIONS) {
672 Slog.e(TAG, "Package has already posted " + count
673 + " toasts. Not showing more. Package=" + pkg);
674 return;
675 }
676 }
677 }
678 }
679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800680 record = new ToastRecord(callingPid, pkg, callback, duration);
681 mToastQueue.add(record);
682 index = mToastQueue.size() - 1;
683 keepProcessAliveLocked(callingPid);
684 }
685 // If it's at index 0, it's the current toast. It doesn't matter if it's
686 // new or just been updated. Call back and tell it to show itself.
687 // If the callback fails, this will remove it from the list, so don't
688 // assume that it's valid after this.
689 if (index == 0) {
690 showNextToastLocked();
691 }
692 } finally {
693 Binder.restoreCallingIdentity(callingId);
694 }
695 }
696 }
697
698 public void cancelToast(String pkg, ITransientNotification callback) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800699 Slog.i(TAG, "cancelToast pkg=" + pkg + " callback=" + callback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800700
701 if (pkg == null || callback == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800702 Slog.e(TAG, "Not cancelling notification. pkg=" + pkg + " callback=" + callback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800703 return ;
704 }
705
706 synchronized (mToastQueue) {
707 long callingId = Binder.clearCallingIdentity();
708 try {
709 int index = indexOfToastLocked(pkg, callback);
710 if (index >= 0) {
711 cancelToastLocked(index);
712 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800713 Slog.w(TAG, "Toast already cancelled. pkg=" + pkg + " callback=" + callback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800714 }
715 } finally {
716 Binder.restoreCallingIdentity(callingId);
717 }
718 }
719 }
720
721 private void showNextToastLocked() {
722 ToastRecord record = mToastQueue.get(0);
723 while (record != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800724 if (DBG) Slog.d(TAG, "Show pkg=" + record.pkg + " callback=" + record.callback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 try {
726 record.callback.show();
727 scheduleTimeoutLocked(record, false);
728 return;
729 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800730 Slog.w(TAG, "Object died trying to show notification " + record.callback
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800731 + " in package " + record.pkg);
732 // remove it from the list and let the process die
733 int index = mToastQueue.indexOf(record);
734 if (index >= 0) {
735 mToastQueue.remove(index);
736 }
737 keepProcessAliveLocked(record.pid);
738 if (mToastQueue.size() > 0) {
739 record = mToastQueue.get(0);
740 } else {
741 record = null;
742 }
743 }
744 }
745 }
746
747 private void cancelToastLocked(int index) {
748 ToastRecord record = mToastQueue.get(index);
749 try {
750 record.callback.hide();
751 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800752 Slog.w(TAG, "Object died trying to hide notification " + record.callback
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800753 + " in package " + record.pkg);
754 // don't worry about this, we're about to remove it from
755 // the list anyway
756 }
757 mToastQueue.remove(index);
758 keepProcessAliveLocked(record.pid);
759 if (mToastQueue.size() > 0) {
760 // Show the next one. If the callback fails, this will remove
761 // it from the list, so don't assume that the list hasn't changed
762 // after this point.
763 showNextToastLocked();
764 }
765 }
766
767 private void scheduleTimeoutLocked(ToastRecord r, boolean immediate)
768 {
769 Message m = Message.obtain(mHandler, MESSAGE_TIMEOUT, r);
770 long delay = immediate ? 0 : (r.duration == Toast.LENGTH_LONG ? LONG_DELAY : SHORT_DELAY);
771 mHandler.removeCallbacksAndMessages(r);
772 mHandler.sendMessageDelayed(m, delay);
773 }
774
775 private void handleTimeout(ToastRecord record)
776 {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800777 if (DBG) Slog.d(TAG, "Timeout pkg=" + record.pkg + " callback=" + record.callback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800778 synchronized (mToastQueue) {
779 int index = indexOfToastLocked(record.pkg, record.callback);
780 if (index >= 0) {
781 cancelToastLocked(index);
782 }
783 }
784 }
785
786 // lock on mToastQueue
787 private int indexOfToastLocked(String pkg, ITransientNotification callback)
788 {
789 IBinder cbak = callback.asBinder();
790 ArrayList<ToastRecord> list = mToastQueue;
791 int len = list.size();
792 for (int i=0; i<len; i++) {
793 ToastRecord r = list.get(i);
794 if (r.pkg.equals(pkg) && r.callback.asBinder() == cbak) {
795 return i;
796 }
797 }
798 return -1;
799 }
800
801 // lock on mToastQueue
802 private void keepProcessAliveLocked(int pid)
803 {
804 int toastCount = 0; // toasts from this pid
805 ArrayList<ToastRecord> list = mToastQueue;
806 int N = list.size();
807 for (int i=0; i<N; i++) {
808 ToastRecord r = list.get(i);
809 if (r.pid == pid) {
810 toastCount++;
811 }
812 }
813 try {
814 mAm.setProcessForeground(mForegroundToken, pid, toastCount > 0);
815 } catch (RemoteException e) {
816 // Shouldn't happen.
817 }
818 }
819
820 private final class WorkerHandler extends Handler
821 {
822 @Override
823 public void handleMessage(Message msg)
824 {
825 switch (msg.what)
826 {
827 case MESSAGE_TIMEOUT:
828 handleTimeout((ToastRecord)msg.obj);
829 break;
830 }
831 }
832 }
833
834
835 // Notifications
836 // ============================================================================
Andy Stadler110988c2010-12-03 14:29:16 -0800837 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800838 public void enqueueNotification(String pkg, int id, Notification notification, int[] idOut)
839 {
Fred Quintana6ecaff12009-09-25 14:23:13 -0700840 enqueueNotificationWithTag(pkg, null /* tag */, id, notification, idOut);
841 }
842
Daniel Sandlerd0a2f862010-08-03 15:29:31 -0400843 public void enqueueNotificationWithTag(String pkg, String tag, int id, Notification notification,
844 int[] idOut)
Fred Quintana6ecaff12009-09-25 14:23:13 -0700845 {
Daniel Sandlerd0a2f862010-08-03 15:29:31 -0400846 enqueueNotificationInternal(pkg, Binder.getCallingUid(), Binder.getCallingPid(),
847 tag, id, notification, idOut);
848 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500849
850 private final static int clamp(int x, int low, int high) {
851 return (x < low) ? low : ((x > high) ? high : x);
Daniel Sandlere40451a2011-02-03 14:51:35 -0500852 }
853
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500854
Daniel Sandlerd0a2f862010-08-03 15:29:31 -0400855 // Not exposed via Binder; for system use only (otherwise malicious apps could spoof the
856 // uid/pid of another application)
857 public void enqueueNotificationInternal(String pkg, int callingUid, int callingPid,
858 String tag, int id, Notification notification, int[] idOut)
859 {
Daniel Sandler0da673f2012-04-11 12:33:16 -0400860 if (DBG) {
861 Slog.v(TAG, "enqueueNotificationInternal: pkg=" + pkg + " id=" + id + " notification=" + notification);
862 }
863 checkCallerIsSystemOrSameApp(pkg);
864 final boolean isSystemNotification = ("android".equals(pkg));
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800865
Joe Onoratobd73d012010-06-04 11:44:54 -0700866 // Limit the number of notifications that any given package except the android
867 // package can enqueue. Prevents DOS attacks and deals with leaks.
Daniel Sandler0da673f2012-04-11 12:33:16 -0400868 if (!isSystemNotification) {
Joe Onoratobd73d012010-06-04 11:44:54 -0700869 synchronized (mNotificationList) {
870 int count = 0;
871 final int N = mNotificationList.size();
872 for (int i=0; i<N; i++) {
873 final NotificationRecord r = mNotificationList.get(i);
874 if (r.pkg.equals(pkg)) {
875 count++;
876 if (count >= MAX_PACKAGE_NOTIFICATIONS) {
877 Slog.e(TAG, "Package has already posted " + count
878 + " notifications. Not showing more. package=" + pkg);
879 return;
880 }
881 }
882 }
883 }
884 }
885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800886 // This conditional is a dirty hack to limit the logging done on
887 // behalf of the download manager without affecting other apps.
888 if (!pkg.equals("com.android.providers.downloads")
889 || Log.isLoggable("DownloadManager", Log.VERBOSE)) {
Daniel Sandlerb64cb882011-11-29 23:48:29 -0500890 EventLog.writeEvent(EventLogTags.NOTIFICATION_ENQUEUE, pkg, id, tag,
891 notification.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800892 }
893
894 if (pkg == null || notification == null) {
895 throw new IllegalArgumentException("null not allowed: pkg=" + pkg
896 + " id=" + id + " notification=" + notification);
897 }
898 if (notification.icon != 0) {
899 if (notification.contentView == null) {
900 throw new IllegalArgumentException("contentView required: pkg=" + pkg
901 + " id=" + id + " notification=" + notification);
902 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800903 }
904
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500905 // === Scoring ===
Daniel Sandler0da673f2012-04-11 12:33:16 -0400906
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500907 // 0. Sanitize inputs
908 notification.priority = clamp(notification.priority, Notification.PRIORITY_MIN, Notification.PRIORITY_MAX);
909 // Migrate notification flags to scores
910 if (0 != (notification.flags & Notification.FLAG_HIGH_PRIORITY)) {
911 if (notification.priority < Notification.PRIORITY_MAX) notification.priority = Notification.PRIORITY_MAX;
Daniel Sandler49a2ad12012-03-28 15:46:39 -0400912 } else if (SCORE_ONGOING_HIGHER && 0 != (notification.flags & Notification.FLAG_ONGOING_EVENT)) {
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500913 if (notification.priority < Notification.PRIORITY_HIGH) notification.priority = Notification.PRIORITY_HIGH;
914 }
Daniel Sandler0da673f2012-04-11 12:33:16 -0400915
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500916 // 1. initial score: buckets of 10, around the app
Daniel Sandler0da673f2012-04-11 12:33:16 -0400917 int score = notification.priority * NOTIFICATION_PRIORITY_MULTIPLIER; //[-20..20]
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500918
Daniel Sandler0da673f2012-04-11 12:33:16 -0400919 // 2. Consult external heuristics (TBD)
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500920
Daniel Sandler0da673f2012-04-11 12:33:16 -0400921 // 3. Apply local rules
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500922
923 // blocked apps
Daniel Sandler0da673f2012-04-11 12:33:16 -0400924 if (ENABLE_BLOCKED_NOTIFICATIONS && !isSystemNotification && !areNotificationsEnabledForPackageInt(pkg)) {
925 score = JUNK_SCORE;
926 Slog.e(TAG, "Suppressing notification from package " + pkg + " by user request.");
927 }
928
929 if (DBG) {
930 Slog.v(TAG, "Assigned score=" + score + " to " + notification);
931 }
932
933 if (score < SCORE_DISPLAY_THRESHOLD) {
934 // Notification will be blocked because the score is too low.
935 return;
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500936 }
937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800938 synchronized (mNotificationList) {
Daniel Sandlere40451a2011-02-03 14:51:35 -0500939 NotificationRecord r = new NotificationRecord(pkg, tag, id,
940 callingUid, callingPid,
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500941 score,
Daniel Sandlere40451a2011-02-03 14:51:35 -0500942 notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800943 NotificationRecord old = null;
944
Fred Quintana6ecaff12009-09-25 14:23:13 -0700945 int index = indexOfNotificationLocked(pkg, tag, id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946 if (index < 0) {
947 mNotificationList.add(r);
948 } else {
949 old = mNotificationList.remove(index);
950 mNotificationList.add(index, r);
Dianne Hackbornd8a43f62009-08-17 23:33:56 -0700951 // Make sure we don't lose the foreground service state.
952 if (old != null) {
953 notification.flags |=
954 old.notification.flags&Notification.FLAG_FOREGROUND_SERVICE;
955 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800956 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800957
Dianne Hackbornd8a43f62009-08-17 23:33:56 -0700958 // Ensure if this is a foreground service that the proper additional
959 // flags are set.
960 if ((notification.flags&Notification.FLAG_FOREGROUND_SERVICE) != 0) {
961 notification.flags |= Notification.FLAG_ONGOING_EVENT
962 | Notification.FLAG_NO_CLEAR;
963 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800965 if (notification.icon != 0) {
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -0700966 StatusBarNotification n = new StatusBarNotification(pkg, id, tag,
Daniel Sandler2561b0b2012-02-13 21:04:12 -0500967 r.uid, r.initialPid, score, notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800968 if (old != null && old.statusBarKey != null) {
969 r.statusBarKey = old.statusBarKey;
970 long identity = Binder.clearCallingIdentity();
971 try {
Joe Onorato18e69df2010-05-17 22:26:12 -0700972 mStatusBar.updateNotification(r.statusBarKey, n);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800973 }
974 finally {
975 Binder.restoreCallingIdentity(identity);
976 }
977 } else {
978 long identity = Binder.clearCallingIdentity();
979 try {
Joe Onorato18e69df2010-05-17 22:26:12 -0700980 r.statusBarKey = mStatusBar.addNotification(n);
Mike Lockwoodece18ef2012-02-13 20:42:19 -0800981 if ((n.notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0) {
982 mAttentionLight.pulse();
983 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800984 }
985 finally {
986 Binder.restoreCallingIdentity(identity);
987 }
988 }
Joe Onorato30275482009-07-08 17:09:14 -0700989 sendAccessibilityEvent(notification, pkg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800990 } else {
Daniel Sandlere40451a2011-02-03 14:51:35 -0500991 Slog.e(TAG, "Ignoring notification with icon==0: " + notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800992 if (old != null && old.statusBarKey != null) {
993 long identity = Binder.clearCallingIdentity();
994 try {
Joe Onorato0cbda992010-05-02 16:28:15 -0700995 mStatusBar.removeNotification(old.statusBarKey);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800996 }
997 finally {
998 Binder.restoreCallingIdentity(identity);
999 }
1000 }
1001 }
1002
1003 // If we're not supposed to beep, vibrate, etc. then don't.
1004 if (((mDisabledNotifications & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) == 0)
1005 && (!(old != null
Joe Onorato30275482009-07-08 17:09:14 -07001006 && (notification.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0 ))
1007 && mSystemReady) {
Eric Laurent524dc042009-11-27 05:07:55 -08001008
1009 final AudioManager audioManager = (AudioManager) mContext
1010 .getSystemService(Context.AUDIO_SERVICE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001011 // sound
1012 final boolean useDefaultSound =
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001013 (notification.defaults & Notification.DEFAULT_SOUND) != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001014 if (useDefaultSound || notification.sound != null) {
1015 Uri uri;
1016 if (useDefaultSound) {
1017 uri = Settings.System.DEFAULT_NOTIFICATION_URI;
1018 } else {
1019 uri = notification.sound;
1020 }
1021 boolean looping = (notification.flags & Notification.FLAG_INSISTENT) != 0;
1022 int audioStreamType;
1023 if (notification.audioStreamType >= 0) {
1024 audioStreamType = notification.audioStreamType;
1025 } else {
1026 audioStreamType = DEFAULT_STREAM_TYPE;
1027 }
1028 mSoundNotification = r;
Eric Laurent524dc042009-11-27 05:07:55 -08001029 // do not play notifications if stream volume is 0
1030 // (typically because ringer mode is silent).
1031 if (audioManager.getStreamVolume(audioStreamType) != 0) {
Jeff Sharkey098d5802012-04-26 17:30:34 -07001032 final long identity = Binder.clearCallingIdentity();
Eric Laurent524dc042009-11-27 05:07:55 -08001033 try {
Jeff Sharkey098d5802012-04-26 17:30:34 -07001034 final IRingtonePlayer player = mAudioService.getRingtonePlayer();
1035 if (player != null) {
1036 player.playAsync(uri, looping, audioStreamType);
1037 }
1038 } catch (RemoteException e) {
1039 } finally {
Eric Laurent524dc042009-11-27 05:07:55 -08001040 Binder.restoreCallingIdentity(identity);
1041 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001042 }
1043 }
1044
1045 // vibrate
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001046 final boolean useDefaultVibrate =
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001047 (notification.defaults & Notification.DEFAULT_VIBRATE) != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001048 if ((useDefaultVibrate || notification.vibrate != null)
Eric Laurentbffc3d12012-05-07 17:43:49 -07001049 && !(audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001050 mVibrateNotification = r;
1051
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001052 mVibrator.vibrate(useDefaultVibrate ? DEFAULT_VIBRATE_PATTERN
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001053 : notification.vibrate,
1054 ((notification.flags & Notification.FLAG_INSISTENT) != 0) ? 0: -1);
1055 }
1056 }
1057
1058 // this option doesn't shut off the lights
1059
1060 // light
1061 // the most recent thing gets the light
1062 mLights.remove(old);
1063 if (mLedNotification == old) {
1064 mLedNotification = null;
1065 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001066 //Slog.i(TAG, "notification.lights="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 // + ((old.notification.lights.flags & Notification.FLAG_SHOW_LIGHTS) != 0));
1068 if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0) {
1069 mLights.add(r);
1070 updateLightsLocked();
1071 } else {
1072 if (old != null
1073 && ((old.notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0)) {
1074 updateLightsLocked();
1075 }
1076 }
1077 }
1078
1079 idOut[0] = id;
1080 }
1081
Joe Onorato30275482009-07-08 17:09:14 -07001082 private void sendAccessibilityEvent(Notification notification, CharSequence packageName) {
svetoslavganov75986cf2009-05-14 22:28:01 -07001083 AccessibilityManager manager = AccessibilityManager.getInstance(mContext);
1084 if (!manager.isEnabled()) {
1085 return;
1086 }
1087
1088 AccessibilityEvent event =
1089 AccessibilityEvent.obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
1090 event.setPackageName(packageName);
1091 event.setClassName(Notification.class.getName());
1092 event.setParcelableData(notification);
1093 CharSequence tickerText = notification.tickerText;
1094 if (!TextUtils.isEmpty(tickerText)) {
1095 event.getText().add(tickerText);
1096 }
1097
1098 manager.sendAccessibilityEvent(event);
1099 }
1100
Joe Onorato46439ce2010-11-19 13:56:21 -08001101 private void cancelNotificationLocked(NotificationRecord r, boolean sendDelete) {
1102 // tell the app
1103 if (sendDelete) {
1104 if (r.notification.deleteIntent != null) {
1105 try {
1106 r.notification.deleteIntent.send();
1107 } catch (PendingIntent.CanceledException ex) {
1108 // do nothing - there's no relevant way to recover, and
1109 // no reason to let this propagate
1110 Slog.w(TAG, "canceled PendingIntent for " + r.pkg, ex);
1111 }
1112 }
1113 }
1114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 // status bar
1116 if (r.notification.icon != 0) {
1117 long identity = Binder.clearCallingIdentity();
1118 try {
Joe Onorato0cbda992010-05-02 16:28:15 -07001119 mStatusBar.removeNotification(r.statusBarKey);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120 }
1121 finally {
1122 Binder.restoreCallingIdentity(identity);
1123 }
1124 r.statusBarKey = null;
1125 }
1126
1127 // sound
1128 if (mSoundNotification == r) {
1129 mSoundNotification = null;
Jeff Sharkey098d5802012-04-26 17:30:34 -07001130 final long identity = Binder.clearCallingIdentity();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001131 try {
Jeff Sharkey098d5802012-04-26 17:30:34 -07001132 final IRingtonePlayer player = mAudioService.getRingtonePlayer();
1133 if (player != null) {
1134 player.stopAsync();
1135 }
1136 } catch (RemoteException e) {
1137 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001138 Binder.restoreCallingIdentity(identity);
1139 }
1140 }
1141
1142 // vibrate
1143 if (mVibrateNotification == r) {
1144 mVibrateNotification = null;
1145 long identity = Binder.clearCallingIdentity();
1146 try {
1147 mVibrator.cancel();
1148 }
1149 finally {
1150 Binder.restoreCallingIdentity(identity);
1151 }
1152 }
1153
1154 // light
1155 mLights.remove(r);
1156 if (mLedNotification == r) {
1157 mLedNotification = null;
1158 }
1159 }
1160
1161 /**
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001162 * Cancels a notification ONLY if it has all of the {@code mustHaveFlags}
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001163 * and none of the {@code mustNotHaveFlags}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001164 */
Fred Quintana6ecaff12009-09-25 14:23:13 -07001165 private void cancelNotification(String pkg, String tag, int id, int mustHaveFlags,
Joe Onorato46439ce2010-11-19 13:56:21 -08001166 int mustNotHaveFlags, boolean sendDelete) {
Daniel Sandlerb64cb882011-11-29 23:48:29 -05001167 EventLog.writeEvent(EventLogTags.NOTIFICATION_CANCEL, pkg, id, tag,
1168 mustHaveFlags, mustNotHaveFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001169
1170 synchronized (mNotificationList) {
Fred Quintana6ecaff12009-09-25 14:23:13 -07001171 int index = indexOfNotificationLocked(pkg, tag, id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001172 if (index >= 0) {
Fred Quintana6ecaff12009-09-25 14:23:13 -07001173 NotificationRecord r = mNotificationList.get(index);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 if ((r.notification.flags & mustHaveFlags) != mustHaveFlags) {
1176 return;
1177 }
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001178 if ((r.notification.flags & mustNotHaveFlags) != 0) {
1179 return;
1180 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001182 mNotificationList.remove(index);
1183
Joe Onorato46439ce2010-11-19 13:56:21 -08001184 cancelNotificationLocked(r, sendDelete);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001185 updateLightsLocked();
1186 }
1187 }
1188 }
1189
1190 /**
1191 * Cancels all notifications from a given package that have all of the
1192 * {@code mustHaveFlags}.
1193 */
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001194 boolean cancelAllNotificationsInt(String pkg, int mustHaveFlags,
1195 int mustNotHaveFlags, boolean doit) {
Daniel Sandlerb64cb882011-11-29 23:48:29 -05001196 EventLog.writeEvent(EventLogTags.NOTIFICATION_CANCEL_ALL, pkg, mustHaveFlags,
1197 mustNotHaveFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001198
1199 synchronized (mNotificationList) {
1200 final int N = mNotificationList.size();
1201 boolean canceledSomething = false;
1202 for (int i = N-1; i >= 0; --i) {
1203 NotificationRecord r = mNotificationList.get(i);
1204 if ((r.notification.flags & mustHaveFlags) != mustHaveFlags) {
1205 continue;
1206 }
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001207 if ((r.notification.flags & mustNotHaveFlags) != 0) {
1208 continue;
1209 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001210 if (!r.pkg.equals(pkg)) {
1211 continue;
1212 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001213 canceledSomething = true;
1214 if (!doit) {
1215 return true;
1216 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001217 mNotificationList.remove(i);
Joe Onorato46439ce2010-11-19 13:56:21 -08001218 cancelNotificationLocked(r, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001219 }
1220 if (canceledSomething) {
1221 updateLightsLocked();
1222 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001223 return canceledSomething;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 }
1225 }
1226
Andy Stadler110988c2010-12-03 14:29:16 -08001227 @Deprecated
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001228 public void cancelNotification(String pkg, int id) {
Fred Quintana6ecaff12009-09-25 14:23:13 -07001229 cancelNotificationWithTag(pkg, null /* tag */, id);
1230 }
1231
1232 public void cancelNotificationWithTag(String pkg, String tag, int id) {
Daniel Sandler0da673f2012-04-11 12:33:16 -04001233 checkCallerIsSystemOrSameApp(pkg);
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001234 // Don't allow client applications to cancel foreground service notis.
Fred Quintana6ecaff12009-09-25 14:23:13 -07001235 cancelNotification(pkg, tag, id, 0,
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001236 Binder.getCallingUid() == Process.SYSTEM_UID
Joe Onorato46439ce2010-11-19 13:56:21 -08001237 ? 0 : Notification.FLAG_FOREGROUND_SERVICE, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001238 }
1239
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001240 public void cancelAllNotifications(String pkg) {
Daniel Sandler0da673f2012-04-11 12:33:16 -04001241 checkCallerIsSystemOrSameApp(pkg);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001242
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001243 // Calling from user space, don't allow the canceling of actively
1244 // running foreground services.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001245 cancelAllNotificationsInt(pkg, 0, Notification.FLAG_FOREGROUND_SERVICE, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001246 }
1247
Daniel Sandler0da673f2012-04-11 12:33:16 -04001248 void checkCallerIsSystem() {
1249 int uid = Binder.getCallingUid();
1250 if (uid == Process.SYSTEM_UID || uid == 0) {
1251 return;
1252 }
1253 throw new SecurityException("Disallowed call for uid " + uid);
1254 }
1255
1256 void checkCallerIsSystemOrSameApp(String pkg) {
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001257 int uid = Binder.getCallingUid();
1258 if (uid == Process.SYSTEM_UID || uid == 0) {
1259 return;
1260 }
1261 try {
1262 ApplicationInfo ai = mContext.getPackageManager().getApplicationInfo(
1263 pkg, 0);
Amith Yamasani742a6712011-05-04 14:49:28 -07001264 if (!UserId.isSameApp(ai.uid, uid)) {
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001265 throw new SecurityException("Calling uid " + uid + " gave package"
1266 + pkg + " which is owned by uid " + ai.uid);
1267 }
1268 } catch (PackageManager.NameNotFoundException e) {
1269 throw new SecurityException("Unknown package " + pkg);
1270 }
1271 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001272
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001273 void cancelAll() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001274 synchronized (mNotificationList) {
1275 final int N = mNotificationList.size();
1276 for (int i=N-1; i>=0; i--) {
1277 NotificationRecord r = mNotificationList.get(i);
1278
1279 if ((r.notification.flags & (Notification.FLAG_ONGOING_EVENT
1280 | Notification.FLAG_NO_CLEAR)) == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001281 mNotificationList.remove(i);
Joe Onorato46439ce2010-11-19 13:56:21 -08001282 cancelNotificationLocked(r, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001283 }
1284 }
1285
1286 updateLightsLocked();
1287 }
1288 }
1289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001290 // lock on mNotificationList
1291 private void updateLightsLocked()
1292 {
The Android Open Source Project10592532009-03-18 17:39:46 -07001293 // handle notification lights
1294 if (mLedNotification == null) {
1295 // get next notification, if any
1296 int n = mLights.size();
1297 if (n > 0) {
1298 mLedNotification = mLights.get(n-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001299 }
1300 }
Mike Lockwoodc22404a2009-12-02 11:15:02 -05001301
Mike Lockwood63b5ad92011-08-30 09:55:30 -04001302 // Don't flash while we are in a call or screen is on
1303 if (mLedNotification == null || mInCall || mScreenOn) {
Mike Lockwood3cb67a32009-11-27 14:25:58 -05001304 mNotificationLight.turnOff();
The Android Open Source Project10592532009-03-18 17:39:46 -07001305 } else {
Mike Lockwood670f9322010-01-20 12:13:36 -05001306 int ledARGB = mLedNotification.notification.ledARGB;
1307 int ledOnMS = mLedNotification.notification.ledOnMS;
1308 int ledOffMS = mLedNotification.notification.ledOffMS;
1309 if ((mLedNotification.notification.defaults & Notification.DEFAULT_LIGHTS) != 0) {
1310 ledARGB = mDefaultNotificationColor;
1311 ledOnMS = mDefaultNotificationLedOn;
1312 ledOffMS = mDefaultNotificationLedOff;
1313 }
1314 if (mNotificationPulseEnabled) {
1315 // pulse repeatedly
1316 mNotificationLight.setFlashing(ledARGB, LightsService.LIGHT_FLASH_TIMED,
1317 ledOnMS, ledOffMS);
Mike Lockwood670f9322010-01-20 12:13:36 -05001318 }
The Android Open Source Project10592532009-03-18 17:39:46 -07001319 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001320 }
1321
1322 // lock on mNotificationList
Fred Quintana6ecaff12009-09-25 14:23:13 -07001323 private int indexOfNotificationLocked(String pkg, String tag, int id)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001324 {
1325 ArrayList<NotificationRecord> list = mNotificationList;
1326 final int len = list.size();
1327 for (int i=0; i<len; i++) {
1328 NotificationRecord r = list.get(i);
Fred Quintana6ecaff12009-09-25 14:23:13 -07001329 if (tag == null) {
1330 if (r.tag != null) {
1331 continue;
1332 }
1333 } else {
1334 if (!tag.equals(r.tag)) {
1335 continue;
1336 }
1337 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001338 if (r.id == id && r.pkg.equals(pkg)) {
1339 return i;
1340 }
1341 }
1342 return -1;
1343 }
1344
Mike Lockwoodc22404a2009-12-02 11:15:02 -05001345 private void updateNotificationPulse() {
1346 synchronized (mNotificationList) {
1347 updateLightsLocked();
1348 }
1349 }
1350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001351 // ======================================================================
1352 @Override
1353 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1354 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
1355 != PackageManager.PERMISSION_GRANTED) {
1356 pw.println("Permission Denial: can't dump NotificationManager from from pid="
1357 + Binder.getCallingPid()
1358 + ", uid=" + Binder.getCallingUid());
1359 return;
1360 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001362 pw.println("Current Notification Manager state:");
1363
1364 int N;
1365
1366 synchronized (mToastQueue) {
1367 N = mToastQueue.size();
1368 if (N > 0) {
1369 pw.println(" Toast Queue:");
1370 for (int i=0; i<N; i++) {
1371 mToastQueue.get(i).dump(pw, " ");
1372 }
1373 pw.println(" ");
1374 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001376 }
1377
1378 synchronized (mNotificationList) {
1379 N = mNotificationList.size();
1380 if (N > 0) {
1381 pw.println(" Notification List:");
1382 for (int i=0; i<N; i++) {
1383 mNotificationList.get(i).dump(pw, " ", mContext);
1384 }
1385 pw.println(" ");
1386 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001388 N = mLights.size();
1389 if (N > 0) {
1390 pw.println(" Lights List:");
1391 for (int i=0; i<N; i++) {
1392 mLights.get(i).dump(pw, " ", mContext);
1393 }
1394 pw.println(" ");
1395 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001397 pw.println(" mSoundNotification=" + mSoundNotification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001398 pw.println(" mVibrateNotification=" + mVibrateNotification);
Joe Onorato39f5b6a2009-07-23 12:29:19 -04001399 pw.println(" mDisabledNotifications=0x" + Integer.toHexString(mDisabledNotifications));
1400 pw.println(" mSystemReady=" + mSystemReady);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001401 }
1402 }
1403}