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