summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorJaikumar Ganesh <jaikumar@google.com>2010-09-27 17:02:23 -0700
committerJaikumar Ganesh <jaikumar@google.com>2010-09-28 20:02:12 -0700
commit3f03496ad97b5f60ab432bca2d17a3e07b4ade47 (patch)
tree23eaeae5b07ad5cd38a908f354480567d7d0f63e /services
parent96a79830ea1ae3ab3d6d3cce2bd1397fcd40ea0e (diff)
downloadframeworks_base-3f03496ad97b5f60ab432bca2d17a3e07b4ade47.zip
frameworks_base-3f03496ad97b5f60ab432bca2d17a3e07b4ade47.tar.gz
frameworks_base-3f03496ad97b5f60ab432bca2d17a3e07b4ade47.tar.bz2
Update code for new BT APIs.
Change-Id: I53aa17b6c2a5ee50d47df91960a7f997eb7b1107
Diffstat (limited to 'services')
-rw-r--r--services/java/com/android/server/am/BatteryStatsService.java39
1 files changed, 35 insertions, 4 deletions
diff --git a/services/java/com/android/server/am/BatteryStatsService.java b/services/java/com/android/server/am/BatteryStatsService.java
index 73a5435..0a98ebd 100644
--- a/services/java/com/android/server/am/BatteryStatsService.java
+++ b/services/java/com/android/server/am/BatteryStatsService.java
@@ -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();
}
}