Skip to content

Commit

Permalink
fix(expo-plugin): add check for existing service in AndroidManifest f…
Browse files Browse the repository at this point in the history
…or notification controls (#4172)

* fix: add check for existing VideoPlaybackService in AndroidManifest

* Update src/expo-plugins/withNotificationControls.ts

Co-authored-by: Seyed Mostafa Hasani <seyedmostafahassani@gmail.com>

* fix: comment spacing

---------

Co-authored-by: Olivier Bouillet <62574056+freeboub@users.noreply.github.com>
Co-authored-by: Seyed Mostafa Hasani <seyedmostafahassani@gmail.com>
  • Loading branch information
3 people authored Sep 17, 2024
1 parent e57c7bd commit 0538b3b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/expo-plugins/withNotificationControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ export const withNotificationControls: ConfigPlugin<boolean> = (
application.service = [];
}

// We check if the VideoPlaybackService is already defined in the AndroidManifest.xml
// to prevent adding duplicate service entries. If the service exists, we will remove
// it before adding the updated configuration to ensure there are no conflicts or redundant
// service declarations in the manifest.
const existingServiceIndex = application.service.findIndex(
(service) =>
service?.$?.['android:name'] ===
'com.brentvatne.exoplayer.VideoPlaybackService',
);
if (existingServiceIndex !== -1) {
application.service.splice(existingServiceIndex, 1);
}

application.service.push({
$: {
'android:name': 'com.brentvatne.exoplayer.VideoPlaybackService',
Expand Down

0 comments on commit 0538b3b

Please sign in to comment.