diff options
author | Sam Mortimer <sam@mortimer.me.uk> | 2013-03-18 18:24:07 -0700 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2015-10-26 02:34:25 -0700 |
commit | aa107df6c5559639daa26883b78edd8fe32cec87 (patch) | |
tree | d69fe1804d397a8e403a72cbdee53f32e743146f | |
parent | 2a2cc073b2b8918b5bd18c535f53de73d578db81 (diff) | |
download | frameworks_base-aa107df6c5559639daa26883b78edd8fe32cec87.zip frameworks_base-aa107df6c5559639daa26883b78edd8fe32cec87.tar.gz frameworks_base-aa107df6c5559639daa26883b78edd8fe32cec87.tar.bz2 |
[1/2] Forward port power connect/disconnect notification support
Original commit info:
[1/2] Power connect/disconnect notification support
part 1/2: frameworks/base PowerUI and Settings
http://review.cyanogenmod.org/#/c/35241/
part 2/2: packages/apps/Settings Sound settings
http://review.cyanogenmod.org/#/c/35242/
V-Old_Change-Id: I36a6b9f924d2cd52191a8e83a744745b37c5b068
OldChange-Id: Ib865e1c296cb8e1d957b2a48616c88ceaba5c008
Change-Id: I5db20ef23bdb644e2af06e8dcbc8fbd0cf7ce321
Signed-off-by: STELIX <ssspinni@gmail.com>
4 files changed, 80 insertions, 0 deletions
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index d807906..cd32a41 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -8026,6 +8026,24 @@ public final class Settings { */ public static final String LOW_POWER_MODE_TRIGGER_LEVEL = "low_power_trigger_level"; + /** + * Whether to sound when charger power is connected/disconnected + * @hide + */ + public static final String POWER_NOTIFICATIONS_ENABLED = "power_notifications_enabled"; + + /** + * Whether to vibrate when charger power is connected/disconnected + * @hide + */ + public static final String POWER_NOTIFICATIONS_VIBRATE = "power_notifications_vibrate"; + + /** + * URI for power notification sounds + * @hide + */ + public static final String POWER_NOTIFICATIONS_RINGTONE = "power_notifications_ringtone"; + /** * If 1, the activity manager will aggressively finish activities and * processes as soon as they are no longer needed. If 0, the normal diff --git a/packages/SettingsProvider/res/values/defaults.xml b/packages/SettingsProvider/res/values/defaults.xml index 24646eb..d7128cd 100644 --- a/packages/SettingsProvider/res/values/defaults.xml +++ b/packages/SettingsProvider/res/values/defaults.xml @@ -78,6 +78,10 @@ <string name="def_trusted_sound" translatable="false">/system/media/audio/ui/Trusted.ogg</string> <string name="def_wireless_charging_started_sound" translatable="false">/system/media/audio/ui/WirelessChargingStarted.ogg</string> + <bool name="def_power_notifications_enabled">false</bool> + <bool name="def_power_notifications_vibrate">false</bool> + <string name="def_power_notifications_ringtone" translatable="false">content://settings/system/notification_sound</string> + <bool name="def_lockscreen_disabled">false</bool> <bool name="def_device_provisioned">false</bool> <integer name="def_dock_audio_media_enabled">1</integer> diff --git a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java index 72a3d8e..cd1546a 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java @@ -1555,6 +1555,12 @@ class DatabaseHelper extends SQLiteOpenHelper { + " VALUES(?,?);"); loadStringSetting(stmt, Settings.Global.WIRELESS_CHARGING_STARTED_SOUND, R.string.def_wireless_charging_started_sound); + loadBooleanSetting(stmt, Settings.Global.POWER_NOTIFICATIONS_ENABLED, + R.bool.def_power_notifications_enabled); + loadBooleanSetting(stmt, Settings.Global.POWER_NOTIFICATIONS_VIBRATE, + R.bool.def_power_notifications_vibrate); + loadStringSetting(stmt, Settings.Global.POWER_NOTIFICATIONS_RINGTONE, + R.string.def_power_notifications_ringtone); db.setTransactionSuccessful(); } finally { db.endTransaction(); diff --git a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java index 9459740..5913bb7 100644 --- a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java +++ b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java @@ -16,12 +16,15 @@ package com.android.systemui.power; +import android.app.Notification; +import android.app.NotificationManager; import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.database.ContentObserver; +import android.net.Uri; import android.os.BatteryManager; import android.os.Handler; import android.os.PowerManager; @@ -57,6 +60,9 @@ public class PowerUI extends SystemUI { private long mScreenOffTime = -1; + // For filtering ACTION_POWER_DISCONNECTED on boot + boolean mIgnoreFirstPowerEvent = true; + public void start() { mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); mScreenOffTime = mPowerManager.isScreenOn() ? -1 : SystemClock.elapsedRealtime(); @@ -140,6 +146,8 @@ public class PowerUI extends SystemUI { filter.addAction(Intent.ACTION_USER_SWITCHED); filter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGING); filter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED); + filter.addAction(Intent.ACTION_POWER_CONNECTED); + filter.addAction(Intent.ACTION_POWER_DISCONNECTED); mContext.registerReceiver(this, filter, null, mHandler); updateSaverMode(); } @@ -165,6 +173,10 @@ public class PowerUI extends SystemUI { final boolean plugged = mPlugType != 0; final boolean oldPlugged = oldPlugType != 0; + if (mIgnoreFirstPowerEvent && plugged) { + mIgnoreFirstPowerEvent = false; + } + int oldBucket = findBatteryLevelBucket(oldBatteryLevel); int bucket = findBatteryLevelBucket(mBatteryLevel); @@ -214,12 +226,52 @@ public class PowerUI extends SystemUI { updateSaverMode(); } else if (PowerManager.ACTION_POWER_SAVE_MODE_CHANGING.equals(action)) { setSaverMode(intent.getBooleanExtra(PowerManager.EXTRA_POWER_SAVE_MODE, false)); + } else if (Intent.ACTION_POWER_CONNECTED.equals(action) + || Intent.ACTION_POWER_DISCONNECTED.equals(action)) { + final ContentResolver cr = mContext.getContentResolver(); + + if (mIgnoreFirstPowerEvent) { + mIgnoreFirstPowerEvent = false; + } else { + if (Settings.Global.getInt(cr, + Settings.Global.POWER_NOTIFICATIONS_ENABLED, 0) == 1) { + playPowerNotificationSound(); + } + } } else { Slog.w(TAG, "unknown intent: " + intent); } } }; + void playPowerNotificationSound() { + final ContentResolver cr = mContext.getContentResolver(); + final String soundPath = + Settings.Global.getString(cr, Settings.Global.POWER_NOTIFICATIONS_RINGTONE); + + NotificationManager notificationManager = + (NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE); + if (notificationManager == null) { + return; + } + + Notification powerNotify=new Notification(); + powerNotify.defaults = Notification.DEFAULT_ALL; + if (soundPath != null) { + powerNotify.sound = Uri.parse(soundPath); + if (powerNotify.sound != null) { + // DEFAULT_SOUND overrides so flip off + powerNotify.defaults &= ~Notification.DEFAULT_SOUND; + } + } + if (Settings.Global.getInt(cr, + Settings.Global.POWER_NOTIFICATIONS_VIBRATE, 0) == 0) { + powerNotify.defaults &= ~Notification.DEFAULT_VIBRATE; + } + + notificationManager.notify(0, powerNotify); + } + public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { pw.print("mLowBatteryAlertCloseLevel="); pw.println(mLowBatteryAlertCloseLevel); |