Skip to content

Differ AudioManager retrieval to whenever AudioFocusManagement is req…#1616

Merged
copybara-service[bot] merged 5 commits intoandroidx:mainfrom
colinkho:chmain
Aug 21, 2024
Merged

Differ AudioManager retrieval to whenever AudioFocusManagement is req…#1616
copybara-service[bot] merged 5 commits intoandroidx:mainfrom
colinkho:chmain

Conversation

@colinkho
Copy link
Copy Markdown
Contributor

…uired

@icbaker icbaker self-requested a review August 14, 2024 11:35
@icbaker icbaker self-assigned this Aug 14, 2024
}

private AudioManager getAudioManager() {
if (audioManager == null) {
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@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.

2 participants