Skip to content

Feature/android 12 fixes#1771

Merged
joeygrover merged 35 commits intodevelopfrom
feature/android_12_fixes
Feb 24, 2022
Merged

Feature/android 12 fixes#1771
joeygrover merged 35 commits intodevelopfrom
feature/android_12_fixes

Conversation

@RHenigan
Copy link
Contributor

@RHenigan RHenigan commented Nov 30, 2021

Fixes #1732, #1751 and #1794

This PR is ready for review.

Risk

This PR makes major 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 Core and verified behavior (if applicable, if not applicable, explain why below).
  • I have tested Android, Java SE, and Java EE

Unit Tests

N/A

Core Tests

Extensive smoke testing was done that is reflected in the Release Testing Template.
Targeting Android 11 should result in the same behavior as before
Target Android 12 tests include:
Connecting to SYNC over USB with BT permissions denied

Router Service Should Start as expected and a notification should be presented to grant permissions

Connecting to SYNC over BT with BT permissions denied

The Router Service should not be started

Connecting to SYNC over USB with BT permissions granted

Router Service Should Start as expected and a notification should NOT be presented to grant permissions

Connecting to SYNC over BT with BT permissions granted

Router Service Should Start as expected

Connecting to SYNC over USB with BT permissions denied, granting permissions once connected, then connecting BT.

Once BT connects, Router service should be connected over BT and USB

Connecting to SYNC with multiple apps targeting android 12 (one app with BT permissions granted, one with BT permissions denied).

Router Service should be started for app with permissions, verify the app without permissions still connects to the router service.

Core version / branch / commit hash / module tested against: SYNC3
HMI name / version / branch / commit hash / module tested against: SYNC3

Summary

This PR addresses the issues that have been introduced by targeting Android 12 as outlined in this proposal (0345).

This includes:

CLA

@RHenigan RHenigan changed the base branch from master to develop November 30, 2021 18:39
@codecov
Copy link

codecov bot commented Nov 30, 2021

Codecov Report

Merging #1771 (03a0682) into develop (b51cda0) will decrease coverage by 0.66%.
The diff coverage is 2.27%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop    #1771      +/-   ##
=============================================
- Coverage      54.39%   53.72%   -0.67%     
- Complexity      5516     5537      +21     
=============================================
  Files            562      562              
  Lines          25543    26070     +527     
  Branches        3328     3481     +153     
=============================================
+ Hits           13893    14006     +113     
- Misses         10391    10796     +405     
- Partials        1259     1268       +9     
Impacted Files Coverage Δ
...link/transport/USBAccessoryAttachmentActivity.java 0.00% <0.00%> (ø)
...in/java/com/smartdevicelink/util/AndroidTools.java 19.17% <0.00%> (-1.72%) ⬇️
.../com/smartdevicelink/protocol/SdlProtocolBase.java 15.71% <0.00%> (-0.04%) ⬇️
.../smartdevicelink/transport/TransportConstants.java 0.00% <ø> (ø)
...om/smartdevicelink/transport/SdlRouterService.java 10.71% <2.19%> (-0.39%) ⬇️
...martdevicelink/transport/SdlBroadcastReceiver.java 3.13% <4.00%> (+0.09%) ⬆️
...ink/managers/screen/BaseTextAndGraphicManager.java 64.58% <0.00%> (+0.83%) ⬆️
...elink/managers/lifecycle/BaseLifecycleManager.java 16.19% <0.00%> (+2.20%) ⬆️
...artdevicelink/transport/utl/SdlDeviceListener.java 10.41% <0.00%> (+2.48%) ⬆️
...smartdevicelink/protocol/SecurityQueryPayload.java 78.84% <0.00%> (+5.76%) ⬆️
... and 1 more

Copy link
Member

@joeygrover joeygrover left a comment

Choose a reason for hiding this comment

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

With the addition of in line comments, you also need to update the bluetoothAvailable() method in SdlRouterService to check for bluetooth permissions. Currently the RS will check for BT availability when deciding if it should stay open and if the RS doesn't have BT permissions then it shouldn't.

<string name="lockscreen_device_image_description">Device Icon</string>
<string name="default_lockscreen_warning_message">Swipe down to dismiss, acknowledging that you are not the driver.</string>
<string name="spp_out_of_resource">Too many apps are using Bluetooth</string>
<string name="allow_bluetooth_permissions">Please grant this app bluetooth permissions</string>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<string name="allow_bluetooth_permissions">Please grant this app bluetooth permissions</string>
<string name="allow_bluetooth_permissions">Please grant this app the Nearby Devices Permission to use bluetooth</string>

Copy link
Member

Choose a reason for hiding this comment

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

The permission name from Android isn't specific to bluetooth so we should make sure to match what it is.

Comment on lines +1886 to +1889
} else {
waitingForBTRuntimePermissions = false;
initBluetoothSerialService();
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
} else {
waitingForBTRuntimePermissions = false;
initBluetoothSerialService();
}
} else {
waitingForBTRuntimePermissions = false;
initBluetoothSerialService();
final NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if(notificationManager != null) {
notificationManager.cancel("SDL", TransportConstants.SDL_ERROR_NOTIFICATION_CHANNEL_ID_INT);
}
}

Copy link
Member

Choose a reason for hiding this comment

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

We want to cancel the notification if the permission has been granted

Comment on lines +28 to +36
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (!checkPermission()) {
requestPermission();
}
} else if (BuildConfig.TRANSPORT.equals("TCP")){
//If we are connected to a module we want to start our SdlService
SdlReceiver.queryForConnectedService(this);
}
} else {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (!checkPermission()) {
requestPermission();
}
} else if (BuildConfig.TRANSPORT.equals("TCP")){
//If we are connected to a module we want to start our SdlService
SdlReceiver.queryForConnectedService(this);
}
} else {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
&& !checkPermission()) {
requestPermission();
return;
}
//If we are connected to a module we want to start our SdlService
SdlReceiver.queryForConnectedService(this);
} else if (BuildConfig.TRANSPORT.equals("TCP")) {

Copy link
Member

Choose a reason for hiding this comment

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

This logic needed to be cleaned up. Basically check for OS version and if permission is granted, if not request them. If OS is less than 12 or permissions are granted, query for the RS. The previous else if was in the wrong position for TCP.

return;
}
serviceIntent.setAction(TransportConstants.BIND_REQUEST_TYPE_ALT_TRANSPORT);
serviceIntent.putExtra(TransportConstants.CONNECTION_TYPE_EXTRA, TransportConstants.ACTION_USB_ACCESSORY_ATTACHED);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
serviceIntent.putExtra(TransportConstants.CONNECTION_TYPE_EXTRA, TransportConstants.ACTION_USB_ACCESSORY_ATTACHED);
serviceIntent.putExtra(TransportConstants.CONNECTION_TYPE_EXTRA, TransportConstants.AOA_USB);

Copy link
Member

Choose a reason for hiding this comment

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

Should avoid using an action string for an extra in an intent.

}
boolean isConnectedOverUSB = false;
if (intent != null && intent.hasExtra(TransportConstants.CONNECTION_TYPE_EXTRA)) {
isConnectedOverUSB = TransportConstants.ACTION_USB_ACCESSORY_ATTACHED.equalsIgnoreCase(intent.getStringExtra(TransportConstants.CONNECTION_TYPE_EXTRA));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
isConnectedOverUSB = TransportConstants.ACTION_USB_ACCESSORY_ATTACHED.equalsIgnoreCase(intent.getStringExtra(TransportConstants.CONNECTION_TYPE_EXTRA));
isConnectedOverUSB = TransportConstants.AOA_USB.equalsIgnoreCase(intent.getStringExtra(TransportConstants.CONNECTION_TYPE_EXTRA));

@RHenigan RHenigan marked this pull request as ready for review February 24, 2022 21:48
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.

Bluetooth Permission Requirements will change in Android 12

3 participants