summaryrefslogtreecommitdiffstats
path: root/src/com/android/bluetooth/hdp
diff options
context:
space:
mode:
authorfredc <fredc@broadcom.com>2012-04-12 00:18:52 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-07-16 21:59:14 -0700
commit6654f5c903de510a70f9e72cd5ad7837b615d93f (patch)
tree293e5e07f1b092f37acd4ecada866cd91016f0ff /src/com/android/bluetooth/hdp
parent990b2cd65392bc6db58eda732ad41de22b713202 (diff)
downloadandroid_packages_apps_Bluetooth-6654f5c903de510a70f9e72cd5ad7837b615d93f.tar.gz
android_packages_apps_Bluetooth-6654f5c903de510a70f9e72cd5ad7837b615d93f.tar.bz2
android_packages_apps_Bluetooth-6654f5c903de510a70f9e72cd5ad7837b615d93f.zip
Non persistent adapter service
Change-Id: I65e1c18e2899cea0a1e5c0102c4d24d39dce0249 Conflicts: jni/com_android_bluetooth_hdp.cpp jni/com_android_bluetooth_hid.cpp Conflicts: jni/com_android_bluetooth_hid.cpp
Diffstat (limited to 'src/com/android/bluetooth/hdp')
-rw-r--r--src/com/android/bluetooth/hdp/HealthService.java82
1 files changed, 66 insertions, 16 deletions
diff --git a/src/com/android/bluetooth/hdp/HealthService.java b/src/com/android/bluetooth/hdp/HealthService.java
index 2ae3f65ed..ee6f39051 100644
--- a/src/com/android/bluetooth/hdp/HealthService.java
+++ b/src/com/android/bluetooth/hdp/HealthService.java
@@ -32,6 +32,8 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.android.bluetooth.Utils;
+import android.content.pm.PackageManager;
+import com.android.bluetooth.btservice.AdapterService;
/**
* Provides Bluetooth Health Device profile, as a service in
@@ -67,18 +69,6 @@ public class HealthService extends Service {
@Override
public void onCreate() {
mAdapter = BluetoothAdapter.getDefaultAdapter();
- mHealthChannels = Collections.synchronizedList(new ArrayList<HealthChannel>());
- mApps = Collections.synchronizedMap(new HashMap<BluetoothHealthAppConfiguration,
- AppInfo>());
- mHealthDevices = Collections.synchronizedMap(new HashMap<BluetoothDevice, Integer>());
-
- HandlerThread thread = new HandlerThread("BluetoothHdpHandler");
- thread.start();
- Looper looper = thread.getLooper();
- mHandler = new HealthServiceMessageHandler(looper);
- mAdapterService = IBluetooth.Stub.asInterface(ServiceManager.getService("bluetooth"));
-
- initializeNativeDataNative();
}
@Override
@@ -92,15 +82,74 @@ public class HealthService extends Service {
log("onStart");
if (mAdapter == null) {
Log.w(TAG, "Stopping Bluetooth HealthService: device does not have BT");
- stopSelf();
+ stop();
+ }
+
+ if (checkCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM)!=PackageManager.PERMISSION_GRANTED) {
+ Log.e(TAG, "Permission denied!");
+ return;
+ }
+
+ String action = intent.getStringExtra(AdapterService.EXTRA_ACTION);
+ if (!AdapterService.ACTION_SERVICE_STATE_CHANGED.equals(action)) {
+ Log.e(TAG, "Invalid action " + action);
+ return;
+ }
+
+ int state= intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
+ if(state==BluetoothAdapter.STATE_OFF) {
+ stop();
+ } else if (state== BluetoothAdapter.STATE_ON){
+ start();
}
}
@Override
public void onDestroy() {
super.onDestroy();
- if (DBG) log("Stopping Bluetooth HealthService");
- // TBD
+ if (DBG) log("Destroying service.");
+ }
+
+ private void start() {
+ if (DBG) log("startService");
+ mHealthChannels = Collections.synchronizedList(new ArrayList<HealthChannel>());
+ mApps = Collections.synchronizedMap(new HashMap<BluetoothHealthAppConfiguration,
+ AppInfo>());
+ mHealthDevices = Collections.synchronizedMap(new HashMap<BluetoothDevice, Integer>());
+
+ HandlerThread thread = new HandlerThread("BluetoothHdpHandler");
+ thread.start();
+ Looper looper = thread.getLooper();
+ mHandler = new HealthServiceMessageHandler(looper);
+ mAdapterService = IBluetooth.Stub.asInterface(ServiceManager.getService("bluetooth"));
+ initializeNative();
+
+ //Notify adapter service
+ AdapterService sAdapter = AdapterService.getAdapterService();
+ if (sAdapter!= null) {
+ sAdapter.onProfileServiceStateChanged(getClass().getName(), BluetoothAdapter.STATE_ON);
+ }
+ }
+
+ private void stop() {
+ if (DBG) log("stop()");
+
+ //Cleanup looper
+ Looper looper = mHandler.getLooper();
+ if (looper != null) {
+ looper.quit();
+ }
+
+ //Cleanup native
+ cleanupNative();
+
+ //Notify adapter service
+ AdapterService sAdapter = AdapterService.getAdapterService();
+ if (sAdapter!= null) {
+ sAdapter.onProfileServiceStateChanged(getClass().getName(), BluetoothAdapter.STATE_OFF);
+ }
+ if (DBG) log("stop() done.");
+ stopSelf();
}
private final class HealthServiceMessageHandler extends Handler {
@@ -716,7 +765,8 @@ public class HealthService extends Service {
private static final int CHANNEL_TYPE_ANY =2;
private native static void classInitNative();
- private native void initializeNativeDataNative();
+ private native void initializeNative();
+ private native void cleanupNative();
private native int registerHealthAppNative(int dataType, int role, String name, int channelType);
private native boolean unregisterHealthAppNative(int appId);
private native int connectChannelNative(byte[] btAddress, int appId);