From d1527b54c5ed6c2f705fb11615e7c0021e4790eb Mon Sep 17 00:00:00 2001 From: ijunaid Date: Tue, 17 Oct 2023 12:51:01 +0500 Subject: [PATCH 1/6] Fixed crash for SDK34 BroadcastReceivers --- app/build.gradle | 9 +++++---- app/src/main/java/ly/count/android/demo/App.java | 7 ++++++- sdk/build.gradle | 9 +++++---- sdk/src/main/java/ly/count/android/sdk/DeviceInfo.java | 8 +++++++- .../java/ly/count/android/sdk/messaging/CountlyPush.java | 8 +++++++- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c85cdac38..a0784c5b6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -91,10 +91,11 @@ dependencies { //implementation 'ly.count.android:sdk:21.11.0' //implementation 'ly.count.android:sdk-plugin:21.11.0' - //required for FCM push - implementation 'com.google.firebase:firebase-messaging:22.0.0' - //required for huawei push - implementation 'com.huawei.hms:push:6.3.0.304' + + //required for FCM push + implementation 'com.google.firebase:firebase-messaging:22.0.0' + //required for huawei push +// implementation 'com.huawei.hms:push:5.3.0.304' implementation 'com.google.android.material:material:1.6.0-alpha02' implementation 'androidx.appcompat:appcompat:1.4.1' diff --git a/app/src/main/java/ly/count/android/demo/App.java b/app/src/main/java/ly/count/android/demo/App.java index e78c35006..a2b9069dc 100644 --- a/app/src/main/java/ly/count/android/demo/App.java +++ b/app/src/main/java/ly/count/android/demo/App.java @@ -293,6 +293,11 @@ public void onReceive(Context context, Intent intent) { }; IntentFilter filter = new IntentFilter(); filter.addAction(CountlyPush.SECURE_NOTIFICATION_BROADCAST); - registerReceiver(messageReceiver, filter, getPackageName() + COUNTLY_BROADCAST_PERMISSION_POSTFIX, null); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + registerReceiver(messageReceiver, filter, getPackageName() + COUNTLY_BROADCAST_PERMISSION_POSTFIX, null, Context.RECEIVER_NOT_EXPORTED); + } + else { + registerReceiver(messageReceiver, filter, getPackageName() + COUNTLY_BROADCAST_PERMISSION_POSTFIX, null); + } } } diff --git a/sdk/build.gradle b/sdk/build.gradle index 5efbbece6..1b436b93f 100644 --- a/sdk/build.gradle +++ b/sdk/build.gradle @@ -12,12 +12,12 @@ buildscript { } android { - compileSdkVersion 33 - buildToolsVersion "33.0.0" + compileSdk 34 + buildToolsVersion "34.0.0" defaultConfig { - minSdkVersion 17 - targetSdkVersion 33 + minSdk 17 + targetSdk 34 testInstrumentationRunner 'ly.count.android.sdk.test.InstrumentationTestRunner' testHandleProfiling true @@ -49,6 +49,7 @@ def mockitoVersion = "2.28.2" dependencies { api fileTree(dir: 'libs', include: ['*.jar']) + implementation 'androidx.core:core-ktx:1.9.0' implementation 'androidx.annotation:annotation:1.6.0' implementation 'androidx.lifecycle:lifecycle-common:2.6.1' implementation 'androidx.lifecycle:lifecycle-process:2.6.1' diff --git a/sdk/src/main/java/ly/count/android/sdk/DeviceInfo.java b/sdk/src/main/java/ly/count/android/sdk/DeviceInfo.java index d01c7a4da..8661d07c2 100644 --- a/sdk/src/main/java/ly/count/android/sdk/DeviceInfo.java +++ b/sdk/src/main/java/ly/count/android/sdk/DeviceInfo.java @@ -431,7 +431,13 @@ public String getDiskTotal() { @Override public String getBatteryLevel(Context context) { try { - Intent batteryIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); + Intent batteryIntent; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + batteryIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); + } + else { + batteryIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); + } if (batteryIntent != null) { int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); diff --git a/sdk/src/main/java/ly/count/android/sdk/messaging/CountlyPush.java b/sdk/src/main/java/ly/count/android/sdk/messaging/CountlyPush.java index 8d325e3fc..35cee168c 100644 --- a/sdk/src/main/java/ly/count/android/sdk/messaging/CountlyPush.java +++ b/sdk/src/main/java/ly/count/android/sdk/messaging/CountlyPush.java @@ -29,6 +29,7 @@ import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -784,7 +785,12 @@ public void onActivityDestroyed(Activity activity) { IntentFilter filter = new IntentFilter(); filter.addAction(Countly.CONSENT_BROADCAST); BroadcastReceiver consentReceiver = new ConsentBroadcastReceiver(); - countlyConfigPush.application.registerReceiver(consentReceiver, filter, countlyConfigPush.application.getPackageName() + COUNTLY_BROADCAST_PERMISSION_POSTFIX, null); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + countlyConfigPush.application.registerReceiver(consentReceiver, filter, countlyConfigPush.application.getPackageName() + COUNTLY_BROADCAST_PERMISSION_POSTFIX, null, Context.RECEIVER_NOT_EXPORTED); + } + else { + countlyConfigPush.application.registerReceiver(consentReceiver, filter, countlyConfigPush.application.getPackageName() + COUNTLY_BROADCAST_PERMISSION_POSTFIX, null); + } } if (countlyConfigPush.provider == Countly.CountlyMessagingProvider.HMS && getPushConsent(countlyConfigPush.application)) { From 876f6742b55ac2f405968fff817489d72ce563b6 Mon Sep 17 00:00:00 2001 From: ijunaid Date: Tue, 17 Oct 2023 12:54:09 +0500 Subject: [PATCH 2/6] updated app/build.gradle --- app/build.gradle | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a0784c5b6..ba26f0e31 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -22,15 +22,15 @@ buildscript { repositories { mavenCentral() - //required for huawei push - maven { - url "https://developer.huawei.com/repo/" - } + //required for huawei push +// maven { +// url "https://developer.huawei.com/repo/" +// } } android { - compileSdkVersion 33 - buildToolsVersion '33.0.0' + compileSdk 34 + namespace 'ly.count.android.demo' signingConfigs { release { @@ -45,8 +45,8 @@ android { defaultConfig { applicationId "ly.count.android.demo" - minSdkVersion 17 - targetSdkVersion 33 + minSdk 17 + targetSdk 34 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -95,10 +95,10 @@ dependencies { //required for FCM push implementation 'com.google.firebase:firebase-messaging:22.0.0' //required for huawei push -// implementation 'com.huawei.hms:push:5.3.0.304' + implementation 'com.huawei.hms:push:5.3.0.304' implementation 'com.google.android.material:material:1.6.0-alpha02' - implementation 'androidx.appcompat:appcompat:1.4.1' + implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.1.3' implementation 'androidx.annotation:annotation:1.3.0' implementation 'androidx.core:core-ktx:1.7.0' From ee05e8a1747eae962bea48335761b8aa9a90c2be Mon Sep 17 00:00:00 2001 From: ijunaid Date: Tue, 17 Oct 2023 12:58:37 +0500 Subject: [PATCH 3/6] reverted huawei changes in app gradle --- app/build.gradle | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index ba26f0e31..1dd8e838b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -22,10 +22,10 @@ buildscript { repositories { mavenCentral() - //required for huawei push -// maven { -// url "https://developer.huawei.com/repo/" -// } + //required for huawei push + maven { + url "https://developer.huawei.com/repo/" + } } android { @@ -92,10 +92,10 @@ dependencies { //implementation 'ly.count.android:sdk-plugin:21.11.0' - //required for FCM push - implementation 'com.google.firebase:firebase-messaging:22.0.0' - //required for huawei push - implementation 'com.huawei.hms:push:5.3.0.304' + //required for FCM push + implementation 'com.google.firebase:firebase-messaging:22.0.0' + //required for huawei push + implementation 'com.huawei.hms:push:5.3.0.304' implementation 'com.google.android.material:material:1.6.0-alpha02' implementation 'androidx.appcompat:appcompat:1.6.1' From 85909167bcd66091e855297b39dac6e8ac834352 Mon Sep 17 00:00:00 2001 From: ijunaid Date: Tue, 17 Oct 2023 13:29:12 +0500 Subject: [PATCH 4/6] Updated with changes mentioned by Deniz in PR --- app/build.gradle | 2 +- sdk/src/main/java/ly/count/android/sdk/DeviceInfo.java | 2 +- .../main/java/ly/count/android/sdk/messaging/CountlyPush.java | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1dd8e838b..9af77157f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -95,7 +95,7 @@ dependencies { //required for FCM push implementation 'com.google.firebase:firebase-messaging:22.0.0' //required for huawei push - implementation 'com.huawei.hms:push:5.3.0.304' + implementation 'com.huawei.hms:push:6.3.0.304' implementation 'com.google.android.material:material:1.6.0-alpha02' implementation 'androidx.appcompat:appcompat:1.6.1' diff --git a/sdk/src/main/java/ly/count/android/sdk/DeviceInfo.java b/sdk/src/main/java/ly/count/android/sdk/DeviceInfo.java index 8661d07c2..ae798565f 100644 --- a/sdk/src/main/java/ly/count/android/sdk/DeviceInfo.java +++ b/sdk/src/main/java/ly/count/android/sdk/DeviceInfo.java @@ -433,7 +433,7 @@ public String getBatteryLevel(Context context) { try { Intent batteryIntent; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - batteryIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); + batteryIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED), null, null, Context.RECEIVER_NOT_EXPORTED); } else { batteryIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); diff --git a/sdk/src/main/java/ly/count/android/sdk/messaging/CountlyPush.java b/sdk/src/main/java/ly/count/android/sdk/messaging/CountlyPush.java index 35cee168c..7353c7854 100644 --- a/sdk/src/main/java/ly/count/android/sdk/messaging/CountlyPush.java +++ b/sdk/src/main/java/ly/count/android/sdk/messaging/CountlyPush.java @@ -29,7 +29,6 @@ import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.core.content.ContextCompat; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; From 33dd4daeb403280067c17ab66aaf5bd6b8f6a397 Mon Sep 17 00:00:00 2001 From: ijunaid Date: Tue, 17 Oct 2023 13:31:58 +0500 Subject: [PATCH 5/6] Removed extra code --- sdk/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/build.gradle b/sdk/build.gradle index 1b436b93f..de770dec7 100644 --- a/sdk/build.gradle +++ b/sdk/build.gradle @@ -49,7 +49,6 @@ def mockitoVersion = "2.28.2" dependencies { api fileTree(dir: 'libs', include: ['*.jar']) - implementation 'androidx.core:core-ktx:1.9.0' implementation 'androidx.annotation:annotation:1.6.0' implementation 'androidx.lifecycle:lifecycle-common:2.6.1' implementation 'androidx.lifecycle:lifecycle-process:2.6.1' From a107868079e3624f66ddf7a36335eea1848e0413 Mon Sep 17 00:00:00 2001 From: ijunaid Date: Tue, 17 Oct 2023 18:53:47 +0500 Subject: [PATCH 6/6] Changelog updated --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d07df27b..4eeaf0b9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ * Added a call to enroll users to A/B tests when getting a remote config value: 'getValueAndEnroll' * Added a call to enroll users to A/B tests when getting all remote config values: 'getAllValuesAndEnroll' +* Fixed crash for SDK34 BroadcastReceivers, now declared broadcast receiver not exported if API is 34 and up. + * Mitigated an issue where users could not enroll to an A/B tests if enrollment request has failed * Mitigated an issue where users could not exit from A/B tests if removal request has failed