diff options
author | Nick Pelly <npelly@google.com> | 2009-09-25 15:00:29 -0700 |
---|---|---|
committer | Nick Pelly <npelly@google.com> | 2009-09-25 15:00:29 -0700 |
commit | 12835478ee687a493d1b5882e67b6725bd539c26 (patch) | |
tree | a9875017a05d51c5bf70c9c8b57638cd17117c59 /core/java/android/server/BluetoothService.java | |
parent | 57a2292bffedaa3fb8f5cd6b0867fdd5772ad3b5 (diff) | |
download | frameworks_base-12835478ee687a493d1b5882e67b6725bd539c26.zip frameworks_base-12835478ee687a493d1b5882e67b6725bd539c26.tar.gz frameworks_base-12835478ee687a493d1b5882e67b6725bd539c26.tar.bz2 |
Handle expiration of discovery mode in system server.
Change-Id: I58fd199b40ffdf8168a5489be8eedb5d25d56722
Diffstat (limited to 'core/java/android/server/BluetoothService.java')
-rw-r--r-- | core/java/android/server/BluetoothService.java | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java index de14b5b..8b9ba84 100644 --- a/core/java/android/server/BluetoothService.java +++ b/core/java/android/server/BluetoothService.java @@ -78,6 +78,7 @@ public class BluetoothService extends IBluetooth.Stub { private static final int MESSAGE_REGISTER_SDP_RECORDS = 1; private static final int MESSAGE_FINISH_DISABLE = 2; private static final int MESSAGE_UUID_INTENT = 3; + private static final int MESSAGE_DISCOVERABLE_TIMEOUT = 4; // The timeout used to sent the UUIDs Intent // This timeout should be greater than the page timeout @@ -308,6 +309,15 @@ public class BluetoothService extends IBluetooth.Stub { if (address != null) sendUuidIntent(address); break; + case MESSAGE_DISCOVERABLE_TIMEOUT: + int mode = msg.arg1; + if (isEnabled()) { + // TODO: Switch back to the previous scan mode + // This is ok for now, because we only use + // CONNECTABLE and CONNECTABLE_DISCOVERABLE + setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE, -1); + } + break; } } }; @@ -679,23 +689,30 @@ public class BluetoothService extends IBluetooth.Stub { return setPropertyInteger("DiscoverableTimeout", timeout); } - public synchronized boolean setScanMode(int mode) { + public synchronized boolean setScanMode(int mode, int duration) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS, "Need WRITE_SECURE_SETTINGS permission"); boolean pairable = false; boolean discoverable = false; + switch (mode) { case BluetoothAdapter.SCAN_MODE_NONE: + mHandler.removeMessages(MESSAGE_DISCOVERABLE_TIMEOUT); pairable = false; discoverable = false; break; case BluetoothAdapter.SCAN_MODE_CONNECTABLE: + mHandler.removeMessages(MESSAGE_DISCOVERABLE_TIMEOUT); pairable = true; discoverable = false; break; case BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE: + mHandler.removeMessages(MESSAGE_DISCOVERABLE_TIMEOUT); pairable = true; discoverable = true; + Message msg = mHandler.obtainMessage(MESSAGE_DISCOVERABLE_TIMEOUT); + mHandler.sendMessageDelayed(msg, duration * 1000); + if (DBG) Log.d(TAG, "BT Discoverable for " + duration + " seconds"); break; default: Log.w(TAG, "Requested invalid scan mode " + mode); |