Skip to content

[SDL-0301] SDL Device Listener#1384

Merged
bilal-alsharifi merged 9 commits intodevelopfrom
feature/sdl_0301_sdl_device_listener
Jun 29, 2020
Merged

[SDL-0301] SDL Device Listener#1384
bilal-alsharifi merged 9 commits intodevelopfrom
feature/sdl_0301_sdl_device_listener

Conversation

@joeygrover
Copy link
Member

Fixes #1348

This PR is ready for review.

Risk

This PR makes minor API changes.

Testing Plan

  • I have verified that I have not introduced new warnings in this PR (or explain why below)
  • I have run the unit tests with this PR
  • I have tested this PR against a TDK and verified behavior (if applicable, if not applicable, explain why below).
  • I have tested Android. Java SE, and Java EE are unaffected

Unit Tests

  • Smoke tests are the most important piece of this PR. It is difficult to simulate much of the transport sequence so in depth tests have been provided here. Most of the logic also occurs privately.

Smoke Tests

Basic Functionality Tests

First Connection (Success)
  1. Turn bluetooth off on phone.
  2. Install Hello SDL and ensure it is the only SDL app installed.
  3. Make sure to clear storage for Hello SDL under settings.
  4. Turn on bluetooth adapter on phone.
  5. Allow BT to connect (A2DP); pair with IVI if necessary.
  6. Observe through logs that the SDL Listener was started and is currently listening on an RFCOMM channel.
  7. IVI should connect with SDL Listener's RFCOMM channel, this will cause the listener to close the connection and attempt to start the router service.
  8. Observe the router service notification appears as an indication the service has started
  9. The IVI should hopefully then connect with the router service's RFCOMM channel and the normal connection flow should occur.
Second Connection When First Connection was Successful
  1. Ensure bluetooth is off on phone after performing the first test.
  2. Ensure only hello SDL app is installed.
  3. Turn on bluetooth adapter on phone and observe that the BT A2DP profile connects.
  4. After the previous step, the router service should immediately start and its notification should be shown in the notification tray.
  5. The IVI should hopefully then connect with the router service's RFCOMM channel and the normal connection flow should occur.
Second Connection When First Connection was NOT Successful
  1. Ensure bluetooth is off on phone after performing the first test.
  2. Ensure only hello SDL app is installed.
  3. Turn on bluetooth adapter on phone and observe that the BT A2DP profile connects.
  4. Observe through logs that the SDL Listener was started and is currently listening on an RFCOMM channel, however, on the subsequent calls this class will only listen for 15 seconds.
  5. Either of two scenarios will occur:
    1. If the IVI system does not connect, the listener should close itself and no service should be started.
    2. If the IVI system does connect to the SDL Device Listener's RFCOMM channel, the flow should be as described in Test 1 Starting at Step 7.
Test with Non SDL Device (Bluetooth headphones)
  1. Turn bluetooth off on phone.
  2. Install Hello SDL and ensure it is the only SDL app installed.
  3. Make sure to clear storage for Hello SDL under settings.
  4. Turn on bluetooth adapter on phone.
  5. Allow BT to connect (A2DP); pair with IVI if necessary.
  6. Observe through logs that the SDL Listener was started and is currently listening on an RFCOMM channel.
  7. After 30 seconds, observer through logs that the SDL Device Listener didn't successfully connect its RFCOMM channel with the connected BT device and has closed down.
  8. Disconnect or turn off the non-SDL Device (headphones)
  9. Turn on the non-SDL device and repeat steps 6-8. This time step 7 should be 15 seconds.

Multiple App Tests

Hello SDL and app with library version 4.11.1
  1. Turn off bluetooth on the phone
  2. Add a log message in the SdlBroadcastReceiver in the method wakeUpRouterService. This should go after the synchronized call on DEVICE_LISTENER_LOCK. After this lock, the code will only continue past if the SDL Device Listener feature is unable to be used.
  3. Install Hello SDL and a second debugging app.
    1. Ensure the second app has the SDL library version of 4.11.1. This is to ensure it has a router service version that is less than 13. In 4.11.1 it should be 12
  4. Turn on bluetooth adapter on phone, pair with IVI system if necessary, and then observe that the BT A2DP profile connects.
  5. Observe the phone logs to see the previously added log is printed out and the router service is started. This indicates the SDL Device Listener feature is skipped because of older app library behavior.
Hello SDL and second app with this branch
This test should be ran multiple times
  1. Turn off bluetooth on the phone and turn on the IVI system
  2. Install Hello SDL and a second debugging app.
    1. Ensure the second app is built using this branch.
  3. Clear storage and cache for both apps
  4. Turn on bluetooth adapter on phone, pair with IVI system if necessary, and then observe that the BT A2DP profile connects.
  5. Observe that only one of the two apps starts an instance of SDL Device Listener
  6. Either of two scenarios will occur:
    1. If the IVI system does not connect, the listener should close itself and no service should be started.
    2. If the IVI system does connect to the SDL Device Listener's RFCOMM channel, the flow should be as described in Test 1 Starting at Step 7.
Hello SDL and second app with this branch but newer router service
  1. Turn off bluetooth on the phone and turn on the IVI system
  2. Install Hello SDL and a second debugging app.
    1. Ensure the second app is built using this branch.
    2. Change the manifest router service version to greater than or equal to 14
  3. Clear storage and cache for both apps
  4. Turn on bluetooth adapter on phone, pair with IVI system if necessary, and then observe that the BT A2DP profile connects.
  5. Observe that the second app starts an instance of SDL Device Listener
  6. Either of two scenarios will occur:
    1. If the IVI system does not connect, the listener should close itself and no service should be started.
    2. If the IVI system does connect to the SDL Device Listener's RFCOMM channel, the flow should be as described in Test 1 Starting at Step 7.
Hello SDL and second app with this branch, save successful connection
  1. Turn off bluetooth on the phone and turn on the IVI system
  2. Install Hello SDL and a second debugging app.
    1. Ensure the second app is built using this branch.
  3. Clear storage and cache for both apps
  4. Turn on bluetooth adapter on phone, pair with IVI system if necessary, and then observe that the BT A2DP profile connects.
  5. Observe that only one of the two apps starts an instance of SDL Device Listener
  6. Either of two scenarios will occur:
    1. If the IVI system does not connect, the listener should close itself and no service should be started.
    2. If the IVI system does connect to the SDL Device Listener's RFCOMM channel, the flow should be as described in Test 1 Starting at Step 7.
  7. Take note of which app started the SDL Device Listener and the SDL router service.
  8. Turn off bluetooth on the phone.
  9. Uninstall the app that started the SDL Device Listener and SDL Router Service
  10. Turn on bluetooth adapter on phone and observe that the BT A2DP profile connects.
  11. After the previous step, the router service should immediately start and its notification should be shown in the notification tray.
  12. The IVI should hopefully then connect with the router service's RFCOMM channel and the normal connection flow should occur.
Additional Test Considerations
  • Should test USB connection works as expected still as a sanity check. The logic for starting the router service for USB are not directly affected, but still important to check.

Summary

With this implementation the router service should not start until the bluetooth device has been confirmed to be an SDL device. This is done by opening an RFCOMM channel from the broadcast receiver that listens first. Only after a successful connection there will it start the router service. The caveat to this feature is that it is breaking behavior from previous library versions. Therefore, a check must be done against all other SDL apps that they have been updated to this version of the router service. If they have not, the old flow will continue, but if they are this feature will be enabled.

Changelog

Enhancements
  • SdlDeviceListener class was added and implemented in supporting proposal SDL-0301

CLA

@joeygrover joeygrover linked an issue Jun 12, 2020 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Jun 12, 2020

Codecov Report

Merging #1384 into develop will decrease coverage by 0.52%.
The diff coverage is 5.81%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop    #1384      +/-   ##
=============================================
- Coverage      46.01%   45.48%   -0.53%     
- Complexity      4461     4463       +2     
=============================================
  Files            494      495       +1     
  Lines          24905    25318     +413     
  Branches        2954     3066     +112     
=============================================
+ Hits           11459    11517      +58     
- Misses         12734    13087     +353     
- Partials         712      714       +2     
Impacted Files Coverage Δ Complexity Δ
...icelink/transport/MultiplexBluetoothTransport.java 5.09% <0.00%> (-0.02%) 10.00 <0.00> (ø)
...om/smartdevicelink/transport/SdlRouterService.java 11.30% <0.00%> (-0.01%) 20.00 <0.00> (ø)
...martdevicelink/transport/SdlBroadcastReceiver.java 3.16% <1.25%> (-0.27%) 2.00 <0.00> (ø)
...artdevicelink/transport/utl/SdlDeviceListener.java 10.34% <10.34%> (ø) 2.00 <2.00> (?)
...elink/managers/lifecycle/BaseLifecycleManager.java 13.86% <0.00%> (+1.25%) 10.00% <0.00%> (ø%)
...tdevicelink/managers/audio/AudioDecoderCompat.java 73.33% <0.00%> (+3.33%) 3.00% <0.00%> (ø%)

* will listen for 30 seconds, if it is not, this will listen for 15 seconds instead.
*/
public void start() {
if (hasSDLConnected(contextWeakReference.get(), connectedDevice.getAddress())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I install the app while BT is already on, the connectedDevice comes as null so the app crashes with this exception

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.bluetooth.BluetoothDevice.getAddress()' on a null object reference
        at com.smartdevicelink.transport.utl.SdlDeviceListener.start(SdlDeviceListener.java:88)
        at com.smartdevicelink.transport.SdlBroadcastReceiver$2.onComplete(SdlBroadcastReceiver.java:298)
        at com.smartdevicelink.util.ServiceFinder.onFinished(ServiceFinder.java:124)
        at com.smartdevicelink.util.ServiceFinder.access$000(ServiceFinder.java:58)
        at com.smartdevicelink.util.ServiceFinder$1.run(ServiceFinder.java:84)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bluetooth had to be on and connected for me to see this error, but added a null check before this now so it should throw an error. It's not an easy task to get the connected bluetooth device, so I'm not sure if it is really worth the effort at the moment.

joeygrover and others added 2 commits June 24, 2020 15:56
Co-authored-by: Bilal Alsharifi <599206+bilal-alsharifi@users.noreply.github.com>
@bilal-alsharifi bilal-alsharifi merged commit b85d06a into develop Jun 29, 2020
@bilal-alsharifi bilal-alsharifi deleted the feature/sdl_0301_sdl_device_listener branch June 29, 2020 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SDL 0301] SDL Device Listener

2 participants