From d8e063f200a7ebfbcdd9bd2ab77c3126bd5fd3bb Mon Sep 17 00:00:00 2001 From: Rahul Sabnis Date: Tue, 29 Mar 2022 17:17:32 -0700 Subject: Update BluetoothAdapter#setScanMode to throw an IllegalArgumentException when the the input is invalid Tag: #feature Bug: 202310885 Test: atest BluetoothHostTest#testSetScanMode Ignore-AOSP-First: Fixing GTS test Change-Id: I4cd64903de7c4b413f551ac6fd4703035e32c7b9 --- framework/java/android/bluetooth/BluetoothAdapter.java | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'framework/java/android/bluetooth/BluetoothAdapter.java') diff --git a/framework/java/android/bluetooth/BluetoothAdapter.java b/framework/java/android/bluetooth/BluetoothAdapter.java index 0a2fb4fb44..e6f91bf128 100644 --- a/framework/java/android/bluetooth/BluetoothAdapter.java +++ b/framework/java/android/bluetooth/BluetoothAdapter.java @@ -1914,6 +1914,7 @@ public final class BluetoothAdapter { * @param mode represents the desired state of the local device scan mode * * @return status code indicating whether the scan mode was successfully set + * @throws IllegalArgumentException if the mode is not a valid scan mode * @hide */ @SystemApi @@ -1927,6 +1928,10 @@ public final class BluetoothAdapter { if (getState() != STATE_ON) { return BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED; } + if (mode != SCAN_MODE_NONE && mode != SCAN_MODE_CONNECTABLE + && mode != SCAN_MODE_CONNECTABLE_DISCOVERABLE) { + throw new IllegalArgumentException("Invalid scan mode param value"); + } try { mServiceLock.readLock().lock(); if (mService != null) { -- cgit v1.2.3