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/BluetoothInputDevice.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/BluetoothInputDevice.java')
| -rwxr-xr-x | framework/java/android/bluetooth/BluetoothInputDevice.java | 64 |
1 files changed, 60 insertions, 4 deletions
diff --git a/framework/java/android/bluetooth/BluetoothInputDevice.java b/framework/java/android/bluetooth/BluetoothInputDevice.java index 478a9d3b69..bff966d4d2 100755 --- a/framework/java/android/bluetooth/BluetoothInputDevice.java +++ b/framework/java/android/bluetooth/BluetoothInputDevice.java @@ -44,7 +44,7 @@ import java.util.List; */ public final class BluetoothInputDevice implements BluetoothProfile { private static final String TAG = "BluetoothInputDevice"; - private static final boolean DBG = false; + private static final boolean DBG = true; /** * Intent used to broadcast the change in connection state of the Input @@ -186,6 +186,37 @@ public final class BluetoothInputDevice implements BluetoothProfile { private BluetoothAdapter mAdapter; private IBluetoothInputDevice mService; + 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(IBluetoothInputDevice.class.getName()), mConnection, 0)) { + Log.e(TAG, "Could not bind to Bluetooth HID Service"); + } + } + } catch (Exception re) { + Log.e(TAG,"",re); + } + } + } + } + }; + /** * Create a BluetoothInputDevice proxy object for interacting with the local * Bluetooth Service which handles the InputDevice profile @@ -195,6 +226,16 @@ public final class BluetoothInputDevice 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(IBluetoothInputDevice.class.getName()), mConnection, 0)) { Log.e(TAG, "Could not bind to Bluetooth HID Service"); @@ -203,9 +244,24 @@ public final class BluetoothInputDevice 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; } |
