Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public class MediaButtonReceiver extends BroadcastReceiver {
* strongly recommended way to handle the intent is using the default implementation.
*/
@Override
public void onReceive(Context context, @Nullable Intent intent) {
public void onReceive(Context context, Intent intent) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I can tell, if there is no @nullable or @NotNull annotation on Android framework code, then there is no nullability information available and we can't assume this is non-null.

Agreed the doc is clear about it and we can't do something sensible without an Intent. Mind adding checkNotNull(intent) when passing it further down. Sorry for being overly picky, I see we would have a NPE right after but I think I'd prefer this being consistently where we get the garbage input. Shouldn't hurt as we agree this doesn't happen.

Copy link
Author

Choose a reason for hiding this comment

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

done

checkNotNull(intent);
handleIntentAndMaybeStartTheService(context, intent);
}

Expand All @@ -136,9 +137,8 @@ public void onReceive(Context context, @Nullable Intent intent) {
*/
@UnstableApi
protected final void handleIntentAndMaybeStartTheService(
Context context, @Nullable Intent intent) {
if (intent == null
|| !Objects.equals(intent.getAction(), Intent.ACTION_MEDIA_BUTTON)
Context context, Intent intent) {
if (!Objects.equals(intent.getAction(), Intent.ACTION_MEDIA_BUTTON)
|| !intent.hasExtra(Intent.EXTRA_KEY_EVENT)) {
Log.d(TAG, "Ignore unsupported intent: " + intent);
return;
Expand Down