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