diff options
| -rw-r--r-- | api/current.xml | 11 | ||||
| -rw-r--r-- | core/java/android/content/Intent.java | 7 | ||||
| -rw-r--r-- | core/res/res/values/strings.xml | 5 | ||||
| -rw-r--r-- | services/java/com/android/server/BatteryService.java | 6 | ||||
| -rw-r--r-- | services/java/com/android/server/NotificationManagerService.java | 98 | ||||
| -rw-r--r-- | services/java/com/android/server/status/StatusBarPolicy.java | 29 |
6 files changed, 142 insertions, 14 deletions
diff --git a/api/current.xml b/api/current.xml index 26902dbdb4f6..e0a62893227b 100644 --- a/api/current.xml +++ b/api/current.xml @@ -34778,6 +34778,17 @@ visibility="public" > </field> +<field name="ACTION_BATTERY_OKAY" + type="java.lang.String" + transient="false" + volatile="false" + value=""android.intent.action.BATTERY_OKAY"" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> <field name="ACTION_BOOT_COMPLETED" type="java.lang.String" transient="false" diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java index 87f762db84c6..a57084cbcd4a 100644 --- a/core/java/android/content/Intent.java +++ b/core/java/android/content/Intent.java @@ -1290,6 +1290,13 @@ public class Intent implements Parcelable { @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String ACTION_BATTERY_LOW = "android.intent.action.BATTERY_LOW"; /** + * Broadcast Action: Indicates the battery is now okay after being low. + * This will be sent after {@link #ACTION_BATTERY_LOW} once the battery has + * gone back up to an okay state. + */ + @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) + public static final String ACTION_BATTERY_OKAY = "android.intent.action.BATTERY_OKAY"; + /** * Broadcast Action: External power has been connected to the device. * This is intended for applications that wish to register specifically to this notification. * Unlike ACTION_BATTERY_CHANGED, applications will be woken for this and so do not have to diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 612e6f4c9cca..eeafbe63967f 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -1790,6 +1790,11 @@ <!-- See EXTMEDIA_FORMAT. This is the button text to format the sd card. --> <string name="extmedia_format_button_format">Format</string> + <!-- Title of notification shown when ADB is actively connected to the phone. --> + <string name="adb_active_notification_title">USB debugging connected</string> + <!-- Message of notification shown when ADB is actively connected to the phone. --> + <string name="adb_active_notification_message">A computer is connected to your phone.</string> + <!-- Used to replace %s in urls retreived from the signin server with locales. For Some --> <!-- devices we don't support all the locales we ship to and need to replace the '%s' with a --> <!-- locale string based on mcc values. By default (0-length string) we don't replace the %s --> diff --git a/services/java/com/android/server/BatteryService.java b/services/java/com/android/server/BatteryService.java index 596053d8091d..5cdce5b3b63f 100644 --- a/services/java/com/android/server/BatteryService.java +++ b/services/java/com/android/server/BatteryService.java @@ -92,6 +92,7 @@ class BatteryService extends Binder { // This should probably be exposed in the API, though it's not critical private static final int BATTERY_PLUGGED_NONE = 0; + private static final int BATTERY_LEVEL_CLOSE_WARNING = 20; private static final int BATTERY_LEVEL_WARNING = 15; private final Context mContext; @@ -122,6 +123,7 @@ class BatteryService extends Binder { private long mDischargeStartTime; private int mDischargeStartLevel; + private boolean mSentLowBatteryBroadcast = false; public BatteryService(Context context) { mContext = context; @@ -286,7 +288,11 @@ class BatteryService extends Binder { sendIntent(); if (sendBatteryLow) { + mSentLowBatteryBroadcast = true; mContext.sendBroadcast(new Intent(Intent.ACTION_BATTERY_LOW)); + } else if (mSentLowBatteryBroadcast && mLastBatteryLevel >= BATTERY_LEVEL_CLOSE_WARNING) { + mSentLowBatteryBroadcast = false; + mContext.sendBroadcast(new Intent(Intent.ACTION_BATTERY_OKAY)); } // This needs to be done after sendIntent() so that we get the lastest battery stats. diff --git a/services/java/com/android/server/NotificationManagerService.java b/services/java/com/android/server/NotificationManagerService.java index 4a2808b50c3d..854138c74085 100644 --- a/services/java/com/android/server/NotificationManagerService.java +++ b/services/java/com/android/server/NotificationManagerService.java @@ -25,15 +25,20 @@ import android.app.IActivityManager; import android.app.INotificationManager; import android.app.ITransientNotification; import android.app.Notification; +import android.app.NotificationManager; import android.app.PendingIntent; import android.app.StatusBarManager; import android.content.BroadcastReceiver; +import android.content.ComponentName; +import android.content.ContentQueryMap; +import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Resources; +import android.database.ContentObserver; import android.media.AsyncPlayer; import android.media.AudioManager; import android.net.Uri; @@ -88,6 +93,12 @@ class NotificationManagerService extends INotificationManager.Stub private NotificationRecord mVibrateNotification; private Vibrator mVibrator = new Vibrator(); + // adb + private int mBatteryPlugged; + private boolean mAdbEnabled = false; + private boolean mAdbNotificationShown = false; + private Notification mAdbNotification; + private ArrayList<NotificationRecord> mNotificationList; private ArrayList<ToastRecord> mToastQueue; @@ -297,6 +308,9 @@ class NotificationManagerService extends INotificationManager.Stub mBatteryFull = batteryFull; updateLights(); } + + mBatteryPlugged = intent.getIntExtra("plugged", 0); + updateAdbNotification(); } else if (action.equals(Intent.ACTION_PACKAGE_REMOVED) || action.equals(Intent.ACTION_PACKAGE_RESTARTED)) { Uri uri = intent.getData(); @@ -312,6 +326,31 @@ class NotificationManagerService extends INotificationManager.Stub } }; + class SettingsObserver extends ContentObserver { + SettingsObserver(Handler handler) { + super(handler); + } + + void observe() { + ContentResolver resolver = mContext.getContentResolver(); + resolver.registerContentObserver(Settings.Secure.getUriFor( + Settings.Secure.ADB_ENABLED), false, this); + update(); + } + + @Override public void onChange(boolean selfChange) { + update(); + } + + public void update() { + ContentResolver resolver = mContext.getContentResolver(); + mAdbEnabled = Settings.Secure.getInt(resolver, + Settings.Secure.ADB_ENABLED, 0) != 0; + updateAdbNotification(); + } + } + private final SettingsObserver mSettingsObserver; + NotificationManagerService(Context context, StatusBarService statusBar, HardwareService hardware) { @@ -333,6 +372,9 @@ class NotificationManagerService extends INotificationManager.Stub filter.addAction(Intent.ACTION_PACKAGE_REMOVED); filter.addAction(Intent.ACTION_PACKAGE_RESTARTED); mContext.registerReceiver(mIntentReceiver, filter); + + mSettingsObserver = new SettingsObserver(mHandler); + mSettingsObserver.observe(); } // Toasts @@ -892,6 +934,62 @@ class NotificationManagerService extends INotificationManager.Stub return -1; } + // This is here instead of StatusBarPolicy because it is an important + // security feature that we don't want people customizing the platform + // to accidentally lose. + private void updateAdbNotification() { + if (mAdbEnabled && mBatteryPlugged == BatteryManager.BATTERY_PLUGGED_USB) { + if (!mAdbNotificationShown) { + NotificationManager notificationManager = (NotificationManager) mContext + .getSystemService(Context.NOTIFICATION_SERVICE); + if (notificationManager != null) { + Resources r = mContext.getResources(); + CharSequence title = r.getText( + com.android.internal.R.string.adb_active_notification_title); + CharSequence message = r.getText( + com.android.internal.R.string.adb_active_notification_message); + + if (mAdbNotification == null) { + mAdbNotification = new Notification(); + mAdbNotification.icon = com.android.internal.R.drawable.stat_sys_warning; + mAdbNotification.when = 0; + mAdbNotification.flags = Notification.FLAG_ONGOING_EVENT; + mAdbNotification.tickerText = title; + mAdbNotification.defaults |= Notification.DEFAULT_SOUND; + } + + Intent intent = new Intent( + Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | + Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); + // Note: we are hard-coding the component because this is + // an important security UI that we don't want anyone + // intercepting. + intent.setComponent(new ComponentName("com.android.settings", + "com.android.settings.DevelopmentSettings")); + PendingIntent pi = PendingIntent.getActivity(mContext, 0, + intent, 0); + + mAdbNotification.setLatestEventInfo(mContext, title, message, pi); + + mAdbNotificationShown = true; + notificationManager.notify( + com.android.internal.R.string.adb_active_notification_title, + mAdbNotification); + } + } + + } else if (mAdbNotificationShown) { + NotificationManager notificationManager = (NotificationManager) mContext + .getSystemService(Context.NOTIFICATION_SERVICE); + if (notificationManager != null) { + mAdbNotificationShown = false; + notificationManager.cancel( + com.android.internal.R.string.adb_active_notification_title); + } + } + } + // ====================================================================== @Override protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { diff --git a/services/java/com/android/server/status/StatusBarPolicy.java b/services/java/com/android/server/status/StatusBarPolicy.java index 059dc7be3e0d..c8db95b7ff9b 100644 --- a/services/java/com/android/server/status/StatusBarPolicy.java +++ b/services/java/com/android/server/status/StatusBarPolicy.java @@ -76,12 +76,8 @@ public class StatusBarPolicy { private static StatusBarPolicy sInstance; // message codes for the handler - private static final int EVENT_DATA_CONN_STATE_CHANGED = 2; - private static final int EVENT_DATA_ACTIVITY = 3; private static final int EVENT_BATTERY_CLOSE = 4; - private static final int BATTERY_LEVEL_CLOSE_WARNING = 20; - private final Context mContext; private final StatusBarService mService; private final Handler mHandler = new StatusBarHandler(); @@ -357,6 +353,9 @@ public class StatusBarPolicy { else if (action.equals(Intent.ACTION_TIME_CHANGED)) { updateClock(); } + else if (action.equals(Intent.ACTION_BATTERY_CHANGED)) { + updateBattery(intent); + } else if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) { updateClock(); } @@ -371,12 +370,12 @@ public class StatusBarPolicy { else if (action.equals(Intent.ACTION_SYNC_STATE_CHANGED)) { updateSyncState(intent); } - else if (action.equals(Intent.ACTION_BATTERY_CHANGED)) { - updateBattery(intent); - } else if (action.equals(Intent.ACTION_BATTERY_LOW)) { onBatteryLow(intent); } + else if (action.equals(Intent.ACTION_BATTERY_OKAY)) { + onBatteryOkay(intent); + } else if (action.equals(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION) || action.equals(BluetoothIntent.HEADSET_STATE_CHANGED_ACTION) || action.equals(BluetoothA2dp.SINK_STATE_CHANGED_ACTION)) { @@ -519,6 +518,7 @@ public class StatusBarPolicy { filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); filter.addAction(Intent.ACTION_BATTERY_CHANGED); filter.addAction(Intent.ACTION_BATTERY_LOW); + filter.addAction(Intent.ACTION_BATTERY_OKAY); filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); filter.addAction(Intent.ACTION_ALARM_CHANGED); filter.addAction(Intent.ACTION_SYNC_STATE_CHANGED); @@ -601,13 +601,6 @@ public class StatusBarPolicy { if (false) { Log.d(TAG, "plugged=" + plugged + " oldPlugged=" + oldPlugged + " level=" + level); } - - if (mLowBatteryDialog != null - && mBatteryLevel >= BATTERY_LEVEL_CLOSE_WARNING - && SHOW_LOW_BATTERY_WARNING) { - mLowBatteryDialog.dismiss(); - mBatteryShowLowOnEndCall = false; - } } private void onBatteryLow(Intent intent) { @@ -626,6 +619,14 @@ public class StatusBarPolicy { } } + private void onBatteryOkay(Intent intent) { + if (mLowBatteryDialog != null + && SHOW_LOW_BATTERY_WARNING) { + mLowBatteryDialog.dismiss(); + mBatteryShowLowOnEndCall = false; + } + } + private void showBatteryView() { closeLastBatteryView(); if (mLowBatteryDialog != null) { |