From 88e7a6c7fcaf71d6dae2b9067db19aaeba7de39b Mon Sep 17 00:00:00 2001 From: Gavin Ni Date: Sat, 16 Jul 2016 15:26:32 +0000 Subject: SystemUI: Display bluetooth battery status when available Change-Id: I659e6270058d02fdd894b8242a6375b1a13237df --- ...stat_sys_data_bluetooth_connected_battery_1.xml | 28 +++++++++++++ ...stat_sys_data_bluetooth_connected_battery_2.xml | 31 ++++++++++++++ ...stat_sys_data_bluetooth_connected_battery_3.xml | 31 ++++++++++++++ ...stat_sys_data_bluetooth_connected_battery_4.xml | 31 ++++++++++++++ ...stat_sys_data_bluetooth_connected_battery_5.xml | 31 ++++++++++++++ .../statusbar/phone/PhoneStatusBarPolicy.java | 48 +++++++++++++++++++++- 6 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_1.xml create mode 100644 packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_2.xml create mode 100644 packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_3.xml create mode 100644 packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_4.xml create mode 100644 packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_5.xml (limited to 'packages/SystemUI') diff --git a/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_1.xml b/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_1.xml new file mode 100644 index 0000000..3a4ee98 --- /dev/null +++ b/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_1.xml @@ -0,0 +1,28 @@ + + + + + + diff --git a/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_2.xml b/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_2.xml new file mode 100644 index 0000000..3a01881 --- /dev/null +++ b/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_2.xml @@ -0,0 +1,31 @@ + + + + + + + diff --git a/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_3.xml b/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_3.xml new file mode 100644 index 0000000..9639d28 --- /dev/null +++ b/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_3.xml @@ -0,0 +1,31 @@ + + + + + + + diff --git a/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_4.xml b/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_4.xml new file mode 100644 index 0000000..1e8ac10 --- /dev/null +++ b/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_4.xml @@ -0,0 +1,31 @@ + + + + + + + diff --git a/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_5.xml b/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_5.xml new file mode 100644 index 0000000..7464bec --- /dev/null +++ b/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_5.xml @@ -0,0 +1,31 @@ + + + + + + + diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java index 0e71bee..1395ff6 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java @@ -22,6 +22,8 @@ import android.app.AlarmManager.AlarmClockInfo; import android.app.IUserSwitchObserver; import android.app.PendingIntent; import android.app.StatusBarManager; +import android.bluetooth.BluetoothAssignedNumbers; +import android.bluetooth.BluetoothHeadset; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -103,6 +105,7 @@ public class PhoneStatusBarPolicy implements Callback { private boolean mZenVisible; private boolean mVolumeVisible; private boolean mCurrentUserSetup; + private Float mBluetoothBatteryLevel = null; private int mZen; @@ -129,6 +132,9 @@ public class PhoneStatusBarPolicy implements Callback { else if (action.equals(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED)) { updateTTY(intent); } + else if (action.equals(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT)) { + updateBluetoothBattery(intent); + } } }; @@ -166,6 +172,9 @@ public class PhoneStatusBarPolicy implements Callback { filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION); filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); filter.addAction(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED); + filter.addAction(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT); + filter.addCategory(BluetoothHeadset.VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY + + "." + Integer.toString(BluetoothAssignedNumbers.APPLE)); mContext.registerReceiver(mIntentReceiver, filter, null, mHandler); // listen for user / profile change. @@ -357,6 +366,27 @@ public class PhoneStatusBarPolicy implements Callback { updateBluetooth(); } + private void updateBluetoothBattery(Intent intent) { + if (intent.hasExtra(BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD)) { + String command = intent.getStringExtra(BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD); + if ("+IPHONEACCEV".equals(command)) { + Object[] args = (Object[]) intent.getSerializableExtra(BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_ARGS); + if (args.length >= 3 && args[0] instanceof Integer && ((Integer)args[0])*2+1<=args.length) { + for (int i=0;i<((Integer)args[0]);i++) { + if (!(args[i*2+1] instanceof Integer) || !(args[i*2+2] instanceof Integer)) { + continue; + } + if (args[i*2+1].equals(1)) { + mBluetoothBatteryLevel = (((Integer)args[i*2+2])+1)/10.0f; + updateBluetooth(); + break; + } + } + } + } + } + } + private final void updateBluetooth() { int iconId = R.drawable.stat_sys_data_bluetooth; String contentDescription = @@ -365,8 +395,24 @@ public class PhoneStatusBarPolicy implements Callback { if (mBluetooth != null) { bluetoothEnabled = mBluetooth.isBluetoothEnabled(); if (mBluetooth.isBluetoothConnected()) { - iconId = R.drawable.stat_sys_data_bluetooth_connected; + if (mBluetoothBatteryLevel == null) { + iconId = R.drawable.stat_sys_data_bluetooth_connected; + } else { + if (mBluetoothBatteryLevel<=0.15f) { + iconId = R.drawable.stat_sys_data_bluetooth_connected_battery_1; + } else if (mBluetoothBatteryLevel<=0.375f) { + iconId = R.drawable.stat_sys_data_bluetooth_connected_battery_2; + } else if (mBluetoothBatteryLevel<=0.625f) { + iconId = R.drawable.stat_sys_data_bluetooth_connected_battery_3; + } else if (mBluetoothBatteryLevel<=0.85f) { + iconId = R.drawable.stat_sys_data_bluetooth_connected_battery_4; + } else { + iconId = R.drawable.stat_sys_data_bluetooth_connected_battery_5; + } + } contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected); + } else { + mBluetoothBatteryLevel = null; } } -- cgit v1.1