| 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 | |
| svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 19 | import com.android.server.status.IconData; |
| 20 | import com.android.server.status.NotificationData; |
| 21 | import com.android.server.status.StatusBarService; |
| 22 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import android.app.ActivityManagerNative; |
| 24 | import android.app.IActivityManager; |
| 25 | import android.app.INotificationManager; |
| 26 | import android.app.ITransientNotification; |
| 27 | import android.app.Notification; |
| Dianne Hackborn | 1dac277 | 2009-06-26 18:16:48 -0700 | [diff] [blame] | 28 | import android.app.NotificationManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.app.PendingIntent; |
| 30 | import android.app.StatusBarManager; |
| 31 | import android.content.BroadcastReceiver; |
| Dianne Hackborn | 1dac277 | 2009-06-26 18:16:48 -0700 | [diff] [blame] | 32 | import android.content.ComponentName; |
| Dianne Hackborn | 1dac277 | 2009-06-26 18:16:48 -0700 | [diff] [blame] | 33 | import android.content.ContentResolver; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.content.Context; |
| 35 | import android.content.Intent; |
| 36 | import android.content.IntentFilter; |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 37 | import android.content.pm.ApplicationInfo; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import android.content.pm.PackageManager; |
| 39 | import android.content.pm.PackageManager.NameNotFoundException; |
| 40 | import android.content.res.Resources; |
| Dianne Hackborn | 1dac277 | 2009-06-26 18:16:48 -0700 | [diff] [blame] | 41 | import android.database.ContentObserver; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | import android.media.AsyncPlayer; |
| svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 43 | import android.media.AudioManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | import android.net.Uri; |
| 45 | import android.os.BatteryManager; |
| 46 | import android.os.Binder; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import android.os.Handler; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | import android.os.IBinder; |
| 49 | import android.os.Message; |
| 50 | import android.os.Power; |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 51 | import android.os.Process; |
| svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 52 | import android.os.RemoteException; |
| Mike Lockwood | ed76037 | 2009-07-09 07:07:27 -0400 | [diff] [blame] | 53 | import android.os.SystemProperties; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | import android.os.Vibrator; |
| 55 | import android.provider.Settings; |
| svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 56 | import android.text.TextUtils; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | import android.util.EventLog; |
| 58 | import android.util.Log; |
| svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 59 | import android.view.accessibility.AccessibilityEvent; |
| 60 | import android.view.accessibility.AccessibilityManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import android.widget.Toast; |
| 62 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | import java.io.FileDescriptor; |
| 64 | import java.io.PrintWriter; |
| 65 | import java.util.ArrayList; |
| 66 | import java.util.Arrays; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | |
| 68 | class NotificationManagerService extends INotificationManager.Stub |
| 69 | { |
| 70 | private static final String TAG = "NotificationService"; |
| 71 | private static final boolean DBG = false; |
| 72 | |
| 73 | // message codes |
| 74 | private static final int MESSAGE_TIMEOUT = 2; |
| 75 | |
| 76 | private static final int LONG_DELAY = 3500; // 3.5 seconds |
| 77 | private static final int SHORT_DELAY = 2000; // 2 seconds |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 78 | |
| 79 | private static final long[] DEFAULT_VIBRATE_PATTERN = {0, 250, 250, 250}; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | |
| 81 | private static final int DEFAULT_STREAM_TYPE = AudioManager.STREAM_NOTIFICATION; |
| 82 | |
| 83 | final Context mContext; |
| 84 | final IActivityManager mAm; |
| 85 | final IBinder mForegroundToken = new Binder(); |
| 86 | |
| 87 | private WorkerHandler mHandler; |
| 88 | private StatusBarService mStatusBarService; |
| Mike Lockwood | 3a32213 | 2009-11-24 00:30:52 -0500 | [diff] [blame] | 89 | private LightsService mLightsService; |
| Mike Lockwood | 3cb67a3 | 2009-11-27 14:25:58 -0500 | [diff] [blame] | 90 | private LightsService.Light mBatteryLight; |
| 91 | private LightsService.Light mNotificationLight; |
| 92 | private LightsService.Light mAttentionLight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | |
| Mike Lockwood | 670f932 | 2010-01-20 12:13:36 -0500 | [diff] [blame] | 94 | private int mDefaultNotificationColor; |
| 95 | private int mDefaultNotificationLedOn; |
| 96 | private int mDefaultNotificationLedOff; |
| 97 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | private NotificationRecord mSoundNotification; |
| 99 | private AsyncPlayer mSound; |
| Joe Onorato | 3027548 | 2009-07-08 17:09:14 -0700 | [diff] [blame] | 100 | private boolean mSystemReady; |
| Joe Onorato | 39f5b6a | 2009-07-23 12:29:19 -0400 | [diff] [blame] | 101 | private int mDisabledNotifications; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | |
| 103 | private NotificationRecord mVibrateNotification; |
| 104 | private Vibrator mVibrator = new Vibrator(); |
| 105 | |
| Mike Lockwood | c22404a | 2009-12-02 11:15:02 -0500 | [diff] [blame] | 106 | // for enabling and disabling notification pulse behavior |
| 107 | private boolean mScreenOn = true; |
| 108 | private boolean mNotificationPulseEnabled; |
| 109 | |
| 110 | // for adb connected notifications |
| Mike Lockwood | ea8b7d5 | 2009-08-04 17:03:15 -0400 | [diff] [blame] | 111 | private boolean mUsbConnected; |
| Dianne Hackborn | 1dac277 | 2009-06-26 18:16:48 -0700 | [diff] [blame] | 112 | private boolean mAdbEnabled = false; |
| 113 | private boolean mAdbNotificationShown = false; |
| 114 | private Notification mAdbNotification; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 115 | |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 116 | private final ArrayList<NotificationRecord> mNotificationList = |
| 117 | new ArrayList<NotificationRecord>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | |
| 119 | private ArrayList<ToastRecord> mToastQueue; |
| 120 | |
| 121 | private ArrayList<NotificationRecord> mLights = new ArrayList<NotificationRecord>(); |
| 122 | |
| 123 | private boolean mBatteryCharging; |
| 124 | private boolean mBatteryLow; |
| 125 | private boolean mBatteryFull; |
| 126 | private NotificationRecord mLedNotification; |
| svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 127 | |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 128 | private static final int BATTERY_LOW_ARGB = 0xFFFF0000; // Charging Low - red solid on |
| 129 | private static final int BATTERY_MEDIUM_ARGB = 0xFFFFFF00; // Charging - orange solid on |
| 130 | private static final int BATTERY_FULL_ARGB = 0xFF00FF00; // Charging Full - green solid on |
| 131 | private static final int BATTERY_BLINK_ON = 125; |
| 132 | private static final int BATTERY_BLINK_OFF = 2875; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | private static String idDebugString(Context baseContext, String packageName, int id) { |
| 135 | Context c = null; |
| 136 | |
| 137 | if (packageName != null) { |
| 138 | try { |
| 139 | c = baseContext.createPackageContext(packageName, 0); |
| 140 | } catch (NameNotFoundException e) { |
| 141 | c = baseContext; |
| 142 | } |
| 143 | } else { |
| 144 | c = baseContext; |
| 145 | } |
| 146 | |
| 147 | String pkg; |
| 148 | String type; |
| 149 | String name; |
| 150 | |
| 151 | Resources r = c.getResources(); |
| 152 | try { |
| 153 | return r.getResourceName(id); |
| 154 | } catch (Resources.NotFoundException e) { |
| 155 | return "<name unknown>"; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | private static final class NotificationRecord |
| 160 | { |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 161 | final String pkg; |
| 162 | final String tag; |
| 163 | final int id; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | ITransientNotification callback; |
| 165 | int duration; |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 166 | final Notification notification; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | IBinder statusBarKey; |
| 168 | |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 169 | NotificationRecord(String pkg, String tag, int id, Notification notification) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | { |
| 171 | this.pkg = pkg; |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 172 | this.tag = tag; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | this.id = id; |
| 174 | this.notification = notification; |
| 175 | } |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 176 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | void dump(PrintWriter pw, String prefix, Context baseContext) { |
| 178 | pw.println(prefix + this); |
| 179 | pw.println(prefix + " icon=0x" + Integer.toHexString(notification.icon) |
| 180 | + " / " + idDebugString(baseContext, this.pkg, notification.icon)); |
| 181 | pw.println(prefix + " contentIntent=" + notification.contentIntent); |
| 182 | pw.println(prefix + " deleteIntent=" + notification.deleteIntent); |
| 183 | pw.println(prefix + " tickerText=" + notification.tickerText); |
| 184 | pw.println(prefix + " contentView=" + notification.contentView); |
| 185 | pw.println(prefix + " defaults=0x" + Integer.toHexString(notification.defaults)); |
| 186 | pw.println(prefix + " flags=0x" + Integer.toHexString(notification.flags)); |
| 187 | pw.println(prefix + " sound=" + notification.sound); |
| 188 | pw.println(prefix + " vibrate=" + Arrays.toString(notification.vibrate)); |
| 189 | pw.println(prefix + " ledARGB=0x" + Integer.toHexString(notification.ledARGB) |
| 190 | + " ledOnMS=" + notification.ledOnMS |
| 191 | + " ledOffMS=" + notification.ledOffMS); |
| 192 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 193 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | @Override |
| 195 | public final String toString() |
| 196 | { |
| 197 | return "NotificationRecord{" |
| 198 | + Integer.toHexString(System.identityHashCode(this)) |
| 199 | + " pkg=" + pkg |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 200 | + " id=" + Integer.toHexString(id) |
| 201 | + " tag=" + tag + "}"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | |
| 205 | private static final class ToastRecord |
| 206 | { |
| 207 | final int pid; |
| 208 | final String pkg; |
| 209 | final ITransientNotification callback; |
| 210 | int duration; |
| 211 | |
| 212 | ToastRecord(int pid, String pkg, ITransientNotification callback, int duration) |
| 213 | { |
| 214 | this.pid = pid; |
| 215 | this.pkg = pkg; |
| 216 | this.callback = callback; |
| 217 | this.duration = duration; |
| 218 | } |
| 219 | |
| 220 | void update(int duration) { |
| 221 | this.duration = duration; |
| 222 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 223 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | void dump(PrintWriter pw, String prefix) { |
| 225 | pw.println(prefix + this); |
| 226 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 227 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | @Override |
| 229 | public final String toString() |
| 230 | { |
| 231 | return "ToastRecord{" |
| 232 | + Integer.toHexString(System.identityHashCode(this)) |
| 233 | + " pkg=" + pkg |
| 234 | + " callback=" + callback |
| 235 | + " duration=" + duration; |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | private StatusBarService.NotificationCallbacks mNotificationCallbacks |
| 240 | = new StatusBarService.NotificationCallbacks() { |
| 241 | |
| 242 | public void onSetDisabled(int status) { |
| 243 | synchronized (mNotificationList) { |
| 244 | mDisabledNotifications = status; |
| 245 | if ((mDisabledNotifications & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0) { |
| 246 | // cancel whatever's going on |
| 247 | long identity = Binder.clearCallingIdentity(); |
| 248 | try { |
| 249 | mSound.stop(); |
| 250 | } |
| 251 | finally { |
| 252 | Binder.restoreCallingIdentity(identity); |
| 253 | } |
| 254 | |
| 255 | identity = Binder.clearCallingIdentity(); |
| 256 | try { |
| 257 | mVibrator.cancel(); |
| 258 | } |
| 259 | finally { |
| 260 | Binder.restoreCallingIdentity(identity); |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | public void onClearAll() { |
| 267 | cancelAll(); |
| 268 | } |
| 269 | |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 270 | public void onNotificationClick(String pkg, String tag, int id) { |
| 271 | cancelNotification(pkg, tag, id, Notification.FLAG_AUTO_CANCEL, |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 272 | Notification.FLAG_FOREGROUND_SERVICE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | public void onPanelRevealed() { |
| 276 | synchronized (mNotificationList) { |
| 277 | // sound |
| 278 | mSoundNotification = null; |
| 279 | long identity = Binder.clearCallingIdentity(); |
| 280 | try { |
| 281 | mSound.stop(); |
| 282 | } |
| 283 | finally { |
| 284 | Binder.restoreCallingIdentity(identity); |
| 285 | } |
| 286 | |
| 287 | // vibrate |
| 288 | mVibrateNotification = null; |
| 289 | identity = Binder.clearCallingIdentity(); |
| 290 | try { |
| 291 | mVibrator.cancel(); |
| 292 | } |
| 293 | finally { |
| 294 | Binder.restoreCallingIdentity(identity); |
| 295 | } |
| 296 | |
| 297 | // light |
| 298 | mLights.clear(); |
| 299 | mLedNotification = null; |
| 300 | updateLightsLocked(); |
| 301 | } |
| 302 | } |
| 303 | }; |
| 304 | |
| 305 | private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { |
| 306 | @Override |
| 307 | public void onReceive(Context context, Intent intent) { |
| 308 | String action = intent.getAction(); |
| 309 | |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 310 | boolean queryRestart = false; |
| 311 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 312 | if (action.equals(Intent.ACTION_BATTERY_CHANGED)) { |
| 313 | boolean batteryCharging = (intent.getIntExtra("plugged", 0) != 0); |
| 314 | int level = intent.getIntExtra("level", -1); |
| 315 | boolean batteryLow = (level >= 0 && level <= Power.LOW_BATTERY_THRESHOLD); |
| 316 | int status = intent.getIntExtra("status", BatteryManager.BATTERY_STATUS_UNKNOWN); |
| 317 | boolean batteryFull = (status == BatteryManager.BATTERY_STATUS_FULL || level >= 90); |
| 318 | |
| 319 | if (batteryCharging != mBatteryCharging || |
| 320 | batteryLow != mBatteryLow || |
| 321 | batteryFull != mBatteryFull) { |
| 322 | mBatteryCharging = batteryCharging; |
| 323 | mBatteryLow = batteryLow; |
| 324 | mBatteryFull = batteryFull; |
| 325 | updateLights(); |
| 326 | } |
| Mike Lockwood | ea8b7d5 | 2009-08-04 17:03:15 -0400 | [diff] [blame] | 327 | } else if (action.equals(Intent.ACTION_UMS_CONNECTED)) { |
| 328 | mUsbConnected = true; |
| 329 | updateAdbNotification(); |
| 330 | } else if (action.equals(Intent.ACTION_UMS_DISCONNECTED)) { |
| 331 | mUsbConnected = false; |
| Dianne Hackborn | 1dac277 | 2009-06-26 18:16:48 -0700 | [diff] [blame] | 332 | updateAdbNotification(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | } else if (action.equals(Intent.ACTION_PACKAGE_REMOVED) |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 334 | || action.equals(Intent.ACTION_PACKAGE_RESTARTED) |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 335 | || (queryRestart=action.equals(Intent.ACTION_QUERY_PACKAGE_RESTART)) |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 336 | || action.equals(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)) { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 337 | String pkgList[] = null; |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 338 | if (action.equals(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)) { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 339 | pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 340 | } else if (queryRestart) { |
| 341 | pkgList = intent.getStringArrayExtra(Intent.EXTRA_PACKAGES); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 342 | } else { |
| 343 | Uri uri = intent.getData(); |
| 344 | if (uri == null) { |
| 345 | return; |
| 346 | } |
| 347 | String pkgName = uri.getSchemeSpecificPart(); |
| 348 | if (pkgName == null) { |
| 349 | return; |
| 350 | } |
| 351 | pkgList = new String[]{pkgName}; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 353 | if (pkgList != null && (pkgList.length > 0)) { |
| 354 | for (String pkgName : pkgList) { |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 355 | cancelAllNotificationsInt(pkgName, 0, 0, !queryRestart); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 356 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 357 | } |
| Mike Lockwood | c22404a | 2009-12-02 11:15:02 -0500 | [diff] [blame] | 358 | } else if (action.equals(Intent.ACTION_SCREEN_ON)) { |
| 359 | mScreenOn = true; |
| 360 | updateNotificationPulse(); |
| 361 | } else if (action.equals(Intent.ACTION_SCREEN_OFF)) { |
| 362 | mScreenOn = false; |
| 363 | updateNotificationPulse(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 364 | } |
| 365 | } |
| 366 | }; |
| 367 | |
| Dianne Hackborn | 1dac277 | 2009-06-26 18:16:48 -0700 | [diff] [blame] | 368 | class SettingsObserver extends ContentObserver { |
| 369 | SettingsObserver(Handler handler) { |
| 370 | super(handler); |
| 371 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 372 | |
| Dianne Hackborn | 1dac277 | 2009-06-26 18:16:48 -0700 | [diff] [blame] | 373 | void observe() { |
| 374 | ContentResolver resolver = mContext.getContentResolver(); |
| 375 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 376 | Settings.Secure.ADB_ENABLED), false, this); |
| Mike Lockwood | c22404a | 2009-12-02 11:15:02 -0500 | [diff] [blame] | 377 | resolver.registerContentObserver(Settings.System.getUriFor( |
| 378 | Settings.System.NOTIFICATION_LIGHT_PULSE), false, this); |
| Dianne Hackborn | 1dac277 | 2009-06-26 18:16:48 -0700 | [diff] [blame] | 379 | update(); |
| 380 | } |
| 381 | |
| 382 | @Override public void onChange(boolean selfChange) { |
| 383 | update(); |
| 384 | } |
| 385 | |
| 386 | public void update() { |
| 387 | ContentResolver resolver = mContext.getContentResolver(); |
| Mike Lockwood | c22404a | 2009-12-02 11:15:02 -0500 | [diff] [blame] | 388 | boolean adbEnabled = Settings.Secure.getInt(resolver, |
| Dianne Hackborn | 1dac277 | 2009-06-26 18:16:48 -0700 | [diff] [blame] | 389 | Settings.Secure.ADB_ENABLED, 0) != 0; |
| Mike Lockwood | c22404a | 2009-12-02 11:15:02 -0500 | [diff] [blame] | 390 | if (mAdbEnabled != adbEnabled) { |
| 391 | mAdbEnabled = adbEnabled; |
| 392 | updateAdbNotification(); |
| 393 | } |
| 394 | boolean pulseEnabled = Settings.System.getInt(resolver, |
| 395 | Settings.System.NOTIFICATION_LIGHT_PULSE, 0) != 0; |
| 396 | if (mNotificationPulseEnabled != pulseEnabled) { |
| 397 | mNotificationPulseEnabled = pulseEnabled; |
| 398 | updateNotificationPulse(); |
| 399 | } |
| Dianne Hackborn | 1dac277 | 2009-06-26 18:16:48 -0700 | [diff] [blame] | 400 | } |
| 401 | } |
| Mike Lockwood | c22404a | 2009-12-02 11:15:02 -0500 | [diff] [blame] | 402 | |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 403 | NotificationManagerService(Context context, StatusBarService statusBar, |
| Mike Lockwood | 3a32213 | 2009-11-24 00:30:52 -0500 | [diff] [blame] | 404 | LightsService lights) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 405 | { |
| 406 | super(); |
| 407 | mContext = context; |
| Mike Lockwood | 3a32213 | 2009-11-24 00:30:52 -0500 | [diff] [blame] | 408 | mLightsService = lights; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | mAm = ActivityManagerNative.getDefault(); |
| 410 | mSound = new AsyncPlayer(TAG); |
| 411 | mSound.setUsesWakeLock(context); |
| 412 | mToastQueue = new ArrayList<ToastRecord>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | mHandler = new WorkerHandler(); |
| San Mehat | 3ee1317 | 2010-02-04 20:54:43 -0800 | [diff] [blame] | 414 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 415 | mStatusBarService = statusBar; |
| 416 | statusBar.setNotificationCallbacks(mNotificationCallbacks); |
| 417 | |
| Mike Lockwood | 3cb67a3 | 2009-11-27 14:25:58 -0500 | [diff] [blame] | 418 | mBatteryLight = lights.getLight(LightsService.LIGHT_ID_BATTERY); |
| 419 | mNotificationLight = lights.getLight(LightsService.LIGHT_ID_NOTIFICATIONS); |
| 420 | mAttentionLight = lights.getLight(LightsService.LIGHT_ID_ATTENTION); |
| 421 | |
| Mike Lockwood | 670f932 | 2010-01-20 12:13:36 -0500 | [diff] [blame] | 422 | Resources resources = mContext.getResources(); |
| 423 | mDefaultNotificationColor = resources.getColor( |
| 424 | com.android.internal.R.color.config_defaultNotificationColor); |
| 425 | mDefaultNotificationLedOn = resources.getInteger( |
| 426 | com.android.internal.R.integer.config_defaultNotificationLedOn); |
| 427 | mDefaultNotificationLedOff = resources.getInteger( |
| 428 | com.android.internal.R.integer.config_defaultNotificationLedOff); |
| 429 | |
| Joe Onorato | 39f5b6a | 2009-07-23 12:29:19 -0400 | [diff] [blame] | 430 | // Don't start allowing notifications until the setup wizard has run once. |
| 431 | // After that, including subsequent boots, init with notifications turned on. |
| 432 | // This works on the first boot because the setup wizard will toggle this |
| 433 | // flag at least once and we'll go back to 0 after that. |
| 434 | if (0 == Settings.Secure.getInt(mContext.getContentResolver(), |
| 435 | Settings.Secure.DEVICE_PROVISIONED, 0)) { |
| 436 | mDisabledNotifications = StatusBarManager.DISABLE_NOTIFICATION_ALERTS; |
| 437 | } |
| 438 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 439 | // register for battery changed notifications |
| 440 | IntentFilter filter = new IntentFilter(); |
| 441 | filter.addAction(Intent.ACTION_BATTERY_CHANGED); |
| Mike Lockwood | ea8b7d5 | 2009-08-04 17:03:15 -0400 | [diff] [blame] | 442 | filter.addAction(Intent.ACTION_UMS_CONNECTED); |
| 443 | filter.addAction(Intent.ACTION_UMS_DISCONNECTED); |
| Mike Lockwood | c22404a | 2009-12-02 11:15:02 -0500 | [diff] [blame] | 444 | filter.addAction(Intent.ACTION_SCREEN_ON); |
| 445 | filter.addAction(Intent.ACTION_SCREEN_OFF); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 446 | mContext.registerReceiver(mIntentReceiver, filter); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 447 | IntentFilter pkgFilter = new IntentFilter(); |
| 448 | pkgFilter.addAction(Intent.ACTION_PACKAGE_REMOVED); |
| 449 | pkgFilter.addAction(Intent.ACTION_PACKAGE_RESTARTED); |
| 450 | pkgFilter.addAction(Intent.ACTION_QUERY_PACKAGE_RESTART); |
| 451 | pkgFilter.addDataScheme("package"); |
| 452 | mContext.registerReceiver(mIntentReceiver, pkgFilter); |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 453 | IntentFilter sdFilter = new IntentFilter(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 454 | mContext.registerReceiver(mIntentReceiver, sdFilter); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 455 | |
| Mike Lockwood | c22404a | 2009-12-02 11:15:02 -0500 | [diff] [blame] | 456 | SettingsObserver observer = new SettingsObserver(mHandler); |
| 457 | observer.observe(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 458 | } |
| 459 | |
| Joe Onorato | 3027548 | 2009-07-08 17:09:14 -0700 | [diff] [blame] | 460 | void systemReady() { |
| 461 | // no beeping until we're basically done booting |
| 462 | mSystemReady = true; |
| 463 | } |
| 464 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 465 | // Toasts |
| 466 | // ============================================================================ |
| 467 | public void enqueueToast(String pkg, ITransientNotification callback, int duration) |
| 468 | { |
| 469 | Log.i(TAG, "enqueueToast pkg=" + pkg + " callback=" + callback + " duration=" + duration); |
| 470 | |
| 471 | if (pkg == null || callback == null) { |
| 472 | Log.e(TAG, "Not doing toast. pkg=" + pkg + " callback=" + callback); |
| 473 | return ; |
| 474 | } |
| 475 | |
| 476 | synchronized (mToastQueue) { |
| 477 | int callingPid = Binder.getCallingPid(); |
| 478 | long callingId = Binder.clearCallingIdentity(); |
| 479 | try { |
| 480 | ToastRecord record; |
| 481 | int index = indexOfToastLocked(pkg, callback); |
| 482 | // If it's already in the queue, we update it in place, we don't |
| 483 | // move it to the end of the queue. |
| 484 | if (index >= 0) { |
| 485 | record = mToastQueue.get(index); |
| 486 | record.update(duration); |
| 487 | } else { |
| 488 | record = new ToastRecord(callingPid, pkg, callback, duration); |
| 489 | mToastQueue.add(record); |
| 490 | index = mToastQueue.size() - 1; |
| 491 | keepProcessAliveLocked(callingPid); |
| 492 | } |
| 493 | // If it's at index 0, it's the current toast. It doesn't matter if it's |
| 494 | // new or just been updated. Call back and tell it to show itself. |
| 495 | // If the callback fails, this will remove it from the list, so don't |
| 496 | // assume that it's valid after this. |
| 497 | if (index == 0) { |
| 498 | showNextToastLocked(); |
| 499 | } |
| 500 | } finally { |
| 501 | Binder.restoreCallingIdentity(callingId); |
| 502 | } |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | public void cancelToast(String pkg, ITransientNotification callback) { |
| 507 | Log.i(TAG, "cancelToast pkg=" + pkg + " callback=" + callback); |
| 508 | |
| 509 | if (pkg == null || callback == null) { |
| 510 | Log.e(TAG, "Not cancelling notification. pkg=" + pkg + " callback=" + callback); |
| 511 | return ; |
| 512 | } |
| 513 | |
| 514 | synchronized (mToastQueue) { |
| 515 | long callingId = Binder.clearCallingIdentity(); |
| 516 | try { |
| 517 | int index = indexOfToastLocked(pkg, callback); |
| 518 | if (index >= 0) { |
| 519 | cancelToastLocked(index); |
| 520 | } else { |
| 521 | Log.w(TAG, "Toast already cancelled. pkg=" + pkg + " callback=" + callback); |
| 522 | } |
| 523 | } finally { |
| 524 | Binder.restoreCallingIdentity(callingId); |
| 525 | } |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | private void showNextToastLocked() { |
| 530 | ToastRecord record = mToastQueue.get(0); |
| 531 | while (record != null) { |
| 532 | if (DBG) Log.d(TAG, "Show pkg=" + record.pkg + " callback=" + record.callback); |
| 533 | try { |
| 534 | record.callback.show(); |
| 535 | scheduleTimeoutLocked(record, false); |
| 536 | return; |
| 537 | } catch (RemoteException e) { |
| 538 | Log.w(TAG, "Object died trying to show notification " + record.callback |
| 539 | + " in package " + record.pkg); |
| 540 | // remove it from the list and let the process die |
| 541 | int index = mToastQueue.indexOf(record); |
| 542 | if (index >= 0) { |
| 543 | mToastQueue.remove(index); |
| 544 | } |
| 545 | keepProcessAliveLocked(record.pid); |
| 546 | if (mToastQueue.size() > 0) { |
| 547 | record = mToastQueue.get(0); |
| 548 | } else { |
| 549 | record = null; |
| 550 | } |
| 551 | } |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | private void cancelToastLocked(int index) { |
| 556 | ToastRecord record = mToastQueue.get(index); |
| 557 | try { |
| 558 | record.callback.hide(); |
| 559 | } catch (RemoteException e) { |
| 560 | Log.w(TAG, "Object died trying to hide notification " + record.callback |
| 561 | + " in package " + record.pkg); |
| 562 | // don't worry about this, we're about to remove it from |
| 563 | // the list anyway |
| 564 | } |
| 565 | mToastQueue.remove(index); |
| 566 | keepProcessAliveLocked(record.pid); |
| 567 | if (mToastQueue.size() > 0) { |
| 568 | // Show the next one. If the callback fails, this will remove |
| 569 | // it from the list, so don't assume that the list hasn't changed |
| 570 | // after this point. |
| 571 | showNextToastLocked(); |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | private void scheduleTimeoutLocked(ToastRecord r, boolean immediate) |
| 576 | { |
| 577 | Message m = Message.obtain(mHandler, MESSAGE_TIMEOUT, r); |
| 578 | long delay = immediate ? 0 : (r.duration == Toast.LENGTH_LONG ? LONG_DELAY : SHORT_DELAY); |
| 579 | mHandler.removeCallbacksAndMessages(r); |
| 580 | mHandler.sendMessageDelayed(m, delay); |
| 581 | } |
| 582 | |
| 583 | private void handleTimeout(ToastRecord record) |
| 584 | { |
| 585 | if (DBG) Log.d(TAG, "Timeout pkg=" + record.pkg + " callback=" + record.callback); |
| 586 | synchronized (mToastQueue) { |
| 587 | int index = indexOfToastLocked(record.pkg, record.callback); |
| 588 | if (index >= 0) { |
| 589 | cancelToastLocked(index); |
| 590 | } |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | // lock on mToastQueue |
| 595 | private int indexOfToastLocked(String pkg, ITransientNotification callback) |
| 596 | { |
| 597 | IBinder cbak = callback.asBinder(); |
| 598 | ArrayList<ToastRecord> list = mToastQueue; |
| 599 | int len = list.size(); |
| 600 | for (int i=0; i<len; i++) { |
| 601 | ToastRecord r = list.get(i); |
| 602 | if (r.pkg.equals(pkg) && r.callback.asBinder() == cbak) { |
| 603 | return i; |
| 604 | } |
| 605 | } |
| 606 | return -1; |
| 607 | } |
| 608 | |
| 609 | // lock on mToastQueue |
| 610 | private void keepProcessAliveLocked(int pid) |
| 611 | { |
| 612 | int toastCount = 0; // toasts from this pid |
| 613 | ArrayList<ToastRecord> list = mToastQueue; |
| 614 | int N = list.size(); |
| 615 | for (int i=0; i<N; i++) { |
| 616 | ToastRecord r = list.get(i); |
| 617 | if (r.pid == pid) { |
| 618 | toastCount++; |
| 619 | } |
| 620 | } |
| 621 | try { |
| 622 | mAm.setProcessForeground(mForegroundToken, pid, toastCount > 0); |
| 623 | } catch (RemoteException e) { |
| 624 | // Shouldn't happen. |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | private final class WorkerHandler extends Handler |
| 629 | { |
| 630 | @Override |
| 631 | public void handleMessage(Message msg) |
| 632 | { |
| 633 | switch (msg.what) |
| 634 | { |
| 635 | case MESSAGE_TIMEOUT: |
| 636 | handleTimeout((ToastRecord)msg.obj); |
| 637 | break; |
| 638 | } |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | |
| 643 | // Notifications |
| 644 | // ============================================================================ |
| 645 | public void enqueueNotification(String pkg, int id, Notification notification, int[] idOut) |
| 646 | { |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 647 | enqueueNotificationWithTag(pkg, null /* tag */, id, notification, idOut); |
| 648 | } |
| 649 | |
| 650 | public void enqueueNotificationWithTag(String pkg, String tag, int id, |
| 651 | Notification notification, int[] idOut) |
| 652 | { |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 653 | checkIncomingCall(pkg); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 654 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 655 | // This conditional is a dirty hack to limit the logging done on |
| 656 | // behalf of the download manager without affecting other apps. |
| 657 | if (!pkg.equals("com.android.providers.downloads") |
| 658 | || Log.isLoggable("DownloadManager", Log.VERBOSE)) { |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 659 | EventLog.writeEvent(EventLogTags.NOTIFICATION_ENQUEUE, pkg, id, notification.toString()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | if (pkg == null || notification == null) { |
| 663 | throw new IllegalArgumentException("null not allowed: pkg=" + pkg |
| 664 | + " id=" + id + " notification=" + notification); |
| 665 | } |
| 666 | if (notification.icon != 0) { |
| 667 | if (notification.contentView == null) { |
| 668 | throw new IllegalArgumentException("contentView required: pkg=" + pkg |
| 669 | + " id=" + id + " notification=" + notification); |
| 670 | } |
| 671 | if (notification.contentIntent == null) { |
| 672 | throw new IllegalArgumentException("contentIntent required: pkg=" + pkg |
| 673 | + " id=" + id + " notification=" + notification); |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | synchronized (mNotificationList) { |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 678 | NotificationRecord r = new NotificationRecord(pkg, tag, id, notification); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 679 | NotificationRecord old = null; |
| 680 | |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 681 | int index = indexOfNotificationLocked(pkg, tag, id); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 682 | if (index < 0) { |
| 683 | mNotificationList.add(r); |
| 684 | } else { |
| 685 | old = mNotificationList.remove(index); |
| 686 | mNotificationList.add(index, r); |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 687 | // Make sure we don't lose the foreground service state. |
| 688 | if (old != null) { |
| 689 | notification.flags |= |
| 690 | old.notification.flags&Notification.FLAG_FOREGROUND_SERVICE; |
| 691 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 692 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 693 | |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 694 | // Ensure if this is a foreground service that the proper additional |
| 695 | // flags are set. |
| 696 | if ((notification.flags&Notification.FLAG_FOREGROUND_SERVICE) != 0) { |
| 697 | notification.flags |= Notification.FLAG_ONGOING_EVENT |
| 698 | | Notification.FLAG_NO_CLEAR; |
| 699 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 700 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 701 | if (notification.icon != 0) { |
| 702 | IconData icon = IconData.makeIcon(null, pkg, notification.icon, |
| 703 | notification.iconLevel, |
| 704 | notification.number); |
| 705 | CharSequence truncatedTicker = notification.tickerText; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 706 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 707 | // TODO: make this restriction do something smarter like never fill |
| 708 | // more than two screens. "Why would anyone need more than 80 characters." :-/ |
| 709 | final int maxTickerLen = 80; |
| 710 | if (truncatedTicker != null && truncatedTicker.length() > maxTickerLen) { |
| 711 | truncatedTicker = truncatedTicker.subSequence(0, maxTickerLen); |
| 712 | } |
| 713 | |
| 714 | NotificationData n = new NotificationData(); |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 715 | n.pkg = pkg; |
| 716 | n.tag = tag; |
| 717 | n.id = id; |
| 718 | n.when = notification.when; |
| 719 | n.tickerText = truncatedTicker; |
| 720 | n.ongoingEvent = (notification.flags & Notification.FLAG_ONGOING_EVENT) != 0; |
| 721 | if (!n.ongoingEvent && (notification.flags & Notification.FLAG_NO_CLEAR) == 0) { |
| 722 | n.clearable = true; |
| 723 | } |
| 724 | n.contentView = notification.contentView; |
| 725 | n.contentIntent = notification.contentIntent; |
| 726 | n.deleteIntent = notification.deleteIntent; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 727 | if (old != null && old.statusBarKey != null) { |
| 728 | r.statusBarKey = old.statusBarKey; |
| 729 | long identity = Binder.clearCallingIdentity(); |
| 730 | try { |
| 731 | mStatusBarService.updateIcon(r.statusBarKey, icon, n); |
| 732 | } |
| 733 | finally { |
| 734 | Binder.restoreCallingIdentity(identity); |
| 735 | } |
| 736 | } else { |
| 737 | long identity = Binder.clearCallingIdentity(); |
| 738 | try { |
| 739 | r.statusBarKey = mStatusBarService.addIcon(icon, n); |
| Mike Lockwood | 3cb67a3 | 2009-11-27 14:25:58 -0500 | [diff] [blame] | 740 | mAttentionLight.pulse(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 741 | } |
| 742 | finally { |
| 743 | Binder.restoreCallingIdentity(identity); |
| 744 | } |
| 745 | } |
| svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 746 | |
| Joe Onorato | 3027548 | 2009-07-08 17:09:14 -0700 | [diff] [blame] | 747 | sendAccessibilityEvent(notification, pkg); |
| svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 748 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 749 | } else { |
| 750 | if (old != null && old.statusBarKey != null) { |
| 751 | long identity = Binder.clearCallingIdentity(); |
| 752 | try { |
| 753 | mStatusBarService.removeIcon(old.statusBarKey); |
| 754 | } |
| 755 | finally { |
| 756 | Binder.restoreCallingIdentity(identity); |
| 757 | } |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | // If we're not supposed to beep, vibrate, etc. then don't. |
| 762 | if (((mDisabledNotifications & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) == 0) |
| 763 | && (!(old != null |
| Joe Onorato | 3027548 | 2009-07-08 17:09:14 -0700 | [diff] [blame] | 764 | && (notification.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0 )) |
| 765 | && mSystemReady) { |
| Eric Laurent | 524dc04 | 2009-11-27 05:07:55 -0800 | [diff] [blame] | 766 | |
| 767 | final AudioManager audioManager = (AudioManager) mContext |
| 768 | .getSystemService(Context.AUDIO_SERVICE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 769 | // sound |
| 770 | final boolean useDefaultSound = |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 771 | (notification.defaults & Notification.DEFAULT_SOUND) != 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 772 | if (useDefaultSound || notification.sound != null) { |
| 773 | Uri uri; |
| 774 | if (useDefaultSound) { |
| 775 | uri = Settings.System.DEFAULT_NOTIFICATION_URI; |
| 776 | } else { |
| 777 | uri = notification.sound; |
| 778 | } |
| 779 | boolean looping = (notification.flags & Notification.FLAG_INSISTENT) != 0; |
| 780 | int audioStreamType; |
| 781 | if (notification.audioStreamType >= 0) { |
| 782 | audioStreamType = notification.audioStreamType; |
| 783 | } else { |
| 784 | audioStreamType = DEFAULT_STREAM_TYPE; |
| 785 | } |
| 786 | mSoundNotification = r; |
| Eric Laurent | 524dc04 | 2009-11-27 05:07:55 -0800 | [diff] [blame] | 787 | // do not play notifications if stream volume is 0 |
| 788 | // (typically because ringer mode is silent). |
| 789 | if (audioManager.getStreamVolume(audioStreamType) != 0) { |
| 790 | long identity = Binder.clearCallingIdentity(); |
| 791 | try { |
| 792 | mSound.play(mContext, uri, looping, audioStreamType); |
| 793 | } |
| 794 | finally { |
| 795 | Binder.restoreCallingIdentity(identity); |
| 796 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 797 | } |
| 798 | } |
| 799 | |
| 800 | // vibrate |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 801 | final boolean useDefaultVibrate = |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 802 | (notification.defaults & Notification.DEFAULT_VIBRATE) != 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 803 | if ((useDefaultVibrate || notification.vibrate != null) |
| 804 | && audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_NOTIFICATION)) { |
| 805 | mVibrateNotification = r; |
| 806 | |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 807 | mVibrator.vibrate(useDefaultVibrate ? DEFAULT_VIBRATE_PATTERN |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 808 | : notification.vibrate, |
| 809 | ((notification.flags & Notification.FLAG_INSISTENT) != 0) ? 0: -1); |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | // this option doesn't shut off the lights |
| 814 | |
| 815 | // light |
| 816 | // the most recent thing gets the light |
| 817 | mLights.remove(old); |
| 818 | if (mLedNotification == old) { |
| 819 | mLedNotification = null; |
| 820 | } |
| 821 | //Log.i(TAG, "notification.lights=" |
| 822 | // + ((old.notification.lights.flags & Notification.FLAG_SHOW_LIGHTS) != 0)); |
| 823 | if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0) { |
| 824 | mLights.add(r); |
| 825 | updateLightsLocked(); |
| 826 | } else { |
| 827 | if (old != null |
| 828 | && ((old.notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0)) { |
| 829 | updateLightsLocked(); |
| 830 | } |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | idOut[0] = id; |
| 835 | } |
| 836 | |
| Joe Onorato | 3027548 | 2009-07-08 17:09:14 -0700 | [diff] [blame] | 837 | private void sendAccessibilityEvent(Notification notification, CharSequence packageName) { |
| svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 838 | AccessibilityManager manager = AccessibilityManager.getInstance(mContext); |
| 839 | if (!manager.isEnabled()) { |
| 840 | return; |
| 841 | } |
| 842 | |
| 843 | AccessibilityEvent event = |
| 844 | AccessibilityEvent.obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED); |
| 845 | event.setPackageName(packageName); |
| 846 | event.setClassName(Notification.class.getName()); |
| 847 | event.setParcelableData(notification); |
| 848 | CharSequence tickerText = notification.tickerText; |
| 849 | if (!TextUtils.isEmpty(tickerText)) { |
| 850 | event.getText().add(tickerText); |
| 851 | } |
| 852 | |
| 853 | manager.sendAccessibilityEvent(event); |
| 854 | } |
| 855 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 856 | private void cancelNotificationLocked(NotificationRecord r) { |
| 857 | // status bar |
| 858 | if (r.notification.icon != 0) { |
| 859 | long identity = Binder.clearCallingIdentity(); |
| 860 | try { |
| 861 | mStatusBarService.removeIcon(r.statusBarKey); |
| 862 | } |
| 863 | finally { |
| 864 | Binder.restoreCallingIdentity(identity); |
| 865 | } |
| 866 | r.statusBarKey = null; |
| 867 | } |
| 868 | |
| 869 | // sound |
| 870 | if (mSoundNotification == r) { |
| 871 | mSoundNotification = null; |
| 872 | long identity = Binder.clearCallingIdentity(); |
| 873 | try { |
| 874 | mSound.stop(); |
| 875 | } |
| 876 | finally { |
| 877 | Binder.restoreCallingIdentity(identity); |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | // vibrate |
| 882 | if (mVibrateNotification == r) { |
| 883 | mVibrateNotification = null; |
| 884 | long identity = Binder.clearCallingIdentity(); |
| 885 | try { |
| 886 | mVibrator.cancel(); |
| 887 | } |
| 888 | finally { |
| 889 | Binder.restoreCallingIdentity(identity); |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | // light |
| 894 | mLights.remove(r); |
| 895 | if (mLedNotification == r) { |
| 896 | mLedNotification = null; |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | /** |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 901 | * Cancels a notification ONLY if it has all of the {@code mustHaveFlags} |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 902 | * and none of the {@code mustNotHaveFlags}. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 903 | */ |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 904 | private void cancelNotification(String pkg, String tag, int id, int mustHaveFlags, |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 905 | int mustNotHaveFlags) { |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 906 | EventLog.writeEvent(EventLogTags.NOTIFICATION_CANCEL, pkg, id, mustHaveFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 907 | |
| 908 | synchronized (mNotificationList) { |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 909 | int index = indexOfNotificationLocked(pkg, tag, id); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 910 | if (index >= 0) { |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 911 | NotificationRecord r = mNotificationList.get(index); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 912 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 913 | if ((r.notification.flags & mustHaveFlags) != mustHaveFlags) { |
| 914 | return; |
| 915 | } |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 916 | if ((r.notification.flags & mustNotHaveFlags) != 0) { |
| 917 | return; |
| 918 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 919 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 920 | mNotificationList.remove(index); |
| 921 | |
| 922 | cancelNotificationLocked(r); |
| 923 | updateLightsLocked(); |
| 924 | } |
| 925 | } |
| 926 | } |
| 927 | |
| 928 | /** |
| 929 | * Cancels all notifications from a given package that have all of the |
| 930 | * {@code mustHaveFlags}. |
| 931 | */ |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 932 | boolean cancelAllNotificationsInt(String pkg, int mustHaveFlags, |
| 933 | int mustNotHaveFlags, boolean doit) { |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 934 | EventLog.writeEvent(EventLogTags.NOTIFICATION_CANCEL_ALL, pkg, mustHaveFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 935 | |
| 936 | synchronized (mNotificationList) { |
| 937 | final int N = mNotificationList.size(); |
| 938 | boolean canceledSomething = false; |
| 939 | for (int i = N-1; i >= 0; --i) { |
| 940 | NotificationRecord r = mNotificationList.get(i); |
| 941 | if ((r.notification.flags & mustHaveFlags) != mustHaveFlags) { |
| 942 | continue; |
| 943 | } |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 944 | if ((r.notification.flags & mustNotHaveFlags) != 0) { |
| 945 | continue; |
| 946 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 947 | if (!r.pkg.equals(pkg)) { |
| 948 | continue; |
| 949 | } |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 950 | canceledSomething = true; |
| 951 | if (!doit) { |
| 952 | return true; |
| 953 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 954 | mNotificationList.remove(i); |
| 955 | cancelNotificationLocked(r); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 956 | } |
| 957 | if (canceledSomething) { |
| 958 | updateLightsLocked(); |
| 959 | } |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 960 | return canceledSomething; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 961 | } |
| 962 | } |
| 963 | |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 964 | |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 965 | public void cancelNotification(String pkg, int id) { |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 966 | cancelNotificationWithTag(pkg, null /* tag */, id); |
| 967 | } |
| 968 | |
| 969 | public void cancelNotificationWithTag(String pkg, String tag, int id) { |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 970 | checkIncomingCall(pkg); |
| 971 | // Don't allow client applications to cancel foreground service notis. |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 972 | cancelNotification(pkg, tag, id, 0, |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 973 | Binder.getCallingUid() == Process.SYSTEM_UID |
| 974 | ? 0 : Notification.FLAG_FOREGROUND_SERVICE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 975 | } |
| 976 | |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 977 | public void cancelAllNotifications(String pkg) { |
| 978 | checkIncomingCall(pkg); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 979 | |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 980 | // Calling from user space, don't allow the canceling of actively |
| 981 | // running foreground services. |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 982 | cancelAllNotificationsInt(pkg, 0, Notification.FLAG_FOREGROUND_SERVICE, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 983 | } |
| 984 | |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 985 | void checkIncomingCall(String pkg) { |
| 986 | int uid = Binder.getCallingUid(); |
| 987 | if (uid == Process.SYSTEM_UID || uid == 0) { |
| 988 | return; |
| 989 | } |
| 990 | try { |
| 991 | ApplicationInfo ai = mContext.getPackageManager().getApplicationInfo( |
| 992 | pkg, 0); |
| 993 | if (ai.uid != uid) { |
| 994 | throw new SecurityException("Calling uid " + uid + " gave package" |
| 995 | + pkg + " which is owned by uid " + ai.uid); |
| 996 | } |
| 997 | } catch (PackageManager.NameNotFoundException e) { |
| 998 | throw new SecurityException("Unknown package " + pkg); |
| 999 | } |
| 1000 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1001 | |
| Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 1002 | void cancelAll() { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1003 | synchronized (mNotificationList) { |
| 1004 | final int N = mNotificationList.size(); |
| 1005 | for (int i=N-1; i>=0; i--) { |
| 1006 | NotificationRecord r = mNotificationList.get(i); |
| 1007 | |
| 1008 | if ((r.notification.flags & (Notification.FLAG_ONGOING_EVENT |
| 1009 | | Notification.FLAG_NO_CLEAR)) == 0) { |
| 1010 | if (r.notification.deleteIntent != null) { |
| 1011 | try { |
| 1012 | r.notification.deleteIntent.send(); |
| 1013 | } catch (PendingIntent.CanceledException ex) { |
| 1014 | // do nothing - there's no relevant way to recover, and |
| 1015 | // no reason to let this propagate |
| 1016 | Log.w(TAG, "canceled PendingIntent for " + r.pkg, ex); |
| 1017 | } |
| 1018 | } |
| 1019 | mNotificationList.remove(i); |
| 1020 | cancelNotificationLocked(r); |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | updateLightsLocked(); |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | private void updateLights() { |
| 1029 | synchronized (mNotificationList) { |
| 1030 | updateLightsLocked(); |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | // lock on mNotificationList |
| 1035 | private void updateLightsLocked() |
| 1036 | { |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1037 | // Battery low always shows, other states only show if charging. |
| 1038 | if (mBatteryLow) { |
| Mike Lockwood | 445f430 | 2009-09-04 11:06:46 -0400 | [diff] [blame] | 1039 | if (mBatteryCharging) { |
| Mike Lockwood | 3cb67a3 | 2009-11-27 14:25:58 -0500 | [diff] [blame] | 1040 | mBatteryLight.setColor(BATTERY_LOW_ARGB); |
| Mike Lockwood | 445f430 | 2009-09-04 11:06:46 -0400 | [diff] [blame] | 1041 | } else { |
| 1042 | // Flash when battery is low and not charging |
| Mike Lockwood | 3cb67a3 | 2009-11-27 14:25:58 -0500 | [diff] [blame] | 1043 | mBatteryLight.setFlashing(BATTERY_LOW_ARGB, LightsService.LIGHT_FLASH_TIMED, |
| 1044 | BATTERY_BLINK_ON, BATTERY_BLINK_OFF); |
| Mike Lockwood | 445f430 | 2009-09-04 11:06:46 -0400 | [diff] [blame] | 1045 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1046 | } else if (mBatteryCharging) { |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1047 | if (mBatteryFull) { |
| Mike Lockwood | 3cb67a3 | 2009-11-27 14:25:58 -0500 | [diff] [blame] | 1048 | mBatteryLight.setColor(BATTERY_FULL_ARGB); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | } else { |
| Mike Lockwood | 3cb67a3 | 2009-11-27 14:25:58 -0500 | [diff] [blame] | 1050 | mBatteryLight.setColor(BATTERY_MEDIUM_ARGB); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1051 | } |
| 1052 | } else { |
| Mike Lockwood | 3cb67a3 | 2009-11-27 14:25:58 -0500 | [diff] [blame] | 1053 | mBatteryLight.turnOff(); |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1054 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1055 | |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1056 | // handle notification lights |
| 1057 | if (mLedNotification == null) { |
| 1058 | // get next notification, if any |
| 1059 | int n = mLights.size(); |
| 1060 | if (n > 0) { |
| 1061 | mLedNotification = mLights.get(n-1); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1062 | } |
| 1063 | } |
| Mike Lockwood | c22404a | 2009-12-02 11:15:02 -0500 | [diff] [blame] | 1064 | |
| 1065 | // we only flash if screen is off and persistent pulsing is enabled |
| Mike Lockwood | 670f932 | 2010-01-20 12:13:36 -0500 | [diff] [blame] | 1066 | if (mLedNotification == null || mScreenOn) { |
| Mike Lockwood | 3cb67a3 | 2009-11-27 14:25:58 -0500 | [diff] [blame] | 1067 | mNotificationLight.turnOff(); |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1068 | } else { |
| Mike Lockwood | 670f932 | 2010-01-20 12:13:36 -0500 | [diff] [blame] | 1069 | int ledARGB = mLedNotification.notification.ledARGB; |
| 1070 | int ledOnMS = mLedNotification.notification.ledOnMS; |
| 1071 | int ledOffMS = mLedNotification.notification.ledOffMS; |
| 1072 | if ((mLedNotification.notification.defaults & Notification.DEFAULT_LIGHTS) != 0) { |
| 1073 | ledARGB = mDefaultNotificationColor; |
| 1074 | ledOnMS = mDefaultNotificationLedOn; |
| 1075 | ledOffMS = mDefaultNotificationLedOff; |
| 1076 | } |
| 1077 | if (mNotificationPulseEnabled) { |
| 1078 | // pulse repeatedly |
| 1079 | mNotificationLight.setFlashing(ledARGB, LightsService.LIGHT_FLASH_TIMED, |
| 1080 | ledOnMS, ledOffMS); |
| 1081 | } else { |
| 1082 | // pulse only once |
| 1083 | mNotificationLight.pulse(ledARGB, ledOnMS); |
| 1084 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1085 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | // lock on mNotificationList |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 1089 | private int indexOfNotificationLocked(String pkg, String tag, int id) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1090 | { |
| 1091 | ArrayList<NotificationRecord> list = mNotificationList; |
| 1092 | final int len = list.size(); |
| 1093 | for (int i=0; i<len; i++) { |
| 1094 | NotificationRecord r = list.get(i); |
| Fred Quintana | 6ecaff1 | 2009-09-25 14:23:13 -0700 | [diff] [blame] | 1095 | if (tag == null) { |
| 1096 | if (r.tag != null) { |
| 1097 | continue; |
| 1098 | } |
| 1099 | } else { |
| 1100 | if (!tag.equals(r.tag)) { |
| 1101 | continue; |
| 1102 | } |
| 1103 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1104 | if (r.id == id && r.pkg.equals(pkg)) { |
| 1105 | return i; |
| 1106 | } |
| 1107 | } |
| 1108 | return -1; |
| 1109 | } |
| 1110 | |
| Dianne Hackborn | 1dac277 | 2009-06-26 18:16:48 -0700 | [diff] [blame] | 1111 | // This is here instead of StatusBarPolicy because it is an important |
| 1112 | // security feature that we don't want people customizing the platform |
| 1113 | // to accidentally lose. |
| 1114 | private void updateAdbNotification() { |
| Mike Lockwood | ea8b7d5 | 2009-08-04 17:03:15 -0400 | [diff] [blame] | 1115 | if (mAdbEnabled && mUsbConnected) { |
| Mike Lockwood | ed76037 | 2009-07-09 07:07:27 -0400 | [diff] [blame] | 1116 | if ("0".equals(SystemProperties.get("persist.adb.notify"))) { |
| 1117 | return; |
| 1118 | } |
| Dianne Hackborn | 1dac277 | 2009-06-26 18:16:48 -0700 | [diff] [blame] | 1119 | if (!mAdbNotificationShown) { |
| 1120 | NotificationManager notificationManager = (NotificationManager) mContext |
| 1121 | .getSystemService(Context.NOTIFICATION_SERVICE); |
| 1122 | if (notificationManager != null) { |
| 1123 | Resources r = mContext.getResources(); |
| 1124 | CharSequence title = r.getText( |
| 1125 | com.android.internal.R.string.adb_active_notification_title); |
| 1126 | CharSequence message = r.getText( |
| 1127 | com.android.internal.R.string.adb_active_notification_message); |
| 1128 | |
| 1129 | if (mAdbNotification == null) { |
| 1130 | mAdbNotification = new Notification(); |
| 1131 | mAdbNotification.icon = com.android.internal.R.drawable.stat_sys_warning; |
| 1132 | mAdbNotification.when = 0; |
| 1133 | mAdbNotification.flags = Notification.FLAG_ONGOING_EVENT; |
| 1134 | mAdbNotification.tickerText = title; |
| 1135 | mAdbNotification.defaults |= Notification.DEFAULT_SOUND; |
| 1136 | } |
| 1137 | |
| 1138 | Intent intent = new Intent( |
| 1139 | Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS); |
| 1140 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | |
| 1141 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 1142 | // Note: we are hard-coding the component because this is |
| 1143 | // an important security UI that we don't want anyone |
| 1144 | // intercepting. |
| 1145 | intent.setComponent(new ComponentName("com.android.settings", |
| 1146 | "com.android.settings.DevelopmentSettings")); |
| 1147 | PendingIntent pi = PendingIntent.getActivity(mContext, 0, |
| 1148 | intent, 0); |
| 1149 | |
| 1150 | mAdbNotification.setLatestEventInfo(mContext, title, message, pi); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1151 | |
| Dianne Hackborn | 1dac277 | 2009-06-26 18:16:48 -0700 | [diff] [blame] | 1152 | mAdbNotificationShown = true; |
| 1153 | notificationManager.notify( |
| 1154 | com.android.internal.R.string.adb_active_notification_title, |
| 1155 | mAdbNotification); |
| 1156 | } |
| 1157 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1158 | |
| Dianne Hackborn | 1dac277 | 2009-06-26 18:16:48 -0700 | [diff] [blame] | 1159 | } else if (mAdbNotificationShown) { |
| 1160 | NotificationManager notificationManager = (NotificationManager) mContext |
| 1161 | .getSystemService(Context.NOTIFICATION_SERVICE); |
| 1162 | if (notificationManager != null) { |
| 1163 | mAdbNotificationShown = false; |
| 1164 | notificationManager.cancel( |
| 1165 | com.android.internal.R.string.adb_active_notification_title); |
| 1166 | } |
| 1167 | } |
| 1168 | } |
| Mike Lockwood | c22404a | 2009-12-02 11:15:02 -0500 | [diff] [blame] | 1169 | |
| 1170 | private void updateNotificationPulse() { |
| 1171 | synchronized (mNotificationList) { |
| 1172 | updateLightsLocked(); |
| 1173 | } |
| 1174 | } |
| 1175 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1176 | // ====================================================================== |
| 1177 | @Override |
| 1178 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 1179 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 1180 | != PackageManager.PERMISSION_GRANTED) { |
| 1181 | pw.println("Permission Denial: can't dump NotificationManager from from pid=" |
| 1182 | + Binder.getCallingPid() |
| 1183 | + ", uid=" + Binder.getCallingUid()); |
| 1184 | return; |
| 1185 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1186 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1187 | pw.println("Current Notification Manager state:"); |
| 1188 | |
| 1189 | int N; |
| 1190 | |
| 1191 | synchronized (mToastQueue) { |
| 1192 | N = mToastQueue.size(); |
| 1193 | if (N > 0) { |
| 1194 | pw.println(" Toast Queue:"); |
| 1195 | for (int i=0; i<N; i++) { |
| 1196 | mToastQueue.get(i).dump(pw, " "); |
| 1197 | } |
| 1198 | pw.println(" "); |
| 1199 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1200 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | synchronized (mNotificationList) { |
| 1204 | N = mNotificationList.size(); |
| 1205 | if (N > 0) { |
| 1206 | pw.println(" Notification List:"); |
| 1207 | for (int i=0; i<N; i++) { |
| 1208 | mNotificationList.get(i).dump(pw, " ", mContext); |
| 1209 | } |
| 1210 | pw.println(" "); |
| 1211 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1212 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1213 | N = mLights.size(); |
| 1214 | if (N > 0) { |
| 1215 | pw.println(" Lights List:"); |
| 1216 | for (int i=0; i<N; i++) { |
| 1217 | mLights.get(i).dump(pw, " ", mContext); |
| 1218 | } |
| 1219 | pw.println(" "); |
| 1220 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1221 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1222 | pw.println(" mSoundNotification=" + mSoundNotification); |
| 1223 | pw.println(" mSound=" + mSound); |
| 1224 | pw.println(" mVibrateNotification=" + mVibrateNotification); |
| Joe Onorato | 39f5b6a | 2009-07-23 12:29:19 -0400 | [diff] [blame] | 1225 | pw.println(" mDisabledNotifications=0x" + Integer.toHexString(mDisabledNotifications)); |
| 1226 | pw.println(" mSystemReady=" + mSystemReady); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1227 | } |
| 1228 | } |
| 1229 | } |