Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/issue 1812 Android 13 Support #1826

Merged
merged 7 commits into from
Sep 6, 2022

Conversation

JulianKast
Copy link
Contributor

@JulianKast JulianKast commented Aug 25, 2022

Fixes #1812

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 Core and verified behavior (if applicable, if not applicable, explain why below).
  • I have tested Android

Unit Tests

n/a

Core Tests

POST_NOTIFICATIONS TESTS

1 app API 33 on Android 13 device

Test 1:

  1. App request POST_NOTIFICATIONS permission.
  2. Accept permission
  3. Connect to core

Results: Notifications appear and the app works as expected

Test 2:

  1. App request POST_NOTIFICATIONS permission.
  2. Click Don't Allow for permission.
  3. Connect to core

Results: Notifications do not appear and the app works as expected

Test 3:

  1. App request POST_NOTIFICATIONS permission.
  2. Swipe away the request to allow notifications.
  3. Connect to core

Results: Notifications do not appear and the app works as expected

Test 4:

  1. App does not request POST_NOTIFICATIONS permission.
  2. Connect to core

Results: Notifications do not appear and the app works as expected

1 app API 31 on Android 13 device

Test 5:

  1. Connect to core
  2. Accept Post Notification permission(Automatically sent by android)

Results: Notifications appear and the app works as expected

Test 6:

  1. Connect to core
  2. Click Don't Allow for Post Notification permission(Automatically sent by android)

Results: Notifications do not appear and the app works as expected

Test 7:

  1. Connect to core
  2. Swip away the request to allow notifications(Automatically sent by android).

Results: Notifications do not appear and the app works as expected

App 1 API 33, App 2 API 31 on Android 13 device

Test 8:

  1. Accept notification permission for App 1.
  2. Connects to core
  3. Accept notification permissions for App 2 (Note Automatically sent by android you have to open app to view dialog to accept/deny permissions)

Results: Notifications appear and the app works as expected

Test 9:

  1. Install in order App 2 then App 1
  2. Accept notification permission for App 1
  3. Connects to core
  4. Deny permission for App 2

Results: Notifications appear for App 1 and RouterScervice but not for App 2. Apps work as expected

Test 10

  1. Install App 1
  2. Deny notification permission
  3. Connect to core
  4. Disconnects from core
  5. Install App 2
  6. Connects to core
  7. Accepts notification permission

Expected Results: No notifications for App 1 and RouterService, App 2 has 1 notification. Apps work as expected.

Observed behavior: No Notifications at all until you disconnect and reconnect to core then App 2 has 1 notification. Outside of that sdl still works fine.

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

Summary

This Pr makes updates to target API 33 as well as update hello_sdl_android to demonstrate how to request POST_NOTIFICATIONS permission added in Android 13.

There is one issue with test 10 where no notification appears when one should, but after a disconnect and reconnect it works itself out and the behavior of SDL is not altered outside of displayed notifications.

Notifications are still required, but they do not have to be displayed if they don't have the proper permissions. Another major downside to this is if you accidentally dismiss the BLUETOOTH_CONNECT permission and the POST_NOTIFICATIONS it does not give the user any sense of what they did wrong, but that should work itself out after the app gets closed and opened again.

Changelog

Bug Fixes
  • Demonstrate requesting POST_NOTIFICATIONS permission

CLA

@codecov
Copy link

codecov bot commented Aug 25, 2022

Codecov Report

Merging #1826 (881bbc2) into develop (4f8e483) will increase coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop    #1826      +/-   ##
=============================================
+ Coverage      54.04%   54.05%   +0.01%     
- Complexity      5532     5535       +3     
=============================================
  Files            562      562              
  Lines          25821    25821              
  Branches        3398     3398              
=============================================
+ Hits           13954    13958       +4     
+ Misses         10596    10594       -2     
+ Partials        1271     1269       -2     
Impacted Files Coverage Δ
...rtdevicelink/streaming/video/SdlRemoteDisplay.java 51.21% <0.00%> (-1.22%) ⬇️
...ink/managers/screen/BaseTextAndGraphicManager.java 64.58% <0.00%> (+0.41%) ⬆️
...managers/screen/TextAndGraphicUpdateOperation.java 71.70% <0.00%> (+0.54%) ⬆️
...nk/managers/audio/AudioDecoderCompatOperation.java 79.54% <0.00%> (+4.54%) ⬆️

Comment on lines 26 to 27
if (permissionsNeeded().length > 0) {
requestPermission(permissionsNeeded(), REQUEST_CODE);
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 (permissionsNeeded().length > 0) {
requestPermission(permissionsNeeded(), REQUEST_CODE);
String[] permissionsNeeded = permissionsNeeded();
if (permissionsNeeded.length > 0) {
requestPermission(permissionsNeeded, REQUEST_CODE);

Comment on lines 28 to 30
if (checkBTPermission()) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason this is still needed? Seems like we could get rid of it.

Suggested change
if (checkBTPermission()) {
return;
}

Copy link
Contributor Author

@JulianKast JulianKast Aug 31, 2022

Choose a reason for hiding this comment

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

This is needed because we need to not call SdlReceiver.queryForConnectedService(this); below only if we need the BLUETOOTH_CONNECT permission.

We could change it below at line 35 to

            if (!checkBTPermission()) {
                //If we are connected to a module we want to start our SdlService
                SdlReceiver.queryForConnectedService(this);
            }

Copy link
Member

Choose a reason for hiding this comment

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

With having an array with strings that contain our permission needs already it seems like we could check those with something like:

for (String permission : permissionsNeeded) {
    if(Manifest.permission.BLUETOOTH_CONNECT.equals(permission)){
        return;
    }
}

I just don't know the efficiency of checking for the permission again, and it seems redundant. At the very least I would say your suggestions should be used as it's bit more concise.

Copy link
Member

Choose a reason for hiding this comment

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

Another option would be to flip the methods for checking permission into returning if the permission is granted instead of currently returning if it is not granted, because that in itself is a big confusing as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that it was confusing especially with the naming of those methods, I flipped them and renamed to hasPNPermission and hasBTPermission. I wanted to not flip them and name them needPNPermision and needBTPermission since its checking the API level and then the permission, But need really isn't a proper java naming convention that I could find, so I added some JavDocs to them.

ActivityCompat.requestPermissions(this, permissions, REQUEST_CODE);
}

private String[] permissionsNeeded() {
Copy link
Member

Choose a reason for hiding this comment

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

This isn't a big deal, but still a good idea.

Suggested change
private String[] permissionsNeeded() {
private @NonNull String[] permissionsNeeded() {

return;
String[] permissionsNeeded = permissionsNeeded();
if (permissionsNeeded.length > 0) {
requestPermission(permissionsNeeded(), REQUEST_CODE);
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
requestPermission(permissionsNeeded(), REQUEST_CODE);
requestPermission(permissionsNeeded, REQUEST_CODE);

Comment on lines 28 to 30
if (checkBTPermission()) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

With having an array with strings that contain our permission needs already it seems like we could check those with something like:

for (String permission : permissionsNeeded) {
    if(Manifest.permission.BLUETOOTH_CONNECT.equals(permission)){
        return;
    }
}

I just don't know the efficiency of checking for the permission again, and it seems redundant. At the very least I would say your suggestions should be used as it's bit more concise.

Comment on lines 28 to 30
if (checkBTPermission()) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

Another option would be to flip the methods for checking permission into returning if the permission is granted instead of currently returning if it is not granted, because that in itself is a big confusing as well.

@joeygrover joeygrover merged commit 77db656 into develop Sep 6, 2022
@joeygrover joeygrover deleted the bugfix/issue_1812_Android_13 branch September 6, 2022 20:33
@joeygrover joeygrover mentioned this pull request Sep 6, 2022
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.

2 participants