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