summaryrefslogtreecommitdiffstats
path: root/core/java/android/server
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-09 11:52:12 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-09 11:52:12 -0700
commitb2a3dd88a53cc8c6d19f6dc8ec4f3d6c4abd9b54 (patch)
treee167affc928677f3dd70e173150a77e3943e97a9 /core/java/android/server
parentf5b4b98fada53d91c4c2ebeb5a1d33ccc95c94d2 (diff)
downloadframeworks_base-b2a3dd88a53cc8c6d19f6dc8ec4f3d6c4abd9b54.zip
frameworks_base-b2a3dd88a53cc8c6d19f6dc8ec4f3d6c4abd9b54.tar.gz
frameworks_base-b2a3dd88a53cc8c6d19f6dc8ec4f3d6c4abd9b54.tar.bz2
auto import from //branches/cupcake/...@137197
Diffstat (limited to 'core/java/android/server')
-rw-r--r--core/java/android/server/BluetoothDeviceService.java33
-rw-r--r--core/java/android/server/BluetoothEventLoop.java9
2 files changed, 37 insertions, 5 deletions
diff --git a/core/java/android/server/BluetoothDeviceService.java b/core/java/android/server/BluetoothDeviceService.java
index 87153cf..6f5513a 100644
--- a/core/java/android/server/BluetoothDeviceService.java
+++ b/core/java/android/server/BluetoothDeviceService.java
@@ -237,7 +237,28 @@ public class BluetoothDeviceService extends IBluetoothDevice.Stub {
public void run() {
boolean res = (enableNative() == 0);
if (res) {
- mEventLoop.start();
+ int retryCount = 2;
+ boolean running = false;
+ while ((retryCount-- > 0) && !running) {
+ mEventLoop.start();
+ // it may take a momement for the other thread to do its
+ // thing. Check periodically for a while.
+ int pollCount = 5;
+ while ((pollCount-- > 0) && !running) {
+ if (mEventLoop.isEventLoopRunning()) {
+ running = true;
+ break;
+ }
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {}
+ }
+ }
+ if (!running) {
+ log("bt EnableThread giving up");
+ res = false;
+ disableNative();
+ }
}
if (mEnableCallback != null) {
@@ -254,14 +275,20 @@ public class BluetoothDeviceService extends IBluetoothDevice.Stub {
persistBluetoothOnSetting(true);
}
mIsDiscovering = false;
- Intent intent = new Intent(BluetoothIntent.ENABLED_ACTION);
mBondState.loadBondState();
- mContext.sendBroadcast(intent, BLUETOOTH_PERM);
mHandler.sendMessageDelayed(mHandler.obtainMessage(REGISTER_SDP_RECORDS), 3000);
// Update mode
mEventLoop.onModeChanged(getModeNative());
}
+ Intent intent = null;
+ if (res) {
+ intent = new Intent(BluetoothIntent.ENABLED_ACTION);
+ } else {
+ intent = new Intent(BluetoothIntent.DISABLED_ACTION);
+ }
+ mContext.sendBroadcast(intent, BLUETOOTH_PERM);
+
mEnableThread = null;
}
}
diff --git a/core/java/android/server/BluetoothEventLoop.java b/core/java/android/server/BluetoothEventLoop.java
index 8b09583..e4ebcca 100644
--- a/core/java/android/server/BluetoothEventLoop.java
+++ b/core/java/android/server/BluetoothEventLoop.java
@@ -44,6 +44,7 @@ class BluetoothEventLoop {
private int mNativeData;
private Thread mThread;
+ private boolean mStarted;
private boolean mInterrupted;
private HashMap<String, Integer> mPasskeyAgentRequestData;
private HashMap<String, IBluetoothDeviceCallback> mGetRemoteServiceChannelCallbacks;
@@ -122,14 +123,18 @@ class BluetoothEventLoop {
public void run() {
try {
if (setUpEventLoopNative()) {
+ mStarted = true;
while (!mInterrupted) {
waitForAndDispatchEvent(0);
sleep(500);
}
- tearDownEventLoopNative();
}
+ // tear down even in the error case to clean
+ // up anything we started to setup
+ tearDownEventLoopNative();
} catch (InterruptedException e) { }
if (DBG) log("Event Loop thread finished");
+ mThread = null;
}
};
if (DBG) log("Starting Event Loop thread");
@@ -152,7 +157,7 @@ class BluetoothEventLoop {
}
public synchronized boolean isEventLoopRunning() {
- return mThread != null;
+ return mThread != null && mStarted;
}
/*package*/ void onModeChanged(String bluezMode) {