From 8bc19edeb44970b9496829553e221f950e027c7f Mon Sep 17 00:00:00 2001 From: Nathan Kerr Date: Fri, 22 Apr 2022 09:01:07 -0700 Subject: [PATCH] Fix for PendingIntent mutability and AndroidX --- CHANGELOG.md | 5 +++++ package.json | 2 +- plugin.xml | 3 ++- src/android/ForegroundService.java | 4 ++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1641472..2db7983 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ ## ChangeLog + +#### Version 0.8.0 +- Set PendingIntent mutability (fixes #45) +- Depend on cordova-androidx-build to automatically work with AndroidX + #### Version 0.7.3 (not yet released) - Check if screen is off on Android - Wake-up device on Android diff --git a/package.json b/package.json index e41184f..0f25b45 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-background-mode", - "version": "0.7.3", + "version": "0.8.0", "description": "Prevent apps from going to sleep in background.", "cordova": { "id": "cordova-plugin-background-mode", diff --git a/plugin.xml b/plugin.xml index 0a6cee4..a365534 100644 --- a/plugin.xml +++ b/plugin.xml @@ -3,7 +3,7 @@ + version="0.8.0"> BackgroundMode @@ -94,6 +94,7 @@ target-dir="src/de/appplant/cordova/plugin/background" /> + diff --git a/src/android/ForegroundService.java b/src/android/ForegroundService.java index c0edae6..1133a66 100644 --- a/src/android/ForegroundService.java +++ b/src/android/ForegroundService.java @@ -215,7 +215,7 @@ public class ForegroundService extends Service { if (settings.optBoolean("allowClose", false)) { final Intent clostAppIntent = new Intent("com.backgroundmode.close" + pkgName); - final PendingIntent closeIntent = PendingIntent.getBroadcast(context, 1337, clostAppIntent, 0); + final PendingIntent closeIntent = PendingIntent.getBroadcast(context, 1337, clostAppIntent, PendingIntent.FLAG_IMMUTABLE); final String closeIconName = settings.optString("closeIcon", "power"); NotificationCompat.Action.Builder closeAction = new NotificationCompat.Action.Builder(getIconResId(closeIconName), settings.optString("closeTitle", "Close"), closeIntent); notification.addAction(closeAction.build()); @@ -240,7 +240,7 @@ public class ForegroundService extends Service { intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity( context, NOTIFICATION_ID, intent, - PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent.FLAG_UPDATE_CURRENT & PendingIntent.FLAG_IMMUTABLE); notification.setContentIntent(contentIntent);