blob: 97120bfd36ea36c667c17c3d584c068f0320d6a3 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
Jeff Sharkey098d5802012-04-26 17:30:34 -070019import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
20import static org.xmlpull.v1.XmlPullParser.END_TAG;
21import static org.xmlpull.v1.XmlPullParser.START_TAG;
svetoslavganov75986cf2009-05-14 22:28:01 -070022
Dianne Hackborn41203752012-08-31 14:05:51 -070023import android.app.ActivityManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.app.ActivityManagerNative;
Amith Yamasanif203aee2012-08-29 18:41:53 -070025import android.app.AppGlobals;
Daniel Sandler4a900acd2013-01-30 14:04:10 -050026import android.app.AppOpsManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.app.IActivityManager;
28import android.app.INotificationManager;
29import android.app.ITransientNotification;
30import android.app.Notification;
31import android.app.PendingIntent;
32import android.app.StatusBarManager;
33import android.content.BroadcastReceiver;
Daniel Sandler5feceeb2013-03-22 18:29:23 -070034import android.content.ComponentName;
Dianne Hackborn1dac2772009-06-26 18:16:48 -070035import android.content.ContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.content.Context;
37import android.content.Intent;
38import android.content.IntentFilter;
Daniel Sandler5feceeb2013-03-22 18:29:23 -070039import android.content.ServiceConnection;
Dianne Hackbornd8a43f62009-08-17 23:33:56 -070040import android.content.pm.ApplicationInfo;
Daniel Sandler4a900acd2013-01-30 14:04:10 -050041import android.content.pm.PackageInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import android.content.pm.PackageManager;
43import android.content.pm.PackageManager.NameNotFoundException;
44import android.content.res.Resources;
Dianne Hackborn1dac2772009-06-26 18:16:48 -070045import android.database.ContentObserver;
Daniel Sandlerf45564e2013-04-15 15:05:08 -040046import android.graphics.Bitmap;
svetoslavganov75986cf2009-05-14 22:28:01 -070047import android.media.AudioManager;
Jeff Sharkey098d5802012-04-26 17:30:34 -070048import android.media.IAudioService;
49import android.media.IRingtonePlayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050import android.net.Uri;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import android.os.Binder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053import android.os.IBinder;
54import android.os.Message;
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;
Daniel Sandler4b749ef2013-03-18 21:53:04 -040059import android.os.UserManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.os.Vibrator;
61import android.provider.Settings;
Daniel Sandler5feceeb2013-03-22 18:29:23 -070062import android.service.notification.INotificationListener;
63import android.service.notification.NotificationListenerService;
64import android.service.notification.StatusBarNotification;
Daniel Sandlere96ffb12010-03-11 13:38:06 -050065import android.telephony.TelephonyManager;
svetoslavganov75986cf2009-05-14 22:28:01 -070066import android.text.TextUtils;
Dianne Hackborn39606a02012-07-31 17:54:35 -070067import android.util.AtomicFile;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068import android.util.EventLog;
69import android.util.Log;
Andy Stadler110988c2010-12-03 14:29:16 -080070import android.util.Slog;
Daniel Sandler0da673f2012-04-11 12:33:16 -040071import android.util.Xml;
svetoslavganov75986cf2009-05-14 22:28:01 -070072import android.view.accessibility.AccessibilityEvent;
73import android.view.accessibility.AccessibilityManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074import android.widget.Toast;
75
Jeff Sharkey098d5802012-04-26 17:30:34 -070076import org.xmlpull.v1.XmlPullParser;
77import org.xmlpull.v1.XmlPullParserException;
Jeff Sharkey098d5802012-04-26 17:30:34 -070078
Daniel Sandler0da673f2012-04-11 12:33:16 -040079import java.io.File;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080import java.io.FileDescriptor;
Daniel Sandler0da673f2012-04-11 12:33:16 -040081import java.io.FileInputStream;
82import java.io.FileNotFoundException;
Daniel Sandler0da673f2012-04-11 12:33:16 -040083import java.io.IOException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084import java.io.PrintWriter;
Daniel Sandlerf45564e2013-04-15 15:05:08 -040085import java.lang.reflect.Array;
Daniel Sandlerfde19b12013-01-17 00:21:05 -050086import java.util.ArrayDeque;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087import java.util.ArrayList;
88import java.util.Arrays;
Daniel Sandler0da673f2012-04-11 12:33:16 -040089import java.util.HashSet;
Daniel Sandlerfde19b12013-01-17 00:21:05 -050090import java.util.Iterator;
91import java.util.NoSuchElementException;
Daniel Sandler0da673f2012-04-11 12:33:16 -040092
93import libcore.io.IoUtils;
94
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095
Daniel Sandlerd0a2f862010-08-03 15:29:31 -040096/** {@hide} */
97public class NotificationManagerService extends INotificationManager.Stub
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098{
99 private static final String TAG = "NotificationService";
100 private static final boolean DBG = false;
101
Joe Onoratobd73d012010-06-04 11:44:54 -0700102 private static final int MAX_PACKAGE_NOTIFICATIONS = 50;
103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 // message codes
105 private static final int MESSAGE_TIMEOUT = 2;
106
107 private static final int LONG_DELAY = 3500; // 3.5 seconds
108 private static final int SHORT_DELAY = 2000; // 2 seconds
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800109
110 private static final long[] DEFAULT_VIBRATE_PATTERN = {0, 250, 250, 250};
Daniel Sandleredbb3802012-11-13 20:49:47 -0800111 private static final int VIBRATE_PATTERN_MAXLEN = 8 * 2 + 1; // up to eight bumps
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112
113 private static final int DEFAULT_STREAM_TYPE = AudioManager.STREAM_NOTIFICATION;
Daniel Sandler49a2ad12012-03-28 15:46:39 -0400114 private static final boolean SCORE_ONGOING_HIGHER = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115
Daniel Sandler0da673f2012-04-11 12:33:16 -0400116 private static final int JUNK_SCORE = -1000;
117 private static final int NOTIFICATION_PRIORITY_MULTIPLIER = 10;
118 private static final int SCORE_DISPLAY_THRESHOLD = Notification.PRIORITY_MIN * NOTIFICATION_PRIORITY_MULTIPLIER;
119
Daniel Sandler526fa0e2012-12-04 14:51:50 -0500120 // Notifications with scores below this will not interrupt the user, either via LED or
121 // sound or vibration
122 private static final int SCORE_INTERRUPTION_THRESHOLD =
123 Notification.PRIORITY_LOW * NOTIFICATION_PRIORITY_MULTIPLIER;
124
Daniel Sandler0da673f2012-04-11 12:33:16 -0400125 private static final boolean ENABLE_BLOCKED_NOTIFICATIONS = true;
126 private static final boolean ENABLE_BLOCKED_TOASTS = true;
127
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700128 private static final String ENABLED_NOTIFICATION_LISTENERS_SEPARATOR = ":";
129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 final Context mContext;
131 final IActivityManager mAm;
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400132 final UserManager mUserManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 final IBinder mForegroundToken = new Binder();
134
135 private WorkerHandler mHandler;
Joe Onorato089de882010-04-12 08:18:45 -0700136 private StatusBarManagerService mStatusBar;
Mike Lockwood3cb67a32009-11-27 14:25:58 -0500137 private LightsService.Light mNotificationLight;
138 private LightsService.Light mAttentionLight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139
Mike Lockwood670f9322010-01-20 12:13:36 -0500140 private int mDefaultNotificationColor;
141 private int mDefaultNotificationLedOn;
142 private int mDefaultNotificationLedOff;
143
Daniel Sandleredbb3802012-11-13 20:49:47 -0800144 private long[] mDefaultVibrationPattern;
145 private long[] mFallbackVibrationPattern;
146
Joe Onorato30275482009-07-08 17:09:14 -0700147 private boolean mSystemReady;
Joe Onorato39f5b6a2009-07-23 12:29:19 -0400148 private int mDisabledNotifications;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149
Jeff Sharkey098d5802012-04-26 17:30:34 -0700150 private NotificationRecord mSoundNotification;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 private NotificationRecord mVibrateNotification;
Jeff Sharkey098d5802012-04-26 17:30:34 -0700152
153 private IAudioService mAudioService;
Jeff Brownc2346132012-04-13 01:55:38 -0700154 private Vibrator mVibrator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155
Mike Lockwoodc22404a2009-12-02 11:15:02 -0500156 // for enabling and disabling notification pulse behavior
Mike Lockwood63b5ad92011-08-30 09:55:30 -0400157 private boolean mScreenOn = true;
Daniel Sandlere96ffb12010-03-11 13:38:06 -0500158 private boolean mInCall = false;
Mike Lockwoodc22404a2009-12-02 11:15:02 -0500159 private boolean mNotificationPulseEnabled;
160
Daniel Sandler09a247e2013-02-14 10:24:17 -0500161 // used as a mutex for access to all active notifications & listeners
Fred Quintana6ecaff12009-09-25 14:23:13 -0700162 private final ArrayList<NotificationRecord> mNotificationList =
163 new ArrayList<NotificationRecord>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164
165 private ArrayList<ToastRecord> mToastQueue;
166
167 private ArrayList<NotificationRecord> mLights = new ArrayList<NotificationRecord>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 private NotificationRecord mLedNotification;
svetoslavganov75986cf2009-05-14 22:28:01 -0700169
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500170 private final AppOpsManager mAppOps;
171
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700172 // contains connections to all connected listeners, including app services
173 // and system listeners
174 private ArrayList<NotificationListenerInfo> mListeners
175 = new ArrayList<NotificationListenerInfo>();
176 // things that will be put into mListeners as soon as they're ready
177 private ArrayList<String> mServicesBinding = new ArrayList<String>();
178 // lists the component names of all enabled (and therefore connected) listener
179 // app services for the current user only
180 private HashSet<ComponentName> mEnabledListenersForCurrentUser
181 = new HashSet<ComponentName>();
182 // Just the packages from mEnabledListenersForCurrentUser
183 private HashSet<String> mEnabledListenerPackageNames = new HashSet<String>();
Daniel Sandler09a247e2013-02-14 10:24:17 -0500184
Daniel Sandler0da673f2012-04-11 12:33:16 -0400185 // Notification control database. For now just contains disabled packages.
186 private AtomicFile mPolicyFile;
187 private HashSet<String> mBlockedPackages = new HashSet<String>();
188
189 private static final int DB_VERSION = 1;
190
191 private static final String TAG_BODY = "notification-policy";
192 private static final String ATTR_VERSION = "version";
193
194 private static final String TAG_BLOCKED_PKGS = "blocked-packages";
195 private static final String TAG_PACKAGE = "package";
196 private static final String ATTR_NAME = "name";
197
Daniel Sandler09a247e2013-02-14 10:24:17 -0500198 private class NotificationListenerInfo implements DeathRecipient {
199 INotificationListener listener;
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700200 ComponentName component;
Daniel Sandler09a247e2013-02-14 10:24:17 -0500201 int userid;
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400202 boolean isSystem;
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700203 ServiceConnection connection;
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400204
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700205 public NotificationListenerInfo(INotificationListener listener, ComponentName component,
206 int userid, boolean isSystem) {
Daniel Sandler09a247e2013-02-14 10:24:17 -0500207 this.listener = listener;
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700208 this.component = component;
Daniel Sandler09a247e2013-02-14 10:24:17 -0500209 this.userid = userid;
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400210 this.isSystem = isSystem;
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700211 this.connection = null;
212 }
213
214 public NotificationListenerInfo(INotificationListener listener, ComponentName component,
215 int userid, ServiceConnection connection) {
216 this.listener = listener;
217 this.component = component;
218 this.userid = userid;
219 this.isSystem = false;
220 this.connection = connection;
Daniel Sandler09a247e2013-02-14 10:24:17 -0500221 }
222
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400223 boolean enabledAndUserMatches(StatusBarNotification sbn) {
224 final int nid = sbn.getUserId();
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700225 if (!isEnabledForCurrentUser()) {
226 return false;
227 }
Daniel Sandler21ca44d2013-03-07 13:58:00 -0500228 if (this.userid == UserHandle.USER_ALL) return true;
Daniel Sandler21ca44d2013-03-07 13:58:00 -0500229 return (nid == UserHandle.USER_ALL || nid == this.userid);
230 }
231
Daniel Sandler09a247e2013-02-14 10:24:17 -0500232 public void notifyPostedIfUserMatch(StatusBarNotification sbn) {
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700233 if (!enabledAndUserMatches(sbn)) {
234 return;
235 }
Daniel Sandler09a247e2013-02-14 10:24:17 -0500236 try {
237 listener.onNotificationPosted(sbn);
238 } catch (RemoteException ex) {
239 // not there?
240 }
241 }
242
243 public void notifyRemovedIfUserMatch(StatusBarNotification sbn) {
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400244 if (!enabledAndUserMatches(sbn)) return;
Daniel Sandler09a247e2013-02-14 10:24:17 -0500245 try {
246 listener.onNotificationRemoved(sbn);
247 } catch (RemoteException ex) {
248 // not there?
249 }
250 }
251
252 @Override
253 public void binderDied() {
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700254 if (connection == null) {
255 // This is not a service; it won't be recreated. We can give up this connection.
256 unregisterListener(this.listener, this.userid);
257 }
Daniel Sandler09a247e2013-02-14 10:24:17 -0500258 }
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400259
260 /** convenience method for looking in mEnabledListenersForCurrentUser */
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700261 public boolean isEnabledForCurrentUser() {
262 if (this.isSystem) return true;
263 if (this.connection == null) return false;
264 return mEnabledListenersForCurrentUser.contains(this.component);
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400265 }
Daniel Sandler09a247e2013-02-14 10:24:17 -0500266 }
267
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500268 private static class Archive {
269 static final int BUFFER_SIZE = 1000;
270 ArrayDeque<StatusBarNotification> mBuffer = new ArrayDeque<StatusBarNotification>(BUFFER_SIZE);
271
272 public Archive() {
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500273 }
Jeff Sharkey0c1baf92013-04-03 13:08:52 -0700274
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500275 public void record(StatusBarNotification nr) {
Jeff Sharkey0c1baf92013-04-03 13:08:52 -0700276 // Nuke heavy parts of notification before storing in archive
277 nr.notification.tickerView = null;
278 nr.notification.contentView = null;
279 nr.notification.bigContentView = null;
280 nr.notification.largeIcon = null;
281
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500282 if (mBuffer.size() == BUFFER_SIZE) {
283 mBuffer.removeFirst();
284 }
285 mBuffer.addLast(nr);
286 }
287
288 public void clear() {
289 mBuffer.clear();
290 }
291
292 public Iterator<StatusBarNotification> descendingIterator() {
293 return mBuffer.descendingIterator();
294 }
295 public Iterator<StatusBarNotification> ascendingIterator() {
296 return mBuffer.iterator();
297 }
298 public Iterator<StatusBarNotification> filter(
299 final Iterator<StatusBarNotification> iter, final String pkg, final int userId) {
300 return new Iterator<StatusBarNotification>() {
301 StatusBarNotification mNext = findNext();
302
303 private StatusBarNotification findNext() {
304 while (iter.hasNext()) {
305 StatusBarNotification nr = iter.next();
306 if ((pkg == null || nr.pkg == pkg)
307 && (userId == UserHandle.USER_ALL || nr.getUserId() == userId)) {
308 return nr;
309 }
310 }
311 return null;
312 }
313
314 @Override
315 public boolean hasNext() {
316 return mNext == null;
317 }
318
319 @Override
320 public StatusBarNotification next() {
321 StatusBarNotification next = mNext;
322 if (next == null) {
323 throw new NoSuchElementException();
324 }
325 mNext = findNext();
326 return next;
327 }
328
329 @Override
330 public void remove() {
331 iter.remove();
332 }
333 };
334 }
Daniel Sandler78d0d252013-02-12 08:14:52 -0500335
336 public StatusBarNotification[] getArray(int count) {
337 if (count == 0) count = Archive.BUFFER_SIZE;
338 final StatusBarNotification[] a
339 = new StatusBarNotification[Math.min(count, mBuffer.size())];
340 Iterator<StatusBarNotification> iter = descendingIterator();
341 int i=0;
342 while (iter.hasNext() && i < count) {
343 a[i++] = iter.next();
344 }
345 return a;
346 }
347
348 public StatusBarNotification[] getArray(int count, String pkg, int userId) {
349 if (count == 0) count = Archive.BUFFER_SIZE;
350 final StatusBarNotification[] a
351 = new StatusBarNotification[Math.min(count, mBuffer.size())];
352 Iterator<StatusBarNotification> iter = filter(descendingIterator(), pkg, userId);
353 int i=0;
354 while (iter.hasNext() && i < count) {
355 a[i++] = iter.next();
356 }
357 return a;
358 }
359
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500360 }
361
362 Archive mArchive = new Archive();
363
Daniel Sandler0da673f2012-04-11 12:33:16 -0400364 private void loadBlockDb() {
365 synchronized(mBlockedPackages) {
366 if (mPolicyFile == null) {
367 File dir = new File("/data/system");
368 mPolicyFile = new AtomicFile(new File(dir, "notification_policy.xml"));
369
370 mBlockedPackages.clear();
371
372 FileInputStream infile = null;
373 try {
374 infile = mPolicyFile.openRead();
375 final XmlPullParser parser = Xml.newPullParser();
376 parser.setInput(infile, null);
377
378 int type;
379 String tag;
380 int version = DB_VERSION;
381 while ((type = parser.next()) != END_DOCUMENT) {
382 tag = parser.getName();
383 if (type == START_TAG) {
384 if (TAG_BODY.equals(tag)) {
385 version = Integer.parseInt(parser.getAttributeValue(null, ATTR_VERSION));
386 } else if (TAG_BLOCKED_PKGS.equals(tag)) {
387 while ((type = parser.next()) != END_DOCUMENT) {
388 tag = parser.getName();
389 if (TAG_PACKAGE.equals(tag)) {
390 mBlockedPackages.add(parser.getAttributeValue(null, ATTR_NAME));
391 } else if (TAG_BLOCKED_PKGS.equals(tag) && type == END_TAG) {
392 break;
393 }
394 }
395 }
396 }
397 }
398 } catch (FileNotFoundException e) {
399 // No data yet
400 } catch (IOException e) {
401 Log.wtf(TAG, "Unable to read blocked notifications database", e);
402 } catch (NumberFormatException e) {
403 Log.wtf(TAG, "Unable to parse blocked notifications database", e);
404 } catch (XmlPullParserException e) {
405 Log.wtf(TAG, "Unable to parse blocked notifications database", e);
406 } finally {
407 IoUtils.closeQuietly(infile);
408 }
409 }
410 }
411 }
412
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500413 /**
414 * Use this when you just want to know if notifications are OK for this package.
415 */
416 public boolean areNotificationsEnabledForPackage(String pkg, int uid) {
Daniel Sandler0da673f2012-04-11 12:33:16 -0400417 checkCallerIsSystem();
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500418 return (mAppOps.checkOpNoThrow(AppOpsManager.OP_POST_NOTIFICATION, uid, pkg)
419 == AppOpsManager.MODE_ALLOWED);
Daniel Sandler0da673f2012-04-11 12:33:16 -0400420 }
421
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500422 /** Use this when you actually want to post a notification or toast.
423 *
424 * Unchecked. Not exposed via Binder, but can be called in the course of enqueue*().
425 */
426 private boolean noteNotificationOp(String pkg, int uid) {
427 if (mAppOps.noteOpNoThrow(AppOpsManager.OP_POST_NOTIFICATION, uid, pkg)
428 != AppOpsManager.MODE_ALLOWED) {
429 Slog.v(TAG, "notifications are disabled by AppOps for " + pkg);
430 return false;
Daniel Sandler0da673f2012-04-11 12:33:16 -0400431 }
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500432 return true;
Daniel Sandler0da673f2012-04-11 12:33:16 -0400433 }
434
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500435 public void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled) {
Daniel Sandler0da673f2012-04-11 12:33:16 -0400436 checkCallerIsSystem();
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500437 if (true||DBG) {
Daniel Sandler0da673f2012-04-11 12:33:16 -0400438 Slog.v(TAG, (enabled?"en":"dis") + "abling notifications for " + pkg);
439 }
Daniel Sandler4a900acd2013-01-30 14:04:10 -0500440 mAppOps.setMode(AppOpsManager.OP_POST_NOTIFICATION, uid, pkg,
441 enabled ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_IGNORED);
Daniel Sandler0da673f2012-04-11 12:33:16 -0400442 }
443
444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445 private static String idDebugString(Context baseContext, String packageName, int id) {
446 Context c = null;
447
448 if (packageName != null) {
449 try {
450 c = baseContext.createPackageContext(packageName, 0);
451 } catch (NameNotFoundException e) {
452 c = baseContext;
453 }
454 } else {
455 c = baseContext;
456 }
457
458 String pkg;
459 String type;
460 String name;
461
462 Resources r = c.getResources();
463 try {
464 return r.getResourceName(id);
465 } catch (Resources.NotFoundException e) {
466 return "<name unknown>";
467 }
468 }
469
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700470 /**
471 * System-only API for getting a list of current (i.e. not cleared) notifications.
472 *
473 * Requires ACCESS_NOTIFICATIONS which is signature|system.
474 */
475 @Override
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500476 public StatusBarNotification[] getActiveNotifications(String callingPkg) {
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400477 // enforce() will ensure the calling uid has the correct permission
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500478 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NOTIFICATIONS,
Daniel Sandler78d0d252013-02-12 08:14:52 -0500479 "NotificationManagerService.getActiveNotifications");
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500480
481 StatusBarNotification[] tmp = null;
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500482 int uid = Binder.getCallingUid();
483
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400484 // noteOp will check to make sure the callingPkg matches the uid
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500485 if (mAppOps.noteOpNoThrow(AppOpsManager.OP_ACCESS_NOTIFICATIONS, uid, callingPkg)
486 == AppOpsManager.MODE_ALLOWED) {
487 synchronized (mNotificationList) {
488 tmp = new StatusBarNotification[mNotificationList.size()];
489 final int N = mNotificationList.size();
490 for (int i=0; i<N; i++) {
491 tmp[i] = mNotificationList.get(i).sbn;
492 }
493 }
494 }
495 return tmp;
496 }
497
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700498 /**
499 * System-only API for getting a list of recent (cleared, no longer shown) notifications.
500 *
501 * Requires ACCESS_NOTIFICATIONS which is signature|system.
502 */
503 @Override
Daniel Sandler78d0d252013-02-12 08:14:52 -0500504 public StatusBarNotification[] getHistoricalNotifications(String callingPkg, int count) {
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400505 // enforce() will ensure the calling uid has the correct permission
Daniel Sandler78d0d252013-02-12 08:14:52 -0500506 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NOTIFICATIONS,
507 "NotificationManagerService.getHistoricalNotifications");
508
509 StatusBarNotification[] tmp = null;
510 int uid = Binder.getCallingUid();
511
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400512 // noteOp will check to make sure the callingPkg matches the uid
Daniel Sandler78d0d252013-02-12 08:14:52 -0500513 if (mAppOps.noteOpNoThrow(AppOpsManager.OP_ACCESS_NOTIFICATIONS, uid, callingPkg)
514 == AppOpsManager.MODE_ALLOWED) {
515 synchronized (mArchive) {
516 tmp = mArchive.getArray(count);
517 }
518 }
519 return tmp;
520 }
521
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700522 /**
523 * Called whenever packages change, the user switches, or ENABLED_NOTIFICATION_LISTENERS
524 * is altered. (For example in response to USER_SWITCHED in our broadcast receiver)
525 */
526 void rebindListenerServices() {
527 String flat = Settings.Secure.getString(
528 mContext.getContentResolver(),
529 Settings.Secure.ENABLED_NOTIFICATION_LISTENERS);
530
531 NotificationListenerInfo[] toRemove = new NotificationListenerInfo[mListeners.size()];
532 final ArrayList<ComponentName> toAdd;
533 final int currentUser = ActivityManager.getCurrentUser();
534
535 synchronized (mNotificationList) {
536 // unbind and remove all existing listeners
537 toRemove = mListeners.toArray(toRemove);
538
539 toAdd = new ArrayList<ComponentName>();
540 final HashSet<ComponentName> newEnabled = new HashSet<ComponentName>();
541 final HashSet<String> newPackages = new HashSet<String>();
542
543 // decode the list of components
544 if (flat != null) {
545 String[] components = flat.split(ENABLED_NOTIFICATION_LISTENERS_SEPARATOR);
546 for (int i=0; i<components.length; i++) {
547 final ComponentName component
548 = ComponentName.unflattenFromString(components[i]);
549 if (component != null) {
550 newEnabled.add(component);
551 toAdd.add(component);
552 newPackages.add(component.getPackageName());
553 }
554 }
555
556 mEnabledListenersForCurrentUser = newEnabled;
557 mEnabledListenerPackageNames = newPackages;
558 }
559 }
560
561 for (NotificationListenerInfo info : toRemove) {
562 final ComponentName component = info.component;
563 final int oldUser = info.userid;
564 Slog.v(TAG, "disabling notification listener for user " + oldUser + ": " + component);
565 unregisterListenerService(component, info.userid);
566 }
567
568 final int N = toAdd.size();
569 for (int i=0; i<N; i++) {
570 final ComponentName component = toAdd.get(i);
571 Slog.v(TAG, "enabling notification listener for user " + currentUser + ": "
572 + component);
573 registerListenerService(component, currentUser);
574 }
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400575 }
576
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700577 /**
578 * Register a listener binder directly with the notification manager.
579 *
580 * Only works with system callers. Apps should extend
581 * {@link android.service.notification.NotificationListenerService}.
582 */
Daniel Sandler09a247e2013-02-14 10:24:17 -0500583 @Override
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400584 public void registerListener(final INotificationListener listener,
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700585 final ComponentName component, final int userid) {
586 checkCallerIsSystem();
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400587
Daniel Sandler09a247e2013-02-14 10:24:17 -0500588 synchronized (mNotificationList) {
589 try {
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400590 NotificationListenerInfo info
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700591 = new NotificationListenerInfo(listener, component, userid, true);
Daniel Sandler09a247e2013-02-14 10:24:17 -0500592 listener.asBinder().linkToDeath(info, 0);
593 mListeners.add(info);
594 } catch (RemoteException e) {
595 // already dead
596 }
597 }
598 }
599
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700600 /**
601 * Version of registerListener that takes the name of a
602 * {@link android.service.notification.NotificationListenerService} to bind to.
603 *
604 * This is the mechanism by which third parties may subscribe to notifications.
605 */
606 private void registerListenerService(final ComponentName name, final int userid) {
607 checkCallerIsSystem();
608
609 if (DBG) Slog.v(TAG, "registerListenerService: " + name + " u=" + userid);
610
611 synchronized (mNotificationList) {
612 final String servicesBindingTag = name.toString() + "/" + userid;
613 if (mServicesBinding.contains(servicesBindingTag)) {
614 // stop registering this thing already! we're working on it
615 return;
616 }
617 mServicesBinding.add(servicesBindingTag);
618
619 final int N = mListeners.size();
620 for (int i=N-1; i>=0; i--) {
621 final NotificationListenerInfo info = mListeners.get(i);
622 if (name.equals(info.component)
623 && info.userid == userid) {
624 // cut old connections
625 if (DBG) Slog.v(TAG, " disconnecting old listener: " + info.listener);
626 mListeners.remove(i);
627 if (info.connection != null) {
628 mContext.unbindService(info.connection);
629 }
630 }
631 }
632
633 Intent intent = new Intent(NotificationListenerService.SERVICE_INTERFACE);
634 intent.setComponent(name);
635
636 intent.putExtra(Intent.EXTRA_CLIENT_LABEL,
637 com.android.internal.R.string.notification_listener_binding_label);
638 intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity(
639 mContext, 0, new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS), 0));
640
641 try {
642 if (DBG) Slog.v(TAG, "binding: " + intent);
643 if (!mContext.bindServiceAsUser(intent,
644 new ServiceConnection() {
645 INotificationListener mListener;
646 @Override
647 public void onServiceConnected(ComponentName name, IBinder service) {
648 synchronized (mNotificationList) {
649 mServicesBinding.remove(servicesBindingTag);
650 try {
651 mListener = INotificationListener.Stub.asInterface(service);
652 NotificationListenerInfo info = new NotificationListenerInfo(
653 mListener, name, userid, this);
654 service.linkToDeath(info, 0);
655 mListeners.add(info);
656 } catch (RemoteException e) {
657 // already dead
658 }
659 }
660 }
661
662 @Override
663 public void onServiceDisconnected(ComponentName name) {
664 Slog.v(TAG, "notification listener connection lost: " + name);
665 }
666 },
667 Context.BIND_AUTO_CREATE,
668 new UserHandle(userid)))
669 {
670 mServicesBinding.remove(servicesBindingTag);
671 Slog.w(TAG, "Unable to bind listener service: " + intent);
672 return;
673 }
674 } catch (SecurityException ex) {
675 Slog.e(TAG, "Unable to bind listener service: " + intent, ex);
676 return;
677 }
678 }
679 }
680
681 /**
682 * Remove a listener binder directly
683 */
Daniel Sandler09a247e2013-02-14 10:24:17 -0500684 @Override
685 public void unregisterListener(INotificationListener listener, int userid) {
Daniel Sandler4b749ef2013-03-18 21:53:04 -0400686 // no need to check permissions; if your listener binder is in the list,
687 // that's proof that you had permission to add it in the first place
688
Daniel Sandler09a247e2013-02-14 10:24:17 -0500689 synchronized (mNotificationList) {
690 final int N = mListeners.size();
691 for (int i=N-1; i>=0; i--) {
692 final NotificationListenerInfo info = mListeners.get(i);
693 if (info.listener == listener && info.userid == userid) {
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700694 mListeners.remove(i);
695 if (info.connection != null) {
696 mContext.unbindService(info.connection);
697 }
Daniel Sandler09a247e2013-02-14 10:24:17 -0500698 }
699 }
700 }
701 }
702
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700703 /**
704 * Remove a listener service for the given user by ComponentName
705 */
706 private void unregisterListenerService(ComponentName name, int userid) {
707 checkCallerIsSystem();
708
709 synchronized (mNotificationList) {
710 final int N = mListeners.size();
711 for (int i=N-1; i>=0; i--) {
712 final NotificationListenerInfo info = mListeners.get(i);
713 if (name.equals(info.component)
714 && info.userid == userid) {
715 mListeners.remove(i);
716 if (info.connection != null) {
717 mContext.unbindService(info.connection);
718 }
719 }
720 }
721 }
722 }
723
724 /**
725 * asynchronously notify all listeners about a new notification
726 */
Daniel Sandler09a247e2013-02-14 10:24:17 -0500727 private void notifyPostedLocked(NotificationRecord n) {
728 final StatusBarNotification sbn = n.sbn;
729 for (final NotificationListenerInfo info : mListeners) {
730 mHandler.post(new Runnable() {
731 @Override
732 public void run() {
733 info.notifyPostedIfUserMatch(sbn);
734 }});
735 }
736 }
737
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700738 /**
739 * asynchronously notify all listeners about a removed notification
740 */
Daniel Sandler09a247e2013-02-14 10:24:17 -0500741 private void notifyRemovedLocked(NotificationRecord n) {
742 final StatusBarNotification sbn = n.sbn;
743 for (final NotificationListenerInfo info : mListeners) {
744 mHandler.post(new Runnable() {
745 @Override
746 public void run() {
747 info.notifyRemovedIfUserMatch(sbn);
748 }});
749 }
750 }
751
Daniel Sandler5feceeb2013-03-22 18:29:23 -0700752 // -- APIs to support listeners clicking/clearing notifications --
753
754 private NotificationListenerInfo checkListenerToken(INotificationListener listener) {
755 final IBinder token = listener.asBinder();
756 final int N = mListeners.size();
757 for (int i=0; i<N; i++) {
758 final NotificationListenerInfo info = mListeners.get(i);
759 if (info.listener.asBinder() == token) return info;
760 }
761 throw new SecurityException("Disallowed call from unknown listener: " + listener);
762 }
763
764 /**
765 * Allow an INotificationListener to simulate a "clear all" operation.
766 *
767 * {@see com.android.server.StatusBarManagerService.NotificationCallbacks#onClearAllNotifications}
768 *
769 * @param token The binder for the listener, to check that the caller is allowed
770 */
771 public void clearAllNotificationsFromListener(INotificationListener token) {
772 NotificationListenerInfo info = checkListenerToken(token);
773 long identity = Binder.clearCallingIdentity();
774 try {
775 cancelAll(info.userid);
776 } finally {
777 Binder.restoreCallingIdentity(identity);
778 }
779 }
780
781 /**
782 * Allow an INotificationListener to simulate clearing (dismissing) a single notification.
783 *
784 * {@see com.android.server.StatusBarManagerService.NotificationCallbacks#onNotificationClear}
785 *
786 * @param token The binder for the listener, to check that the caller is allowed
787 */
788 public void clearNotificationFromListener(INotificationListener token, String pkg, String tag, int id) {
789 NotificationListenerInfo info = checkListenerToken(token);
790 long identity = Binder.clearCallingIdentity();
791 try {
792 cancelNotification(pkg, tag, id, 0,
793 Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE,
794 true,
795 info.userid);
796 } finally {
797 Binder.restoreCallingIdentity(identity);
798 }
799 }
800
801 // -- end of listener APIs --
802
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500803 public static final class NotificationRecord
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800804 {
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500805 final StatusBarNotification sbn;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800806 IBinder statusBarKey;
807
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500808 NotificationRecord(StatusBarNotification sbn)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800809 {
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500810 this.sbn = sbn;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800811 }
Fred Quintana6ecaff12009-09-25 14:23:13 -0700812
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500813 public Notification getNotification() { return sbn.notification; }
814 public int getFlags() { return sbn.notification.flags; }
815 public int getUserId() { return sbn.getUserId(); }
816
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800817 void dump(PrintWriter pw, String prefix, Context baseContext) {
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500818 final Notification notification = sbn.notification;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800819 pw.println(prefix + this);
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400820 pw.println(prefix + " uid=" + sbn.uid + " userId=" + sbn.getUserId());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821 pw.println(prefix + " icon=0x" + Integer.toHexString(notification.icon)
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400822 + " / " + idDebugString(baseContext, sbn.pkg, notification.icon));
823 pw.println(prefix + " pri=" + notification.priority + " score=" + sbn.score);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800824 pw.println(prefix + " contentIntent=" + notification.contentIntent);
825 pw.println(prefix + " deleteIntent=" + notification.deleteIntent);
826 pw.println(prefix + " tickerText=" + notification.tickerText);
827 pw.println(prefix + " contentView=" + notification.contentView);
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400828 pw.println(prefix + String.format(" defaults=0x%08x flags=0x%08x",
829 notification.defaults, notification.flags));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800830 pw.println(prefix + " sound=" + notification.sound);
831 pw.println(prefix + " vibrate=" + Arrays.toString(notification.vibrate));
Daniel Sandlerf45564e2013-04-15 15:05:08 -0400832 pw.println(prefix + String.format(" led=0x%08x onMs=%d offMs=%d",
833 notification.ledARGB, notification.ledOnMS, notification.ledOffMS));
834 if (notification.actions != null && notification.actions.length > 0) {
835 pw.println(prefix + " actions={");
836 final int N = notification.actions.length;
837 for (int i=0; i<N; i++) {
838 final Notification.Action action = notification.actions[i];
839 pw.println(String.format("%s [%d] \"%s\" -> %s",
840 prefix,
841 i,
842 action.title,
843 action.actionIntent.toString()
844 ));
845 }
846 pw.println(prefix + " }");
847 }
848 if (notification.extras != null && notification.extras.size() > 0) {
849 pw.println(prefix + " extras={");
850 for (String key : notification.extras.keySet()) {
851 pw.print(prefix + " " + key + "=");
852 Object val = notification.extras.get(key);
853 if (val == null) {
854 pw.println("null");
855 } else {
856 pw.print(val.toString());
857 if (val instanceof Bitmap) {
858 pw.print(String.format(" (%dx%d)",
859 ((Bitmap) val).getWidth(),
860 ((Bitmap) val).getHeight()));
861 } else if (val.getClass().isArray()) {
862 pw.println(" {");
863 final int N = Array.getLength(val);
864 for (int i=0; i<N; i++) {
865 if (i > 0) pw.println(",");
866 pw.print(prefix + " " + Array.get(val, i));
867 }
868 pw.print("\n" + prefix + " }");
869 }
870 pw.println();
871 }
872 }
873 pw.println(prefix + " }");
874 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800875 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877 @Override
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500878 public final String toString() {
879 return String.format(
880 "NotificationRecord(0x%08x: pkg=%s user=%s id=%d tag=%s score=%d: %s)",
881 System.identityHashCode(this),
882 this.sbn.pkg, this.sbn.user, this.sbn.id, this.sbn.tag,
883 this.sbn.score, this.sbn.notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800884 }
885 }
886
887 private static final class ToastRecord
888 {
889 final int pid;
890 final String pkg;
891 final ITransientNotification callback;
892 int duration;
893
894 ToastRecord(int pid, String pkg, ITransientNotification callback, int duration)
895 {
896 this.pid = pid;
897 this.pkg = pkg;
898 this.callback = callback;
899 this.duration = duration;
900 }
901
902 void update(int duration) {
903 this.duration = duration;
904 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906 void dump(PrintWriter pw, String prefix) {
907 pw.println(prefix + this);
908 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800910 @Override
911 public final String toString()
912 {
913 return "ToastRecord{"
914 + Integer.toHexString(System.identityHashCode(this))
915 + " pkg=" + pkg
916 + " callback=" + callback
917 + " duration=" + duration;
918 }
919 }
920
Joe Onorato089de882010-04-12 08:18:45 -0700921 private StatusBarManagerService.NotificationCallbacks mNotificationCallbacks
922 = new StatusBarManagerService.NotificationCallbacks() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923
924 public void onSetDisabled(int status) {
925 synchronized (mNotificationList) {
926 mDisabledNotifications = status;
927 if ((mDisabledNotifications & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0) {
928 // cancel whatever's going on
929 long identity = Binder.clearCallingIdentity();
930 try {
Jeff Sharkey098d5802012-04-26 17:30:34 -0700931 final IRingtonePlayer player = mAudioService.getRingtonePlayer();
932 if (player != null) {
933 player.stopAsync();
934 }
935 } catch (RemoteException e) {
936 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800937 Binder.restoreCallingIdentity(identity);
938 }
939
940 identity = Binder.clearCallingIdentity();
941 try {
942 mVibrator.cancel();
Jeff Sharkey098d5802012-04-26 17:30:34 -0700943 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800944 Binder.restoreCallingIdentity(identity);
945 }
946 }
947 }
948 }
949
950 public void onClearAll() {
Dianne Hackborn41203752012-08-31 14:05:51 -0700951 // XXX to be totally correct, the caller should tell us which user
952 // this is for.
953 cancelAll(ActivityManager.getCurrentUser());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800954 }
955
Fred Quintana6ecaff12009-09-25 14:23:13 -0700956 public void onNotificationClick(String pkg, String tag, int id) {
Dianne Hackborn41203752012-08-31 14:05:51 -0700957 // XXX to be totally correct, the caller should tell us which user
958 // this is for.
Fred Quintana6ecaff12009-09-25 14:23:13 -0700959 cancelNotification(pkg, tag, id, Notification.FLAG_AUTO_CANCEL,
Dianne Hackborn41203752012-08-31 14:05:51 -0700960 Notification.FLAG_FOREGROUND_SERVICE, false,
961 ActivityManager.getCurrentUser());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800962 }
963
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400964 public void onNotificationClear(String pkg, String tag, int id) {
Dianne Hackborn41203752012-08-31 14:05:51 -0700965 // XXX to be totally correct, the caller should tell us which user
966 // this is for.
Joe Onorato46439ce2010-11-19 13:56:21 -0800967 cancelNotification(pkg, tag, id, 0,
968 Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE,
Dianne Hackborn41203752012-08-31 14:05:51 -0700969 true, ActivityManager.getCurrentUser());
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400970 }
971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800972 public void onPanelRevealed() {
973 synchronized (mNotificationList) {
974 // sound
975 mSoundNotification = null;
Jeff Sharkey098d5802012-04-26 17:30:34 -0700976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800977 long identity = Binder.clearCallingIdentity();
978 try {
Jeff Sharkey098d5802012-04-26 17:30:34 -0700979 final IRingtonePlayer player = mAudioService.getRingtonePlayer();
980 if (player != null) {
981 player.stopAsync();
982 }
983 } catch (RemoteException e) {
984 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800985 Binder.restoreCallingIdentity(identity);
986 }
987
988 // vibrate
989 mVibrateNotification = null;
990 identity = Binder.clearCallingIdentity();
991 try {
992 mVibrator.cancel();
Jeff Sharkey098d5802012-04-26 17:30:34 -0700993 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800994 Binder.restoreCallingIdentity(identity);
995 }
996
997 // light
998 mLights.clear();
999 mLedNotification = null;
1000 updateLightsLocked();
1001 }
1002 }
Joe Onorato005847b2010-06-04 16:08:02 -04001003
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -07001004 public void onNotificationError(String pkg, String tag, int id,
1005 int uid, int initialPid, String message) {
Daniel Sandlerd0a2f862010-08-03 15:29:31 -04001006 Slog.d(TAG, "onNotification error pkg=" + pkg + " tag=" + tag + " id=" + id
1007 + "; will crashApplication(uid=" + uid + ", pid=" + initialPid + ")");
Dianne Hackborn41203752012-08-31 14:05:51 -07001008 // XXX to be totally correct, the caller should tell us which user
1009 // this is for.
1010 cancelNotification(pkg, tag, id, 0, 0, false, UserHandle.getUserId(uid));
Dianne Hackborn9d39d0c2010-06-24 15:57:42 -07001011 long ident = Binder.clearCallingIdentity();
1012 try {
1013 ActivityManagerNative.getDefault().crashApplication(uid, initialPid, pkg,
1014 "Bad notification posted from package " + pkg
1015 + ": " + message);
1016 } catch (RemoteException e) {
1017 }
1018 Binder.restoreCallingIdentity(ident);
Joe Onorato005847b2010-06-04 16:08:02 -04001019 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001020 };
1021
1022 private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
1023 @Override
1024 public void onReceive(Context context, Intent intent) {
1025 String action = intent.getAction();
1026
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001027 boolean queryRestart = false;
Daniel Sandler26ece572012-06-01 15:38:46 -04001028 boolean packageChanged = false;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001029
Mike Lockwood541c9942011-06-12 19:35:45 -04001030 if (action.equals(Intent.ACTION_PACKAGE_REMOVED)
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001031 || action.equals(Intent.ACTION_PACKAGE_RESTARTED)
Daniel Sandler26ece572012-06-01 15:38:46 -04001032 || (packageChanged=action.equals(Intent.ACTION_PACKAGE_CHANGED))
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001033 || (queryRestart=action.equals(Intent.ACTION_QUERY_PACKAGE_RESTART))
Suchi Amalapurapub56ae202010-02-04 22:51:07 -08001034 || action.equals(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)) {
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001035 String pkgList[] = null;
Suchi Amalapurapub56ae202010-02-04 22:51:07 -08001036 if (action.equals(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)) {
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001037 pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001038 } else if (queryRestart) {
1039 pkgList = intent.getStringArrayExtra(Intent.EXTRA_PACKAGES);
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001040 } else {
1041 Uri uri = intent.getData();
1042 if (uri == null) {
1043 return;
1044 }
1045 String pkgName = uri.getSchemeSpecificPart();
1046 if (pkgName == null) {
1047 return;
1048 }
Daniel Sandler26ece572012-06-01 15:38:46 -04001049 if (packageChanged) {
1050 // We cancel notifications for packages which have just been disabled
1051 final int enabled = mContext.getPackageManager()
1052 .getApplicationEnabledSetting(pkgName);
1053 if (enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1054 || enabled == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
1055 return;
1056 }
1057 }
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001058 pkgList = new String[]{pkgName};
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001059 }
Daniel Sandler5feceeb2013-03-22 18:29:23 -07001060
1061 boolean anyListenersInvolved = false;
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001062 if (pkgList != null && (pkgList.length > 0)) {
1063 for (String pkgName : pkgList) {
Dianne Hackborn41203752012-08-31 14:05:51 -07001064 cancelAllNotificationsInt(pkgName, 0, 0, !queryRestart,
1065 UserHandle.USER_ALL);
Daniel Sandler5feceeb2013-03-22 18:29:23 -07001066 if (mEnabledListenerPackageNames.contains(pkgName)) {
1067 anyListenersInvolved = true;
1068 }
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001069 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001070 }
Daniel Sandler5feceeb2013-03-22 18:29:23 -07001071
1072 if (anyListenersInvolved) {
1073 // make sure we're still bound to any of our
1074 // listeners who may have just upgraded
1075 rebindListenerServices();
1076 }
Mike Lockwood63b5ad92011-08-30 09:55:30 -04001077 } else if (action.equals(Intent.ACTION_SCREEN_ON)) {
1078 // Keep track of screen on/off state, but do not turn off the notification light
1079 // until user passes through the lock screen or views the notification.
1080 mScreenOn = true;
1081 } else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
1082 mScreenOn = false;
Daniel Sandlere96ffb12010-03-11 13:38:06 -05001083 } else if (action.equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
Mike Lockwood63b5ad92011-08-30 09:55:30 -04001084 mInCall = (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
1085 TelephonyManager.EXTRA_STATE_OFFHOOK));
Daniel Sandlere96ffb12010-03-11 13:38:06 -05001086 updateNotificationPulse();
Dianne Hackborn80a4af22012-08-27 19:18:31 -07001087 } else if (action.equals(Intent.ACTION_USER_STOPPED)) {
1088 int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
1089 if (userHandle >= 0) {
Dianne Hackborn41203752012-08-31 14:05:51 -07001090 cancelAllNotificationsInt(null, 0, 0, true, userHandle);
Dianne Hackborn80a4af22012-08-27 19:18:31 -07001091 }
Mike Lockwood63b5ad92011-08-30 09:55:30 -04001092 } else if (action.equals(Intent.ACTION_USER_PRESENT)) {
1093 // turn off LED when user passes through lock screen
1094 mNotificationLight.turnOff();
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001095 } else if (action.equals(Intent.ACTION_USER_SWITCHED)) {
1096 // reload per-user settings
1097 mSettingsObserver.update(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001098 }
1099 }
1100 };
1101
Dianne Hackborn1dac2772009-06-26 18:16:48 -07001102 class SettingsObserver extends ContentObserver {
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001103 private final Uri NOTIFICATION_LIGHT_PULSE_URI
1104 = Settings.System.getUriFor(Settings.System.NOTIFICATION_LIGHT_PULSE);
1105
1106 private final Uri ENABLED_NOTIFICATION_LISTENERS_URI
Daniel Sandler5feceeb2013-03-22 18:29:23 -07001107 = Settings.Secure.getUriFor(Settings.Secure.ENABLED_NOTIFICATION_LISTENERS);
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001108
Dianne Hackborn1dac2772009-06-26 18:16:48 -07001109 SettingsObserver(Handler handler) {
1110 super(handler);
1111 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001112
Dianne Hackborn1dac2772009-06-26 18:16:48 -07001113 void observe() {
1114 ContentResolver resolver = mContext.getContentResolver();
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001115 resolver.registerContentObserver(NOTIFICATION_LIGHT_PULSE_URI,
Daniel Sandler5feceeb2013-03-22 18:29:23 -07001116 false, this, UserHandle.USER_ALL);
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001117 resolver.registerContentObserver(ENABLED_NOTIFICATION_LISTENERS_URI,
Daniel Sandler5feceeb2013-03-22 18:29:23 -07001118 false, this, UserHandle.USER_ALL);
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001119 update(null);
Dianne Hackborn1dac2772009-06-26 18:16:48 -07001120 }
1121
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001122 @Override public void onChange(boolean selfChange, Uri uri) {
1123 update(uri);
Dianne Hackborn1dac2772009-06-26 18:16:48 -07001124 }
1125
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001126 public void update(Uri uri) {
Dianne Hackborn1dac2772009-06-26 18:16:48 -07001127 ContentResolver resolver = mContext.getContentResolver();
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001128 if (uri == null || NOTIFICATION_LIGHT_PULSE_URI.equals(uri)) {
1129 boolean pulseEnabled = Settings.System.getInt(resolver,
1130 Settings.System.NOTIFICATION_LIGHT_PULSE, 0) != 0;
1131 if (mNotificationPulseEnabled != pulseEnabled) {
1132 mNotificationPulseEnabled = pulseEnabled;
1133 updateNotificationPulse();
1134 }
1135 }
1136 if (uri == null || ENABLED_NOTIFICATION_LISTENERS_URI.equals(uri)) {
Daniel Sandler5feceeb2013-03-22 18:29:23 -07001137 rebindListenerServices();
Mike Lockwoodc22404a2009-12-02 11:15:02 -05001138 }
Dianne Hackborn1dac2772009-06-26 18:16:48 -07001139 }
1140 }
Mike Lockwoodc22404a2009-12-02 11:15:02 -05001141
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001142 private SettingsObserver mSettingsObserver;
1143
Daniel Sandleredbb3802012-11-13 20:49:47 -08001144 static long[] getLongArray(Resources r, int resid, int maxlen, long[] def) {
1145 int[] ar = r.getIntArray(resid);
1146 if (ar == null) {
1147 return def;
1148 }
1149 final int len = ar.length > maxlen ? maxlen : ar.length;
1150 long[] out = new long[len];
1151 for (int i=0; i<len; i++) {
1152 out[i] = ar[i];
1153 }
1154 return out;
1155 }
1156
Joe Onorato089de882010-04-12 08:18:45 -07001157 NotificationManagerService(Context context, StatusBarManagerService statusBar,
Mike Lockwood3a322132009-11-24 00:30:52 -05001158 LightsService lights)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001159 {
1160 super();
1161 mContext = context;
Jeff Brownc2346132012-04-13 01:55:38 -07001162 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001163 mAm = ActivityManagerNative.getDefault();
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001164 mUserManager = (UserManager)context.getSystemService(Context.USER_SERVICE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001165 mToastQueue = new ArrayList<ToastRecord>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001166 mHandler = new WorkerHandler();
San Mehat3ee13172010-02-04 20:54:43 -08001167
Daniel Sandler4a900acd2013-01-30 14:04:10 -05001168 mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE);
1169
1170 importOldBlockDb();
Daniel Sandler0da673f2012-04-11 12:33:16 -04001171
Joe Onorato089de882010-04-12 08:18:45 -07001172 mStatusBar = statusBar;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001173 statusBar.setNotificationCallbacks(mNotificationCallbacks);
1174
Mike Lockwood3cb67a32009-11-27 14:25:58 -05001175 mNotificationLight = lights.getLight(LightsService.LIGHT_ID_NOTIFICATIONS);
1176 mAttentionLight = lights.getLight(LightsService.LIGHT_ID_ATTENTION);
1177
Mike Lockwood670f9322010-01-20 12:13:36 -05001178 Resources resources = mContext.getResources();
1179 mDefaultNotificationColor = resources.getColor(
1180 com.android.internal.R.color.config_defaultNotificationColor);
1181 mDefaultNotificationLedOn = resources.getInteger(
1182 com.android.internal.R.integer.config_defaultNotificationLedOn);
1183 mDefaultNotificationLedOff = resources.getInteger(
1184 com.android.internal.R.integer.config_defaultNotificationLedOff);
1185
Daniel Sandleredbb3802012-11-13 20:49:47 -08001186 mDefaultVibrationPattern = getLongArray(resources,
1187 com.android.internal.R.array.config_defaultNotificationVibePattern,
1188 VIBRATE_PATTERN_MAXLEN,
1189 DEFAULT_VIBRATE_PATTERN);
1190
1191 mFallbackVibrationPattern = getLongArray(resources,
1192 com.android.internal.R.array.config_notificationFallbackVibePattern,
1193 VIBRATE_PATTERN_MAXLEN,
1194 DEFAULT_VIBRATE_PATTERN);
1195
Joe Onorato39f5b6a2009-07-23 12:29:19 -04001196 // Don't start allowing notifications until the setup wizard has run once.
1197 // After that, including subsequent boots, init with notifications turned on.
1198 // This works on the first boot because the setup wizard will toggle this
1199 // flag at least once and we'll go back to 0 after that.
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001200 if (0 == Settings.Global.getInt(mContext.getContentResolver(),
1201 Settings.Global.DEVICE_PROVISIONED, 0)) {
Joe Onorato39f5b6a2009-07-23 12:29:19 -04001202 mDisabledNotifications = StatusBarManager.DISABLE_NOTIFICATION_ALERTS;
1203 }
1204
Mike Lockwood35e16bf2010-11-30 19:53:36 -05001205 // register for various Intents
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001206 IntentFilter filter = new IntentFilter();
Mike Lockwoodc22404a2009-12-02 11:15:02 -05001207 filter.addAction(Intent.ACTION_SCREEN_ON);
1208 filter.addAction(Intent.ACTION_SCREEN_OFF);
Daniel Sandlere96ffb12010-03-11 13:38:06 -05001209 filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
Mike Lockwood63b5ad92011-08-30 09:55:30 -04001210 filter.addAction(Intent.ACTION_USER_PRESENT);
Dianne Hackborn80a4af22012-08-27 19:18:31 -07001211 filter.addAction(Intent.ACTION_USER_STOPPED);
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001212 filter.addAction(Intent.ACTION_USER_SWITCHED);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001213 mContext.registerReceiver(mIntentReceiver, filter);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001214 IntentFilter pkgFilter = new IntentFilter();
1215 pkgFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
Daniel Sandleraac0eb02011-08-06 22:51:56 -04001216 pkgFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001217 pkgFilter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
1218 pkgFilter.addAction(Intent.ACTION_QUERY_PACKAGE_RESTART);
1219 pkgFilter.addDataScheme("package");
1220 mContext.registerReceiver(mIntentReceiver, pkgFilter);
Suchi Amalapurapub56ae202010-02-04 22:51:07 -08001221 IntentFilter sdFilter = new IntentFilter(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001222 mContext.registerReceiver(mIntentReceiver, sdFilter);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001223
Daniel Sandler4b749ef2013-03-18 21:53:04 -04001224 mSettingsObserver = new SettingsObserver(mHandler);
1225 mSettingsObserver.observe();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 }
1227
Daniel Sandler4a900acd2013-01-30 14:04:10 -05001228 /**
1229 * Read the old XML-based app block database and import those blockages into the AppOps system.
1230 */
1231 private void importOldBlockDb() {
1232 loadBlockDb();
1233
1234 PackageManager pm = mContext.getPackageManager();
1235 for (String pkg : mBlockedPackages) {
1236 PackageInfo info = null;
1237 try {
1238 info = pm.getPackageInfo(pkg, 0);
1239 setNotificationsEnabledForPackage(pkg, info.applicationInfo.uid, false);
1240 } catch (NameNotFoundException e) {
1241 // forget you
1242 }
1243 }
1244 mBlockedPackages.clear();
1245 if (mPolicyFile != null) {
1246 mPolicyFile.delete();
1247 }
1248 }
1249
Joe Onorato30275482009-07-08 17:09:14 -07001250 void systemReady() {
Jeff Sharkey098d5802012-04-26 17:30:34 -07001251 mAudioService = IAudioService.Stub.asInterface(
1252 ServiceManager.getService(Context.AUDIO_SERVICE));
1253
Joe Onorato30275482009-07-08 17:09:14 -07001254 // no beeping until we're basically done booting
1255 mSystemReady = true;
Daniel Sandler5feceeb2013-03-22 18:29:23 -07001256
1257 // make sure our listener services are properly bound
1258 rebindListenerServices();
Joe Onorato30275482009-07-08 17:09:14 -07001259 }
1260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001261 // Toasts
1262 // ============================================================================
1263 public void enqueueToast(String pkg, ITransientNotification callback, int duration)
1264 {
Daniel Sandlera7035902010-03-30 15:45:31 -04001265 if (DBG) Slog.i(TAG, "enqueueToast pkg=" + pkg + " callback=" + callback + " duration=" + duration);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001266
1267 if (pkg == null || callback == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001268 Slog.e(TAG, "Not doing toast. pkg=" + pkg + " callback=" + callback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001269 return ;
1270 }
1271
Daniel Sandler0da673f2012-04-11 12:33:16 -04001272 final boolean isSystemToast = ("android".equals(pkg));
1273
Daniel Sandler4a900acd2013-01-30 14:04:10 -05001274 if (ENABLE_BLOCKED_TOASTS && !noteNotificationOp(pkg, Binder.getCallingUid())) {
1275 if (!isSystemToast) {
1276 Slog.e(TAG, "Suppressing toast from package " + pkg + " by user request.");
1277 return;
1278 }
Daniel Sandler0da673f2012-04-11 12:33:16 -04001279 }
1280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001281 synchronized (mToastQueue) {
1282 int callingPid = Binder.getCallingPid();
1283 long callingId = Binder.clearCallingIdentity();
1284 try {
1285 ToastRecord record;
1286 int index = indexOfToastLocked(pkg, callback);
1287 // If it's already in the queue, we update it in place, we don't
1288 // move it to the end of the queue.
1289 if (index >= 0) {
1290 record = mToastQueue.get(index);
1291 record.update(duration);
1292 } else {
Vairavan Srinivasanf9eb06c2011-01-21 18:08:36 -08001293 // Limit the number of toasts that any given package except the android
1294 // package can enqueue. Prevents DOS attacks and deals with leaks.
Daniel Sandler0da673f2012-04-11 12:33:16 -04001295 if (!isSystemToast) {
Vairavan Srinivasanf9eb06c2011-01-21 18:08:36 -08001296 int count = 0;
1297 final int N = mToastQueue.size();
1298 for (int i=0; i<N; i++) {
1299 final ToastRecord r = mToastQueue.get(i);
1300 if (r.pkg.equals(pkg)) {
1301 count++;
1302 if (count >= MAX_PACKAGE_NOTIFICATIONS) {
1303 Slog.e(TAG, "Package has already posted " + count
1304 + " toasts. Not showing more. Package=" + pkg);
1305 return;
1306 }
1307 }
1308 }
1309 }
1310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001311 record = new ToastRecord(callingPid, pkg, callback, duration);
1312 mToastQueue.add(record);
1313 index = mToastQueue.size() - 1;
1314 keepProcessAliveLocked(callingPid);
1315 }
1316 // If it's at index 0, it's the current toast. It doesn't matter if it's
1317 // new or just been updated. Call back and tell it to show itself.
1318 // If the callback fails, this will remove it from the list, so don't
1319 // assume that it's valid after this.
1320 if (index == 0) {
1321 showNextToastLocked();
1322 }
1323 } finally {
1324 Binder.restoreCallingIdentity(callingId);
1325 }
1326 }
1327 }
1328
1329 public void cancelToast(String pkg, ITransientNotification callback) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001330 Slog.i(TAG, "cancelToast pkg=" + pkg + " callback=" + callback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001331
1332 if (pkg == null || callback == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001333 Slog.e(TAG, "Not cancelling notification. pkg=" + pkg + " callback=" + callback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001334 return ;
1335 }
1336
1337 synchronized (mToastQueue) {
1338 long callingId = Binder.clearCallingIdentity();
1339 try {
1340 int index = indexOfToastLocked(pkg, callback);
1341 if (index >= 0) {
1342 cancelToastLocked(index);
1343 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001344 Slog.w(TAG, "Toast already cancelled. pkg=" + pkg + " callback=" + callback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001345 }
1346 } finally {
1347 Binder.restoreCallingIdentity(callingId);
1348 }
1349 }
1350 }
1351
1352 private void showNextToastLocked() {
1353 ToastRecord record = mToastQueue.get(0);
1354 while (record != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001355 if (DBG) Slog.d(TAG, "Show pkg=" + record.pkg + " callback=" + record.callback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001356 try {
1357 record.callback.show();
1358 scheduleTimeoutLocked(record, false);
1359 return;
1360 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001361 Slog.w(TAG, "Object died trying to show notification " + record.callback
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001362 + " in package " + record.pkg);
1363 // remove it from the list and let the process die
1364 int index = mToastQueue.indexOf(record);
1365 if (index >= 0) {
1366 mToastQueue.remove(index);
1367 }
1368 keepProcessAliveLocked(record.pid);
1369 if (mToastQueue.size() > 0) {
1370 record = mToastQueue.get(0);
1371 } else {
1372 record = null;
1373 }
1374 }
1375 }
1376 }
1377
1378 private void cancelToastLocked(int index) {
1379 ToastRecord record = mToastQueue.get(index);
1380 try {
1381 record.callback.hide();
1382 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001383 Slog.w(TAG, "Object died trying to hide notification " + record.callback
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001384 + " in package " + record.pkg);
1385 // don't worry about this, we're about to remove it from
1386 // the list anyway
1387 }
1388 mToastQueue.remove(index);
1389 keepProcessAliveLocked(record.pid);
1390 if (mToastQueue.size() > 0) {
1391 // Show the next one. If the callback fails, this will remove
1392 // it from the list, so don't assume that the list hasn't changed
1393 // after this point.
1394 showNextToastLocked();
1395 }
1396 }
1397
1398 private void scheduleTimeoutLocked(ToastRecord r, boolean immediate)
1399 {
1400 Message m = Message.obtain(mHandler, MESSAGE_TIMEOUT, r);
1401 long delay = immediate ? 0 : (r.duration == Toast.LENGTH_LONG ? LONG_DELAY : SHORT_DELAY);
1402 mHandler.removeCallbacksAndMessages(r);
1403 mHandler.sendMessageDelayed(m, delay);
1404 }
1405
1406 private void handleTimeout(ToastRecord record)
1407 {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001408 if (DBG) Slog.d(TAG, "Timeout pkg=" + record.pkg + " callback=" + record.callback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001409 synchronized (mToastQueue) {
1410 int index = indexOfToastLocked(record.pkg, record.callback);
1411 if (index >= 0) {
1412 cancelToastLocked(index);
1413 }
1414 }
1415 }
1416
1417 // lock on mToastQueue
1418 private int indexOfToastLocked(String pkg, ITransientNotification callback)
1419 {
1420 IBinder cbak = callback.asBinder();
1421 ArrayList<ToastRecord> list = mToastQueue;
1422 int len = list.size();
1423 for (int i=0; i<len; i++) {
1424 ToastRecord r = list.get(i);
1425 if (r.pkg.equals(pkg) && r.callback.asBinder() == cbak) {
1426 return i;
1427 }
1428 }
1429 return -1;
1430 }
1431
1432 // lock on mToastQueue
1433 private void keepProcessAliveLocked(int pid)
1434 {
1435 int toastCount = 0; // toasts from this pid
1436 ArrayList<ToastRecord> list = mToastQueue;
1437 int N = list.size();
1438 for (int i=0; i<N; i++) {
1439 ToastRecord r = list.get(i);
1440 if (r.pid == pid) {
1441 toastCount++;
1442 }
1443 }
1444 try {
1445 mAm.setProcessForeground(mForegroundToken, pid, toastCount > 0);
1446 } catch (RemoteException e) {
1447 // Shouldn't happen.
1448 }
1449 }
1450
1451 private final class WorkerHandler extends Handler
1452 {
1453 @Override
1454 public void handleMessage(Message msg)
1455 {
1456 switch (msg.what)
1457 {
1458 case MESSAGE_TIMEOUT:
1459 handleTimeout((ToastRecord)msg.obj);
1460 break;
1461 }
1462 }
1463 }
1464
1465
1466 // Notifications
1467 // ============================================================================
Dianne Hackbornf265ea92013-01-31 15:00:51 -08001468 public void enqueueNotificationWithTag(String pkg, String basePkg, String tag, int id,
1469 Notification notification, int[] idOut, int userId)
Fred Quintana6ecaff12009-09-25 14:23:13 -07001470 {
Dianne Hackbornf265ea92013-01-31 15:00:51 -08001471 enqueueNotificationInternal(pkg, basePkg, Binder.getCallingUid(), Binder.getCallingPid(),
Dianne Hackborn41203752012-08-31 14:05:51 -07001472 tag, id, notification, idOut, userId);
Daniel Sandlerd0a2f862010-08-03 15:29:31 -04001473 }
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001474
1475 private final static int clamp(int x, int low, int high) {
1476 return (x < low) ? low : ((x > high) ? high : x);
Daniel Sandlere40451a2011-02-03 14:51:35 -05001477 }
1478
Daniel Sandlerd0a2f862010-08-03 15:29:31 -04001479 // Not exposed via Binder; for system use only (otherwise malicious apps could spoof the
1480 // uid/pid of another application)
Dianne Hackbornf265ea92013-01-31 15:00:51 -08001481 public void enqueueNotificationInternal(String pkg, String basePkg, int callingUid,
1482 int callingPid, String tag, int id, Notification notification, int[] idOut, int userId)
Daniel Sandlerd0a2f862010-08-03 15:29:31 -04001483 {
Daniel Sandler0da673f2012-04-11 12:33:16 -04001484 if (DBG) {
1485 Slog.v(TAG, "enqueueNotificationInternal: pkg=" + pkg + " id=" + id + " notification=" + notification);
1486 }
1487 checkCallerIsSystemOrSameApp(pkg);
1488 final boolean isSystemNotification = ("android".equals(pkg));
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001489
Dianne Hackborn41203752012-08-31 14:05:51 -07001490 userId = ActivityManager.handleIncomingUser(callingPid,
Amith Yamasani2c7ebea2012-10-30 15:28:27 -07001491 callingUid, userId, true, false, "enqueueNotification", pkg);
Jeff Sharkey65c4a2b2012-09-25 17:22:27 -07001492 final UserHandle user = new UserHandle(userId);
Dianne Hackborn41203752012-08-31 14:05:51 -07001493
Joe Onoratobd73d012010-06-04 11:44:54 -07001494 // Limit the number of notifications that any given package except the android
1495 // package can enqueue. Prevents DOS attacks and deals with leaks.
Daniel Sandler0da673f2012-04-11 12:33:16 -04001496 if (!isSystemNotification) {
Joe Onoratobd73d012010-06-04 11:44:54 -07001497 synchronized (mNotificationList) {
1498 int count = 0;
1499 final int N = mNotificationList.size();
1500 for (int i=0; i<N; i++) {
1501 final NotificationRecord r = mNotificationList.get(i);
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001502 if (r.sbn.pkg.equals(pkg) && r.sbn.getUserId() == userId) {
Joe Onoratobd73d012010-06-04 11:44:54 -07001503 count++;
1504 if (count >= MAX_PACKAGE_NOTIFICATIONS) {
1505 Slog.e(TAG, "Package has already posted " + count
1506 + " notifications. Not showing more. package=" + pkg);
1507 return;
1508 }
1509 }
1510 }
1511 }
1512 }
1513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001514 // This conditional is a dirty hack to limit the logging done on
1515 // behalf of the download manager without affecting other apps.
1516 if (!pkg.equals("com.android.providers.downloads")
1517 || Log.isLoggable("DownloadManager", Log.VERBOSE)) {
Daniel Sandler321e9c52012-10-12 10:59:26 -07001518 EventLog.writeEvent(EventLogTags.NOTIFICATION_ENQUEUE, pkg, id, tag, userId,
Daniel Sandlerb64cb882011-11-29 23:48:29 -05001519 notification.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001520 }
1521
1522 if (pkg == null || notification == null) {
1523 throw new IllegalArgumentException("null not allowed: pkg=" + pkg
1524 + " id=" + id + " notification=" + notification);
1525 }
1526 if (notification.icon != 0) {
1527 if (notification.contentView == null) {
1528 throw new IllegalArgumentException("contentView required: pkg=" + pkg
1529 + " id=" + id + " notification=" + notification);
1530 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001531 }
1532
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001533 // === Scoring ===
Daniel Sandler0da673f2012-04-11 12:33:16 -04001534
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001535 // 0. Sanitize inputs
1536 notification.priority = clamp(notification.priority, Notification.PRIORITY_MIN, Notification.PRIORITY_MAX);
1537 // Migrate notification flags to scores
1538 if (0 != (notification.flags & Notification.FLAG_HIGH_PRIORITY)) {
1539 if (notification.priority < Notification.PRIORITY_MAX) notification.priority = Notification.PRIORITY_MAX;
Daniel Sandler49a2ad12012-03-28 15:46:39 -04001540 } else if (SCORE_ONGOING_HIGHER && 0 != (notification.flags & Notification.FLAG_ONGOING_EVENT)) {
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001541 if (notification.priority < Notification.PRIORITY_HIGH) notification.priority = Notification.PRIORITY_HIGH;
1542 }
Daniel Sandler0da673f2012-04-11 12:33:16 -04001543
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001544 // 1. initial score: buckets of 10, around the app
Daniel Sandler0da673f2012-04-11 12:33:16 -04001545 int score = notification.priority * NOTIFICATION_PRIORITY_MULTIPLIER; //[-20..20]
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001546
Daniel Sandler0da673f2012-04-11 12:33:16 -04001547 // 2. Consult external heuristics (TBD)
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001548
Daniel Sandler0da673f2012-04-11 12:33:16 -04001549 // 3. Apply local rules
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001550
1551 // blocked apps
Daniel Sandler4a900acd2013-01-30 14:04:10 -05001552 if (ENABLE_BLOCKED_NOTIFICATIONS && !noteNotificationOp(pkg, callingUid)) {
1553 if (!isSystemNotification) {
1554 score = JUNK_SCORE;
1555 Slog.e(TAG, "Suppressing notification from package " + pkg + " by user request.");
1556 }
Daniel Sandler0da673f2012-04-11 12:33:16 -04001557 }
1558
1559 if (DBG) {
1560 Slog.v(TAG, "Assigned score=" + score + " to " + notification);
1561 }
1562
1563 if (score < SCORE_DISPLAY_THRESHOLD) {
1564 // Notification will be blocked because the score is too low.
1565 return;
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001566 }
1567
Daniel Sandler526fa0e2012-12-04 14:51:50 -05001568 // Should this notification make noise, vibe, or use the LED?
1569 final boolean canInterrupt = (score >= SCORE_INTERRUPTION_THRESHOLD);
1570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001571 synchronized (mNotificationList) {
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001572 final StatusBarNotification n = new StatusBarNotification(
1573 pkg, id, tag, callingUid, callingPid, score, notification, user);
1574 NotificationRecord r = new NotificationRecord(n);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001575 NotificationRecord old = null;
1576
Dianne Hackborn41203752012-08-31 14:05:51 -07001577 int index = indexOfNotificationLocked(pkg, tag, id, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001578 if (index < 0) {
1579 mNotificationList.add(r);
1580 } else {
1581 old = mNotificationList.remove(index);
1582 mNotificationList.add(index, r);
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001583 // Make sure we don't lose the foreground service state.
1584 if (old != null) {
1585 notification.flags |=
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001586 old.getNotification().flags&Notification.FLAG_FOREGROUND_SERVICE;
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001587 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001588 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001589
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001590 // Ensure if this is a foreground service that the proper additional
1591 // flags are set.
1592 if ((notification.flags&Notification.FLAG_FOREGROUND_SERVICE) != 0) {
1593 notification.flags |= Notification.FLAG_ONGOING_EVENT
1594 | Notification.FLAG_NO_CLEAR;
1595 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001596
Svetoslav Ganovc31ed392012-10-10 14:58:28 -07001597 final int currentUser;
1598 final long token = Binder.clearCallingIdentity();
1599 try {
1600 currentUser = ActivityManager.getCurrentUser();
1601 } finally {
1602 Binder.restoreCallingIdentity(token);
1603 }
1604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001605 if (notification.icon != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001606 if (old != null && old.statusBarKey != null) {
1607 r.statusBarKey = old.statusBarKey;
1608 long identity = Binder.clearCallingIdentity();
1609 try {
Joe Onorato18e69df2010-05-17 22:26:12 -07001610 mStatusBar.updateNotification(r.statusBarKey, n);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001611 }
1612 finally {
1613 Binder.restoreCallingIdentity(identity);
1614 }
1615 } else {
1616 long identity = Binder.clearCallingIdentity();
1617 try {
Joe Onorato18e69df2010-05-17 22:26:12 -07001618 r.statusBarKey = mStatusBar.addNotification(n);
Daniel Sandler526fa0e2012-12-04 14:51:50 -05001619 if ((n.notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0
1620 && canInterrupt) {
Mike Lockwoodece18ef2012-02-13 20:42:19 -08001621 mAttentionLight.pulse();
1622 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001623 }
1624 finally {
1625 Binder.restoreCallingIdentity(identity);
1626 }
1627 }
Svetoslav Ganovc31ed392012-10-10 14:58:28 -07001628 // Send accessibility events only for the current user.
1629 if (currentUser == userId) {
1630 sendAccessibilityEvent(notification, pkg);
1631 }
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001632
Daniel Sandler09a247e2013-02-14 10:24:17 -05001633 notifyPostedLocked(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001634 } else {
Daniel Sandlere40451a2011-02-03 14:51:35 -05001635 Slog.e(TAG, "Ignoring notification with icon==0: " + notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001636 if (old != null && old.statusBarKey != null) {
1637 long identity = Binder.clearCallingIdentity();
1638 try {
Joe Onorato0cbda992010-05-02 16:28:15 -07001639 mStatusBar.removeNotification(old.statusBarKey);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001640 }
1641 finally {
1642 Binder.restoreCallingIdentity(identity);
1643 }
Daniel Sandler09a247e2013-02-14 10:24:17 -05001644
1645 notifyRemovedLocked(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001646 }
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001647 return; // do not play sounds, show lights, etc. for invalid notifications
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001648 }
1649
1650 // If we're not supposed to beep, vibrate, etc. then don't.
1651 if (((mDisabledNotifications & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) == 0)
1652 && (!(old != null
Joe Onorato30275482009-07-08 17:09:14 -07001653 && (notification.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0 ))
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001654 && (r.getUserId() == UserHandle.USER_ALL ||
1655 (r.getUserId() == userId && r.getUserId() == currentUser))
Daniel Sandler526fa0e2012-12-04 14:51:50 -05001656 && canInterrupt
Joe Onorato30275482009-07-08 17:09:14 -07001657 && mSystemReady) {
Eric Laurent524dc042009-11-27 05:07:55 -08001658
1659 final AudioManager audioManager = (AudioManager) mContext
1660 .getSystemService(Context.AUDIO_SERVICE);
Daniel Sandlerd4d2de22012-11-14 11:25:46 -08001661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001662 // sound
1663 final boolean useDefaultSound =
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001664 (notification.defaults & Notification.DEFAULT_SOUND) != 0;
Daniel Sandlerd4d2de22012-11-14 11:25:46 -08001665
1666 Uri soundUri = null;
1667 boolean hasValidSound = false;
1668
1669 if (useDefaultSound) {
1670 soundUri = Settings.System.DEFAULT_NOTIFICATION_URI;
1671
1672 // check to see if the default notification sound is silent
1673 ContentResolver resolver = mContext.getContentResolver();
1674 hasValidSound = Settings.System.getString(resolver,
1675 Settings.System.NOTIFICATION_SOUND) != null;
1676 } else if (notification.sound != null) {
1677 soundUri = notification.sound;
1678 hasValidSound = (soundUri != null);
1679 }
1680
1681 if (hasValidSound) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001682 boolean looping = (notification.flags & Notification.FLAG_INSISTENT) != 0;
1683 int audioStreamType;
1684 if (notification.audioStreamType >= 0) {
1685 audioStreamType = notification.audioStreamType;
1686 } else {
1687 audioStreamType = DEFAULT_STREAM_TYPE;
1688 }
1689 mSoundNotification = r;
Eric Laurent524dc042009-11-27 05:07:55 -08001690 // do not play notifications if stream volume is 0
Jean-Michel Trivid6770542012-10-10 12:03:41 -07001691 // (typically because ringer mode is silent) or if speech recognition is active.
1692 if ((audioManager.getStreamVolume(audioStreamType) != 0)
1693 && !audioManager.isSpeechRecognitionActive()) {
Jeff Sharkey098d5802012-04-26 17:30:34 -07001694 final long identity = Binder.clearCallingIdentity();
Eric Laurent524dc042009-11-27 05:07:55 -08001695 try {
Jeff Sharkey098d5802012-04-26 17:30:34 -07001696 final IRingtonePlayer player = mAudioService.getRingtonePlayer();
1697 if (player != null) {
Daniel Sandlerd4d2de22012-11-14 11:25:46 -08001698 player.playAsync(soundUri, user, looping, audioStreamType);
Jeff Sharkey098d5802012-04-26 17:30:34 -07001699 }
1700 } catch (RemoteException e) {
1701 } finally {
Eric Laurent524dc042009-11-27 05:07:55 -08001702 Binder.restoreCallingIdentity(identity);
1703 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001704 }
1705 }
1706
1707 // vibrate
Daniel Sandleredbb3802012-11-13 20:49:47 -08001708 // Does the notification want to specify its own vibration?
1709 final boolean hasCustomVibrate = notification.vibrate != null;
1710
David Agnew71789e12012-11-09 23:03:26 -05001711 // 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 -05001712 // and no other vibration is specified, we fall back to vibration
David Agnew71789e12012-11-09 23:03:26 -05001713 final boolean convertSoundToVibration =
Daniel Sandleredbb3802012-11-13 20:49:47 -08001714 !hasCustomVibrate
Daniel Sandlerd4d2de22012-11-14 11:25:46 -08001715 && hasValidSound
David Agnew71789e12012-11-09 23:03:26 -05001716 && (audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE);
1717
Daniel Sandler4a7a9b92012-11-20 12:59:41 -05001718 // The DEFAULT_VIBRATE flag trumps any custom vibration AND the fallback.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001719 final boolean useDefaultVibrate =
Daniel Sandleredbb3802012-11-13 20:49:47 -08001720 (notification.defaults & Notification.DEFAULT_VIBRATE) != 0;
David Agnew71789e12012-11-09 23:03:26 -05001721
Daniel Sandleredbb3802012-11-13 20:49:47 -08001722 if ((useDefaultVibrate || convertSoundToVibration || hasCustomVibrate)
Eric Laurentbffc3d12012-05-07 17:43:49 -07001723 && !(audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001724 mVibrateNotification = r;
1725
Daniel Sandleredbb3802012-11-13 20:49:47 -08001726 if (useDefaultVibrate || convertSoundToVibration) {
1727 // Escalate privileges so we can use the vibrator even if the notifying app
1728 // does not have the VIBRATE permission.
1729 long identity = Binder.clearCallingIdentity();
1730 try {
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001731 mVibrator.vibrate(r.sbn.uid, r.sbn.basePkg,
Dianne Hackbornf265ea92013-01-31 15:00:51 -08001732 useDefaultVibrate ? mDefaultVibrationPattern
1733 : mFallbackVibrationPattern,
Daniel Sandleredbb3802012-11-13 20:49:47 -08001734 ((notification.flags & Notification.FLAG_INSISTENT) != 0) ? 0: -1);
1735 } finally {
1736 Binder.restoreCallingIdentity(identity);
1737 }
1738 } else if (notification.vibrate.length > 1) {
1739 // If you want your own vibration pattern, you need the VIBRATE permission
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001740 mVibrator.vibrate(r.sbn.uid, r.sbn.basePkg, notification.vibrate,
Daniel Sandleredbb3802012-11-13 20:49:47 -08001741 ((notification.flags & Notification.FLAG_INSISTENT) != 0) ? 0: -1);
1742 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001743 }
1744 }
1745
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001746 // light
1747 // the most recent thing gets the light
1748 mLights.remove(old);
1749 if (mLedNotification == old) {
1750 mLedNotification = null;
1751 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001752 //Slog.i(TAG, "notification.lights="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001753 // + ((old.notification.lights.flags & Notification.FLAG_SHOW_LIGHTS) != 0));
Daniel Sandler526fa0e2012-12-04 14:51:50 -05001754 if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0
1755 && canInterrupt) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001756 mLights.add(r);
1757 updateLightsLocked();
1758 } else {
1759 if (old != null
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001760 && ((old.getFlags() & Notification.FLAG_SHOW_LIGHTS) != 0)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001761 updateLightsLocked();
1762 }
1763 }
1764 }
1765
1766 idOut[0] = id;
1767 }
1768
Joe Onorato30275482009-07-08 17:09:14 -07001769 private void sendAccessibilityEvent(Notification notification, CharSequence packageName) {
svetoslavganov75986cf2009-05-14 22:28:01 -07001770 AccessibilityManager manager = AccessibilityManager.getInstance(mContext);
1771 if (!manager.isEnabled()) {
1772 return;
1773 }
1774
1775 AccessibilityEvent event =
1776 AccessibilityEvent.obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
1777 event.setPackageName(packageName);
1778 event.setClassName(Notification.class.getName());
1779 event.setParcelableData(notification);
1780 CharSequence tickerText = notification.tickerText;
1781 if (!TextUtils.isEmpty(tickerText)) {
1782 event.getText().add(tickerText);
1783 }
1784
1785 manager.sendAccessibilityEvent(event);
1786 }
1787
Joe Onorato46439ce2010-11-19 13:56:21 -08001788 private void cancelNotificationLocked(NotificationRecord r, boolean sendDelete) {
1789 // tell the app
1790 if (sendDelete) {
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001791 if (r.getNotification().deleteIntent != null) {
Joe Onorato46439ce2010-11-19 13:56:21 -08001792 try {
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001793 r.getNotification().deleteIntent.send();
Joe Onorato46439ce2010-11-19 13:56:21 -08001794 } catch (PendingIntent.CanceledException ex) {
1795 // do nothing - there's no relevant way to recover, and
1796 // no reason to let this propagate
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001797 Slog.w(TAG, "canceled PendingIntent for " + r.sbn.pkg, ex);
Joe Onorato46439ce2010-11-19 13:56:21 -08001798 }
1799 }
1800 }
1801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001802 // status bar
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001803 if (r.getNotification().icon != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001804 long identity = Binder.clearCallingIdentity();
1805 try {
Joe Onorato0cbda992010-05-02 16:28:15 -07001806 mStatusBar.removeNotification(r.statusBarKey);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001807 }
1808 finally {
1809 Binder.restoreCallingIdentity(identity);
1810 }
1811 r.statusBarKey = null;
Daniel Sandler09a247e2013-02-14 10:24:17 -05001812 notifyRemovedLocked(r);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001813 }
1814
1815 // sound
1816 if (mSoundNotification == r) {
1817 mSoundNotification = null;
Jeff Sharkey098d5802012-04-26 17:30:34 -07001818 final long identity = Binder.clearCallingIdentity();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001819 try {
Jeff Sharkey098d5802012-04-26 17:30:34 -07001820 final IRingtonePlayer player = mAudioService.getRingtonePlayer();
1821 if (player != null) {
1822 player.stopAsync();
1823 }
1824 } catch (RemoteException e) {
1825 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001826 Binder.restoreCallingIdentity(identity);
1827 }
1828 }
1829
1830 // vibrate
1831 if (mVibrateNotification == r) {
1832 mVibrateNotification = null;
1833 long identity = Binder.clearCallingIdentity();
1834 try {
1835 mVibrator.cancel();
1836 }
1837 finally {
1838 Binder.restoreCallingIdentity(identity);
1839 }
1840 }
1841
1842 // light
1843 mLights.remove(r);
1844 if (mLedNotification == r) {
1845 mLedNotification = null;
1846 }
Daniel Sandler23d7c702013-03-07 16:32:06 -05001847
1848 // Save it for users of getHistoricalNotifications()
1849 mArchive.record(r.sbn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001850 }
1851
1852 /**
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001853 * Cancels a notification ONLY if it has all of the {@code mustHaveFlags}
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001854 * and none of the {@code mustNotHaveFlags}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001855 */
Fred Quintana6ecaff12009-09-25 14:23:13 -07001856 private void cancelNotification(String pkg, String tag, int id, int mustHaveFlags,
Dianne Hackborn41203752012-08-31 14:05:51 -07001857 int mustNotHaveFlags, boolean sendDelete, int userId) {
Daniel Sandler321e9c52012-10-12 10:59:26 -07001858 EventLog.writeEvent(EventLogTags.NOTIFICATION_CANCEL, pkg, id, tag, userId,
Daniel Sandlerb64cb882011-11-29 23:48:29 -05001859 mustHaveFlags, mustNotHaveFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001860
1861 synchronized (mNotificationList) {
Dianne Hackborn41203752012-08-31 14:05:51 -07001862 int index = indexOfNotificationLocked(pkg, tag, id, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001863 if (index >= 0) {
Fred Quintana6ecaff12009-09-25 14:23:13 -07001864 NotificationRecord r = mNotificationList.get(index);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001865
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001866 if ((r.getNotification().flags & mustHaveFlags) != mustHaveFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001867 return;
1868 }
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001869 if ((r.getNotification().flags & mustNotHaveFlags) != 0) {
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001870 return;
1871 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001872
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001873 mNotificationList.remove(index);
1874
Joe Onorato46439ce2010-11-19 13:56:21 -08001875 cancelNotificationLocked(r, sendDelete);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001876 updateLightsLocked();
1877 }
1878 }
1879 }
1880
1881 /**
Daniel Sandler321e9c52012-10-12 10:59:26 -07001882 * Determine whether the userId applies to the notification in question, either because
1883 * they match exactly, or one of them is USER_ALL (which is treated as a wildcard).
1884 */
1885 private boolean notificationMatchesUserId(NotificationRecord r, int userId) {
1886 return
1887 // looking for USER_ALL notifications? match everything
1888 userId == UserHandle.USER_ALL
1889 // a notification sent to USER_ALL matches any query
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001890 || r.getUserId() == UserHandle.USER_ALL
Daniel Sandler321e9c52012-10-12 10:59:26 -07001891 // an exact user match
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001892 || r.getUserId() == userId;
Daniel Sandler321e9c52012-10-12 10:59:26 -07001893 }
1894
1895 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001896 * Cancels all notifications from a given package that have all of the
1897 * {@code mustHaveFlags}.
1898 */
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001899 boolean cancelAllNotificationsInt(String pkg, int mustHaveFlags,
Dianne Hackborn41203752012-08-31 14:05:51 -07001900 int mustNotHaveFlags, boolean doit, int userId) {
Daniel Sandler321e9c52012-10-12 10:59:26 -07001901 EventLog.writeEvent(EventLogTags.NOTIFICATION_CANCEL_ALL, pkg, userId,
1902 mustHaveFlags, mustNotHaveFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001903
1904 synchronized (mNotificationList) {
1905 final int N = mNotificationList.size();
1906 boolean canceledSomething = false;
1907 for (int i = N-1; i >= 0; --i) {
1908 NotificationRecord r = mNotificationList.get(i);
Daniel Sandler321e9c52012-10-12 10:59:26 -07001909 if (!notificationMatchesUserId(r, userId)) {
Dianne Hackborn41203752012-08-31 14:05:51 -07001910 continue;
1911 }
Amith Yamasani5ec00e92012-11-07 16:58:30 -08001912 // Don't remove notifications to all, if there's no package name specified
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001913 if (r.getUserId() == UserHandle.USER_ALL && pkg == null) {
Amith Yamasani5ec00e92012-11-07 16:58:30 -08001914 continue;
1915 }
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001916 if ((r.getFlags() & mustHaveFlags) != mustHaveFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001917 continue;
1918 }
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001919 if ((r.getFlags() & mustNotHaveFlags) != 0) {
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001920 continue;
1921 }
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001922 if (pkg != null && !r.sbn.pkg.equals(pkg)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001923 continue;
1924 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001925 canceledSomething = true;
1926 if (!doit) {
1927 return true;
1928 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001929 mNotificationList.remove(i);
Joe Onorato46439ce2010-11-19 13:56:21 -08001930 cancelNotificationLocked(r, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001931 }
1932 if (canceledSomething) {
1933 updateLightsLocked();
1934 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001935 return canceledSomething;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001936 }
1937 }
1938
Dianne Hackborn41203752012-08-31 14:05:51 -07001939 public void cancelNotificationWithTag(String pkg, String tag, int id, int userId) {
Daniel Sandler0da673f2012-04-11 12:33:16 -04001940 checkCallerIsSystemOrSameApp(pkg);
Dianne Hackborn41203752012-08-31 14:05:51 -07001941 userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
Amith Yamasani2c7ebea2012-10-30 15:28:27 -07001942 Binder.getCallingUid(), userId, true, false, "cancelNotificationWithTag", pkg);
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001943 // Don't allow client applications to cancel foreground service notis.
Fred Quintana6ecaff12009-09-25 14:23:13 -07001944 cancelNotification(pkg, tag, id, 0,
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001945 Binder.getCallingUid() == Process.SYSTEM_UID
Dianne Hackborn41203752012-08-31 14:05:51 -07001946 ? 0 : Notification.FLAG_FOREGROUND_SERVICE, false, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001947 }
1948
Dianne Hackborn41203752012-08-31 14:05:51 -07001949 public void cancelAllNotifications(String pkg, int userId) {
Daniel Sandler0da673f2012-04-11 12:33:16 -04001950 checkCallerIsSystemOrSameApp(pkg);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001951
Dianne Hackborn41203752012-08-31 14:05:51 -07001952 userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
Amith Yamasani2c7ebea2012-10-30 15:28:27 -07001953 Binder.getCallingUid(), userId, true, false, "cancelAllNotifications", pkg);
Dianne Hackborn41203752012-08-31 14:05:51 -07001954
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001955 // Calling from user space, don't allow the canceling of actively
1956 // running foreground services.
Dianne Hackborn41203752012-08-31 14:05:51 -07001957 cancelAllNotificationsInt(pkg, 0, Notification.FLAG_FOREGROUND_SERVICE, true, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001958 }
1959
Daniel Sandler0da673f2012-04-11 12:33:16 -04001960 void checkCallerIsSystem() {
1961 int uid = Binder.getCallingUid();
Dianne Hackborn0c380492012-08-20 17:23:30 -07001962 if (UserHandle.getAppId(uid) == Process.SYSTEM_UID || uid == 0) {
Daniel Sandler0da673f2012-04-11 12:33:16 -04001963 return;
1964 }
1965 throw new SecurityException("Disallowed call for uid " + uid);
1966 }
1967
1968 void checkCallerIsSystemOrSameApp(String pkg) {
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001969 int uid = Binder.getCallingUid();
Dianne Hackborn0c380492012-08-20 17:23:30 -07001970 if (UserHandle.getAppId(uid) == Process.SYSTEM_UID || uid == 0) {
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001971 return;
1972 }
1973 try {
Amith Yamasanif203aee2012-08-29 18:41:53 -07001974 ApplicationInfo ai = AppGlobals.getPackageManager().getApplicationInfo(
1975 pkg, 0, UserHandle.getCallingUserId());
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07001976 if (!UserHandle.isSameApp(ai.uid, uid)) {
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001977 throw new SecurityException("Calling uid " + uid + " gave package"
1978 + pkg + " which is owned by uid " + ai.uid);
1979 }
Amith Yamasanif203aee2012-08-29 18:41:53 -07001980 } catch (RemoteException re) {
1981 throw new SecurityException("Unknown package " + pkg + "\n" + re);
Dianne Hackbornd8a43f62009-08-17 23:33:56 -07001982 }
1983 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001984
Dianne Hackborn41203752012-08-31 14:05:51 -07001985 void cancelAll(int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001986 synchronized (mNotificationList) {
1987 final int N = mNotificationList.size();
1988 for (int i=N-1; i>=0; i--) {
1989 NotificationRecord r = mNotificationList.get(i);
1990
Daniel Sandler321e9c52012-10-12 10:59:26 -07001991 if (!notificationMatchesUserId(r, userId)) {
Dianne Hackborn41203752012-08-31 14:05:51 -07001992 continue;
1993 }
1994
Daniel Sandlerfde19b12013-01-17 00:21:05 -05001995 if ((r.getFlags() & (Notification.FLAG_ONGOING_EVENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001996 | Notification.FLAG_NO_CLEAR)) == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001997 mNotificationList.remove(i);
Joe Onorato46439ce2010-11-19 13:56:21 -08001998 cancelNotificationLocked(r, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001999 }
2000 }
2001
2002 updateLightsLocked();
2003 }
2004 }
2005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002006 // lock on mNotificationList
2007 private void updateLightsLocked()
2008 {
The Android Open Source Project10592532009-03-18 17:39:46 -07002009 // handle notification lights
2010 if (mLedNotification == null) {
2011 // get next notification, if any
2012 int n = mLights.size();
2013 if (n > 0) {
2014 mLedNotification = mLights.get(n-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002015 }
2016 }
Mike Lockwoodc22404a2009-12-02 11:15:02 -05002017
Mike Lockwood63b5ad92011-08-30 09:55:30 -04002018 // Don't flash while we are in a call or screen is on
2019 if (mLedNotification == null || mInCall || mScreenOn) {
Mike Lockwood3cb67a32009-11-27 14:25:58 -05002020 mNotificationLight.turnOff();
The Android Open Source Project10592532009-03-18 17:39:46 -07002021 } else {
Daniel Sandlerfde19b12013-01-17 00:21:05 -05002022 final Notification ledno = mLedNotification.sbn.notification;
2023 int ledARGB = ledno.ledARGB;
2024 int ledOnMS = ledno.ledOnMS;
2025 int ledOffMS = ledno.ledOffMS;
2026 if ((ledno.defaults & Notification.DEFAULT_LIGHTS) != 0) {
Mike Lockwood670f9322010-01-20 12:13:36 -05002027 ledARGB = mDefaultNotificationColor;
2028 ledOnMS = mDefaultNotificationLedOn;
2029 ledOffMS = mDefaultNotificationLedOff;
2030 }
2031 if (mNotificationPulseEnabled) {
2032 // pulse repeatedly
2033 mNotificationLight.setFlashing(ledARGB, LightsService.LIGHT_FLASH_TIMED,
2034 ledOnMS, ledOffMS);
Mike Lockwood670f9322010-01-20 12:13:36 -05002035 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002036 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002037 }
2038
2039 // lock on mNotificationList
Dianne Hackborn41203752012-08-31 14:05:51 -07002040 private int indexOfNotificationLocked(String pkg, String tag, int id, int userId)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002041 {
2042 ArrayList<NotificationRecord> list = mNotificationList;
2043 final int len = list.size();
2044 for (int i=0; i<len; i++) {
2045 NotificationRecord r = list.get(i);
Daniel Sandlerfde19b12013-01-17 00:21:05 -05002046 if (!notificationMatchesUserId(r, userId) || r.sbn.id != id) {
Dianne Hackborn41203752012-08-31 14:05:51 -07002047 continue;
2048 }
Fred Quintana6ecaff12009-09-25 14:23:13 -07002049 if (tag == null) {
Daniel Sandlerfde19b12013-01-17 00:21:05 -05002050 if (r.sbn.tag != null) {
Fred Quintana6ecaff12009-09-25 14:23:13 -07002051 continue;
2052 }
2053 } else {
Daniel Sandlerfde19b12013-01-17 00:21:05 -05002054 if (!tag.equals(r.sbn.tag)) {
Fred Quintana6ecaff12009-09-25 14:23:13 -07002055 continue;
2056 }
2057 }
Daniel Sandlerfde19b12013-01-17 00:21:05 -05002058 if (r.sbn.pkg.equals(pkg)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002059 return i;
2060 }
2061 }
2062 return -1;
2063 }
2064
Mike Lockwoodc22404a2009-12-02 11:15:02 -05002065 private void updateNotificationPulse() {
2066 synchronized (mNotificationList) {
2067 updateLightsLocked();
2068 }
2069 }
2070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002071 // ======================================================================
2072 @Override
2073 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
2074 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
2075 != PackageManager.PERMISSION_GRANTED) {
2076 pw.println("Permission Denial: can't dump NotificationManager from from pid="
2077 + Binder.getCallingPid()
2078 + ", uid=" + Binder.getCallingUid());
2079 return;
2080 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002082 pw.println("Current Notification Manager state:");
2083
Daniel Sandler5feceeb2013-03-22 18:29:23 -07002084 pw.println(" Listeners (" + mEnabledListenersForCurrentUser.size()
2085 + ") enabled for current user:");
2086 for (ComponentName cmpt : mEnabledListenersForCurrentUser) {
2087 pw.println(" " + cmpt);
Daniel Sandler4b749ef2013-03-18 21:53:04 -04002088 }
Daniel Sandler4b749ef2013-03-18 21:53:04 -04002089
Daniel Sandler5feceeb2013-03-22 18:29:23 -07002090 pw.println(" Live listeners (" + mListeners.size() + "):");
Daniel Sandler4b749ef2013-03-18 21:53:04 -04002091 for (NotificationListenerInfo info : mListeners) {
Daniel Sandler5feceeb2013-03-22 18:29:23 -07002092 pw.println(" " + info.component
2093 + " (user " + info.userid + "): " + info.listener
2094 + (info.isSystem?" SYSTEM":""));
Daniel Sandler4b749ef2013-03-18 21:53:04 -04002095 }
2096
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002097 int N;
2098
2099 synchronized (mToastQueue) {
2100 N = mToastQueue.size();
2101 if (N > 0) {
2102 pw.println(" Toast Queue:");
2103 for (int i=0; i<N; i++) {
2104 mToastQueue.get(i).dump(pw, " ");
2105 }
2106 pw.println(" ");
2107 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002109 }
2110
2111 synchronized (mNotificationList) {
2112 N = mNotificationList.size();
2113 if (N > 0) {
2114 pw.println(" Notification List:");
2115 for (int i=0; i<N; i++) {
2116 mNotificationList.get(i).dump(pw, " ", mContext);
2117 }
2118 pw.println(" ");
2119 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002121 N = mLights.size();
2122 if (N > 0) {
2123 pw.println(" Lights List:");
2124 for (int i=0; i<N; i++) {
Daniel Sandlerf45564e2013-04-15 15:05:08 -04002125 pw.println(" " + mLights.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002126 }
2127 pw.println(" ");
2128 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002130 pw.println(" mSoundNotification=" + mSoundNotification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002131 pw.println(" mVibrateNotification=" + mVibrateNotification);
Joe Onorato39f5b6a2009-07-23 12:29:19 -04002132 pw.println(" mDisabledNotifications=0x" + Integer.toHexString(mDisabledNotifications));
2133 pw.println(" mSystemReady=" + mSystemReady);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002134 }
2135 }
2136}