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