diff options
author | jwang1013 <37950852+jwang1013@users.noreply.github.com> | 2020-02-12 14:09:01 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-12 14:09:01 -0800 |
commit | ecc2ee7bd4e3425bb7b4f4cb9cdd6696a2be674e (patch) | |
tree | b9da6c6bd36f1b74d31d44dc5c13daa30072df2e | |
parent | 8c035ba57fe232146004b737e41a83f477a62bd3 (diff) | |
download | mobly-bundled-snippets-ecc2ee7bd4e3425bb7b4f4cb9cdd6696a2be674e.tar.gz |
update btBecomeDiscoverable to handle api level (#129)
Android SDK beyond 29 changed the BluetoothAdapter.setScanMode signature to (Integer, Long). change btBecomeDiscoverable to handle different api level.
-rw-r--r-- | src/main/java/com/google/android/mobly/snippet/bundled/bluetooth/BluetoothAdapterSnippet.java | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/bluetooth/BluetoothAdapterSnippet.java b/src/main/java/com/google/android/mobly/snippet/bundled/bluetooth/BluetoothAdapterSnippet.java index 14393be..f2ff677 100644 --- a/src/main/java/com/google/android/mobly/snippet/bundled/bluetooth/BluetoothAdapterSnippet.java +++ b/src/main/java/com/google/android/mobly/snippet/bundled/bluetooth/BluetoothAdapterSnippet.java @@ -22,6 +22,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.os.Build; import android.os.Bundle; import androidx.test.platform.app.InstrumentationRegistry; import com.google.android.mobly.snippet.Snippet; @@ -202,14 +203,26 @@ public class BluetoothAdapterSnippet implements Snippet { throw new BluetoothAdapterSnippetException( "Bluetooth is not enabled, cannot become discoverable."); } - if (!(boolean) + // TODO(jwang1013): change it to SDK version for R after R is released. + if (Build.VERSION.CODENAME.equals("R") || Build.VERSION.SDK_INT > 29) { + if (!(boolean) + Utils.invokeByReflection( + mBluetoothAdapter, + "setScanMode", + BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE, + (long) duration * 1000)) { + throw new BluetoothAdapterSnippetException("Failed to become discoverable."); + } else { + if (!(boolean) Utils.invokeByReflection( mBluetoothAdapter, "setScanMode", BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE, duration)) { throw new BluetoothAdapterSnippetException("Failed to become discoverable."); + } } + } } @Rpc(description = "Cancel ongoing bluetooth discovery.") |