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

Differ AudioManager retrieval to whenever AudioFocusManagement is req… #1616

Merged
merged 5 commits into from
Aug 21, 2024

Conversation

colinkho
Copy link
Contributor

…uired

@icbaker icbaker self-requested a review August 14, 2024 11:35
@icbaker icbaker self-assigned this Aug 14, 2024
@@ -455,6 +453,13 @@ private void executePlayerCommand(@PlayerCommand int playerCommand) {
}
}

private AudioManager getAudioManager() {
if (audioManager == null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

NIt: you can use Guava's Suppliers.memoize for this, to avoid manually needing to check for null, so change private final AudioManager audioManager; above to private final Supplier<AudioManager> audioManager;, change the instantiation to:

this.audioManager =
        Suppliers.memoize(() -> checkNotNull(
            (AudioManager) context.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)));

And then change the usage sites from audioManager to audioManager.get()

Maybe change the field name to audioManagerSupplier too - up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion. Will change accordingly

@icbaker
Copy link
Collaborator

icbaker commented Aug 15, 2024

I'm going to send this for internal review now. You may see some more commits being added as I make changes in response to review feedback. Please refrain from pushing any more substantive changes as it will complicate the internal review - thanks!

@copybara-service copybara-service bot merged commit 1bb48b1 into androidx:main Aug 21, 2024
1 check passed
@androidx androidx locked and limited conversation to collaborators Oct 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants