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 <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>
This commit is contained in:
Amin Meshk 2024-09-17 15:39:39 +03:30 committed by GitHub
parent e57c7bda5d
commit 0538b3b468
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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',