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