| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server; |
| 18 | |
| Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 19 | import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT; |
| 20 | import static org.xmlpull.v1.XmlPullParser.END_TAG; |
| 21 | import static org.xmlpull.v1.XmlPullParser.START_TAG; |
| svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 22 | |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 23 | import android.app.ActivityManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.app.ActivityManagerNative; |
| Amith Yamasani | f203aee | 2012-08-29 18:41:53 -0700 | [diff] [blame] | 25 | import android.app.AppGlobals; |
| Daniel Sandler | 4a900acd | 2013-01-30 14:04:10 -0500 | [diff] [blame] | 26 | import android.app.AppOpsManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import android.app.IActivityManager; |
| 28 | import android.app.INotificationManager; |
| Daniel Sandler | 09a247e | 2013-02-14 10:24:17 -0500 | [diff] [blame] | 29 | import android.app.INotificationListener; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.app.ITransientNotification; |
| 31 | import android.app.Notification; |
| 32 | import android.app.PendingIntent; |
| 33 | import android.app.StatusBarManager; |
| 34 | import android.content.BroadcastReceiver; |
| Dianne Hackborn | 1dac277 | 2009-06-26 18:16:48 -0700 | [diff] [blame] | 35 | import android.content.ContentResolver; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.content.Context; |
| 37 | import android.content.Intent; |
| 38 | import android.content.IntentFilter; |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 39 | import android.content.pm.ApplicationInfo; |
| Daniel Sandler | 4a900acd | 2013-01-30 14:04:10 -0500 | [diff] [blame] | 40 | import android.content.pm.PackageInfo; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.content.pm.PackageManager; |
| 42 | import android.content.pm.PackageManager.NameNotFoundException; |
| 43 | import android.content.res.Resources; |
| Dianne Hackborn | 1dac277 | 2009-06-26 18:16:48 -0700 | [diff] [blame] | 44 | import android.database.ContentObserver; |
| svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 45 | import android.media.AudioManager; |
| Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 46 | import android.media.IAudioService; |
| 47 | import android.media.IRingtonePlayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | import android.net.Uri; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | import android.os.Binder; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | import android.os.Handler; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import android.os.IBinder; |
| 52 | import android.os.Message; |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 53 | import android.os.Process; |
| svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 54 | import android.os.RemoteException; |
| Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 55 | import android.os.ServiceManager; |
| Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 56 | import android.os.UserHandle; |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 57 | import android.os.UserManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | import android.os.Vibrator; |
| 59 | import android.provider.Settings; |
| Daniel Sandler | e96ffb1 | 2010-03-11 13:38:06 -0500 | [diff] [blame] | 60 | import android.telephony.TelephonyManager; |
| svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 61 | import android.text.TextUtils; |
| Dianne Hackborn | 39606a0 | 2012-07-31 17:54:35 -0700 | [diff] [blame] | 62 | import android.util.AtomicFile; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | import android.util.EventLog; |
| 64 | import android.util.Log; |
| Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 65 | import android.util.Slog; |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 66 | import android.util.Xml; |
| svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 67 | import android.view.accessibility.AccessibilityEvent; |
| 68 | import android.view.accessibility.AccessibilityManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | import android.widget.Toast; |
| 70 | |
| Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 71 | import com.android.internal.statusbar.StatusBarNotification; |
| Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 72 | |
| 73 | import org.xmlpull.v1.XmlPullParser; |
| 74 | import org.xmlpull.v1.XmlPullParserException; |
| Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 75 | |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 76 | import java.io.File; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | import java.io.FileDescriptor; |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 78 | import java.io.FileInputStream; |
| 79 | import java.io.FileNotFoundException; |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 80 | import java.io.IOException; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | import java.io.PrintWriter; |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 82 | import java.util.ArrayDeque; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | import java.util.ArrayList; |
| 84 | import java.util.Arrays; |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 85 | import java.util.HashSet; |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 86 | import java.util.Iterator; |
| 87 | import java.util.NoSuchElementException; |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 88 | |
| 89 | import libcore.io.IoUtils; |
| 90 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | |
| Daniel Sandler | d0a2f86 | 2010-08-03 15:29:31 -0400 | [diff] [blame] | 92 | /** {@hide} */ |
| 93 | public class NotificationManagerService extends INotificationManager.Stub |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | { |
| 95 | private static final String TAG = "NotificationService"; |
| 96 | private static final boolean DBG = false; |
| 97 | |
| Joe Onorato | bd73d01 | 2010-06-04 11:44:54 -0700 | [diff] [blame] | 98 | private static final int MAX_PACKAGE_NOTIFICATIONS = 50; |
| 99 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | // message codes |
| 101 | private static final int MESSAGE_TIMEOUT = 2; |
| 102 | |
| 103 | private static final int LONG_DELAY = 3500; // 3.5 seconds |
| 104 | private static final int SHORT_DELAY = 2000; // 2 seconds |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 105 | |
| 106 | private static final long[] DEFAULT_VIBRATE_PATTERN = {0, 250, 250, 250}; |
| Daniel Sandler | edbb380 | 2012-11-13 20:49:47 -0800 | [diff] [blame] | 107 | private static final int VIBRATE_PATTERN_MAXLEN = 8 * 2 + 1; // up to eight bumps |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | |
| 109 | private static final int DEFAULT_STREAM_TYPE = AudioManager.STREAM_NOTIFICATION; |
| Daniel Sandler | 49a2ad1 | 2012-03-28 15:46:39 -0400 | [diff] [blame] | 110 | private static final boolean SCORE_ONGOING_HIGHER = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 112 | private static final int JUNK_SCORE = -1000; |
| 113 | private static final int NOTIFICATION_PRIORITY_MULTIPLIER = 10; |
| 114 | private static final int SCORE_DISPLAY_THRESHOLD = Notification.PRIORITY_MIN * NOTIFICATION_PRIORITY_MULTIPLIER; |
| 115 | |
| Daniel Sandler | 526fa0e | 2012-12-04 14:51:50 -0500 | [diff] [blame] | 116 | // Notifications with scores below this will not interrupt the user, either via LED or |
| 117 | // sound or vibration |
| 118 | private static final int SCORE_INTERRUPTION_THRESHOLD = |
| 119 | Notification.PRIORITY_LOW * NOTIFICATION_PRIORITY_MULTIPLIER; |
| 120 | |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 121 | private static final boolean ENABLE_BLOCKED_NOTIFICATIONS = true; |
| 122 | private static final boolean ENABLE_BLOCKED_TOASTS = true; |
| 123 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | final Context mContext; |
| 125 | final IActivityManager mAm; |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 126 | final UserManager mUserManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | final IBinder mForegroundToken = new Binder(); |
| 128 | |
| 129 | private WorkerHandler mHandler; |
| Joe Onorato | 089de88 | 2010-04-12 08:18:45 -0700 | [diff] [blame] | 130 | private StatusBarManagerService mStatusBar; |
| Mike Lockwood | 3cb67a3 | 2009-11-27 14:25:58 -0500 | [diff] [blame] | 131 | private LightsService.Light mNotificationLight; |
| 132 | private LightsService.Light mAttentionLight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | |
| Mike Lockwood | 670f932 | 2010-01-20 12:13:36 -0500 | [diff] [blame] | 134 | private int mDefaultNotificationColor; |
| 135 | private int mDefaultNotificationLedOn; |
| 136 | private int mDefaultNotificationLedOff; |
| 137 | |
| Daniel Sandler | edbb380 | 2012-11-13 20:49:47 -0800 | [diff] [blame] | 138 | private long[] mDefaultVibrationPattern; |
| 139 | private long[] mFallbackVibrationPattern; |
| 140 | |
| Joe Onorato | 3027548 | 2009-07-08 17:09:14 -0700 | [diff] [blame] | 141 | private boolean mSystemReady; |
| Joe Onorato | 39f5b6a | 2009-07-23 12:29:19 -0400 | [diff] [blame] | 142 | private int mDisabledNotifications; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | |
| Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 144 | private NotificationRecord mSoundNotification; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | private NotificationRecord mVibrateNotification; |
| Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 146 | |
| 147 | private IAudioService mAudioService; |
| Jeff Brown | c234613 | 2012-04-13 01:55:38 -0700 | [diff] [blame] | 148 | private Vibrator mVibrator; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | |
| Mike Lockwood | c22404a | 2009-12-02 11:15:02 -0500 | [diff] [blame] | 150 | // for enabling and disabling notification pulse behavior |
| Mike Lockwood | 63b5ad9 | 2011-08-30 09:55:30 -0400 | [diff] [blame] | 151 | private boolean mScreenOn = true; |
| Daniel Sandler | e96ffb1 | 2010-03-11 13:38:06 -0500 | [diff] [blame] | 152 | private boolean mInCall = false; |
| Mike Lockwood | c22404a | 2009-12-02 11:15:02 -0500 | [diff] [blame] | 153 | private boolean mNotificationPulseEnabled; |
| 154 | |
| Daniel Sandler | 09a247e | 2013-02-14 10:24:17 -0500 | [diff] [blame] | 155 | // used as a mutex for access to all active notifications & listeners |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 156 | private final ArrayList<NotificationRecord> mNotificationList = |
| 157 | new ArrayList<NotificationRecord>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | |
| 159 | private ArrayList<ToastRecord> mToastQueue; |
| 160 | |
| 161 | private ArrayList<NotificationRecord> mLights = new ArrayList<NotificationRecord>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | private NotificationRecord mLedNotification; |
| svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 163 | |
| Daniel Sandler | 4a900acd | 2013-01-30 14:04:10 -0500 | [diff] [blame] | 164 | private final AppOpsManager mAppOps; |
| 165 | |
| Daniel Sandler | 09a247e | 2013-02-14 10:24:17 -0500 | [diff] [blame] | 166 | private ArrayList<NotificationListenerInfo> mListeners = new ArrayList<NotificationListenerInfo>(); |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 167 | private ArrayList<String> mEnabledListenersForCurrentUser = new ArrayList<String>(); |
| Daniel Sandler | 09a247e | 2013-02-14 10:24:17 -0500 | [diff] [blame] | 168 | |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 169 | // Notification control database. For now just contains disabled packages. |
| 170 | private AtomicFile mPolicyFile; |
| 171 | private HashSet<String> mBlockedPackages = new HashSet<String>(); |
| 172 | |
| 173 | private static final int DB_VERSION = 1; |
| 174 | |
| 175 | private static final String TAG_BODY = "notification-policy"; |
| 176 | private static final String ATTR_VERSION = "version"; |
| 177 | |
| 178 | private static final String TAG_BLOCKED_PKGS = "blocked-packages"; |
| 179 | private static final String TAG_PACKAGE = "package"; |
| 180 | private static final String ATTR_NAME = "name"; |
| 181 | |
| Daniel Sandler | 09a247e | 2013-02-14 10:24:17 -0500 | [diff] [blame] | 182 | private class NotificationListenerInfo implements DeathRecipient { |
| 183 | INotificationListener listener; |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 184 | String pkg; |
| Daniel Sandler | 09a247e | 2013-02-14 10:24:17 -0500 | [diff] [blame] | 185 | int userid; |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 186 | boolean isSystem; |
| 187 | |
| 188 | public NotificationListenerInfo(INotificationListener listener, String pkg, int userid, |
| 189 | boolean isSystem) { |
| Daniel Sandler | 09a247e | 2013-02-14 10:24:17 -0500 | [diff] [blame] | 190 | this.listener = listener; |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 191 | this.pkg = pkg; |
| Daniel Sandler | 09a247e | 2013-02-14 10:24:17 -0500 | [diff] [blame] | 192 | this.userid = userid; |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 193 | this.isSystem = isSystem; |
| Daniel Sandler | 09a247e | 2013-02-14 10:24:17 -0500 | [diff] [blame] | 194 | } |
| 195 | |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 196 | boolean enabledAndUserMatches(StatusBarNotification sbn) { |
| 197 | final int nid = sbn.getUserId(); |
| 198 | if (!(isSystem || isEnabledForUser(nid))) return false; |
| Daniel Sandler | 21ca44d | 2013-03-07 13:58:00 -0500 | [diff] [blame] | 199 | if (this.userid == UserHandle.USER_ALL) return true; |
| Daniel Sandler | 21ca44d | 2013-03-07 13:58:00 -0500 | [diff] [blame] | 200 | return (nid == UserHandle.USER_ALL || nid == this.userid); |
| 201 | } |
| 202 | |
| Daniel Sandler | 09a247e | 2013-02-14 10:24:17 -0500 | [diff] [blame] | 203 | public void notifyPostedIfUserMatch(StatusBarNotification sbn) { |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 204 | if (!enabledAndUserMatches(sbn)) return; |
| Daniel Sandler | 09a247e | 2013-02-14 10:24:17 -0500 | [diff] [blame] | 205 | try { |
| 206 | listener.onNotificationPosted(sbn); |
| 207 | } catch (RemoteException ex) { |
| 208 | // not there? |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | public void notifyRemovedIfUserMatch(StatusBarNotification sbn) { |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 213 | if (!enabledAndUserMatches(sbn)) return; |
| Daniel Sandler | 09a247e | 2013-02-14 10:24:17 -0500 | [diff] [blame] | 214 | try { |
| 215 | listener.onNotificationRemoved(sbn); |
| 216 | } catch (RemoteException ex) { |
| 217 | // not there? |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | @Override |
| 222 | public void binderDied() { |
| 223 | unregisterListener(this.listener, this.userid); |
| 224 | } |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 225 | |
| 226 | /** convenience method for looking in mEnabledListenersForCurrentUser */ |
| 227 | public boolean isEnabledForUser(int userid) { |
| 228 | for (int i=0; i<mEnabledListenersForCurrentUser.size(); i++) { |
| 229 | if (this.pkg.equals(mEnabledListenersForCurrentUser.get(i))) return true; |
| 230 | } |
| 231 | return false; |
| 232 | } |
| Daniel Sandler | 09a247e | 2013-02-14 10:24:17 -0500 | [diff] [blame] | 233 | } |
| 234 | |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 235 | private static class Archive { |
| 236 | static final int BUFFER_SIZE = 1000; |
| 237 | ArrayDeque<StatusBarNotification> mBuffer = new ArrayDeque<StatusBarNotification>(BUFFER_SIZE); |
| 238 | |
| 239 | public Archive() { |
| 240 | |
| 241 | } |
| 242 | public void record(StatusBarNotification nr) { |
| 243 | if (mBuffer.size() == BUFFER_SIZE) { |
| 244 | mBuffer.removeFirst(); |
| 245 | } |
| 246 | mBuffer.addLast(nr); |
| 247 | } |
| 248 | |
| 249 | public void clear() { |
| 250 | mBuffer.clear(); |
| 251 | } |
| 252 | |
| 253 | public Iterator<StatusBarNotification> descendingIterator() { |
| 254 | return mBuffer.descendingIterator(); |
| 255 | } |
| 256 | public Iterator<StatusBarNotification> ascendingIterator() { |
| 257 | return mBuffer.iterator(); |
| 258 | } |
| 259 | public Iterator<StatusBarNotification> filter( |
| 260 | final Iterator<StatusBarNotification> iter, final String pkg, final int userId) { |
| 261 | return new Iterator<StatusBarNotification>() { |
| 262 | StatusBarNotification mNext = findNext(); |
| 263 | |
| 264 | private StatusBarNotification findNext() { |
| 265 | while (iter.hasNext()) { |
| 266 | StatusBarNotification nr = iter.next(); |
| 267 | if ((pkg == null || nr.pkg == pkg) |
| 268 | && (userId == UserHandle.USER_ALL || nr.getUserId() == userId)) { |
| 269 | return nr; |
| 270 | } |
| 271 | } |
| 272 | return null; |
| 273 | } |
| 274 | |
| 275 | @Override |
| 276 | public boolean hasNext() { |
| 277 | return mNext == null; |
| 278 | } |
| 279 | |
| 280 | @Override |
| 281 | public StatusBarNotification next() { |
| 282 | StatusBarNotification next = mNext; |
| 283 | if (next == null) { |
| 284 | throw new NoSuchElementException(); |
| 285 | } |
| 286 | mNext = findNext(); |
| 287 | return next; |
| 288 | } |
| 289 | |
| 290 | @Override |
| 291 | public void remove() { |
| 292 | iter.remove(); |
| 293 | } |
| 294 | }; |
| 295 | } |
| Daniel Sandler | 78d0d25 | 2013-02-12 08:14:52 -0500 | [diff] [blame] | 296 | |
| 297 | public StatusBarNotification[] getArray(int count) { |
| 298 | if (count == 0) count = Archive.BUFFER_SIZE; |
| 299 | final StatusBarNotification[] a |
| 300 | = new StatusBarNotification[Math.min(count, mBuffer.size())]; |
| 301 | Iterator<StatusBarNotification> iter = descendingIterator(); |
| 302 | int i=0; |
| 303 | while (iter.hasNext() && i < count) { |
| 304 | a[i++] = iter.next(); |
| 305 | } |
| 306 | return a; |
| 307 | } |
| 308 | |
| 309 | public StatusBarNotification[] getArray(int count, String pkg, int userId) { |
| 310 | if (count == 0) count = Archive.BUFFER_SIZE; |
| 311 | final StatusBarNotification[] a |
| 312 | = new StatusBarNotification[Math.min(count, mBuffer.size())]; |
| 313 | Iterator<StatusBarNotification> iter = filter(descendingIterator(), pkg, userId); |
| 314 | int i=0; |
| 315 | while (iter.hasNext() && i < count) { |
| 316 | a[i++] = iter.next(); |
| 317 | } |
| 318 | return a; |
| 319 | } |
| 320 | |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | Archive mArchive = new Archive(); |
| 324 | |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 325 | private void loadBlockDb() { |
| 326 | synchronized(mBlockedPackages) { |
| 327 | if (mPolicyFile == null) { |
| 328 | File dir = new File("/data/system"); |
| 329 | mPolicyFile = new AtomicFile(new File(dir, "notification_policy.xml")); |
| 330 | |
| 331 | mBlockedPackages.clear(); |
| 332 | |
| 333 | FileInputStream infile = null; |
| 334 | try { |
| 335 | infile = mPolicyFile.openRead(); |
| 336 | final XmlPullParser parser = Xml.newPullParser(); |
| 337 | parser.setInput(infile, null); |
| 338 | |
| 339 | int type; |
| 340 | String tag; |
| 341 | int version = DB_VERSION; |
| 342 | while ((type = parser.next()) != END_DOCUMENT) { |
| 343 | tag = parser.getName(); |
| 344 | if (type == START_TAG) { |
| 345 | if (TAG_BODY.equals(tag)) { |
| 346 | version = Integer.parseInt(parser.getAttributeValue(null, ATTR_VERSION)); |
| 347 | } else if (TAG_BLOCKED_PKGS.equals(tag)) { |
| 348 | while ((type = parser.next()) != END_DOCUMENT) { |
| 349 | tag = parser.getName(); |
| 350 | if (TAG_PACKAGE.equals(tag)) { |
| 351 | mBlockedPackages.add(parser.getAttributeValue(null, ATTR_NAME)); |
| 352 | } else if (TAG_BLOCKED_PKGS.equals(tag) && type == END_TAG) { |
| 353 | break; |
| 354 | } |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | } catch (FileNotFoundException e) { |
| 360 | // No data yet |
| 361 | } catch (IOException e) { |
| 362 | Log.wtf(TAG, "Unable to read blocked notifications database", e); |
| 363 | } catch (NumberFormatException e) { |
| 364 | Log.wtf(TAG, "Unable to parse blocked notifications database", e); |
| 365 | } catch (XmlPullParserException e) { |
| 366 | Log.wtf(TAG, "Unable to parse blocked notifications database", e); |
| 367 | } finally { |
| 368 | IoUtils.closeQuietly(infile); |
| 369 | } |
| 370 | } |
| 371 | } |
| 372 | } |
| 373 | |
| Daniel Sandler | 4a900acd | 2013-01-30 14:04:10 -0500 | [diff] [blame] | 374 | /** |
| 375 | * Use this when you just want to know if notifications are OK for this package. |
| 376 | */ |
| 377 | public boolean areNotificationsEnabledForPackage(String pkg, int uid) { |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 378 | checkCallerIsSystem(); |
| Daniel Sandler | 4a900acd | 2013-01-30 14:04:10 -0500 | [diff] [blame] | 379 | return (mAppOps.checkOpNoThrow(AppOpsManager.OP_POST_NOTIFICATION, uid, pkg) |
| 380 | == AppOpsManager.MODE_ALLOWED); |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 381 | } |
| 382 | |
| Daniel Sandler | 4a900acd | 2013-01-30 14:04:10 -0500 | [diff] [blame] | 383 | /** Use this when you actually want to post a notification or toast. |
| 384 | * |
| 385 | * Unchecked. Not exposed via Binder, but can be called in the course of enqueue*(). |
| 386 | */ |
| 387 | private boolean noteNotificationOp(String pkg, int uid) { |
| 388 | if (mAppOps.noteOpNoThrow(AppOpsManager.OP_POST_NOTIFICATION, uid, pkg) |
| 389 | != AppOpsManager.MODE_ALLOWED) { |
| 390 | Slog.v(TAG, "notifications are disabled by AppOps for " + pkg); |
| 391 | return false; |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 392 | } |
| Daniel Sandler | 4a900acd | 2013-01-30 14:04:10 -0500 | [diff] [blame] | 393 | return true; |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 394 | } |
| 395 | |
| Daniel Sandler | 4a900acd | 2013-01-30 14:04:10 -0500 | [diff] [blame] | 396 | public void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled) { |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 397 | checkCallerIsSystem(); |
| Daniel Sandler | 4a900acd | 2013-01-30 14:04:10 -0500 | [diff] [blame] | 398 | if (true||DBG) { |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 399 | Slog.v(TAG, (enabled?"en":"dis") + "abling notifications for " + pkg); |
| 400 | } |
| Daniel Sandler | 4a900acd | 2013-01-30 14:04:10 -0500 | [diff] [blame] | 401 | mAppOps.setMode(AppOpsManager.OP_POST_NOTIFICATION, uid, pkg, |
| 402 | enabled ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_IGNORED); |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | private static String idDebugString(Context baseContext, String packageName, int id) { |
| 407 | Context c = null; |
| 408 | |
| 409 | if (packageName != null) { |
| 410 | try { |
| 411 | c = baseContext.createPackageContext(packageName, 0); |
| 412 | } catch (NameNotFoundException e) { |
| 413 | c = baseContext; |
| 414 | } |
| 415 | } else { |
| 416 | c = baseContext; |
| 417 | } |
| 418 | |
| 419 | String pkg; |
| 420 | String type; |
| 421 | String name; |
| 422 | |
| 423 | Resources r = c.getResources(); |
| 424 | try { |
| 425 | return r.getResourceName(id); |
| 426 | } catch (Resources.NotFoundException e) { |
| 427 | return "<name unknown>"; |
| 428 | } |
| 429 | } |
| 430 | |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 431 | public StatusBarNotification[] getActiveNotifications(String callingPkg) { |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 432 | // enforce() will ensure the calling uid has the correct permission |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 433 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NOTIFICATIONS, |
| Daniel Sandler | 78d0d25 | 2013-02-12 08:14:52 -0500 | [diff] [blame] | 434 | "NotificationManagerService.getActiveNotifications"); |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 435 | |
| 436 | StatusBarNotification[] tmp = null; |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 437 | int uid = Binder.getCallingUid(); |
| 438 | |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 439 | // noteOp will check to make sure the callingPkg matches the uid |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 440 | if (mAppOps.noteOpNoThrow(AppOpsManager.OP_ACCESS_NOTIFICATIONS, uid, callingPkg) |
| 441 | == AppOpsManager.MODE_ALLOWED) { |
| 442 | synchronized (mNotificationList) { |
| 443 | tmp = new StatusBarNotification[mNotificationList.size()]; |
| 444 | final int N = mNotificationList.size(); |
| 445 | for (int i=0; i<N; i++) { |
| 446 | tmp[i] = mNotificationList.get(i).sbn; |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | return tmp; |
| 451 | } |
| 452 | |
| Daniel Sandler | 78d0d25 | 2013-02-12 08:14:52 -0500 | [diff] [blame] | 453 | public StatusBarNotification[] getHistoricalNotifications(String callingPkg, int count) { |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 454 | // enforce() will ensure the calling uid has the correct permission |
| Daniel Sandler | 78d0d25 | 2013-02-12 08:14:52 -0500 | [diff] [blame] | 455 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NOTIFICATIONS, |
| 456 | "NotificationManagerService.getHistoricalNotifications"); |
| 457 | |
| 458 | StatusBarNotification[] tmp = null; |
| 459 | int uid = Binder.getCallingUid(); |
| 460 | |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 461 | // noteOp will check to make sure the callingPkg matches the uid |
| Daniel Sandler | 78d0d25 | 2013-02-12 08:14:52 -0500 | [diff] [blame] | 462 | if (mAppOps.noteOpNoThrow(AppOpsManager.OP_ACCESS_NOTIFICATIONS, uid, callingPkg) |
| 463 | == AppOpsManager.MODE_ALLOWED) { |
| 464 | synchronized (mArchive) { |
| 465 | tmp = mArchive.getArray(count); |
| 466 | } |
| 467 | } |
| 468 | return tmp; |
| 469 | } |
| 470 | |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 471 | boolean packageCanTapNotificationsForUser(final int uid, final String pkg) { |
| 472 | // Make sure the package and uid match, and that the package is allowed access |
| 473 | return (AppOpsManager.MODE_ALLOWED |
| 474 | == mAppOps.checkOpNoThrow(AppOpsManager.OP_ACCESS_NOTIFICATIONS, uid, pkg)); |
| 475 | } |
| 476 | |
| Daniel Sandler | 09a247e | 2013-02-14 10:24:17 -0500 | [diff] [blame] | 477 | @Override |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 478 | public void registerListener(final INotificationListener listener, |
| 479 | final String pkg, final int userid) { |
| 480 | // ensure system or allowed pkg |
| 481 | int uid = Binder.getCallingUid(); |
| 482 | boolean isSystem = (UserHandle.getAppId(uid) == Process.SYSTEM_UID || uid == 0); |
| 483 | if (!(isSystem || packageCanTapNotificationsForUser(uid, pkg))) { |
| 484 | throw new SecurityException("Package " + pkg |
| 485 | + " may not listen for notifications"); |
| 486 | } |
| 487 | |
| Daniel Sandler | 09a247e | 2013-02-14 10:24:17 -0500 | [diff] [blame] | 488 | synchronized (mNotificationList) { |
| 489 | try { |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 490 | NotificationListenerInfo info |
| 491 | = new NotificationListenerInfo(listener, pkg, userid, isSystem); |
| Daniel Sandler | 09a247e | 2013-02-14 10:24:17 -0500 | [diff] [blame] | 492 | listener.asBinder().linkToDeath(info, 0); |
| 493 | mListeners.add(info); |
| 494 | } catch (RemoteException e) { |
| 495 | // already dead |
| 496 | } |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | @Override |
| 501 | public void unregisterListener(INotificationListener listener, int userid) { |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 502 | // no need to check permissions; if your listener binder is in the list, |
| 503 | // that's proof that you had permission to add it in the first place |
| 504 | |
| Daniel Sandler | 09a247e | 2013-02-14 10:24:17 -0500 | [diff] [blame] | 505 | synchronized (mNotificationList) { |
| 506 | final int N = mListeners.size(); |
| 507 | for (int i=N-1; i>=0; i--) { |
| 508 | final NotificationListenerInfo info = mListeners.get(i); |
| 509 | if (info.listener == listener && info.userid == userid) { |
| 510 | mListeners.remove(listener); |
| 511 | } |
| 512 | } |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | private void notifyPostedLocked(NotificationRecord n) { |
| 517 | final StatusBarNotification sbn = n.sbn; |
| 518 | for (final NotificationListenerInfo info : mListeners) { |
| 519 | mHandler.post(new Runnable() { |
| 520 | @Override |
| 521 | public void run() { |
| 522 | info.notifyPostedIfUserMatch(sbn); |
| 523 | }}); |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | private void notifyRemovedLocked(NotificationRecord n) { |
| 528 | final StatusBarNotification sbn = n.sbn; |
| 529 | for (final NotificationListenerInfo info : mListeners) { |
| 530 | mHandler.post(new Runnable() { |
| 531 | @Override |
| 532 | public void run() { |
| 533 | info.notifyRemovedIfUserMatch(sbn); |
| 534 | }}); |
| 535 | } |
| 536 | } |
| 537 | |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 538 | public static final class NotificationRecord |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 539 | { |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 540 | final StatusBarNotification sbn; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 541 | IBinder statusBarKey; |
| 542 | |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 543 | NotificationRecord(StatusBarNotification sbn) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 544 | { |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 545 | this.sbn = sbn; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | } |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 547 | |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 548 | public Notification getNotification() { return sbn.notification; } |
| 549 | public int getFlags() { return sbn.notification.flags; } |
| 550 | public int getUserId() { return sbn.getUserId(); } |
| 551 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 552 | void dump(PrintWriter pw, String prefix, Context baseContext) { |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 553 | final Notification notification = sbn.notification; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 554 | pw.println(prefix + this); |
| 555 | pw.println(prefix + " icon=0x" + Integer.toHexString(notification.icon) |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 556 | + " / " + idDebugString(baseContext, this.sbn.pkg, notification.icon)); |
| Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 557 | pw.println(prefix + " pri=" + notification.priority); |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 558 | pw.println(prefix + " score=" + this.sbn.score); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 559 | pw.println(prefix + " contentIntent=" + notification.contentIntent); |
| 560 | pw.println(prefix + " deleteIntent=" + notification.deleteIntent); |
| 561 | pw.println(prefix + " tickerText=" + notification.tickerText); |
| 562 | pw.println(prefix + " contentView=" + notification.contentView); |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 563 | pw.println(prefix + " uid=" + this.sbn.uid + " userId=" + this.sbn.getUserId()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 564 | pw.println(prefix + " defaults=0x" + Integer.toHexString(notification.defaults)); |
| 565 | pw.println(prefix + " flags=0x" + Integer.toHexString(notification.flags)); |
| 566 | pw.println(prefix + " sound=" + notification.sound); |
| 567 | pw.println(prefix + " vibrate=" + Arrays.toString(notification.vibrate)); |
| 568 | pw.println(prefix + " ledARGB=0x" + Integer.toHexString(notification.ledARGB) |
| 569 | + " ledOnMS=" + notification.ledOnMS |
| 570 | + " ledOffMS=" + notification.ledOffMS); |
| 571 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 572 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 573 | @Override |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 574 | public final String toString() { |
| 575 | return String.format( |
| 576 | "NotificationRecord(0x%08x: pkg=%s user=%s id=%d tag=%s score=%d: %s)", |
| 577 | System.identityHashCode(this), |
| 578 | this.sbn.pkg, this.sbn.user, this.sbn.id, this.sbn.tag, |
| 579 | this.sbn.score, this.sbn.notification); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 580 | } |
| 581 | } |
| 582 | |
| 583 | private static final class ToastRecord |
| 584 | { |
| 585 | final int pid; |
| 586 | final String pkg; |
| 587 | final ITransientNotification callback; |
| 588 | int duration; |
| 589 | |
| 590 | ToastRecord(int pid, String pkg, ITransientNotification callback, int duration) |
| 591 | { |
| 592 | this.pid = pid; |
| 593 | this.pkg = pkg; |
| 594 | this.callback = callback; |
| 595 | this.duration = duration; |
| 596 | } |
| 597 | |
| 598 | void update(int duration) { |
| 599 | this.duration = duration; |
| 600 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 601 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 602 | void dump(PrintWriter pw, String prefix) { |
| 603 | pw.println(prefix + this); |
| 604 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 605 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 606 | @Override |
| 607 | public final String toString() |
| 608 | { |
| 609 | return "ToastRecord{" |
| 610 | + Integer.toHexString(System.identityHashCode(this)) |
| 611 | + " pkg=" + pkg |
| 612 | + " callback=" + callback |
| 613 | + " duration=" + duration; |
| 614 | } |
| 615 | } |
| 616 | |
| Joe Onorato | 089de88 | 2010-04-12 08:18:45 -0700 | [diff] [blame] | 617 | private StatusBarManagerService.NotificationCallbacks mNotificationCallbacks |
| 618 | = new StatusBarManagerService.NotificationCallbacks() { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 619 | |
| 620 | public void onSetDisabled(int status) { |
| 621 | synchronized (mNotificationList) { |
| 622 | mDisabledNotifications = status; |
| 623 | if ((mDisabledNotifications & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0) { |
| 624 | // cancel whatever's going on |
| 625 | long identity = Binder.clearCallingIdentity(); |
| 626 | try { |
| Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 627 | final IRingtonePlayer player = mAudioService.getRingtonePlayer(); |
| 628 | if (player != null) { |
| 629 | player.stopAsync(); |
| 630 | } |
| 631 | } catch (RemoteException e) { |
| 632 | } finally { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 633 | Binder.restoreCallingIdentity(identity); |
| 634 | } |
| 635 | |
| 636 | identity = Binder.clearCallingIdentity(); |
| 637 | try { |
| 638 | mVibrator.cancel(); |
| Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 639 | } finally { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 640 | Binder.restoreCallingIdentity(identity); |
| 641 | } |
| 642 | } |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | public void onClearAll() { |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 647 | // XXX to be totally correct, the caller should tell us which user |
| 648 | // this is for. |
| 649 | cancelAll(ActivityManager.getCurrentUser()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 650 | } |
| 651 | |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 652 | public void onNotificationClick(String pkg, String tag, int id) { |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 653 | // XXX to be totally correct, the caller should tell us which user |
| 654 | // this is for. |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 655 | cancelNotification(pkg, tag, id, Notification.FLAG_AUTO_CANCEL, |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 656 | Notification.FLAG_FOREGROUND_SERVICE, false, |
| 657 | ActivityManager.getCurrentUser()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 658 | } |
| 659 | |
| Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 660 | public void onNotificationClear(String pkg, String tag, int id) { |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 661 | // XXX to be totally correct, the caller should tell us which user |
| 662 | // this is for. |
| Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 663 | cancelNotification(pkg, tag, id, 0, |
| 664 | Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE, |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 665 | true, ActivityManager.getCurrentUser()); |
| Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 666 | } |
| 667 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 668 | public void onPanelRevealed() { |
| 669 | synchronized (mNotificationList) { |
| 670 | // sound |
| 671 | mSoundNotification = null; |
| Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 672 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 673 | long identity = Binder.clearCallingIdentity(); |
| 674 | try { |
| Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 675 | final IRingtonePlayer player = mAudioService.getRingtonePlayer(); |
| 676 | if (player != null) { |
| 677 | player.stopAsync(); |
| 678 | } |
| 679 | } catch (RemoteException e) { |
| 680 | } finally { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 681 | Binder.restoreCallingIdentity(identity); |
| 682 | } |
| 683 | |
| 684 | // vibrate |
| 685 | mVibrateNotification = null; |
| 686 | identity = Binder.clearCallingIdentity(); |
| 687 | try { |
| 688 | mVibrator.cancel(); |
| Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 689 | } finally { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 690 | Binder.restoreCallingIdentity(identity); |
| 691 | } |
| 692 | |
| 693 | // light |
| 694 | mLights.clear(); |
| 695 | mLedNotification = null; |
| 696 | updateLightsLocked(); |
| 697 | } |
| 698 | } |
| Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 699 | |
| Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 700 | public void onNotificationError(String pkg, String tag, int id, |
| 701 | int uid, int initialPid, String message) { |
| Daniel Sandler | d0a2f86 | 2010-08-03 15:29:31 -0400 | [diff] [blame] | 702 | Slog.d(TAG, "onNotification error pkg=" + pkg + " tag=" + tag + " id=" + id |
| 703 | + "; will crashApplication(uid=" + uid + ", pid=" + initialPid + ")"); |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 704 | // XXX to be totally correct, the caller should tell us which user |
| 705 | // this is for. |
| 706 | cancelNotification(pkg, tag, id, 0, 0, false, UserHandle.getUserId(uid)); |
| Dianne Hackborn | 9d39d0c | 2010-06-24 15:57:42 -0700 | [diff] [blame] | 707 | long ident = Binder.clearCallingIdentity(); |
| 708 | try { |
| 709 | ActivityManagerNative.getDefault().crashApplication(uid, initialPid, pkg, |
| 710 | "Bad notification posted from package " + pkg |
| 711 | + ": " + message); |
| 712 | } catch (RemoteException e) { |
| 713 | } |
| 714 | Binder.restoreCallingIdentity(ident); |
| Joe Onorato | 005847b | 2010-06-04 16:08:02 -0400 | [diff] [blame] | 715 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 716 | }; |
| 717 | |
| 718 | private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { |
| 719 | @Override |
| 720 | public void onReceive(Context context, Intent intent) { |
| 721 | String action = intent.getAction(); |
| 722 | |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 723 | boolean queryRestart = false; |
| Daniel Sandler | 26ece57 | 2012-06-01 15:38:46 -0400 | [diff] [blame] | 724 | boolean packageChanged = false; |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 725 | |
| Mike Lockwood | 541c994 | 2011-06-12 19:35:45 -0400 | [diff] [blame] | 726 | if (action.equals(Intent.ACTION_PACKAGE_REMOVED) |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 727 | || action.equals(Intent.ACTION_PACKAGE_RESTARTED) |
| Daniel Sandler | 26ece57 | 2012-06-01 15:38:46 -0400 | [diff] [blame] | 728 | || (packageChanged=action.equals(Intent.ACTION_PACKAGE_CHANGED)) |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 729 | || (queryRestart=action.equals(Intent.ACTION_QUERY_PACKAGE_RESTART)) |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 730 | || action.equals(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)) { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 731 | String pkgList[] = null; |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 732 | if (action.equals(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)) { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 733 | pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 734 | } else if (queryRestart) { |
| 735 | pkgList = intent.getStringArrayExtra(Intent.EXTRA_PACKAGES); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 736 | } else { |
| 737 | Uri uri = intent.getData(); |
| 738 | if (uri == null) { |
| 739 | return; |
| 740 | } |
| 741 | String pkgName = uri.getSchemeSpecificPart(); |
| 742 | if (pkgName == null) { |
| 743 | return; |
| 744 | } |
| Daniel Sandler | 26ece57 | 2012-06-01 15:38:46 -0400 | [diff] [blame] | 745 | if (packageChanged) { |
| 746 | // We cancel notifications for packages which have just been disabled |
| 747 | final int enabled = mContext.getPackageManager() |
| 748 | .getApplicationEnabledSetting(pkgName); |
| 749 | if (enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED |
| 750 | || enabled == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) { |
| 751 | return; |
| 752 | } |
| 753 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 754 | pkgList = new String[]{pkgName}; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 755 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 756 | if (pkgList != null && (pkgList.length > 0)) { |
| 757 | for (String pkgName : pkgList) { |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 758 | cancelAllNotificationsInt(pkgName, 0, 0, !queryRestart, |
| 759 | UserHandle.USER_ALL); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 760 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 761 | } |
| Mike Lockwood | 63b5ad9 | 2011-08-30 09:55:30 -0400 | [diff] [blame] | 762 | } else if (action.equals(Intent.ACTION_SCREEN_ON)) { |
| 763 | // Keep track of screen on/off state, but do not turn off the notification light |
| 764 | // until user passes through the lock screen or views the notification. |
| 765 | mScreenOn = true; |
| 766 | } else if (action.equals(Intent.ACTION_SCREEN_OFF)) { |
| 767 | mScreenOn = false; |
| Daniel Sandler | e96ffb1 | 2010-03-11 13:38:06 -0500 | [diff] [blame] | 768 | } else if (action.equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) { |
| Mike Lockwood | 63b5ad9 | 2011-08-30 09:55:30 -0400 | [diff] [blame] | 769 | mInCall = (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals( |
| 770 | TelephonyManager.EXTRA_STATE_OFFHOOK)); |
| Daniel Sandler | e96ffb1 | 2010-03-11 13:38:06 -0500 | [diff] [blame] | 771 | updateNotificationPulse(); |
| Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 772 | } else if (action.equals(Intent.ACTION_USER_STOPPED)) { |
| 773 | int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1); |
| 774 | if (userHandle >= 0) { |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 775 | cancelAllNotificationsInt(null, 0, 0, true, userHandle); |
| Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 776 | } |
| Mike Lockwood | 63b5ad9 | 2011-08-30 09:55:30 -0400 | [diff] [blame] | 777 | } else if (action.equals(Intent.ACTION_USER_PRESENT)) { |
| 778 | // turn off LED when user passes through lock screen |
| 779 | mNotificationLight.turnOff(); |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 780 | } else if (action.equals(Intent.ACTION_USER_SWITCHED)) { |
| 781 | // reload per-user settings |
| 782 | mSettingsObserver.update(null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 783 | } |
| 784 | } |
| 785 | }; |
| 786 | |
| Dianne Hackborn | 1dac277 | 2009-06-26 18:16:48 -0700 | [diff] [blame] | 787 | class SettingsObserver extends ContentObserver { |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 788 | private final Uri NOTIFICATION_LIGHT_PULSE_URI |
| 789 | = Settings.System.getUriFor(Settings.System.NOTIFICATION_LIGHT_PULSE); |
| 790 | |
| 791 | private final Uri ENABLED_NOTIFICATION_LISTENERS_URI |
| 792 | = Settings.System.getUriFor(Settings.Secure.ENABLED_NOTIFICATION_LISTENERS); |
| 793 | |
| Dianne Hackborn | 1dac277 | 2009-06-26 18:16:48 -0700 | [diff] [blame] | 794 | SettingsObserver(Handler handler) { |
| 795 | super(handler); |
| 796 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 797 | |
| Dianne Hackborn | 1dac277 | 2009-06-26 18:16:48 -0700 | [diff] [blame] | 798 | void observe() { |
| 799 | ContentResolver resolver = mContext.getContentResolver(); |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 800 | resolver.registerContentObserver(NOTIFICATION_LIGHT_PULSE_URI, |
| 801 | false, this); |
| 802 | resolver.registerContentObserver(ENABLED_NOTIFICATION_LISTENERS_URI, |
| 803 | false, this); |
| 804 | update(null); |
| Dianne Hackborn | 1dac277 | 2009-06-26 18:16:48 -0700 | [diff] [blame] | 805 | } |
| 806 | |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 807 | @Override public void onChange(boolean selfChange, Uri uri) { |
| 808 | update(uri); |
| Dianne Hackborn | 1dac277 | 2009-06-26 18:16:48 -0700 | [diff] [blame] | 809 | } |
| 810 | |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 811 | public void update(Uri uri) { |
| Dianne Hackborn | 1dac277 | 2009-06-26 18:16:48 -0700 | [diff] [blame] | 812 | ContentResolver resolver = mContext.getContentResolver(); |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 813 | if (uri == null || NOTIFICATION_LIGHT_PULSE_URI.equals(uri)) { |
| 814 | boolean pulseEnabled = Settings.System.getInt(resolver, |
| 815 | Settings.System.NOTIFICATION_LIGHT_PULSE, 0) != 0; |
| 816 | if (mNotificationPulseEnabled != pulseEnabled) { |
| 817 | mNotificationPulseEnabled = pulseEnabled; |
| 818 | updateNotificationPulse(); |
| 819 | } |
| 820 | } |
| 821 | if (uri == null || ENABLED_NOTIFICATION_LISTENERS_URI.equals(uri)) { |
| 822 | String pkglist = Settings.Secure.getString( |
| 823 | mContext.getContentResolver(), |
| 824 | Settings.Secure.ENABLED_NOTIFICATION_LISTENERS); |
| 825 | mEnabledListenersForCurrentUser.clear(); |
| 826 | if (pkglist != null) { |
| 827 | String[] pkgs = pkglist.split(";"); |
| 828 | for (int i=0; i<pkgs.length; i++) { |
| 829 | final String pkg = pkgs[i]; |
| 830 | if (pkg != null && ! "".equals(pkg)) { |
| 831 | mEnabledListenersForCurrentUser.add(pkgs[i]); |
| 832 | } |
| 833 | } |
| 834 | } |
| Mike Lockwood | c22404a | 2009-12-02 11:15:02 -0500 | [diff] [blame] | 835 | } |
| Dianne Hackborn | 1dac277 | 2009-06-26 18:16:48 -0700 | [diff] [blame] | 836 | } |
| 837 | } |
| Mike Lockwood | c22404a | 2009-12-02 11:15:02 -0500 | [diff] [blame] | 838 | |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 839 | private SettingsObserver mSettingsObserver; |
| 840 | |
| Daniel Sandler | edbb380 | 2012-11-13 20:49:47 -0800 | [diff] [blame] | 841 | static long[] getLongArray(Resources r, int resid, int maxlen, long[] def) { |
| 842 | int[] ar = r.getIntArray(resid); |
| 843 | if (ar == null) { |
| 844 | return def; |
| 845 | } |
| 846 | final int len = ar.length > maxlen ? maxlen : ar.length; |
| 847 | long[] out = new long[len]; |
| 848 | for (int i=0; i<len; i++) { |
| 849 | out[i] = ar[i]; |
| 850 | } |
| 851 | return out; |
| 852 | } |
| 853 | |
| Joe Onorato | 089de88 | 2010-04-12 08:18:45 -0700 | [diff] [blame] | 854 | NotificationManagerService(Context context, StatusBarManagerService statusBar, |
| Mike Lockwood | 3a32213 | 2009-11-24 00:30:52 -0500 | [diff] [blame] | 855 | LightsService lights) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 856 | { |
| 857 | super(); |
| 858 | mContext = context; |
| Jeff Brown | c234613 | 2012-04-13 01:55:38 -0700 | [diff] [blame] | 859 | mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 860 | mAm = ActivityManagerNative.getDefault(); |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 861 | mUserManager = (UserManager)context.getSystemService(Context.USER_SERVICE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 862 | mToastQueue = new ArrayList<ToastRecord>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 863 | mHandler = new WorkerHandler(); |
| San Mehat | 3ee1317 | 2010-02-04 20:54:43 -0800 | [diff] [blame] | 864 | |
| Daniel Sandler | 4a900acd | 2013-01-30 14:04:10 -0500 | [diff] [blame] | 865 | mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE); |
| 866 | |
| 867 | importOldBlockDb(); |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 868 | |
| Joe Onorato | 089de88 | 2010-04-12 08:18:45 -0700 | [diff] [blame] | 869 | mStatusBar = statusBar; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 870 | statusBar.setNotificationCallbacks(mNotificationCallbacks); |
| 871 | |
| Mike Lockwood | 3cb67a3 | 2009-11-27 14:25:58 -0500 | [diff] [blame] | 872 | mNotificationLight = lights.getLight(LightsService.LIGHT_ID_NOTIFICATIONS); |
| 873 | mAttentionLight = lights.getLight(LightsService.LIGHT_ID_ATTENTION); |
| 874 | |
| Mike Lockwood | 670f932 | 2010-01-20 12:13:36 -0500 | [diff] [blame] | 875 | Resources resources = mContext.getResources(); |
| 876 | mDefaultNotificationColor = resources.getColor( |
| 877 | com.android.internal.R.color.config_defaultNotificationColor); |
| 878 | mDefaultNotificationLedOn = resources.getInteger( |
| 879 | com.android.internal.R.integer.config_defaultNotificationLedOn); |
| 880 | mDefaultNotificationLedOff = resources.getInteger( |
| 881 | com.android.internal.R.integer.config_defaultNotificationLedOff); |
| 882 | |
| Daniel Sandler | edbb380 | 2012-11-13 20:49:47 -0800 | [diff] [blame] | 883 | mDefaultVibrationPattern = getLongArray(resources, |
| 884 | com.android.internal.R.array.config_defaultNotificationVibePattern, |
| 885 | VIBRATE_PATTERN_MAXLEN, |
| 886 | DEFAULT_VIBRATE_PATTERN); |
| 887 | |
| 888 | mFallbackVibrationPattern = getLongArray(resources, |
| 889 | com.android.internal.R.array.config_notificationFallbackVibePattern, |
| 890 | VIBRATE_PATTERN_MAXLEN, |
| 891 | DEFAULT_VIBRATE_PATTERN); |
| 892 | |
| Joe Onorato | 39f5b6a | 2009-07-23 12:29:19 -0400 | [diff] [blame] | 893 | // Don't start allowing notifications until the setup wizard has run once. |
| 894 | // After that, including subsequent boots, init with notifications turned on. |
| 895 | // This works on the first boot because the setup wizard will toggle this |
| 896 | // flag at least once and we'll go back to 0 after that. |
| Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 897 | if (0 == Settings.Global.getInt(mContext.getContentResolver(), |
| 898 | Settings.Global.DEVICE_PROVISIONED, 0)) { |
| Joe Onorato | 39f5b6a | 2009-07-23 12:29:19 -0400 | [diff] [blame] | 899 | mDisabledNotifications = StatusBarManager.DISABLE_NOTIFICATION_ALERTS; |
| 900 | } |
| 901 | |
| Mike Lockwood | 35e16bf | 2010-11-30 19:53:36 -0500 | [diff] [blame] | 902 | // register for various Intents |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 903 | IntentFilter filter = new IntentFilter(); |
| Mike Lockwood | c22404a | 2009-12-02 11:15:02 -0500 | [diff] [blame] | 904 | filter.addAction(Intent.ACTION_SCREEN_ON); |
| 905 | filter.addAction(Intent.ACTION_SCREEN_OFF); |
| Daniel Sandler | e96ffb1 | 2010-03-11 13:38:06 -0500 | [diff] [blame] | 906 | filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED); |
| Mike Lockwood | 63b5ad9 | 2011-08-30 09:55:30 -0400 | [diff] [blame] | 907 | filter.addAction(Intent.ACTION_USER_PRESENT); |
| Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 908 | filter.addAction(Intent.ACTION_USER_STOPPED); |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 909 | filter.addAction(Intent.ACTION_USER_SWITCHED); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 910 | mContext.registerReceiver(mIntentReceiver, filter); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 911 | IntentFilter pkgFilter = new IntentFilter(); |
| 912 | pkgFilter.addAction(Intent.ACTION_PACKAGE_REMOVED); |
| Daniel Sandler | aac0eb0 | 2011-08-06 22:51:56 -0400 | [diff] [blame] | 913 | pkgFilter.addAction(Intent.ACTION_PACKAGE_CHANGED); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 914 | pkgFilter.addAction(Intent.ACTION_PACKAGE_RESTARTED); |
| 915 | pkgFilter.addAction(Intent.ACTION_QUERY_PACKAGE_RESTART); |
| 916 | pkgFilter.addDataScheme("package"); |
| 917 | mContext.registerReceiver(mIntentReceiver, pkgFilter); |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 918 | IntentFilter sdFilter = new IntentFilter(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 919 | mContext.registerReceiver(mIntentReceiver, sdFilter); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 920 | |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 921 | mSettingsObserver = new SettingsObserver(mHandler); |
| 922 | mSettingsObserver.observe(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 923 | } |
| 924 | |
| Daniel Sandler | 4a900acd | 2013-01-30 14:04:10 -0500 | [diff] [blame] | 925 | /** |
| 926 | * Read the old XML-based app block database and import those blockages into the AppOps system. |
| 927 | */ |
| 928 | private void importOldBlockDb() { |
| 929 | loadBlockDb(); |
| 930 | |
| 931 | PackageManager pm = mContext.getPackageManager(); |
| 932 | for (String pkg : mBlockedPackages) { |
| 933 | PackageInfo info = null; |
| 934 | try { |
| 935 | info = pm.getPackageInfo(pkg, 0); |
| 936 | setNotificationsEnabledForPackage(pkg, info.applicationInfo.uid, false); |
| 937 | } catch (NameNotFoundException e) { |
| 938 | // forget you |
| 939 | } |
| 940 | } |
| 941 | mBlockedPackages.clear(); |
| 942 | if (mPolicyFile != null) { |
| 943 | mPolicyFile.delete(); |
| 944 | } |
| 945 | } |
| 946 | |
| Joe Onorato | 3027548 | 2009-07-08 17:09:14 -0700 | [diff] [blame] | 947 | void systemReady() { |
| Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 948 | mAudioService = IAudioService.Stub.asInterface( |
| 949 | ServiceManager.getService(Context.AUDIO_SERVICE)); |
| 950 | |
| Joe Onorato | 3027548 | 2009-07-08 17:09:14 -0700 | [diff] [blame] | 951 | // no beeping until we're basically done booting |
| 952 | mSystemReady = true; |
| 953 | } |
| 954 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 955 | // Toasts |
| 956 | // ============================================================================ |
| 957 | public void enqueueToast(String pkg, ITransientNotification callback, int duration) |
| 958 | { |
| Daniel Sandler | a703590 | 2010-03-30 15:45:31 -0400 | [diff] [blame] | 959 | if (DBG) Slog.i(TAG, "enqueueToast pkg=" + pkg + " callback=" + callback + " duration=" + duration); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 960 | |
| 961 | if (pkg == null || callback == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 962 | Slog.e(TAG, "Not doing toast. pkg=" + pkg + " callback=" + callback); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 963 | return ; |
| 964 | } |
| 965 | |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 966 | final boolean isSystemToast = ("android".equals(pkg)); |
| 967 | |
| Daniel Sandler | 4a900acd | 2013-01-30 14:04:10 -0500 | [diff] [blame] | 968 | if (ENABLE_BLOCKED_TOASTS && !noteNotificationOp(pkg, Binder.getCallingUid())) { |
| 969 | if (!isSystemToast) { |
| 970 | Slog.e(TAG, "Suppressing toast from package " + pkg + " by user request."); |
| 971 | return; |
| 972 | } |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 973 | } |
| 974 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 975 | synchronized (mToastQueue) { |
| 976 | int callingPid = Binder.getCallingPid(); |
| 977 | long callingId = Binder.clearCallingIdentity(); |
| 978 | try { |
| 979 | ToastRecord record; |
| 980 | int index = indexOfToastLocked(pkg, callback); |
| 981 | // If it's already in the queue, we update it in place, we don't |
| 982 | // move it to the end of the queue. |
| 983 | if (index >= 0) { |
| 984 | record = mToastQueue.get(index); |
| 985 | record.update(duration); |
| 986 | } else { |
| Vairavan Srinivasan | f9eb06c | 2011-01-21 18:08:36 -0800 | [diff] [blame] | 987 | // Limit the number of toasts that any given package except the android |
| 988 | // package can enqueue. Prevents DOS attacks and deals with leaks. |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 989 | if (!isSystemToast) { |
| Vairavan Srinivasan | f9eb06c | 2011-01-21 18:08:36 -0800 | [diff] [blame] | 990 | int count = 0; |
| 991 | final int N = mToastQueue.size(); |
| 992 | for (int i=0; i<N; i++) { |
| 993 | final ToastRecord r = mToastQueue.get(i); |
| 994 | if (r.pkg.equals(pkg)) { |
| 995 | count++; |
| 996 | if (count >= MAX_PACKAGE_NOTIFICATIONS) { |
| 997 | Slog.e(TAG, "Package has already posted " + count |
| 998 | + " toasts. Not showing more. Package=" + pkg); |
| 999 | return; |
| 1000 | } |
| 1001 | } |
| 1002 | } |
| 1003 | } |
| 1004 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1005 | record = new ToastRecord(callingPid, pkg, callback, duration); |
| 1006 | mToastQueue.add(record); |
| 1007 | index = mToastQueue.size() - 1; |
| 1008 | keepProcessAliveLocked(callingPid); |
| 1009 | } |
| 1010 | // If it's at index 0, it's the current toast. It doesn't matter if it's |
| 1011 | // new or just been updated. Call back and tell it to show itself. |
| 1012 | // If the callback fails, this will remove it from the list, so don't |
| 1013 | // assume that it's valid after this. |
| 1014 | if (index == 0) { |
| 1015 | showNextToastLocked(); |
| 1016 | } |
| 1017 | } finally { |
| 1018 | Binder.restoreCallingIdentity(callingId); |
| 1019 | } |
| 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | public void cancelToast(String pkg, ITransientNotification callback) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1024 | Slog.i(TAG, "cancelToast pkg=" + pkg + " callback=" + callback); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1025 | |
| 1026 | if (pkg == null || callback == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1027 | Slog.e(TAG, "Not cancelling notification. pkg=" + pkg + " callback=" + callback); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1028 | return ; |
| 1029 | } |
| 1030 | |
| 1031 | synchronized (mToastQueue) { |
| 1032 | long callingId = Binder.clearCallingIdentity(); |
| 1033 | try { |
| 1034 | int index = indexOfToastLocked(pkg, callback); |
| 1035 | if (index >= 0) { |
| 1036 | cancelToastLocked(index); |
| 1037 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1038 | Slog.w(TAG, "Toast already cancelled. pkg=" + pkg + " callback=" + callback); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1039 | } |
| 1040 | } finally { |
| 1041 | Binder.restoreCallingIdentity(callingId); |
| 1042 | } |
| 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | private void showNextToastLocked() { |
| 1047 | ToastRecord record = mToastQueue.get(0); |
| 1048 | while (record != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1049 | if (DBG) Slog.d(TAG, "Show pkg=" + record.pkg + " callback=" + record.callback); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1050 | try { |
| 1051 | record.callback.show(); |
| 1052 | scheduleTimeoutLocked(record, false); |
| 1053 | return; |
| 1054 | } catch (RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1055 | Slog.w(TAG, "Object died trying to show notification " + record.callback |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1056 | + " in package " + record.pkg); |
| 1057 | // remove it from the list and let the process die |
| 1058 | int index = mToastQueue.indexOf(record); |
| 1059 | if (index >= 0) { |
| 1060 | mToastQueue.remove(index); |
| 1061 | } |
| 1062 | keepProcessAliveLocked(record.pid); |
| 1063 | if (mToastQueue.size() > 0) { |
| 1064 | record = mToastQueue.get(0); |
| 1065 | } else { |
| 1066 | record = null; |
| 1067 | } |
| 1068 | } |
| 1069 | } |
| 1070 | } |
| 1071 | |
| 1072 | private void cancelToastLocked(int index) { |
| 1073 | ToastRecord record = mToastQueue.get(index); |
| 1074 | try { |
| 1075 | record.callback.hide(); |
| 1076 | } catch (RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1077 | Slog.w(TAG, "Object died trying to hide notification " + record.callback |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1078 | + " in package " + record.pkg); |
| 1079 | // don't worry about this, we're about to remove it from |
| 1080 | // the list anyway |
| 1081 | } |
| 1082 | mToastQueue.remove(index); |
| 1083 | keepProcessAliveLocked(record.pid); |
| 1084 | if (mToastQueue.size() > 0) { |
| 1085 | // Show the next one. If the callback fails, this will remove |
| 1086 | // it from the list, so don't assume that the list hasn't changed |
| 1087 | // after this point. |
| 1088 | showNextToastLocked(); |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | private void scheduleTimeoutLocked(ToastRecord r, boolean immediate) |
| 1093 | { |
| 1094 | Message m = Message.obtain(mHandler, MESSAGE_TIMEOUT, r); |
| 1095 | long delay = immediate ? 0 : (r.duration == Toast.LENGTH_LONG ? LONG_DELAY : SHORT_DELAY); |
| 1096 | mHandler.removeCallbacksAndMessages(r); |
| 1097 | mHandler.sendMessageDelayed(m, delay); |
| 1098 | } |
| 1099 | |
| 1100 | private void handleTimeout(ToastRecord record) |
| 1101 | { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1102 | if (DBG) Slog.d(TAG, "Timeout pkg=" + record.pkg + " callback=" + record.callback); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1103 | synchronized (mToastQueue) { |
| 1104 | int index = indexOfToastLocked(record.pkg, record.callback); |
| 1105 | if (index >= 0) { |
| 1106 | cancelToastLocked(index); |
| 1107 | } |
| 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | // lock on mToastQueue |
| 1112 | private int indexOfToastLocked(String pkg, ITransientNotification callback) |
| 1113 | { |
| 1114 | IBinder cbak = callback.asBinder(); |
| 1115 | ArrayList<ToastRecord> list = mToastQueue; |
| 1116 | int len = list.size(); |
| 1117 | for (int i=0; i<len; i++) { |
| 1118 | ToastRecord r = list.get(i); |
| 1119 | if (r.pkg.equals(pkg) && r.callback.asBinder() == cbak) { |
| 1120 | return i; |
| 1121 | } |
| 1122 | } |
| 1123 | return -1; |
| 1124 | } |
| 1125 | |
| 1126 | // lock on mToastQueue |
| 1127 | private void keepProcessAliveLocked(int pid) |
| 1128 | { |
| 1129 | int toastCount = 0; // toasts from this pid |
| 1130 | ArrayList<ToastRecord> list = mToastQueue; |
| 1131 | int N = list.size(); |
| 1132 | for (int i=0; i<N; i++) { |
| 1133 | ToastRecord r = list.get(i); |
| 1134 | if (r.pid == pid) { |
| 1135 | toastCount++; |
| 1136 | } |
| 1137 | } |
| 1138 | try { |
| 1139 | mAm.setProcessForeground(mForegroundToken, pid, toastCount > 0); |
| 1140 | } catch (RemoteException e) { |
| 1141 | // Shouldn't happen. |
| 1142 | } |
| 1143 | } |
| 1144 | |
| 1145 | private final class WorkerHandler extends Handler |
| 1146 | { |
| 1147 | @Override |
| 1148 | public void handleMessage(Message msg) |
| 1149 | { |
| 1150 | switch (msg.what) |
| 1151 | { |
| 1152 | case MESSAGE_TIMEOUT: |
| 1153 | handleTimeout((ToastRecord)msg.obj); |
| 1154 | break; |
| 1155 | } |
| 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | |
| 1160 | // Notifications |
| 1161 | // ============================================================================ |
| Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1162 | public void enqueueNotificationWithTag(String pkg, String basePkg, String tag, int id, |
| 1163 | Notification notification, int[] idOut, int userId) |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 1164 | { |
| Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1165 | enqueueNotificationInternal(pkg, basePkg, Binder.getCallingUid(), Binder.getCallingPid(), |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 1166 | tag, id, notification, idOut, userId); |
| Daniel Sandler | d0a2f86 | 2010-08-03 15:29:31 -0400 | [diff] [blame] | 1167 | } |
| Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1168 | |
| 1169 | private final static int clamp(int x, int low, int high) { |
| 1170 | return (x < low) ? low : ((x > high) ? high : x); |
| Daniel Sandler | e40451a | 2011-02-03 14:51:35 -0500 | [diff] [blame] | 1171 | } |
| 1172 | |
| Daniel Sandler | d0a2f86 | 2010-08-03 15:29:31 -0400 | [diff] [blame] | 1173 | // Not exposed via Binder; for system use only (otherwise malicious apps could spoof the |
| 1174 | // uid/pid of another application) |
| Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1175 | public void enqueueNotificationInternal(String pkg, String basePkg, int callingUid, |
| 1176 | int callingPid, String tag, int id, Notification notification, int[] idOut, int userId) |
| Daniel Sandler | d0a2f86 | 2010-08-03 15:29:31 -0400 | [diff] [blame] | 1177 | { |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 1178 | if (DBG) { |
| 1179 | Slog.v(TAG, "enqueueNotificationInternal: pkg=" + pkg + " id=" + id + " notification=" + notification); |
| 1180 | } |
| 1181 | checkCallerIsSystemOrSameApp(pkg); |
| 1182 | final boolean isSystemNotification = ("android".equals(pkg)); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1183 | |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 1184 | userId = ActivityManager.handleIncomingUser(callingPid, |
| Amith Yamasani | 2c7ebea | 2012-10-30 15:28:27 -0700 | [diff] [blame] | 1185 | callingUid, userId, true, false, "enqueueNotification", pkg); |
| Jeff Sharkey | 65c4a2b | 2012-09-25 17:22:27 -0700 | [diff] [blame] | 1186 | final UserHandle user = new UserHandle(userId); |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 1187 | |
| Joe Onorato | bd73d01 | 2010-06-04 11:44:54 -0700 | [diff] [blame] | 1188 | // Limit the number of notifications that any given package except the android |
| 1189 | // package can enqueue. Prevents DOS attacks and deals with leaks. |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 1190 | if (!isSystemNotification) { |
| Joe Onorato | bd73d01 | 2010-06-04 11:44:54 -0700 | [diff] [blame] | 1191 | synchronized (mNotificationList) { |
| 1192 | int count = 0; |
| 1193 | final int N = mNotificationList.size(); |
| 1194 | for (int i=0; i<N; i++) { |
| 1195 | final NotificationRecord r = mNotificationList.get(i); |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1196 | if (r.sbn.pkg.equals(pkg) && r.sbn.getUserId() == userId) { |
| Joe Onorato | bd73d01 | 2010-06-04 11:44:54 -0700 | [diff] [blame] | 1197 | count++; |
| 1198 | if (count >= MAX_PACKAGE_NOTIFICATIONS) { |
| 1199 | Slog.e(TAG, "Package has already posted " + count |
| 1200 | + " notifications. Not showing more. package=" + pkg); |
| 1201 | return; |
| 1202 | } |
| 1203 | } |
| 1204 | } |
| 1205 | } |
| 1206 | } |
| 1207 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1208 | // This conditional is a dirty hack to limit the logging done on |
| 1209 | // behalf of the download manager without affecting other apps. |
| 1210 | if (!pkg.equals("com.android.providers.downloads") |
| 1211 | || Log.isLoggable("DownloadManager", Log.VERBOSE)) { |
| Daniel Sandler | 321e9c5 | 2012-10-12 10:59:26 -0700 | [diff] [blame] | 1212 | EventLog.writeEvent(EventLogTags.NOTIFICATION_ENQUEUE, pkg, id, tag, userId, |
| Daniel Sandler | b64cb88 | 2011-11-29 23:48:29 -0500 | [diff] [blame] | 1213 | notification.toString()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | if (pkg == null || notification == null) { |
| 1217 | throw new IllegalArgumentException("null not allowed: pkg=" + pkg |
| 1218 | + " id=" + id + " notification=" + notification); |
| 1219 | } |
| 1220 | if (notification.icon != 0) { |
| 1221 | if (notification.contentView == null) { |
| 1222 | throw new IllegalArgumentException("contentView required: pkg=" + pkg |
| 1223 | + " id=" + id + " notification=" + notification); |
| 1224 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1225 | } |
| 1226 | |
| Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1227 | // === Scoring === |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 1228 | |
| Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1229 | // 0. Sanitize inputs |
| 1230 | notification.priority = clamp(notification.priority, Notification.PRIORITY_MIN, Notification.PRIORITY_MAX); |
| 1231 | // Migrate notification flags to scores |
| 1232 | if (0 != (notification.flags & Notification.FLAG_HIGH_PRIORITY)) { |
| 1233 | if (notification.priority < Notification.PRIORITY_MAX) notification.priority = Notification.PRIORITY_MAX; |
| Daniel Sandler | 49a2ad1 | 2012-03-28 15:46:39 -0400 | [diff] [blame] | 1234 | } else if (SCORE_ONGOING_HIGHER && 0 != (notification.flags & Notification.FLAG_ONGOING_EVENT)) { |
| Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1235 | if (notification.priority < Notification.PRIORITY_HIGH) notification.priority = Notification.PRIORITY_HIGH; |
| 1236 | } |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 1237 | |
| Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1238 | // 1. initial score: buckets of 10, around the app |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 1239 | int score = notification.priority * NOTIFICATION_PRIORITY_MULTIPLIER; //[-20..20] |
| Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1240 | |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 1241 | // 2. Consult external heuristics (TBD) |
| Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1242 | |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 1243 | // 3. Apply local rules |
| Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1244 | |
| 1245 | // blocked apps |
| Daniel Sandler | 4a900acd | 2013-01-30 14:04:10 -0500 | [diff] [blame] | 1246 | if (ENABLE_BLOCKED_NOTIFICATIONS && !noteNotificationOp(pkg, callingUid)) { |
| 1247 | if (!isSystemNotification) { |
| 1248 | score = JUNK_SCORE; |
| 1249 | Slog.e(TAG, "Suppressing notification from package " + pkg + " by user request."); |
| 1250 | } |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | if (DBG) { |
| 1254 | Slog.v(TAG, "Assigned score=" + score + " to " + notification); |
| 1255 | } |
| 1256 | |
| 1257 | if (score < SCORE_DISPLAY_THRESHOLD) { |
| 1258 | // Notification will be blocked because the score is too low. |
| 1259 | return; |
| Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1260 | } |
| 1261 | |
| Daniel Sandler | 526fa0e | 2012-12-04 14:51:50 -0500 | [diff] [blame] | 1262 | // Should this notification make noise, vibe, or use the LED? |
| 1263 | final boolean canInterrupt = (score >= SCORE_INTERRUPTION_THRESHOLD); |
| 1264 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1265 | synchronized (mNotificationList) { |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1266 | final StatusBarNotification n = new StatusBarNotification( |
| 1267 | pkg, id, tag, callingUid, callingPid, score, notification, user); |
| 1268 | NotificationRecord r = new NotificationRecord(n); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1269 | NotificationRecord old = null; |
| 1270 | |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 1271 | int index = indexOfNotificationLocked(pkg, tag, id, userId); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1272 | if (index < 0) { |
| 1273 | mNotificationList.add(r); |
| 1274 | } else { |
| 1275 | old = mNotificationList.remove(index); |
| 1276 | mNotificationList.add(index, r); |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 1277 | // Make sure we don't lose the foreground service state. |
| 1278 | if (old != null) { |
| 1279 | notification.flags |= |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1280 | old.getNotification().flags&Notification.FLAG_FOREGROUND_SERVICE; |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 1281 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1282 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1283 | |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 1284 | // Ensure if this is a foreground service that the proper additional |
| 1285 | // flags are set. |
| 1286 | if ((notification.flags&Notification.FLAG_FOREGROUND_SERVICE) != 0) { |
| 1287 | notification.flags |= Notification.FLAG_ONGOING_EVENT |
| 1288 | | Notification.FLAG_NO_CLEAR; |
| 1289 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1290 | |
| Svetoslav Ganov | c31ed39 | 2012-10-10 14:58:28 -0700 | [diff] [blame] | 1291 | final int currentUser; |
| 1292 | final long token = Binder.clearCallingIdentity(); |
| 1293 | try { |
| 1294 | currentUser = ActivityManager.getCurrentUser(); |
| 1295 | } finally { |
| 1296 | Binder.restoreCallingIdentity(token); |
| 1297 | } |
| 1298 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1299 | if (notification.icon != 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1300 | if (old != null && old.statusBarKey != null) { |
| 1301 | r.statusBarKey = old.statusBarKey; |
| 1302 | long identity = Binder.clearCallingIdentity(); |
| 1303 | try { |
| Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1304 | mStatusBar.updateNotification(r.statusBarKey, n); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1305 | } |
| 1306 | finally { |
| 1307 | Binder.restoreCallingIdentity(identity); |
| 1308 | } |
| 1309 | } else { |
| 1310 | long identity = Binder.clearCallingIdentity(); |
| 1311 | try { |
| Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1312 | r.statusBarKey = mStatusBar.addNotification(n); |
| Daniel Sandler | 526fa0e | 2012-12-04 14:51:50 -0500 | [diff] [blame] | 1313 | if ((n.notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0 |
| 1314 | && canInterrupt) { |
| Mike Lockwood | ece18ef | 2012-02-13 20:42:19 -0800 | [diff] [blame] | 1315 | mAttentionLight.pulse(); |
| 1316 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1317 | } |
| 1318 | finally { |
| 1319 | Binder.restoreCallingIdentity(identity); |
| 1320 | } |
| 1321 | } |
| Svetoslav Ganov | c31ed39 | 2012-10-10 14:58:28 -0700 | [diff] [blame] | 1322 | // Send accessibility events only for the current user. |
| 1323 | if (currentUser == userId) { |
| 1324 | sendAccessibilityEvent(notification, pkg); |
| 1325 | } |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1326 | |
| Daniel Sandler | 09a247e | 2013-02-14 10:24:17 -0500 | [diff] [blame] | 1327 | notifyPostedLocked(r); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1328 | } else { |
| Daniel Sandler | e40451a | 2011-02-03 14:51:35 -0500 | [diff] [blame] | 1329 | Slog.e(TAG, "Ignoring notification with icon==0: " + notification); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1330 | if (old != null && old.statusBarKey != null) { |
| 1331 | long identity = Binder.clearCallingIdentity(); |
| 1332 | try { |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 1333 | mStatusBar.removeNotification(old.statusBarKey); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1334 | } |
| 1335 | finally { |
| 1336 | Binder.restoreCallingIdentity(identity); |
| 1337 | } |
| Daniel Sandler | 09a247e | 2013-02-14 10:24:17 -0500 | [diff] [blame] | 1338 | |
| 1339 | notifyRemovedLocked(r); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1340 | } |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1341 | return; // do not play sounds, show lights, etc. for invalid notifications |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | // If we're not supposed to beep, vibrate, etc. then don't. |
| 1345 | if (((mDisabledNotifications & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) == 0) |
| 1346 | && (!(old != null |
| Joe Onorato | 3027548 | 2009-07-08 17:09:14 -0700 | [diff] [blame] | 1347 | && (notification.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0 )) |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1348 | && (r.getUserId() == UserHandle.USER_ALL || |
| 1349 | (r.getUserId() == userId && r.getUserId() == currentUser)) |
| Daniel Sandler | 526fa0e | 2012-12-04 14:51:50 -0500 | [diff] [blame] | 1350 | && canInterrupt |
| Joe Onorato | 3027548 | 2009-07-08 17:09:14 -0700 | [diff] [blame] | 1351 | && mSystemReady) { |
| Eric Laurent | 524dc04 | 2009-11-27 05:07:55 -0800 | [diff] [blame] | 1352 | |
| 1353 | final AudioManager audioManager = (AudioManager) mContext |
| 1354 | .getSystemService(Context.AUDIO_SERVICE); |
| Daniel Sandler | d4d2de2 | 2012-11-14 11:25:46 -0800 | [diff] [blame] | 1355 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1356 | // sound |
| 1357 | final boolean useDefaultSound = |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1358 | (notification.defaults & Notification.DEFAULT_SOUND) != 0; |
| Daniel Sandler | d4d2de2 | 2012-11-14 11:25:46 -0800 | [diff] [blame] | 1359 | |
| 1360 | Uri soundUri = null; |
| 1361 | boolean hasValidSound = false; |
| 1362 | |
| 1363 | if (useDefaultSound) { |
| 1364 | soundUri = Settings.System.DEFAULT_NOTIFICATION_URI; |
| 1365 | |
| 1366 | // check to see if the default notification sound is silent |
| 1367 | ContentResolver resolver = mContext.getContentResolver(); |
| 1368 | hasValidSound = Settings.System.getString(resolver, |
| 1369 | Settings.System.NOTIFICATION_SOUND) != null; |
| 1370 | } else if (notification.sound != null) { |
| 1371 | soundUri = notification.sound; |
| 1372 | hasValidSound = (soundUri != null); |
| 1373 | } |
| 1374 | |
| 1375 | if (hasValidSound) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1376 | boolean looping = (notification.flags & Notification.FLAG_INSISTENT) != 0; |
| 1377 | int audioStreamType; |
| 1378 | if (notification.audioStreamType >= 0) { |
| 1379 | audioStreamType = notification.audioStreamType; |
| 1380 | } else { |
| 1381 | audioStreamType = DEFAULT_STREAM_TYPE; |
| 1382 | } |
| 1383 | mSoundNotification = r; |
| Eric Laurent | 524dc04 | 2009-11-27 05:07:55 -0800 | [diff] [blame] | 1384 | // do not play notifications if stream volume is 0 |
| Jean-Michel Trivi | d677054 | 2012-10-10 12:03:41 -0700 | [diff] [blame] | 1385 | // (typically because ringer mode is silent) or if speech recognition is active. |
| 1386 | if ((audioManager.getStreamVolume(audioStreamType) != 0) |
| 1387 | && !audioManager.isSpeechRecognitionActive()) { |
| Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 1388 | final long identity = Binder.clearCallingIdentity(); |
| Eric Laurent | 524dc04 | 2009-11-27 05:07:55 -0800 | [diff] [blame] | 1389 | try { |
| Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 1390 | final IRingtonePlayer player = mAudioService.getRingtonePlayer(); |
| 1391 | if (player != null) { |
| Daniel Sandler | d4d2de2 | 2012-11-14 11:25:46 -0800 | [diff] [blame] | 1392 | player.playAsync(soundUri, user, looping, audioStreamType); |
| Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 1393 | } |
| 1394 | } catch (RemoteException e) { |
| 1395 | } finally { |
| Eric Laurent | 524dc04 | 2009-11-27 05:07:55 -0800 | [diff] [blame] | 1396 | Binder.restoreCallingIdentity(identity); |
| 1397 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1398 | } |
| 1399 | } |
| 1400 | |
| 1401 | // vibrate |
| Daniel Sandler | edbb380 | 2012-11-13 20:49:47 -0800 | [diff] [blame] | 1402 | // Does the notification want to specify its own vibration? |
| 1403 | final boolean hasCustomVibrate = notification.vibrate != null; |
| 1404 | |
| David Agnew | 71789e1 | 2012-11-09 23:03:26 -0500 | [diff] [blame] | 1405 | // new in 4.2: if there was supposed to be a sound and we're in vibrate mode, |
| Daniel Sandler | 4a7a9b9 | 2012-11-20 12:59:41 -0500 | [diff] [blame] | 1406 | // and no other vibration is specified, we fall back to vibration |
| David Agnew | 71789e1 | 2012-11-09 23:03:26 -0500 | [diff] [blame] | 1407 | final boolean convertSoundToVibration = |
| Daniel Sandler | edbb380 | 2012-11-13 20:49:47 -0800 | [diff] [blame] | 1408 | !hasCustomVibrate |
| Daniel Sandler | d4d2de2 | 2012-11-14 11:25:46 -0800 | [diff] [blame] | 1409 | && hasValidSound |
| David Agnew | 71789e1 | 2012-11-09 23:03:26 -0500 | [diff] [blame] | 1410 | && (audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE); |
| 1411 | |
| Daniel Sandler | 4a7a9b9 | 2012-11-20 12:59:41 -0500 | [diff] [blame] | 1412 | // The DEFAULT_VIBRATE flag trumps any custom vibration AND the fallback. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1413 | final boolean useDefaultVibrate = |
| Daniel Sandler | edbb380 | 2012-11-13 20:49:47 -0800 | [diff] [blame] | 1414 | (notification.defaults & Notification.DEFAULT_VIBRATE) != 0; |
| David Agnew | 71789e1 | 2012-11-09 23:03:26 -0500 | [diff] [blame] | 1415 | |
| Daniel Sandler | edbb380 | 2012-11-13 20:49:47 -0800 | [diff] [blame] | 1416 | if ((useDefaultVibrate || convertSoundToVibration || hasCustomVibrate) |
| Eric Laurent | bffc3d1 | 2012-05-07 17:43:49 -0700 | [diff] [blame] | 1417 | && !(audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1418 | mVibrateNotification = r; |
| 1419 | |
| Daniel Sandler | edbb380 | 2012-11-13 20:49:47 -0800 | [diff] [blame] | 1420 | if (useDefaultVibrate || convertSoundToVibration) { |
| 1421 | // Escalate privileges so we can use the vibrator even if the notifying app |
| 1422 | // does not have the VIBRATE permission. |
| 1423 | long identity = Binder.clearCallingIdentity(); |
| 1424 | try { |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1425 | mVibrator.vibrate(r.sbn.uid, r.sbn.basePkg, |
| Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1426 | useDefaultVibrate ? mDefaultVibrationPattern |
| 1427 | : mFallbackVibrationPattern, |
| Daniel Sandler | edbb380 | 2012-11-13 20:49:47 -0800 | [diff] [blame] | 1428 | ((notification.flags & Notification.FLAG_INSISTENT) != 0) ? 0: -1); |
| 1429 | } finally { |
| 1430 | Binder.restoreCallingIdentity(identity); |
| 1431 | } |
| 1432 | } else if (notification.vibrate.length > 1) { |
| 1433 | // If you want your own vibration pattern, you need the VIBRATE permission |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1434 | mVibrator.vibrate(r.sbn.uid, r.sbn.basePkg, notification.vibrate, |
| Daniel Sandler | edbb380 | 2012-11-13 20:49:47 -0800 | [diff] [blame] | 1435 | ((notification.flags & Notification.FLAG_INSISTENT) != 0) ? 0: -1); |
| 1436 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1437 | } |
| 1438 | } |
| 1439 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1440 | // light |
| 1441 | // the most recent thing gets the light |
| 1442 | mLights.remove(old); |
| 1443 | if (mLedNotification == old) { |
| 1444 | mLedNotification = null; |
| 1445 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1446 | //Slog.i(TAG, "notification.lights=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1447 | // + ((old.notification.lights.flags & Notification.FLAG_SHOW_LIGHTS) != 0)); |
| Daniel Sandler | 526fa0e | 2012-12-04 14:51:50 -0500 | [diff] [blame] | 1448 | if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0 |
| 1449 | && canInterrupt) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1450 | mLights.add(r); |
| 1451 | updateLightsLocked(); |
| 1452 | } else { |
| 1453 | if (old != null |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1454 | && ((old.getFlags() & Notification.FLAG_SHOW_LIGHTS) != 0)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1455 | updateLightsLocked(); |
| 1456 | } |
| 1457 | } |
| 1458 | } |
| 1459 | |
| 1460 | idOut[0] = id; |
| 1461 | } |
| 1462 | |
| Joe Onorato | 3027548 | 2009-07-08 17:09:14 -0700 | [diff] [blame] | 1463 | private void sendAccessibilityEvent(Notification notification, CharSequence packageName) { |
| svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1464 | AccessibilityManager manager = AccessibilityManager.getInstance(mContext); |
| 1465 | if (!manager.isEnabled()) { |
| 1466 | return; |
| 1467 | } |
| 1468 | |
| 1469 | AccessibilityEvent event = |
| 1470 | AccessibilityEvent.obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED); |
| 1471 | event.setPackageName(packageName); |
| 1472 | event.setClassName(Notification.class.getName()); |
| 1473 | event.setParcelableData(notification); |
| 1474 | CharSequence tickerText = notification.tickerText; |
| 1475 | if (!TextUtils.isEmpty(tickerText)) { |
| 1476 | event.getText().add(tickerText); |
| 1477 | } |
| 1478 | |
| 1479 | manager.sendAccessibilityEvent(event); |
| 1480 | } |
| 1481 | |
| Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1482 | private void cancelNotificationLocked(NotificationRecord r, boolean sendDelete) { |
| 1483 | // tell the app |
| 1484 | if (sendDelete) { |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1485 | if (r.getNotification().deleteIntent != null) { |
| Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1486 | try { |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1487 | r.getNotification().deleteIntent.send(); |
| Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1488 | } catch (PendingIntent.CanceledException ex) { |
| 1489 | // do nothing - there's no relevant way to recover, and |
| 1490 | // no reason to let this propagate |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1491 | Slog.w(TAG, "canceled PendingIntent for " + r.sbn.pkg, ex); |
| Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1492 | } |
| 1493 | } |
| 1494 | } |
| 1495 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1496 | // status bar |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1497 | if (r.getNotification().icon != 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1498 | long identity = Binder.clearCallingIdentity(); |
| 1499 | try { |
| Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 1500 | mStatusBar.removeNotification(r.statusBarKey); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1501 | } |
| 1502 | finally { |
| 1503 | Binder.restoreCallingIdentity(identity); |
| 1504 | } |
| 1505 | r.statusBarKey = null; |
| Daniel Sandler | 09a247e | 2013-02-14 10:24:17 -0500 | [diff] [blame] | 1506 | notifyRemovedLocked(r); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | // sound |
| 1510 | if (mSoundNotification == r) { |
| 1511 | mSoundNotification = null; |
| Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 1512 | final long identity = Binder.clearCallingIdentity(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1513 | try { |
| Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 1514 | final IRingtonePlayer player = mAudioService.getRingtonePlayer(); |
| 1515 | if (player != null) { |
| 1516 | player.stopAsync(); |
| 1517 | } |
| 1518 | } catch (RemoteException e) { |
| 1519 | } finally { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1520 | Binder.restoreCallingIdentity(identity); |
| 1521 | } |
| 1522 | } |
| 1523 | |
| 1524 | // vibrate |
| 1525 | if (mVibrateNotification == r) { |
| 1526 | mVibrateNotification = null; |
| 1527 | long identity = Binder.clearCallingIdentity(); |
| 1528 | try { |
| 1529 | mVibrator.cancel(); |
| 1530 | } |
| 1531 | finally { |
| 1532 | Binder.restoreCallingIdentity(identity); |
| 1533 | } |
| 1534 | } |
| 1535 | |
| 1536 | // light |
| 1537 | mLights.remove(r); |
| 1538 | if (mLedNotification == r) { |
| 1539 | mLedNotification = null; |
| 1540 | } |
| Daniel Sandler | 23d7c70 | 2013-03-07 16:32:06 -0500 | [diff] [blame] | 1541 | |
| 1542 | // Save it for users of getHistoricalNotifications() |
| 1543 | mArchive.record(r.sbn); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1544 | } |
| 1545 | |
| 1546 | /** |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 1547 | * Cancels a notification ONLY if it has all of the {@code mustHaveFlags} |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1548 | * and none of the {@code mustNotHaveFlags}. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1549 | */ |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 1550 | private void cancelNotification(String pkg, String tag, int id, int mustHaveFlags, |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 1551 | int mustNotHaveFlags, boolean sendDelete, int userId) { |
| Daniel Sandler | 321e9c5 | 2012-10-12 10:59:26 -0700 | [diff] [blame] | 1552 | EventLog.writeEvent(EventLogTags.NOTIFICATION_CANCEL, pkg, id, tag, userId, |
| Daniel Sandler | b64cb88 | 2011-11-29 23:48:29 -0500 | [diff] [blame] | 1553 | mustHaveFlags, mustNotHaveFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1554 | |
| 1555 | synchronized (mNotificationList) { |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 1556 | int index = indexOfNotificationLocked(pkg, tag, id, userId); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1557 | if (index >= 0) { |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 1558 | NotificationRecord r = mNotificationList.get(index); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1559 | |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1560 | if ((r.getNotification().flags & mustHaveFlags) != mustHaveFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1561 | return; |
| 1562 | } |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1563 | if ((r.getNotification().flags & mustNotHaveFlags) != 0) { |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 1564 | return; |
| 1565 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1566 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1567 | mNotificationList.remove(index); |
| 1568 | |
| Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1569 | cancelNotificationLocked(r, sendDelete); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1570 | updateLightsLocked(); |
| 1571 | } |
| 1572 | } |
| 1573 | } |
| 1574 | |
| 1575 | /** |
| Daniel Sandler | 321e9c5 | 2012-10-12 10:59:26 -0700 | [diff] [blame] | 1576 | * Determine whether the userId applies to the notification in question, either because |
| 1577 | * they match exactly, or one of them is USER_ALL (which is treated as a wildcard). |
| 1578 | */ |
| 1579 | private boolean notificationMatchesUserId(NotificationRecord r, int userId) { |
| 1580 | return |
| 1581 | // looking for USER_ALL notifications? match everything |
| 1582 | userId == UserHandle.USER_ALL |
| 1583 | // a notification sent to USER_ALL matches any query |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1584 | || r.getUserId() == UserHandle.USER_ALL |
| Daniel Sandler | 321e9c5 | 2012-10-12 10:59:26 -0700 | [diff] [blame] | 1585 | // an exact user match |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1586 | || r.getUserId() == userId; |
| Daniel Sandler | 321e9c5 | 2012-10-12 10:59:26 -0700 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1590 | * Cancels all notifications from a given package that have all of the |
| 1591 | * {@code mustHaveFlags}. |
| 1592 | */ |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1593 | boolean cancelAllNotificationsInt(String pkg, int mustHaveFlags, |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 1594 | int mustNotHaveFlags, boolean doit, int userId) { |
| Daniel Sandler | 321e9c5 | 2012-10-12 10:59:26 -0700 | [diff] [blame] | 1595 | EventLog.writeEvent(EventLogTags.NOTIFICATION_CANCEL_ALL, pkg, userId, |
| 1596 | mustHaveFlags, mustNotHaveFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1597 | |
| 1598 | synchronized (mNotificationList) { |
| 1599 | final int N = mNotificationList.size(); |
| 1600 | boolean canceledSomething = false; |
| 1601 | for (int i = N-1; i >= 0; --i) { |
| 1602 | NotificationRecord r = mNotificationList.get(i); |
| Daniel Sandler | 321e9c5 | 2012-10-12 10:59:26 -0700 | [diff] [blame] | 1603 | if (!notificationMatchesUserId(r, userId)) { |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 1604 | continue; |
| 1605 | } |
| Amith Yamasani | 5ec00e9 | 2012-11-07 16:58:30 -0800 | [diff] [blame] | 1606 | // Don't remove notifications to all, if there's no package name specified |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1607 | if (r.getUserId() == UserHandle.USER_ALL && pkg == null) { |
| Amith Yamasani | 5ec00e9 | 2012-11-07 16:58:30 -0800 | [diff] [blame] | 1608 | continue; |
| 1609 | } |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1610 | if ((r.getFlags() & mustHaveFlags) != mustHaveFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1611 | continue; |
| 1612 | } |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1613 | if ((r.getFlags() & mustNotHaveFlags) != 0) { |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 1614 | continue; |
| 1615 | } |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1616 | if (pkg != null && !r.sbn.pkg.equals(pkg)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1617 | continue; |
| 1618 | } |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1619 | canceledSomething = true; |
| 1620 | if (!doit) { |
| 1621 | return true; |
| 1622 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1623 | mNotificationList.remove(i); |
| Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1624 | cancelNotificationLocked(r, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1625 | } |
| 1626 | if (canceledSomething) { |
| 1627 | updateLightsLocked(); |
| 1628 | } |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1629 | return canceledSomething; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1630 | } |
| 1631 | } |
| 1632 | |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 1633 | public void cancelNotificationWithTag(String pkg, String tag, int id, int userId) { |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 1634 | checkCallerIsSystemOrSameApp(pkg); |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 1635 | userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), |
| Amith Yamasani | 2c7ebea | 2012-10-30 15:28:27 -0700 | [diff] [blame] | 1636 | Binder.getCallingUid(), userId, true, false, "cancelNotificationWithTag", pkg); |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 1637 | // Don't allow client applications to cancel foreground service notis. |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 1638 | cancelNotification(pkg, tag, id, 0, |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 1639 | Binder.getCallingUid() == Process.SYSTEM_UID |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 1640 | ? 0 : Notification.FLAG_FOREGROUND_SERVICE, false, userId); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1641 | } |
| 1642 | |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 1643 | public void cancelAllNotifications(String pkg, int userId) { |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 1644 | checkCallerIsSystemOrSameApp(pkg); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1645 | |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 1646 | userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), |
| Amith Yamasani | 2c7ebea | 2012-10-30 15:28:27 -0700 | [diff] [blame] | 1647 | Binder.getCallingUid(), userId, true, false, "cancelAllNotifications", pkg); |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 1648 | |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 1649 | // Calling from user space, don't allow the canceling of actively |
| 1650 | // running foreground services. |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 1651 | cancelAllNotificationsInt(pkg, 0, Notification.FLAG_FOREGROUND_SERVICE, true, userId); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1652 | } |
| 1653 | |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 1654 | void checkCallerIsSystem() { |
| 1655 | int uid = Binder.getCallingUid(); |
| Dianne Hackborn | 0c38049 | 2012-08-20 17:23:30 -0700 | [diff] [blame] | 1656 | if (UserHandle.getAppId(uid) == Process.SYSTEM_UID || uid == 0) { |
| Daniel Sandler | 0da673f | 2012-04-11 12:33:16 -0400 | [diff] [blame] | 1657 | return; |
| 1658 | } |
| 1659 | throw new SecurityException("Disallowed call for uid " + uid); |
| 1660 | } |
| 1661 | |
| 1662 | void checkCallerIsSystemOrSameApp(String pkg) { |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 1663 | int uid = Binder.getCallingUid(); |
| Dianne Hackborn | 0c38049 | 2012-08-20 17:23:30 -0700 | [diff] [blame] | 1664 | if (UserHandle.getAppId(uid) == Process.SYSTEM_UID || uid == 0) { |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 1665 | return; |
| 1666 | } |
| 1667 | try { |
| Amith Yamasani | f203aee | 2012-08-29 18:41:53 -0700 | [diff] [blame] | 1668 | ApplicationInfo ai = AppGlobals.getPackageManager().getApplicationInfo( |
| 1669 | pkg, 0, UserHandle.getCallingUserId()); |
| Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 1670 | if (!UserHandle.isSameApp(ai.uid, uid)) { |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 1671 | throw new SecurityException("Calling uid " + uid + " gave package" |
| 1672 | + pkg + " which is owned by uid " + ai.uid); |
| 1673 | } |
| Amith Yamasani | f203aee | 2012-08-29 18:41:53 -0700 | [diff] [blame] | 1674 | } catch (RemoteException re) { |
| 1675 | throw new SecurityException("Unknown package " + pkg + "\n" + re); |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 1676 | } |
| 1677 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1678 | |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 1679 | void cancelAll(int userId) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1680 | synchronized (mNotificationList) { |
| 1681 | final int N = mNotificationList.size(); |
| 1682 | for (int i=N-1; i>=0; i--) { |
| 1683 | NotificationRecord r = mNotificationList.get(i); |
| 1684 | |
| Daniel Sandler | 321e9c5 | 2012-10-12 10:59:26 -0700 | [diff] [blame] | 1685 | if (!notificationMatchesUserId(r, userId)) { |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 1686 | continue; |
| 1687 | } |
| 1688 | |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1689 | if ((r.getFlags() & (Notification.FLAG_ONGOING_EVENT |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1690 | | Notification.FLAG_NO_CLEAR)) == 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1691 | mNotificationList.remove(i); |
| Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1692 | cancelNotificationLocked(r, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1693 | } |
| 1694 | } |
| 1695 | |
| 1696 | updateLightsLocked(); |
| 1697 | } |
| 1698 | } |
| 1699 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1700 | // lock on mNotificationList |
| 1701 | private void updateLightsLocked() |
| 1702 | { |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1703 | // handle notification lights |
| 1704 | if (mLedNotification == null) { |
| 1705 | // get next notification, if any |
| 1706 | int n = mLights.size(); |
| 1707 | if (n > 0) { |
| 1708 | mLedNotification = mLights.get(n-1); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1709 | } |
| 1710 | } |
| Mike Lockwood | c22404a | 2009-12-02 11:15:02 -0500 | [diff] [blame] | 1711 | |
| Mike Lockwood | 63b5ad9 | 2011-08-30 09:55:30 -0400 | [diff] [blame] | 1712 | // Don't flash while we are in a call or screen is on |
| 1713 | if (mLedNotification == null || mInCall || mScreenOn) { |
| Mike Lockwood | 3cb67a3 | 2009-11-27 14:25:58 -0500 | [diff] [blame] | 1714 | mNotificationLight.turnOff(); |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1715 | } else { |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1716 | final Notification ledno = mLedNotification.sbn.notification; |
| 1717 | int ledARGB = ledno.ledARGB; |
| 1718 | int ledOnMS = ledno.ledOnMS; |
| 1719 | int ledOffMS = ledno.ledOffMS; |
| 1720 | if ((ledno.defaults & Notification.DEFAULT_LIGHTS) != 0) { |
| Mike Lockwood | 670f932 | 2010-01-20 12:13:36 -0500 | [diff] [blame] | 1721 | ledARGB = mDefaultNotificationColor; |
| 1722 | ledOnMS = mDefaultNotificationLedOn; |
| 1723 | ledOffMS = mDefaultNotificationLedOff; |
| 1724 | } |
| 1725 | if (mNotificationPulseEnabled) { |
| 1726 | // pulse repeatedly |
| 1727 | mNotificationLight.setFlashing(ledARGB, LightsService.LIGHT_FLASH_TIMED, |
| 1728 | ledOnMS, ledOffMS); |
| Mike Lockwood | 670f932 | 2010-01-20 12:13:36 -0500 | [diff] [blame] | 1729 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1730 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1731 | } |
| 1732 | |
| 1733 | // lock on mNotificationList |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 1734 | private int indexOfNotificationLocked(String pkg, String tag, int id, int userId) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1735 | { |
| 1736 | ArrayList<NotificationRecord> list = mNotificationList; |
| 1737 | final int len = list.size(); |
| 1738 | for (int i=0; i<len; i++) { |
| 1739 | NotificationRecord r = list.get(i); |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1740 | if (!notificationMatchesUserId(r, userId) || r.sbn.id != id) { |
| Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 1741 | continue; |
| 1742 | } |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 1743 | if (tag == null) { |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1744 | if (r.sbn.tag != null) { |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 1745 | continue; |
| 1746 | } |
| 1747 | } else { |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1748 | if (!tag.equals(r.sbn.tag)) { |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 1749 | continue; |
| 1750 | } |
| 1751 | } |
| Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1752 | if (r.sbn.pkg.equals(pkg)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1753 | return i; |
| 1754 | } |
| 1755 | } |
| 1756 | return -1; |
| 1757 | } |
| 1758 | |
| Mike Lockwood | c22404a | 2009-12-02 11:15:02 -0500 | [diff] [blame] | 1759 | private void updateNotificationPulse() { |
| 1760 | synchronized (mNotificationList) { |
| 1761 | updateLightsLocked(); |
| 1762 | } |
| 1763 | } |
| 1764 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1765 | // ====================================================================== |
| 1766 | @Override |
| 1767 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 1768 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 1769 | != PackageManager.PERMISSION_GRANTED) { |
| 1770 | pw.println("Permission Denial: can't dump NotificationManager from from pid=" |
| 1771 | + Binder.getCallingPid() |
| 1772 | + ", uid=" + Binder.getCallingUid()); |
| 1773 | return; |
| 1774 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1775 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1776 | pw.println("Current Notification Manager state:"); |
| 1777 | |
| Daniel Sandler | 4b749ef | 2013-03-18 21:53:04 -0400 | [diff] [blame] | 1778 | pw.print(" Enabled listeners: ["); |
| 1779 | for (String pkg : mEnabledListenersForCurrentUser) { |
| 1780 | pw.print(" " + pkg); |
| 1781 | } |
| 1782 | pw.println(" ]"); |
| 1783 | |
| 1784 | pw.println(" Live listeners:"); |
| 1785 | for (NotificationListenerInfo info : mListeners) { |
| 1786 | pw.println(" " + info.pkg + " (user " + info.userid + "): " + info.listener |
| 1787 | + (info.isSystem?" SYSTEM":"")); |
| 1788 | } |
| 1789 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1790 | int N; |
| 1791 | |
| 1792 | synchronized (mToastQueue) { |
| 1793 | N = mToastQueue.size(); |
| 1794 | if (N > 0) { |
| 1795 | pw.println(" Toast Queue:"); |
| 1796 | for (int i=0; i<N; i++) { |
| 1797 | mToastQueue.get(i).dump(pw, " "); |
| 1798 | } |
| 1799 | pw.println(" "); |
| 1800 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1801 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | synchronized (mNotificationList) { |
| 1805 | N = mNotificationList.size(); |
| 1806 | if (N > 0) { |
| 1807 | pw.println(" Notification List:"); |
| 1808 | for (int i=0; i<N; i++) { |
| 1809 | mNotificationList.get(i).dump(pw, " ", mContext); |
| 1810 | } |
| 1811 | pw.println(" "); |
| 1812 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1813 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1814 | N = mLights.size(); |
| 1815 | if (N > 0) { |
| 1816 | pw.println(" Lights List:"); |
| 1817 | for (int i=0; i<N; i++) { |
| 1818 | mLights.get(i).dump(pw, " ", mContext); |
| 1819 | } |
| 1820 | pw.println(" "); |
| 1821 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1822 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1823 | pw.println(" mSoundNotification=" + mSoundNotification); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1824 | pw.println(" mVibrateNotification=" + mVibrateNotification); |
| Joe Onorato | 39f5b6a | 2009-07-23 12:29:19 -0400 | [diff] [blame] | 1825 | pw.println(" mDisabledNotifications=0x" + Integer.toHexString(mDisabledNotifications)); |
| 1826 | pw.println(" mSystemReady=" + mSystemReady); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1827 | } |
| 1828 | } |
| 1829 | } |