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

Add multiple checks to supportsSoftButtonImages() #1801

Merged
merged 1 commit into from
Apr 8, 2022

Conversation

noah-livio
Copy link
Contributor

@noah-livio noah-livio commented Mar 30, 2022

Fixes #1800

This PR is ready for review.

Risk

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

Unit Tests

N/A

Core Tests

On Core, I ran the following code in testBlank() of a local clone of sdl_test_suite_java and a modified local copy of sdl_java_suite in which PresentAlertOperation.supportSoftButtonImages() is public.

Test Code
AlertView.Builder builder = new AlertView.Builder();

        builder.setText("Test Alert");

        AlertView view = builder.build();

        //test null capability
        try {
            WindowCapability windowCapability = null;
            //WindowCapability windowCapability = new WindowCapability();
            //windowCapability.setSoftButtonCapabilities(Collections.emptyList());
            //windowCapability.setSoftButtonCapabilities(Collections.singletonList(null));

            PresentAlertOperation presentAlertOperation = new PresentAlertOperation(null, view,
                windowCapability, null, null, 0, new AlertCompletionListener() {
                @Override
                public void onComplete(boolean success, Integer tryAgainTime) {
                    if (success) {
                        messageLogger.logInfo(TAG, "Alert successful", true);
                    } else {
                        messageLogger.logError(TAG, "Alert failed", true);
                    }
                }
            }, null);

            messageLogger.logInfo(TAG,
                "Supports soft button images: " + presentAlertOperation.supportsSoftButtonImages(),
                true);
        } catch (Exception e) {
            messageLogger.logError(TAG, "Null capability crash", true);
        }

        //test null list
        try {
            //WindowCapability windowCapability = null;
            WindowCapability windowCapability = new WindowCapability();
            //windowCapability.setSoftButtonCapabilities(Collections.emptyList());
            //windowCapability.setSoftButtonCapabilities(Collections.singletonList(null));

            PresentAlertOperation presentAlertOperation = new PresentAlertOperation(null, view,
                windowCapability, null, null, 0, new AlertCompletionListener() {
                @Override
                public void onComplete(boolean success, Integer tryAgainTime) {
                    if (success) {
                        messageLogger.logInfo(TAG, "Alert successful", true);
                    } else {
                        messageLogger.logError(TAG, "Alert failed", true);
                    }
                }
            }, null);

            messageLogger.logInfo(TAG,
                "Supports soft button images: " + presentAlertOperation.supportsSoftButtonImages(),
                true);
        } catch (Exception e) {
            messageLogger.logError(TAG, "Null list crash", true);
        }

        //test empty list
        try {
            //WindowCapability windowCapability = null;
            WindowCapability windowCapability = new WindowCapability();
            windowCapability.setSoftButtonCapabilities(Collections.emptyList());
            //windowCapability.setSoftButtonCapabilities(Collections.singletonList(null));

            PresentAlertOperation presentAlertOperation = new PresentAlertOperation(null, view,
                windowCapability, null, null, 0, new AlertCompletionListener() {
                @Override
                public void onComplete(boolean success, Integer tryAgainTime) {
                    if (success) {
                        messageLogger.logInfo(TAG, "Alert successful", true);
                    } else {
                        messageLogger.logError(TAG, "Alert failed", true);
                    }
                }
            }, null);

            messageLogger.logInfo(TAG,
                "Supports soft button images: " + presentAlertOperation.supportsSoftButtonImages(),
                true);
        } catch (Exception e) {
            messageLogger.logError(TAG, "Empty list crash", true);
        }

        //test null button capability crash
        try {
            //WindowCapability windowCapability = null;
            WindowCapability windowCapability = new WindowCapability();
            //windowCapability.setSoftButtonCapabilities(Collections.emptyList());
            windowCapability.setSoftButtonCapabilities(Collections.singletonList(null));

            PresentAlertOperation presentAlertOperation = new PresentAlertOperation(null, view,
                windowCapability, null, null, 0, new AlertCompletionListener() {
                @Override
                public void onComplete(boolean success, Integer tryAgainTime) {
                    if (success) {
                        messageLogger.logInfo(TAG, "Alert successful", true);
                    } else {
                        messageLogger.logError(TAG, "Alert failed", true);
                    }
                }
            }, null);

            messageLogger.logInfo(TAG,
                "Supports soft button images: " + presentAlertOperation.supportsSoftButtonImages(),
                true);
        } catch (Exception e) {
            messageLogger.logError(TAG, "Null button capability crash", true);
        }

Core version / branch / commit hash / module tested against: Core release/8.1.0 b30f01258aeea4ec4c9cde22e942f091ade1cbfb
HMI name / version / branch / commit hash / module tested against: Generic HMI release/0.12.0 3ec306d2521f5151c215e4d98d9a230d6c544d6e

Summary

This PR adds null checks and a List.size() check to PresentAlertOperation.supportsSoftButtonImages(). These checks prevent crashes and returns true when soft button capabilities are unavailable. This new behavior improves alignment with the other SDL libraries.

Changelog

Breaking Changes
  • None
Enhancements
  • None
Bug Fixes

CLA

This commit adds null checks and a List.size() check to PresentAlertOperation.supportsSoftButtonImages()
These checks prevent crashes and returns true when soft button capabilities are unavailable
This new behavior improves alignment with the other SDL libraries
@codecov
Copy link

codecov bot commented Mar 30, 2022

Codecov Report

Merging #1801 (1b9ea15) into 5.4.0_RC (a624a06) will decrease coverage by 0.01%.
The diff coverage is 0.00%.

Impacted file tree graph

@@              Coverage Diff               @@
##             5.4.0_RC    #1801      +/-   ##
==============================================
- Coverage       54.05%   54.04%   -0.02%     
  Complexity       5519     5519              
==============================================
  Files             562      562              
  Lines           25723    25728       +5     
  Branches         3372     3375       +3     
==============================================
  Hits            13904    13904              
- Misses          10562    10563       +1     
- Partials         1257     1261       +4     
Impacted Files Coverage Δ
...icelink/managers/screen/PresentAlertOperation.java 55.94% <0.00%> (-1.27%) ⬇️
...nk/managers/audio/AudioDecoderCompatOperation.java 75.00% <0.00%> (-4.55%) ⬇️
...rtdevicelink/streaming/video/SdlRemoteDisplay.java 52.43% <0.00%> (+2.43%) ⬆️

@noah-livio noah-livio marked this pull request as ready for review March 30, 2022 20:19
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