diff options
author | fredc <fredc@broadcom.com> | 2012-04-12 00:02:00 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-07-16 21:20:54 -0700 |
commit | 3c7196448a62414bf1bfcc94947bfcfa2d60278a (patch) | |
tree | 8c6be2ed45eeadc53202eb7956519f9b96808b6b /framework/java/android/bluetooth/BluetoothHealth.java | |
parent | a5d5a9c3c2dd28a5bd5a719af0a52f5e5a03f6e1 (diff) |
Non persistent adapter service
Change-Id: Ib13d5c77416e58161df0e04d7a15ec0dddbde8b5
Conflicts:
core/java/android/bluetooth/BluetoothInputDevice.java
Conflicts:
core/java/com/android/internal/app/ShutdownThread.java
services/java/com/android/server/SystemServer.java
Conflicts:
services/java/com/android/server/SystemServer.java
services/java/com/android/server/pm/ShutdownThread.java
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothHealth.java')
-rw-r--r-- | framework/java/android/bluetooth/BluetoothHealth.java | 63 |
1 files changed, 59 insertions, 4 deletions
diff --git a/framework/java/android/bluetooth/BluetoothHealth.java b/framework/java/android/bluetooth/BluetoothHealth.java index 5dad291c1a..4a0bc7e37a 100644 --- a/framework/java/android/bluetooth/BluetoothHealth.java +++ b/framework/java/android/bluetooth/BluetoothHealth.java @@ -57,7 +57,7 @@ import java.util.List; */ public final class BluetoothHealth implements BluetoothProfile { private static final String TAG = "BluetoothHealth"; - private static final boolean DBG = false; + private static final boolean DBG = true; /** * Health Profile Source Role - the health device. @@ -97,6 +97,37 @@ public final class BluetoothHealth implements BluetoothProfile { /** @hide */ public static final int HEALTH_OPERATION_NOT_ALLOWED = 6005; + final private IBluetoothStateChangeCallback mBluetoothStateChangeCallback = + new IBluetoothStateChangeCallback.Stub() { + public void onBluetoothStateChange(boolean up) { + if (DBG) Log.d(TAG, "onBluetoothStateChange: up=" + up); + if (!up) { + if (DBG) Log.d(TAG,"Unbinding service..."); + synchronized (mConnection) { + try { + mService = null; + mContext.unbindService(mConnection); + } catch (Exception re) { + Log.e(TAG,"",re); + } + } + } else { + synchronized (mConnection) { + try { + if (mService == null) { + if (DBG) Log.d(TAG,"Binding service..."); + if (!mContext.bindService(new Intent(IBluetoothHealth.class.getName()), mConnection, 0)) { + Log.e(TAG, "Could not bind to Bluetooth Health Service"); + } + } + } catch (Exception re) { + Log.e(TAG,"",re); + } + } + } + } + }; + /** * Register an application configuration that acts as a Health SINK. @@ -442,6 +473,15 @@ public final class BluetoothHealth implements BluetoothProfile { mContext = context; mServiceListener = l; mAdapter = BluetoothAdapter.getDefaultAdapter(); + IBluetoothManager mgr = mAdapter.getBluetoothManager(); + if (mgr != null) { + try { + mgr.registerStateChangeCallback(mBluetoothStateChangeCallback); + } catch (RemoteException e) { + Log.e(TAG,"",e); + } + } + if (!context.bindService(new Intent(IBluetoothHealth.class.getName()), mConnection, 0)) { Log.e(TAG, "Could not bind to Bluetooth Health Service"); } @@ -449,9 +489,24 @@ public final class BluetoothHealth implements BluetoothProfile { /*package*/ void close() { if (DBG) log("close()"); - if (mConnection != null) { - mContext.unbindService(mConnection); - mConnection = null; + IBluetoothManager mgr = mAdapter.getBluetoothManager(); + if (mgr != null) { + try { + mgr.unregisterStateChangeCallback(mBluetoothStateChangeCallback); + } catch (Exception e) { + Log.e(TAG,"",e); + } + } + + synchronized (mConnection) { + if (mService != null) { + try { + mService = null; + mContext.unbindService(mConnection); + } catch (Exception re) { + Log.e(TAG,"",re); + } + } } mServiceListener = null; } |