Merge change 27142 into eclair
* changes: Handle expiration of discovery mode in system server.
This commit is contained in:
@@ -412,10 +412,10 @@ public final class BluetoothAdapter {
|
|||||||
* Set the Bluetooth scan mode of the local Bluetooth adapter.
|
* Set the Bluetooth scan mode of the local Bluetooth adapter.
|
||||||
* <p>The Bluetooth scan mode determines if the local adapter is
|
* <p>The Bluetooth scan mode determines if the local adapter is
|
||||||
* connectable and/or discoverable from remote Bluetooth devices.
|
* connectable and/or discoverable from remote Bluetooth devices.
|
||||||
* <p>For privacy reasons, it is recommended to limit the duration of time
|
* <p>For privacy reasons, discoverable mode is automatically turned off
|
||||||
* that the local adapter remains in a discoverable scan mode. For example,
|
* after <code>duration</code> seconds. For example, 120 seconds should be
|
||||||
* 2 minutes is a generous time to allow a remote Bluetooth device to
|
* enough for a remote device to initiate and complete its discovery
|
||||||
* initiate and complete its discovery process.
|
* process.
|
||||||
* <p>Valid scan mode values are:
|
* <p>Valid scan mode values are:
|
||||||
* {@link #SCAN_MODE_NONE},
|
* {@link #SCAN_MODE_NONE},
|
||||||
* {@link #SCAN_MODE_CONNECTABLE},
|
* {@link #SCAN_MODE_CONNECTABLE},
|
||||||
@@ -427,16 +427,23 @@ public final class BluetoothAdapter {
|
|||||||
* </code>instead.
|
* </code>instead.
|
||||||
*
|
*
|
||||||
* @param mode valid scan mode
|
* @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
|
* @return true if the scan mode was set, false otherwise
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public boolean setScanMode(int mode) {
|
public boolean setScanMode(int mode, int duration) {
|
||||||
try {
|
try {
|
||||||
return mService.setScanMode(mode);
|
return mService.setScanMode(mode, duration);
|
||||||
} catch (RemoteException e) {Log.e(TAG, "", e);}
|
} catch (RemoteException e) {Log.e(TAG, "", e);}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @hide */
|
||||||
|
public boolean setScanMode(int mode) {
|
||||||
|
return setScanMode(mode, 120);
|
||||||
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public int getDiscoverableTimeout() {
|
public int getDiscoverableTimeout() {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ interface IBluetooth
|
|||||||
boolean setName(in String name);
|
boolean setName(in String name);
|
||||||
|
|
||||||
int getScanMode();
|
int getScanMode();
|
||||||
boolean setScanMode(int mode);
|
boolean setScanMode(int mode, int duration);
|
||||||
|
|
||||||
int getDiscoverableTimeout();
|
int getDiscoverableTimeout();
|
||||||
boolean setDiscoverableTimeout(int timeout);
|
boolean setDiscoverableTimeout(int timeout);
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ public class BluetoothService extends IBluetooth.Stub {
|
|||||||
private static final int MESSAGE_REGISTER_SDP_RECORDS = 1;
|
private static final int MESSAGE_REGISTER_SDP_RECORDS = 1;
|
||||||
private static final int MESSAGE_FINISH_DISABLE = 2;
|
private static final int MESSAGE_FINISH_DISABLE = 2;
|
||||||
private static final int MESSAGE_UUID_INTENT = 3;
|
private static final int MESSAGE_UUID_INTENT = 3;
|
||||||
|
private static final int MESSAGE_DISCOVERABLE_TIMEOUT = 4;
|
||||||
|
|
||||||
// The timeout used to sent the UUIDs Intent
|
// The timeout used to sent the UUIDs Intent
|
||||||
// This timeout should be greater than the page timeout
|
// This timeout should be greater than the page timeout
|
||||||
@@ -308,6 +309,15 @@ public class BluetoothService extends IBluetooth.Stub {
|
|||||||
if (address != null)
|
if (address != null)
|
||||||
sendUuidIntent(address);
|
sendUuidIntent(address);
|
||||||
break;
|
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);
|
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,
|
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS,
|
||||||
"Need WRITE_SECURE_SETTINGS permission");
|
"Need WRITE_SECURE_SETTINGS permission");
|
||||||
boolean pairable = false;
|
boolean pairable = false;
|
||||||
boolean discoverable = false;
|
boolean discoverable = false;
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case BluetoothAdapter.SCAN_MODE_NONE:
|
case BluetoothAdapter.SCAN_MODE_NONE:
|
||||||
|
mHandler.removeMessages(MESSAGE_DISCOVERABLE_TIMEOUT);
|
||||||
pairable = false;
|
pairable = false;
|
||||||
discoverable = false;
|
discoverable = false;
|
||||||
break;
|
break;
|
||||||
case BluetoothAdapter.SCAN_MODE_CONNECTABLE:
|
case BluetoothAdapter.SCAN_MODE_CONNECTABLE:
|
||||||
|
mHandler.removeMessages(MESSAGE_DISCOVERABLE_TIMEOUT);
|
||||||
pairable = true;
|
pairable = true;
|
||||||
discoverable = false;
|
discoverable = false;
|
||||||
break;
|
break;
|
||||||
case BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE:
|
case BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE:
|
||||||
|
mHandler.removeMessages(MESSAGE_DISCOVERABLE_TIMEOUT);
|
||||||
pairable = true;
|
pairable = true;
|
||||||
discoverable = 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;
|
break;
|
||||||
default:
|
default:
|
||||||
Log.w(TAG, "Requested invalid scan mode " + mode);
|
Log.w(TAG, "Requested invalid scan mode " + mode);
|
||||||
|
|||||||
Reference in New Issue
Block a user