Merge "Change data type of duration param from int representing seconds to long representing milliseconds in BluetoothAdapter#setScanMode"
This commit is contained in:
@@ -1306,8 +1306,8 @@ package android.bluetooth {
|
|||||||
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean removeActiveDevice(int);
|
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean removeActiveDevice(int);
|
||||||
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean removeOnMetadataChangedListener(@NonNull android.bluetooth.BluetoothDevice, @NonNull android.bluetooth.BluetoothAdapter.OnMetadataChangedListener);
|
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean removeOnMetadataChangedListener(@NonNull android.bluetooth.BluetoothDevice, @NonNull android.bluetooth.BluetoothAdapter.OnMetadataChangedListener);
|
||||||
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean setActiveDevice(@NonNull android.bluetooth.BluetoothDevice, int);
|
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean setActiveDevice(@NonNull android.bluetooth.BluetoothDevice, int);
|
||||||
method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public boolean setScanMode(int, int);
|
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean setScanMode(int, long);
|
||||||
method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public boolean setScanMode(int);
|
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean setScanMode(int);
|
||||||
field public static final String ACTION_BLE_STATE_CHANGED = "android.bluetooth.adapter.action.BLE_STATE_CHANGED";
|
field public static final String ACTION_BLE_STATE_CHANGED = "android.bluetooth.adapter.action.BLE_STATE_CHANGED";
|
||||||
field public static final String ACTION_REQUEST_BLE_SCAN_ALWAYS_AVAILABLE = "android.bluetooth.adapter.action.REQUEST_BLE_SCAN_ALWAYS_AVAILABLE";
|
field public static final String ACTION_REQUEST_BLE_SCAN_ALWAYS_AVAILABLE = "android.bluetooth.adapter.action.REQUEST_BLE_SCAN_ALWAYS_AVAILABLE";
|
||||||
field public static final int ACTIVE_DEVICE_ALL = 2; // 0x2
|
field public static final int ACTIVE_DEVICE_ALL = 2; // 0x2
|
||||||
|
|||||||
@@ -1485,9 +1485,8 @@ public final class BluetoothAdapter {
|
|||||||
* <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, discoverable mode is automatically turned off
|
* <p>For privacy reasons, discoverable mode is automatically turned off
|
||||||
* after <code>duration</code> seconds. For example, 120 seconds should be
|
* after <code>durationMillis</code> milliseconds. For example, 120000 milliseconds should be
|
||||||
* enough for a remote device to initiate and complete its discovery
|
* enough for a remote device to 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},
|
||||||
@@ -1502,24 +1501,29 @@ 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
|
* @param durationMillis time in milliseconds to apply scan mode, only used for {@link
|
||||||
* #SCAN_MODE_CONNECTABLE_DISCOVERABLE}
|
* #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
|
||||||
*/
|
*/
|
||||||
@SystemApi
|
@SystemApi
|
||||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
@RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
|
||||||
public boolean setScanMode(@ScanMode int mode, int duration) {
|
public boolean setScanMode(@ScanMode int mode, long durationMillis) {
|
||||||
if (getState() != STATE_ON) {
|
if (getState() != STATE_ON) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
mServiceLock.readLock().lock();
|
mServiceLock.readLock().lock();
|
||||||
if (mService != null) {
|
if (mService != null) {
|
||||||
return mService.setScanMode(mode, duration);
|
int durationSeconds = Math.toIntExact(durationMillis / 1000);
|
||||||
|
return mService.setScanMode(mode, durationSeconds);
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "", e);
|
Log.e(TAG, "", e);
|
||||||
|
} catch (ArithmeticException ex) {
|
||||||
|
Log.e(TAG, "setScanMode: Duration in seconds outside of the bounds of an int");
|
||||||
|
throw new IllegalArgumentException("Duration not in bounds. In seconds, the "
|
||||||
|
+ "durationMillis must be in the range of an int");
|
||||||
} finally {
|
} finally {
|
||||||
mServiceLock.readLock().unlock();
|
mServiceLock.readLock().unlock();
|
||||||
}
|
}
|
||||||
@@ -1552,13 +1556,22 @@ public final class BluetoothAdapter {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@SystemApi
|
@SystemApi
|
||||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
@RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
|
||||||
public boolean setScanMode(@ScanMode int mode) {
|
public boolean setScanMode(@ScanMode int mode) {
|
||||||
if (getState() != STATE_ON) {
|
if (getState() != STATE_ON) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/* getDiscoverableTimeout() to use the latest from NV than use 0 */
|
try {
|
||||||
return setScanMode(mode, getDiscoverableTimeout());
|
mServiceLock.readLock().lock();
|
||||||
|
if (mService != null) {
|
||||||
|
return mService.setScanMode(mode, getDiscoverableTimeout());
|
||||||
|
}
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "", e);
|
||||||
|
} finally {
|
||||||
|
mServiceLock.readLock().unlock();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
|
|||||||
Reference in New Issue
Block a user