Merge change 27142 into eclair

* changes:
  Handle expiration of discovery mode in system server.
This commit is contained in:
Android (Google) Code Review
2009-09-27 15:42:14 -04:00
3 changed files with 32 additions and 8 deletions

View File

@@ -412,10 +412,10 @@ public final class BluetoothAdapter {
* Set the Bluetooth scan mode of the local Bluetooth adapter.
* <p>The Bluetooth scan mode determines if the local adapter is
* connectable and/or discoverable from remote Bluetooth devices.
* <p>For privacy reasons, it is recommended to limit the duration of time
* that the local adapter remains in a discoverable scan mode. For example,
* 2 minutes is a generous time to allow a remote Bluetooth device to
* initiate and complete its discovery process.
* <p>For privacy reasons, discoverable mode is automatically turned off
* after <code>duration</code> seconds. For example, 120 seconds should be
* enough for a remote device to initiate and complete its discovery
* process.
* <p>Valid scan mode values are:
* {@link #SCAN_MODE_NONE},
* {@link #SCAN_MODE_CONNECTABLE},
@@ -427,16 +427,23 @@ public final class BluetoothAdapter {
* </code>instead.
*
* @param mode valid scan mode
* @param duration time in seconds to apply scan mode, only used for
* {@link #SCAN_MODE_CONNECTABLE_DISCOVERABLE}
* @return true if the scan mode was set, false otherwise
* @hide
*/
public boolean setScanMode(int mode) {
public boolean setScanMode(int mode, int duration) {
try {
return mService.setScanMode(mode);
return mService.setScanMode(mode, duration);
} catch (RemoteException e) {Log.e(TAG, "", e);}
return false;
}
/** @hide */
public boolean setScanMode(int mode) {
return setScanMode(mode, 120);
}
/** @hide */
public int getDiscoverableTimeout() {
try {

View File

@@ -35,7 +35,7 @@ interface IBluetooth
boolean setName(in String name);
int getScanMode();
boolean setScanMode(int mode);
boolean setScanMode(int mode, int duration);
int getDiscoverableTimeout();
boolean setDiscoverableTimeout(int timeout);

View File

@@ -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);