diff options
author | Zhaoming Yin <stplaydog@gmail.com> | 2023-07-18 11:13:05 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-18 11:13:05 -0700 |
commit | b57a94f79b790c26e29cc44ba48a3a77a70f8e18 (patch) | |
tree | 2ea0d040b38591e8bca99272f1790f592a016c55 | |
parent | 3e878ee8167f00a5ab69ab82c682e1592fc9c063 (diff) | |
parent | d56020d155e315bab4e1877a917dc83dabedef86 (diff) | |
download | mobly-bundled-snippets-b57a94f79b790c26e29cc44ba48a3a77a70f8e18.tar.gz |
Merge branch 'master' into btfix
-rw-r--r-- | src/main/java/com/google/android/mobly/snippet/bundled/bluetooth/BluetoothAdapterSnippet.java | 21 |
1 files changed, 17 insertions, 4 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 6f1c3f7..3c845f7 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.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; import androidx.test.platform.app.InstrumentationRegistry; @@ -65,6 +66,7 @@ public class BluetoothAdapterSnippet implements Snippet { // Default timeout in seconds. private static final int TIMEOUT_TOGGLE_STATE_SEC = 30; private final Context mContext; + private final PackageManager mPackageManager; private static final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); private final JsonSerializer mJsonSerializer = new JsonSerializer(); private static final ConcurrentHashMap<String, BluetoothDevice> mDiscoveryResults = @@ -77,6 +79,7 @@ public class BluetoothAdapterSnippet implements Snippet { // Use a synchronized map to avoid racing problems mReceivers = Collections.synchronizedMap(new HashMap<String, BroadcastReceiver>()); Utils.adaptShellPermissionIfRequired(mContext); + mPackageManager = mContext.getPackageManager(); } /** @@ -261,10 +264,18 @@ public class BluetoothAdapterSnippet implements Snippet { discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, duration); // Triggers the system UI popup to ask for explicit permission. mContext.startActivity(discoverableIntent); - // Clicks the "ALLOW" button. - BySelector allowButtonSelector = By.text(TEXT_PATTERN_ALLOW).clickable(true); - uiDevice.wait(Until.findObject(allowButtonSelector), 10); - uiDevice.findObject(allowButtonSelector).click(); + + if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_WATCH)) { + // Clicks the "OK" button. + BySelector okButtonSelector = By.desc(TEXT_PATTERN_OK).clickable(true); + uiDevice.wait(Until.findObject(okButtonSelector), 10); + uiDevice.findObject(okButtonSelector).click(); + } else { + // Clicks the "ALLOW" button. + BySelector allowButtonSelector = By.text(TEXT_PATTERN_ALLOW).clickable(true); + uiDevice.wait(Until.findObject(allowButtonSelector), 10); + uiDevice.findObject(allowButtonSelector).click(); + } } else if (Build.VERSION.SDK_INT >= 30) { if (!(boolean) Utils.invokeByReflection( @@ -288,6 +299,8 @@ public class BluetoothAdapterSnippet implements Snippet { private static final Pattern TEXT_PATTERN_ALLOW = Pattern.compile("allow", Pattern.CASE_INSENSITIVE); + private static final Pattern TEXT_PATTERN_OK = + Pattern.compile("ok", Pattern.CASE_INSENSITIVE); @Rpc(description = "Cancel ongoing bluetooth discovery.") public void btCancelDiscovery() throws BluetoothAdapterSnippetException { |