Update code for new BT APIs.
Change-Id: I53aa17b6c2a5ee50d47df91960a7f997eb7b1107
This commit is contained in:
@@ -18,6 +18,7 @@ package com.android.internal.os;
|
||||
|
||||
import com.android.internal.util.JournaledFile;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothHeadset;
|
||||
import android.net.TrafficStats;
|
||||
import android.os.BatteryManager;
|
||||
@@ -50,6 +51,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@@ -1150,7 +1152,11 @@ public final class BatteryStatsImpl extends BatteryStats {
|
||||
|
||||
private int getCurrentBluetoothPingCount() {
|
||||
if (mBtHeadset != null) {
|
||||
return mBtHeadset.getBatteryUsageHint();
|
||||
Set<BluetoothDevice> deviceSet = mBtHeadset.getConnectedDevices();
|
||||
BluetoothDevice[] devices = deviceSet.toArray(new BluetoothDevice[deviceSet.size()]);
|
||||
if (devices.length > 0) {
|
||||
return mBtHeadset.getBatteryUsageHint(devices[0]);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
|
||||
package com.android.server.am;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothHeadset;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.Context;
|
||||
import android.os.Binder;
|
||||
import android.os.IBinder;
|
||||
@@ -43,6 +45,8 @@ public final class BatteryStatsService extends IBatteryStats.Stub {
|
||||
|
||||
final BatteryStatsImpl mStats;
|
||||
Context mContext;
|
||||
private boolean mBluetoothPendingStats;
|
||||
private BluetoothHeadset mBluetoothHeadset;
|
||||
|
||||
BatteryStatsService(String filename) {
|
||||
mStats = new BatteryStatsImpl(filename);
|
||||
@@ -283,16 +287,43 @@ public final class BatteryStatsService extends IBatteryStats.Stub {
|
||||
|
||||
public void noteBluetoothOn() {
|
||||
enforceCallingPermission();
|
||||
BluetoothHeadset headset = new BluetoothHeadset(mContext, null);
|
||||
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (adapter != null) {
|
||||
adapter.getProfileProxy(mContext, mBluetoothProfileServiceListener,
|
||||
BluetoothProfile.HEADSET);
|
||||
}
|
||||
synchronized (mStats) {
|
||||
mStats.noteBluetoothOnLocked();
|
||||
mStats.setBtHeadset(headset);
|
||||
if (mBluetoothHeadset != null) {
|
||||
mStats.noteBluetoothOnLocked();
|
||||
mStats.setBtHeadset(mBluetoothHeadset);
|
||||
} else {
|
||||
mBluetoothPendingStats = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private BluetoothProfile.ServiceListener mBluetoothProfileServiceListener =
|
||||
new BluetoothProfile.ServiceListener() {
|
||||
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
||||
mBluetoothHeadset = (BluetoothHeadset) proxy;
|
||||
synchronized (mStats) {
|
||||
if (mBluetoothPendingStats) {
|
||||
mStats.noteBluetoothOnLocked();
|
||||
mStats.setBtHeadset(mBluetoothHeadset);
|
||||
mBluetoothPendingStats = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onServiceDisconnected(int profile) {
|
||||
mBluetoothHeadset = null;
|
||||
}
|
||||
};
|
||||
|
||||
public void noteBluetoothOff() {
|
||||
enforceCallingPermission();
|
||||
synchronized (mStats) {
|
||||
mBluetoothPendingStats = false;
|
||||
mStats.noteBluetoothOffLocked();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user