From 5dd08fc215f01695670d54f3027ae66396fe601e Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Tue, 15 Oct 2024 12:45:18 +0200 Subject: [PATCH] [android-extensions] Set RECEIVER_NOT_EXPORTED in ServerPingWithAlarmManager Set RECEIVER_NOT_EXPORTED when registering the receiver in ServerPingWithAlarmManager, as otherwise this will throw an exception if the application targets Android API level 34 or higher. This requires raising the minimum Android API level to 26 for registerReceiver() with flags. --- .github/workflows/ci.yml | 2 +- .../org.igniterealtime.smack.android-conventions.gradle | 2 +- .../org.igniterealtime.smack.global-conventions.gradle | 2 +- .../smackx/ping/android/ServerPingWithAlarmManager.java | 8 +++++++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fa9bb447a..3dfc78a9f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,7 +56,7 @@ jobs: uses: android-actions/setup-android@v3 - name: Install Android SDK run: | - sdkmanager "platforms;android-23" + sdkmanager "platforms;android-26" # Testing - name: Gradle Check diff --git a/build-logic/src/main/groovy/org.igniterealtime.smack.android-conventions.gradle b/build-logic/src/main/groovy/org.igniterealtime.smack.android-conventions.gradle index 94beb432c..83fe952cd 100644 --- a/build-logic/src/main/groovy/org.igniterealtime.smack.android-conventions.gradle +++ b/build-logic/src/main/groovy/org.igniterealtime.smack.android-conventions.gradle @@ -3,7 +3,7 @@ plugins { id 'org.igniterealtime.smack.global-conventions' } dependencies { - signature "net.sf.androidscents.signature:android-api-level-${smackMinAndroidSdk}:6.0_r3@signature" + signature "net.sf.androidscents.signature:android-api-level-${smackMinAndroidSdk}:8.0.0_r2@signature" } animalsniffer { sourceSets = [sourceSets.main] diff --git a/build-logic/src/main/groovy/org.igniterealtime.smack.global-conventions.gradle b/build-logic/src/main/groovy/org.igniterealtime.smack.global-conventions.gradle index 5bd92c7ee..751178ed0 100644 --- a/build-logic/src/main/groovy/org.igniterealtime.smack.global-conventions.gradle +++ b/build-logic/src/main/groovy/org.igniterealtime.smack.global-conventions.gradle @@ -1,7 +1,7 @@ ext { javaVersion = JavaVersion.VERSION_11 javaMajor = javaVersion.getMajorVersion() - smackMinAndroidSdk = 23 + smackMinAndroidSdk = 26 androidBootClasspath = { getAndroidRuntimeJar() } } diff --git a/smack-android-extensions/src/main/java/org/jivesoftware/smackx/ping/android/ServerPingWithAlarmManager.java b/smack-android-extensions/src/main/java/org/jivesoftware/smackx/ping/android/ServerPingWithAlarmManager.java index 0315629c8..145098281 100644 --- a/smack-android-extensions/src/main/java/org/jivesoftware/smackx/ping/android/ServerPingWithAlarmManager.java +++ b/smack-android-extensions/src/main/java/org/jivesoftware/smackx/ping/android/ServerPingWithAlarmManager.java @@ -173,7 +173,13 @@ public final class ServerPingWithAlarmManager extends Manager { */ public static void onCreate(Context context) { sContext = context; - context.registerReceiver(ALARM_BROADCAST_RECEIVER, new IntentFilter(PING_ALARM_ACTION)); + + int receiverFlags = 0; + if (Build.VERSION.SDK_INT >= 34) { + receiverFlags |= 4; // RECEIVER_NOT_EXPORTED + } + context.registerReceiver(ALARM_BROADCAST_RECEIVER, new IntentFilter(PING_ALARM_ACTION), receiverFlags); + sAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); int pendingIntentFlags = 0; if (Build.VERSION.SDK_INT >= 23) {