diff options
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java | 54 |
1 files changed, 53 insertions, 1 deletions
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 ed4880b..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; } } @@ -474,6 +520,12 @@ public class PhoneStatusBarPolicy implements Callback { @Override public void onUserSwitching(int newUserId, IRemoteCallback reply) { mUserInfoController.reloadUserInfo(); + if (reply != null) { + try { + reply.sendResult(null); + } catch (RemoteException e) { + } + } } @Override |