diff options
author | Nitin Shivpure <nshivpur@codeaurora.org> | 2013-12-12 20:03:49 +0530 |
---|---|---|
committer | Steve Kondik <shade@chemlab.org> | 2014-01-05 13:26:46 -0800 |
commit | 20b8be0589e2a118720af5bedcf9e8fde96d7a3c (patch) | |
tree | eed10056a2bbf172ca48b307aa4af944c9efcc89 | |
parent | eeef98b92d7e9d7760e53359c217a1c3e77dfa80 (diff) | |
download | android_frameworks_base-next.tar.gz android_frameworks_base-next.tar.bz2 android_frameworks_base-next.zip |
Bluetooth: Fix to avoid framework reboot during monkey.next
A case where monkey is running & sometimes framework is
disconnected due to unhandled java Exception during the
binding of DUN, SAP, HID device & PAN service on unsuccessful
binding. So it never handled. Handing java exception while binding
DUN, SAP, HID device & PAN services to solve this issue.
Change-Id: Idea710593a3f9496305f636042605303e73e7749
CRs-Fixed: 564709
-rw-r--r-- | core/java/android/bluetooth/BluetoothDun.java | 33 | ||||
-rw-r--r-- | core/java/android/bluetooth/BluetoothHidDevice.java | 32 | ||||
-rw-r--r-- | core/java/android/bluetooth/BluetoothPan.java | 17 | ||||
-rw-r--r-- | core/java/android/bluetooth/BluetoothSap.java | 32 |
4 files changed, 79 insertions, 35 deletions
diff --git a/core/java/android/bluetooth/BluetoothDun.java b/core/java/android/bluetooth/BluetoothDun.java index 37fc34a4299..aa906d3781f 100644 --- a/core/java/android/bluetooth/BluetoothDun.java +++ b/core/java/android/bluetooth/BluetoothDun.java @@ -98,13 +98,21 @@ public final class BluetoothDun implements BluetoothProfile { Log.w(TAG,"Unable to register BluetoothStateChangeCallback",re); } Log.d(TAG, "BluetoothDun() call bindService"); - if (!context.bindService(new Intent(IBluetoothDun.class.getName()), - mConnection, 0)) { - Log.e(TAG, "Could not bind to Bluetooth DUN Service"); + doBind(); + } + + boolean doBind() { + Intent intent = new Intent(IBluetoothDun.class.getName()); + ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0); + intent.setComponent(comp); + if (comp == null || !mContext.bindService(intent, mConnection, 0)) { + Log.e(TAG, "Could not bind to Bluetooth Dun Service with " + intent); + return false; } - Log.d(TAG, "BluetoothDun(), bindService called"); + return true; } + /*package*/ void close() { if (VDBG) log("close()"); mServiceListener = null; @@ -137,15 +145,20 @@ public final class BluetoothDun implements BluetoothProfile { new IBluetoothStateChangeCallback.Stub() { @Override - public void onBluetoothStateChange(boolean on) throws RemoteException { + public void onBluetoothStateChange(boolean on) { //Handle enable request to bind again. + Log.d(TAG, "onBluetoothStateChange on: " + on); if (on) { - Log.d(TAG, "onBluetoothStateChange(on) call bindService"); - if (!mContext.bindService(new Intent(IBluetoothDun.class.getName()), - mConnection, 0)) { - Log.e(TAG, "Could not bind to Bluetooth DUN Service"); + try { + if (mDunService == null) { + Log.d(TAG, "onBluetoothStateChange call bindService"); + doBind(); + } + } catch (IllegalStateException e) { + Log.e(TAG,"onBluetoothStateChange: could not bind to DUN service: ", e); + } catch (SecurityException e) { + Log.e(TAG,"onBluetoothStateChange: could not bind to DUN service: ", e); } - Log.d(TAG, "BluetoothDun(), bindService called"); } else { if (VDBG) Log.d(TAG,"Unbinding service..."); synchronized (mConnection) { diff --git a/core/java/android/bluetooth/BluetoothHidDevice.java b/core/java/android/bluetooth/BluetoothHidDevice.java index 79bcbe69de8..eee0c68c67e 100644 --- a/core/java/android/bluetooth/BluetoothHidDevice.java +++ b/core/java/android/bluetooth/BluetoothHidDevice.java @@ -136,18 +136,21 @@ public final class BluetoothHidDevice implements BluetoothProfile { public void onBluetoothStateChange(boolean up) { Log.d(TAG, "onBluetoothStateChange: up=" + up); - synchronized (mConnection) { if (!up) { + Log.d(TAG,"Unbinding service..."); mService = null; mContext.unbindService(mConnection); } else { - if (mService == null) { - Log.v(TAG, "Binding service"); - if (!mContext.bindService(new Intent(IBluetoothHidDevice.class.getName()), - mConnection, 0)) { - Log.e(TAG, "Could not bind service"); + try { + if (mService == null) { + Log.d(TAG,"Binding HID Device service..."); + doBind(); } + } catch (IllegalStateException e) { + Log.e(TAG,"onBluetoothStateChange: could not bind to HID Dev service: ", e); + } catch (SecurityException e) { + Log.e(TAG,"onBluetoothStateChange: could not bind to HID Dev service: ", e); } } } @@ -179,7 +182,7 @@ public final class BluetoothHidDevice implements BluetoothProfile { }; BluetoothHidDevice(Context context, ServiceListener listener) { - Log.v(TAG, "BluetoothInputDevice()"); + Log.v(TAG, "BluetoothHidDevice"); mContext = context; mServiceListener = listener; @@ -194,10 +197,19 @@ public final class BluetoothHidDevice implements BluetoothProfile { } } - if (!context.bindService(new Intent(IBluetoothHidDevice.class.getName()), - mConnection, 0)) { - Log.e(TAG, "Could not bind service"); + doBind(); + } + + boolean doBind() { + Intent intent = new Intent(IBluetoothHidDevice.class.getName()); + ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0); + intent.setComponent(comp); + if (comp == null || !mContext.bindService(intent, mConnection, 0)) { + Log.e(TAG, "Could not bind to Bluetooth HID Device Service with " + intent); + return false; } + Log.d(TAG, "Bound to HID Device Service"); + return true; } void close() { diff --git a/core/java/android/bluetooth/BluetoothPan.java b/core/java/android/bluetooth/BluetoothPan.java index b7a37f42b3f..cbb43483a08 100644 --- a/core/java/android/bluetooth/BluetoothPan.java +++ b/core/java/android/bluetooth/BluetoothPan.java @@ -139,7 +139,6 @@ public final class BluetoothPan implements BluetoothProfile { } if (VDBG) Log.d(TAG, "BluetoothPan() call bindService"); doBind(); - if (VDBG) Log.d(TAG, "BluetoothPan(), bindService called"); } boolean doBind() { @@ -185,12 +184,20 @@ public final class BluetoothPan implements BluetoothProfile { final private IBluetoothStateChangeCallback mStateChangeCallback = new IBluetoothStateChangeCallback.Stub() { @Override - public void onBluetoothStateChange(boolean on) throws RemoteException { + public void onBluetoothStateChange(boolean on) { //Handle enable request to bind again. + Log.d(TAG, "onBluetoothStateChange on: " + on); if (on) { - Log.d(TAG, "onBluetoothStateChange(on) call bindService"); - doBind(); - if (VDBG) Log.d(TAG, "BluetoothPan(), bindService called"); + try { + if (mPanService == null) { + Log.d(TAG, "onBluetoothStateChange call bindService"); + doBind(); + } + } catch (IllegalStateException e) { + Log.e(TAG,"onBluetoothStateChange: could not bind to PAN service: ", e); + } catch (SecurityException e) { + Log.e(TAG,"onBluetoothStateChange: could not bind to PAN service: ", e); + } } else { if (VDBG) Log.d(TAG,"Unbinding service..."); synchronized (mConnection) { diff --git a/core/java/android/bluetooth/BluetoothSap.java b/core/java/android/bluetooth/BluetoothSap.java index 4f71e6e8402..5e36fb24568 100644 --- a/core/java/android/bluetooth/BluetoothSap.java +++ b/core/java/android/bluetooth/BluetoothSap.java @@ -98,11 +98,18 @@ public final class BluetoothSap implements BluetoothProfile { Log.w(TAG,"Unable to register BluetoothStateChangeCallback",re); } Log.d(TAG, "BluetoothSap() call bindService"); - if (!context.bindService(new Intent(IBluetoothSap.class.getName()), - mConnection, 0)) { - Log.e(TAG, "Could not bind to Bluetooth SAP Service"); + doBind(); + } + + boolean doBind() { + Intent intent = new Intent(IBluetoothSap.class.getName()); + ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0); + intent.setComponent(comp); + if (comp == null || !mContext.bindService(intent, mConnection, 0)) { + Log.e(TAG, "Could not bind to Bluetooth Sap Service with " + intent); + return false; } - Log.d(TAG, "BluetoothSap(), bindService called"); + return true; } /*package*/ void close() { @@ -137,15 +144,20 @@ public final class BluetoothSap implements BluetoothProfile { private IBluetoothStateChangeCallback mStateChangeCallback = new IBluetoothStateChangeCallback.Stub() { @Override - public void onBluetoothStateChange(boolean on) throws RemoteException { + public void onBluetoothStateChange(boolean on) { //Handle enable request to bind again. + Log.d(TAG, "onBluetoothStateChange on: " + on); if (on) { - Log.d(TAG, "onBluetoothStateChange(on) call bindService"); - if (!mContext.bindService(new Intent(IBluetoothSap.class.getName()), - mConnection, 0)) { - Log.e(TAG, "Could not bind to Bluetooth SAP Service"); + try { + if (mSapService == null) { + Log.d(TAG, "onBluetoothStateChange call bindService"); + doBind(); + } + } catch (IllegalStateException e) { + Log.e(TAG,"onBluetoothStateChange: could not bind to SAP service: ", e); + } catch (SecurityException e) { + Log.e(TAG,"onBluetoothStateChange: could not bind to SAP service: ", e); } - Log.d(TAG, "BluetoothSap(), bindService called"); } else { if (VDBG) Log.d(TAG,"Unbinding service..."); synchronized (mConnection) { |