From 0538b3b46801a535c76cf52db28cee76f2aeb0c5 Mon Sep 17 00:00:00 2001 From: Amin Meshk Date: Tue, 17 Sep 2024 15:39:39 +0330 Subject: [PATCH] fix(expo-plugin): add check for existing service in AndroidManifest for notification controls (#4172) * fix: add check for existing VideoPlaybackService in AndroidManifest * Update src/expo-plugins/withNotificationControls.ts Co-authored-by: Seyed Mostafa Hasani * fix: comment spacing --------- Co-authored-by: Olivier Bouillet <62574056+freeboub@users.noreply.github.com> Co-authored-by: Seyed Mostafa Hasani --- src/expo-plugins/withNotificationControls.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/expo-plugins/withNotificationControls.ts b/src/expo-plugins/withNotificationControls.ts index 8c76f814..df204eeb 100644 --- a/src/expo-plugins/withNotificationControls.ts +++ b/src/expo-plugins/withNotificationControls.ts @@ -24,6 +24,19 @@ export const withNotificationControls: ConfigPlugin = ( 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',