From fc6054ba53ec43e56397827b4fe5d43739f465b4 Mon Sep 17 00:00:00 2001 From: VishnuSanal Date: Sat, 20 Apr 2024 20:07:29 +0530 Subject: [PATCH] fix: exported on `#registerReceiver` Signed-off-by: VishnuSanal --- .../dialogmusicplayer/MainActivity.java | 5 ++- .../MediaPlaybackService.java | 40 ++++++++++++++----- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/phone/vishnu/dialogmusicplayer/MainActivity.java b/app/src/main/java/phone/vishnu/dialogmusicplayer/MainActivity.java index 7cd22a6..b509353 100644 --- a/app/src/main/java/phone/vishnu/dialogmusicplayer/MainActivity.java +++ b/app/src/main/java/phone/vishnu/dialogmusicplayer/MainActivity.java @@ -164,7 +164,10 @@ public void onCreate(@Nullable Bundle savedInstanceState) { viewModel = new ViewModelProvider(this).get(MainViewModel.class); - registerReceiver(killReceiver, new IntentFilter(KILL_APP_KEY)); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) + registerReceiver(killReceiver, new IntentFilter(KILL_APP_KEY), RECEIVER_NOT_EXPORTED); + else + registerReceiver(killReceiver, new IntentFilter(KILL_APP_KEY)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { if (checkSelfPermission(Manifest.permission.READ_MEDIA_AUDIO) diff --git a/app/src/main/java/phone/vishnu/dialogmusicplayer/MediaPlaybackService.java b/app/src/main/java/phone/vishnu/dialogmusicplayer/MediaPlaybackService.java index 263282e..3333235 100644 --- a/app/src/main/java/phone/vishnu/dialogmusicplayer/MediaPlaybackService.java +++ b/app/src/main/java/phone/vishnu/dialogmusicplayer/MediaPlaybackService.java @@ -132,15 +132,6 @@ public void onPlayFromUri(Uri uri, Bundle extras) { setPlaybackState(PlaybackStateCompat.STATE_PLAYING, -1); - registerReceiver( - becomingNoisyReceiver, - new IntentFilter( - AudioManager - .ACTION_AUDIO_BECOMING_NOISY)); - registerReceiver( - mediaButtonActionReceiver, - new IntentFilter(Intent.ACTION_MEDIA_BUTTON)); - IntentFilter notificationFilter = new IntentFilter(); notificationFilter.addAction(ACTION_PLAY_PAUSE); notificationFilter.addAction(ACTION_REPLAY); @@ -148,8 +139,37 @@ public void onPlayFromUri(Uri uri, Bundle extras) { notificationFilter.addAction(ACTION_REWIND); notificationFilter.addAction(ACTION_SEEK); - registerReceiver( + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + + registerReceiver( + becomingNoisyReceiver, + new IntentFilter( + AudioManager + .ACTION_AUDIO_BECOMING_NOISY), + RECEIVER_NOT_EXPORTED); + + registerReceiver( + mediaButtonActionReceiver, + new IntentFilter(Intent.ACTION_MEDIA_BUTTON), + RECEIVER_NOT_EXPORTED); + + registerReceiver( + notificationReceiver, notificationFilter, RECEIVER_NOT_EXPORTED); + } else { + + registerReceiver( + becomingNoisyReceiver, + new IntentFilter( + AudioManager + .ACTION_AUDIO_BECOMING_NOISY)); + + registerReceiver( + mediaButtonActionReceiver, + new IntentFilter(Intent.ACTION_MEDIA_BUTTON)); + + registerReceiver( notificationReceiver, notificationFilter); + } audio = AudioUtils.getMetaData(