From 769a2205843b6c6130c9940b0113d4975b122daa Mon Sep 17 00:00:00 2001 From: Jae Kim Date: Tue, 18 Jan 2022 14:26:03 -0800 Subject: [PATCH 1/4] fix to support android-12+ --- build.gradle | 8 ++++---- test-app/src/main/AndroidManifest.xml | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 904875765..1f0488265 100644 --- a/build.gradle +++ b/build.gradle @@ -59,10 +59,10 @@ allprojects { } ext { - compile_sdk_version = 29 - build_tools_version = "29.0.3" + compile_sdk_version = 32 + build_tools_version = "30.0.2" min_sdk_version = 14 - target_sdk_version = 29 + target_sdk_version = 32 java_core_ver = "3.10.0" android_logger_ver = "1.3.6" jacksonversion= "2.11.2" @@ -76,7 +76,7 @@ ext { gson_ver = "2.8.6" group_id = "com.optimizely.ab" androidx_test = "1.1.1" - work_runtime = "2.5.0" + work_runtime = "2.7.1" } task clean(type: Delete) { diff --git a/test-app/src/main/AndroidManifest.xml b/test-app/src/main/AndroidManifest.xml index 86d4b7886..9061b61aa 100644 --- a/test-app/src/main/AndroidManifest.xml +++ b/test-app/src/main/AndroidManifest.xml @@ -40,6 +40,7 @@ From 8237e681d97c0037f15f3b18fcc78788953eb07f Mon Sep 17 00:00:00 2001 From: Jae Kim Date: Tue, 1 Feb 2022 16:34:21 -0800 Subject: [PATCH 2/4] update androidx test dependency for android 12 --- android-sdk/build.gradle | 11 +++++++---- build.gradle | 12 +++++++----- datafile-handler/build.gradle | 9 +++++---- event-handler/build.gradle | 10 ++++++---- shared/build.gradle | 10 ++++++---- test-app/build.gradle | 12 +++++++----- user-profile/build.gradle | 11 +++++++---- 7 files changed, 45 insertions(+), 30 deletions(-) diff --git a/android-sdk/build.gradle b/android-sdk/build.gradle index f0d2955da..f1a99327b 100644 --- a/android-sdk/build.gradle +++ b/android-sdk/build.gradle @@ -71,11 +71,14 @@ dependencies { testImplementation "org.powermock:powermock-mockito-release-full:$powermock_ver" testImplementation "com.noveogroup.android:android-logger:$android_logger_ver" - androidTestImplementation "androidx.test.ext:junit:$androidx_test" - // Set this dependency to use JUnit 4 rules - androidTestImplementation "androidx.test:rules:$androidx_test" - // Set this dependency to build and run Espresso tests + androidTestImplementation "androidx.work:work-testing:$work_runtime" + androidTestImplementation "androidx.test.ext:junit:$androidx_test_junit" androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_ver" + // Set this dependency to use JUnit 4 rules + androidTestImplementation "androidx.test:rules:$androidx_test_rules" + androidTestImplementation "androidx.test:core:$androidx_test_core" + androidTestImplementation "androidx.test:core-ktx:$androidx_test_core" + androidTestImplementation "org.mockito:mockito-core:$mockito_ver" androidTestImplementation "com.crittercism.dexmaker:dexmaker:$dexmaker_ver" androidTestImplementation "com.crittercism.dexmaker:dexmaker-dx:$dexmaker_ver" diff --git a/build.gradle b/build.gradle index 1f0488265..35c0f4001 100644 --- a/build.gradle +++ b/build.gradle @@ -60,23 +60,25 @@ allprojects { ext { compile_sdk_version = 32 - build_tools_version = "30.0.2" + build_tools_version = "30.0.3" min_sdk_version = 14 target_sdk_version = 32 java_core_ver = "3.10.0" android_logger_ver = "1.3.6" jacksonversion= "2.11.2" - annotations_ver = "1.0.0" + annotations_ver = "1.2.0" junit_ver = "4.12" mockito_ver = "1.10.19" powermock_ver = "1.6.4" support_test_runner_ver = "0.5" dexmaker_ver = "1.4" - espresso_ver = "3.1.0" - gson_ver = "2.8.6" + gson_ver = "2.8.9" group_id = "com.optimizely.ab" - androidx_test = "1.1.1" work_runtime = "2.7.1" + androidx_test_junit = "1.1.3" + androidx_test_core = "1.4.0" + androidx_test_rules = "1.4.0" + espresso_ver = "3.4.0" } task clean(type: Delete) { diff --git a/datafile-handler/build.gradle b/datafile-handler/build.gradle index ceac4c6e3..480bc9dbd 100644 --- a/datafile-handler/build.gradle +++ b/datafile-handler/build.gradle @@ -58,11 +58,12 @@ dependencies { testImplementation "com.noveogroup.android:android-logger:$android_logger_ver" androidTestImplementation "androidx.work:work-testing:$work_runtime" - androidTestImplementation "androidx.test.ext:junit:$androidx_test" - // Set this dependency to use JUnit 4 rules - androidTestImplementation "androidx.test:rules:$androidx_test" - // Set this dependency to build and run Espresso tests + androidTestImplementation "androidx.test.ext:junit:$androidx_test_junit" androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_ver" + // Set this dependency to use JUnit 4 rules + androidTestImplementation "androidx.test:rules:$androidx_test_rules" + androidTestImplementation "androidx.test:core:$androidx_test_core" + androidTestImplementation "androidx.test:core-ktx:$androidx_test_core" androidTestImplementation "org.mockito:mockito-core:$mockito_ver" androidTestImplementation "com.crittercism.dexmaker:dexmaker:$dexmaker_ver" diff --git a/event-handler/build.gradle b/event-handler/build.gradle index 09be11557..28026a850 100644 --- a/event-handler/build.gradle +++ b/event-handler/build.gradle @@ -62,11 +62,13 @@ dependencies { testImplementation "com.noveogroup.android:android-logger:$android_logger_ver" androidTestImplementation "androidx.work:work-testing:$work_runtime" - androidTestImplementation "androidx.test.ext:junit:$androidx_test" - // Set this dependency to use JUnit 4 rules - androidTestImplementation "androidx.test:rules:$androidx_test" - // Set this dependency to build and run Espresso tests + androidTestImplementation "androidx.test.ext:junit:$androidx_test_junit" androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_ver" + // Set this dependency to use JUnit 4 rules + androidTestImplementation "androidx.test:rules:$androidx_test_rules" + androidTestImplementation "androidx.test:core:$androidx_test_core" + androidTestImplementation "androidx.test:core-ktx:$androidx_test_core" + androidTestImplementation "org.mockito:mockito-core:$mockito_ver" androidTestImplementation "com.crittercism.dexmaker:dexmaker:$dexmaker_ver" androidTestImplementation "com.crittercism.dexmaker:dexmaker-dx:$dexmaker_ver" diff --git a/shared/build.gradle b/shared/build.gradle index dde638180..a1efce2d2 100644 --- a/shared/build.gradle +++ b/shared/build.gradle @@ -62,11 +62,13 @@ dependencies { testImplementation "com.noveogroup.android:android-logger:$android_logger_ver" androidTestImplementation "androidx.work:work-testing:$work_runtime" - androidTestImplementation "androidx.test.ext:junit:$androidx_test" - // Set this dependency to use JUnit 4 rules - androidTestImplementation "androidx.test:rules:$androidx_test" - // Set this dependency to build and run Espresso tests + androidTestImplementation "androidx.test.ext:junit:$androidx_test_junit" androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_ver" + // Set this dependency to use JUnit 4 rules + androidTestImplementation "androidx.test:rules:$androidx_test_rules" + androidTestImplementation "androidx.test:core:$androidx_test_core" + androidTestImplementation "androidx.test:core-ktx:$androidx_test_core" + androidTestImplementation "org.mockito:mockito-core:$mockito_ver" androidTestImplementation "com.crittercism.dexmaker:dexmaker:$dexmaker_ver" androidTestImplementation "com.crittercism.dexmaker:dexmaker-dx:$dexmaker_ver" diff --git a/test-app/build.gradle b/test-app/build.gradle index eab7f69da..2a9ec7677 100644 --- a/test-app/build.gradle +++ b/test-app/build.gradle @@ -66,12 +66,14 @@ dependencies { // testImplementation 'com.optimizely.ab:android-sdk:1.0.0' testImplementation project(':android-sdk') - androidTestImplementation('androidx.test.ext:junit:1.1.1') - //androidTestimplementation "androidx.annotation:annotation:$annotations_ver" - // Set this dependency to use JUnit 4 rules - androidTestImplementation "androidx.test:rules:$androidx_test" - // Set this dependency to build and run Espresso tests + androidTestImplementation "androidx.work:work-testing:$work_runtime" + androidTestImplementation "androidx.test.ext:junit:$androidx_test_junit" androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_ver" + // Set this dependency to use JUnit 4 rules + androidTestImplementation "androidx.test:rules:$androidx_test_rules" + androidTestImplementation "androidx.test:core:$androidx_test_core" + androidTestImplementation "androidx.test:core-ktx:$androidx_test_core" + androidTestImplementation "org.mockito:mockito-core:$mockito_ver" androidTestImplementation "com.crittercism.dexmaker:dexmaker:$dexmaker_ver" androidTestImplementation "com.crittercism.dexmaker:dexmaker-dx:$dexmaker_ver" diff --git a/user-profile/build.gradle b/user-profile/build.gradle index 8dc88d55d..368f15512 100644 --- a/user-profile/build.gradle +++ b/user-profile/build.gradle @@ -57,11 +57,14 @@ dependencies { testImplementation "org.mockito:mockito-core:$mockito_ver" testImplementation "com.noveogroup.android:android-logger:$android_logger_ver" - androidTestImplementation "androidx.test.ext:junit:$androidx_test" - // Set this dependency to use JUnit 4 rules - androidTestImplementation "androidx.test:rules:$androidx_test" - // Set this dependency to build and run Espresso tests + androidTestImplementation "androidx.work:work-testing:$work_runtime" + androidTestImplementation "androidx.test.ext:junit:$androidx_test_junit" androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_ver" + // Set this dependency to use JUnit 4 rules + androidTestImplementation "androidx.test:rules:$androidx_test_rules" + androidTestImplementation "androidx.test:core:$androidx_test_core" + androidTestImplementation "androidx.test:core-ktx:$androidx_test_core" + androidTestImplementation "org.mockito:mockito-core:$mockito_ver" androidTestImplementation "com.crittercism.dexmaker:dexmaker:$dexmaker_ver" androidTestImplementation "com.crittercism.dexmaker:dexmaker-dx:$dexmaker_ver" From 56855b61ea2353fbfa822cf1da9573a25b47167e Mon Sep 17 00:00:00 2001 From: Jae Kim Date: Tue, 1 Feb 2022 17:01:57 -0800 Subject: [PATCH 3/4] add PendingIntent.FLAG_IMMUTABLE --- .../com/optimizely/ab/android/shared/ServiceScheduler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/src/main/java/com/optimizely/ab/android/shared/ServiceScheduler.java b/shared/src/main/java/com/optimizely/ab/android/shared/ServiceScheduler.java index e1ffa925b..908c54acb 100644 --- a/shared/src/main/java/com/optimizely/ab/android/shared/ServiceScheduler.java +++ b/shared/src/main/java/com/optimizely/ab/android/shared/ServiceScheduler.java @@ -239,7 +239,7 @@ public boolean hasPendingIntent(Intent intent) { // FLAG_NO_CREATE will cause null to be returned if this Intent hasn't been created yet. // It does matter if you send a new instance or not the equality check is done via // the data, action, and component of an Intent. Ours will always match. - return getPendingIntent(intent, PendingIntent.FLAG_NO_CREATE) != null; + return getPendingIntent(intent, PendingIntent.FLAG_NO_CREATE | PendingIntent.FLAG_IMMUTABLE) != null; } /** @@ -248,7 +248,7 @@ public boolean hasPendingIntent(Intent intent) { * @return a {@link PendingIntent} */ public PendingIntent getPendingIntent(Intent intent) { - return getPendingIntent(intent, PendingIntent.FLAG_UPDATE_CURRENT); + return getPendingIntent(intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); } private PendingIntent getPendingIntent(Intent intent, int flag) { From 8db52a90cbe4437c4aec0fd472ec40c5e2aedd5c Mon Sep 17 00:00:00 2001 From: Jae Kim Date: Tue, 1 Feb 2022 17:10:20 -0800 Subject: [PATCH 4/4] fix FLAG_IMMUTABLE --- .../com/optimizely/ab/android/shared/ServiceScheduler.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/shared/src/main/java/com/optimizely/ab/android/shared/ServiceScheduler.java b/shared/src/main/java/com/optimizely/ab/android/shared/ServiceScheduler.java index 908c54acb..9c0f5610f 100644 --- a/shared/src/main/java/com/optimizely/ab/android/shared/ServiceScheduler.java +++ b/shared/src/main/java/com/optimizely/ab/android/shared/ServiceScheduler.java @@ -239,7 +239,7 @@ public boolean hasPendingIntent(Intent intent) { // FLAG_NO_CREATE will cause null to be returned if this Intent hasn't been created yet. // It does matter if you send a new instance or not the equality check is done via // the data, action, and component of an Intent. Ours will always match. - return getPendingIntent(intent, PendingIntent.FLAG_NO_CREATE | PendingIntent.FLAG_IMMUTABLE) != null; + return getPendingIntent(intent, PendingIntent.FLAG_NO_CREATE) != null; } /** @@ -248,11 +248,12 @@ public boolean hasPendingIntent(Intent intent) { * @return a {@link PendingIntent} */ public PendingIntent getPendingIntent(Intent intent) { - return getPendingIntent(intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); + return getPendingIntent(intent, PendingIntent.FLAG_UPDATE_CURRENT); } private PendingIntent getPendingIntent(Intent intent, int flag) { - return PendingIntent.getService(context, 0, intent, flag); + // Android 31+ requires FLAG_IMMUTABLE explicitly + return PendingIntent.getService(context, 0, intent, flag | PendingIntent.FLAG_IMMUTABLE); } }