Loading core/java/android/bluetooth/BluetoothDevice.java +17 −7 Original line number Diff line number Diff line Loading @@ -230,6 +230,13 @@ public final class BluetoothDevice implements Parcelable { */ public static final int BATTERY_LEVEL_UNKNOWN = -1; /** * Used as an error value for {@link #getBatteryLevel()} to represent bluetooth is off * * @hide */ public static final int BATTERY_LEVEL_BLUETOOTH_OFF = -100; /** * Used as a Parcelable {@link BluetoothDevice} extra field in every intent * broadcast by this class. It contains the {@link BluetoothDevice} that Loading Loading @@ -1116,9 +1123,9 @@ public final class BluetoothDevice implements Parcelable { /** * Get the most recent identified battery level of this Bluetooth device * * @return Battery level in percents from 0 to 100, or {@link #BATTERY_LEVEL_UNKNOWN} if * Bluetooth is disabled, or device is disconnected, or does not have any battery reporting * service, or return value is invalid * @return Battery level in percents from 0 to 100, {@link #BATTERY_LEVEL_BLUETOOTH_OFF} if * Bluetooth is disabled or {@link #BATTERY_LEVEL_UNKNOWN} if device is disconnected, or does * not have any battery reporting service, or return value is invalid * @hide */ @SystemApi Loading @@ -1127,7 +1134,7 @@ public final class BluetoothDevice implements Parcelable { final IBluetooth service = sService; if (service == null) { Log.e(TAG, "Bluetooth disabled. Cannot get remote device battery level"); return BATTERY_LEVEL_UNKNOWN; return BATTERY_LEVEL_BLUETOOTH_OFF; } try { return service.getBatteryLevel(this); Loading Loading @@ -1731,7 +1738,9 @@ public final class BluetoothDevice implements Parcelable { /** * Sets whether the message access is allowed to this device. * * @param value is the value we are setting the message access permission to * @param value Can be {@link #ACCESS_UNKNOWN} if the device is unbonded, * {@link #ACCESS_ALLOWED} if the permission is being granted, or {@link #ACCESS_REJECTED} if * the permission is not being granted. * @return Whether the value has been successfully set. * @hide */ Loading Loading @@ -1778,8 +1787,9 @@ public final class BluetoothDevice implements Parcelable { /** * Sets whether the Sim access is allowed to this device. * * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link * #ACCESS_REJECTED}. * @param value Can be {@link #ACCESS_UNKNOWN} if the device is unbonded, * {@link #ACCESS_ALLOWED} if the permission is being granted, or {@link #ACCESS_REJECTED} if * the permission is not being granted. * @return Whether the value has been successfully set. * @hide */ Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +13 −11 Original line number Diff line number Diff line Loading @@ -494,7 +494,9 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> /** * Get battery level from remote device * @return battery level in percentage [0-100], or {@link BluetoothDevice#BATTERY_LEVEL_UNKNOWN} * @return battery level in percentage [0-100], * {@link BluetoothDevice#BATTERY_LEVEL_BLUETOOTH_OFF}, or * {@link BluetoothDevice#BATTERY_LEVEL_UNKNOWN} */ public int getBatteryLevel() { return mDevice.getBatteryLevel(); Loading Loading @@ -937,12 +939,12 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> } String batteryLevelPercentageString = null; // Android framework should only set mBatteryLevel to valid range [0-100] or // BluetoothDevice.BATTERY_LEVEL_UNKNOWN, any other value should be a framework bug. // Thus assume here that if value is not BluetoothDevice.BATTERY_LEVEL_UNKNOWN, it must // be valid // Android framework should only set mBatteryLevel to valid range [0-100], // BluetoothDevice.BATTERY_LEVEL_BLUETOOTH_OFF, or BluetoothDevice.BATTERY_LEVEL_UNKNOWN, // any other value should be a framework bug. Thus assume here that if value is greater // than BluetoothDevice.BATTERY_LEVEL_UNKNOWN, it must be valid final int batteryLevel = getBatteryLevel(); if (batteryLevel != BluetoothDevice.BATTERY_LEVEL_UNKNOWN) { if (batteryLevel > BluetoothDevice.BATTERY_LEVEL_UNKNOWN) { // TODO: name com.android.settingslib.bluetooth.Utils something different batteryLevelPercentageString = com.android.settingslib.Utils.formatPercentage(batteryLevel); Loading Loading @@ -1050,12 +1052,12 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> } String batteryLevelPercentageString = null; // Android framework should only set mBatteryLevel to valid range [0-100] or // BluetoothDevice.BATTERY_LEVEL_UNKNOWN, any other value should be a framework bug. // Thus assume here that if value is not BluetoothDevice.BATTERY_LEVEL_UNKNOWN, it must // be valid // Android framework should only set mBatteryLevel to valid range [0-100], // BluetoothDevice.BATTERY_LEVEL_BLUETOOTH_OFF, or BluetoothDevice.BATTERY_LEVEL_UNKNOWN, // any other value should be a framework bug. Thus assume here that if value is greater // than BluetoothDevice.BATTERY_LEVEL_UNKNOWN, it must be valid final int batteryLevel = getBatteryLevel(); if (batteryLevel != BluetoothDevice.BATTERY_LEVEL_UNKNOWN) { if (batteryLevel > BluetoothDevice.BATTERY_LEVEL_UNKNOWN) { // TODO: name com.android.settingslib.bluetooth.Utils something different batteryLevelPercentageString = com.android.settingslib.Utils.formatPercentage(batteryLevel); Loading packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java +2 −2 Original line number Diff line number Diff line Loading @@ -197,7 +197,7 @@ public class BluetoothTile extends QSTileImpl<BooleanState> { CachedBluetoothDevice lastDevice = connectedDevices.get(0); final int batteryLevel = lastDevice.getBatteryLevel(); if (batteryLevel != BluetoothDevice.BATTERY_LEVEL_UNKNOWN) { if (batteryLevel > BluetoothDevice.BATTERY_LEVEL_UNKNOWN) { return mContext.getString( R.string.quick_settings_bluetooth_secondary_label_battery_level, Utils.formatPercentage(batteryLevel)); Loading Loading @@ -390,7 +390,7 @@ public class BluetoothTile extends QSTileImpl<BooleanState> { if (state == BluetoothProfile.STATE_CONNECTED) { item.iconResId = R.drawable.ic_bluetooth_connected; int batteryLevel = device.getBatteryLevel(); if (batteryLevel != BluetoothDevice.BATTERY_LEVEL_UNKNOWN) { if (batteryLevel > BluetoothDevice.BATTERY_LEVEL_UNKNOWN) { item.icon = new BluetoothBatteryTileIcon(batteryLevel,1 /* iconScale */); item.line2 = mContext.getString( R.string.quick_settings_connected_battery_level, Loading Loading
core/java/android/bluetooth/BluetoothDevice.java +17 −7 Original line number Diff line number Diff line Loading @@ -230,6 +230,13 @@ public final class BluetoothDevice implements Parcelable { */ public static final int BATTERY_LEVEL_UNKNOWN = -1; /** * Used as an error value for {@link #getBatteryLevel()} to represent bluetooth is off * * @hide */ public static final int BATTERY_LEVEL_BLUETOOTH_OFF = -100; /** * Used as a Parcelable {@link BluetoothDevice} extra field in every intent * broadcast by this class. It contains the {@link BluetoothDevice} that Loading Loading @@ -1116,9 +1123,9 @@ public final class BluetoothDevice implements Parcelable { /** * Get the most recent identified battery level of this Bluetooth device * * @return Battery level in percents from 0 to 100, or {@link #BATTERY_LEVEL_UNKNOWN} if * Bluetooth is disabled, or device is disconnected, or does not have any battery reporting * service, or return value is invalid * @return Battery level in percents from 0 to 100, {@link #BATTERY_LEVEL_BLUETOOTH_OFF} if * Bluetooth is disabled or {@link #BATTERY_LEVEL_UNKNOWN} if device is disconnected, or does * not have any battery reporting service, or return value is invalid * @hide */ @SystemApi Loading @@ -1127,7 +1134,7 @@ public final class BluetoothDevice implements Parcelable { final IBluetooth service = sService; if (service == null) { Log.e(TAG, "Bluetooth disabled. Cannot get remote device battery level"); return BATTERY_LEVEL_UNKNOWN; return BATTERY_LEVEL_BLUETOOTH_OFF; } try { return service.getBatteryLevel(this); Loading Loading @@ -1731,7 +1738,9 @@ public final class BluetoothDevice implements Parcelable { /** * Sets whether the message access is allowed to this device. * * @param value is the value we are setting the message access permission to * @param value Can be {@link #ACCESS_UNKNOWN} if the device is unbonded, * {@link #ACCESS_ALLOWED} if the permission is being granted, or {@link #ACCESS_REJECTED} if * the permission is not being granted. * @return Whether the value has been successfully set. * @hide */ Loading Loading @@ -1778,8 +1787,9 @@ public final class BluetoothDevice implements Parcelable { /** * Sets whether the Sim access is allowed to this device. * * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link * #ACCESS_REJECTED}. * @param value Can be {@link #ACCESS_UNKNOWN} if the device is unbonded, * {@link #ACCESS_ALLOWED} if the permission is being granted, or {@link #ACCESS_REJECTED} if * the permission is not being granted. * @return Whether the value has been successfully set. * @hide */ Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +13 −11 Original line number Diff line number Diff line Loading @@ -494,7 +494,9 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> /** * Get battery level from remote device * @return battery level in percentage [0-100], or {@link BluetoothDevice#BATTERY_LEVEL_UNKNOWN} * @return battery level in percentage [0-100], * {@link BluetoothDevice#BATTERY_LEVEL_BLUETOOTH_OFF}, or * {@link BluetoothDevice#BATTERY_LEVEL_UNKNOWN} */ public int getBatteryLevel() { return mDevice.getBatteryLevel(); Loading Loading @@ -937,12 +939,12 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> } String batteryLevelPercentageString = null; // Android framework should only set mBatteryLevel to valid range [0-100] or // BluetoothDevice.BATTERY_LEVEL_UNKNOWN, any other value should be a framework bug. // Thus assume here that if value is not BluetoothDevice.BATTERY_LEVEL_UNKNOWN, it must // be valid // Android framework should only set mBatteryLevel to valid range [0-100], // BluetoothDevice.BATTERY_LEVEL_BLUETOOTH_OFF, or BluetoothDevice.BATTERY_LEVEL_UNKNOWN, // any other value should be a framework bug. Thus assume here that if value is greater // than BluetoothDevice.BATTERY_LEVEL_UNKNOWN, it must be valid final int batteryLevel = getBatteryLevel(); if (batteryLevel != BluetoothDevice.BATTERY_LEVEL_UNKNOWN) { if (batteryLevel > BluetoothDevice.BATTERY_LEVEL_UNKNOWN) { // TODO: name com.android.settingslib.bluetooth.Utils something different batteryLevelPercentageString = com.android.settingslib.Utils.formatPercentage(batteryLevel); Loading Loading @@ -1050,12 +1052,12 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> } String batteryLevelPercentageString = null; // Android framework should only set mBatteryLevel to valid range [0-100] or // BluetoothDevice.BATTERY_LEVEL_UNKNOWN, any other value should be a framework bug. // Thus assume here that if value is not BluetoothDevice.BATTERY_LEVEL_UNKNOWN, it must // be valid // Android framework should only set mBatteryLevel to valid range [0-100], // BluetoothDevice.BATTERY_LEVEL_BLUETOOTH_OFF, or BluetoothDevice.BATTERY_LEVEL_UNKNOWN, // any other value should be a framework bug. Thus assume here that if value is greater // than BluetoothDevice.BATTERY_LEVEL_UNKNOWN, it must be valid final int batteryLevel = getBatteryLevel(); if (batteryLevel != BluetoothDevice.BATTERY_LEVEL_UNKNOWN) { if (batteryLevel > BluetoothDevice.BATTERY_LEVEL_UNKNOWN) { // TODO: name com.android.settingslib.bluetooth.Utils something different batteryLevelPercentageString = com.android.settingslib.Utils.formatPercentage(batteryLevel); Loading
packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java +2 −2 Original line number Diff line number Diff line Loading @@ -197,7 +197,7 @@ public class BluetoothTile extends QSTileImpl<BooleanState> { CachedBluetoothDevice lastDevice = connectedDevices.get(0); final int batteryLevel = lastDevice.getBatteryLevel(); if (batteryLevel != BluetoothDevice.BATTERY_LEVEL_UNKNOWN) { if (batteryLevel > BluetoothDevice.BATTERY_LEVEL_UNKNOWN) { return mContext.getString( R.string.quick_settings_bluetooth_secondary_label_battery_level, Utils.formatPercentage(batteryLevel)); Loading Loading @@ -390,7 +390,7 @@ public class BluetoothTile extends QSTileImpl<BooleanState> { if (state == BluetoothProfile.STATE_CONNECTED) { item.iconResId = R.drawable.ic_bluetooth_connected; int batteryLevel = device.getBatteryLevel(); if (batteryLevel != BluetoothDevice.BATTERY_LEVEL_UNKNOWN) { if (batteryLevel > BluetoothDevice.BATTERY_LEVEL_UNKNOWN) { item.icon = new BluetoothBatteryTileIcon(batteryLevel,1 /* iconScale */); item.line2 = mContext.getString( R.string.quick_settings_connected_battery_level, Loading