google / mobly-bundled-snippets

Snippets to allow Mobly tests to control Android devices by exposing a simplified Android API.
Apache License 2.0
46 stars 52 forks source link

Introduces BluetoothHeadsetSnippet for interacting with the Bluetooth Headset profile(HFP). #189

Closed nihald2000 closed 6 months ago

nihald2000 commented 6 months ago

The class provides functionality for:

Setting connection policies Connecting and disconnecting from remote devices Retrieving connection states Managing voice recognition Includes methods like:

btHeadsetClientSet btHfp-connect btHfp-disconnect btHfp-getConnectionState btHfp-startVoiceRecognition btHfp-stopVoiceRecognition Also utilizes BroadcastReceiver for handling Bluetooth events.


This change is Reviewable

xpconanfan commented 6 months ago

Please open a separate request for those.

nihald2000 commented 6 months ago

Did you try and confirm that this works?

Yes, I have successfully built the project. its working

ko1in1u commented 6 months ago

The SmsSnippet is an example.

Inside BroadcastReceiver, save data in SnippetEvent then post to EventCache. Outside BroadcastReceiver, use Utils.waitForSnippetEvent to get the data you need.

So you don't have to declare a boolean sIsHFPProfileReady, then both BroadcastReceiver and general methods read from this value.

ko1in1u commented 6 months ago

SnippetEvent event = new SnippetEvent(mCallbackId, SMS_RECEIVED_EVENT_NAME) required: String,String but sIsHFPProfileReadyis boolean value.

Reviewed all commit messages. Reviewable status: 1 of 2 files reviewed, 21 unresolved discussions (waiting on @ko1in1u, @xpconanfan, and @zsyai)

The string here when declaring SnippetEvent is its event name, the data (sIsHFPProfileReady) is put in to Bundle. Example:

// Inside BroadcastReceiver
SnippetEvent event = new SnippetEvent(callbackId, "thisIsTheEventName");
event.getData().putBoolean("isHfpProfileReady", true);
EventCache eventCache = EventCache.getInstance();
eventCache.postEvent(event);

# Out of BroadcastReceiver
SnippetEvent event = Utils.waitForSnippetEvent(callbackId, "thisIsTheEventName", timeout);
Boolean isHfpProfileReady = event.getData().getBoolean("isHfpProfileReady")
ko1in1u commented 6 months ago

java.util.concurrent.TimeoutException: Timed out waiting(60000 millis) for SnippetEvent: BluetoothHeadsetCallback getting above TimeoutException

Reviewable status: all files reviewed, 21 unresolved discussions (waiting on @ko1in1u, @xpconanfan, and @zsyai)

The TimeoutException is bc of not receive such event until timeout, it should debug from the logic when posting event. (e.g. never receive the expected event?)