From bb0f0270d165ae82f8e6f6485c14cdbdbfa47f40 Mon Sep 17 00:00:00 2001 From: James Tauzin Date: Fri, 29 Oct 2021 11:16:54 -0500 Subject: [PATCH 1/4] Added mutability flags for Android 12 (SDK 31) compatibility --- .../chuck/internal/support/NotificationHelper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/com/readystatesoftware/chuck/internal/support/NotificationHelper.java b/library/src/main/java/com/readystatesoftware/chuck/internal/support/NotificationHelper.java index 4003c78a..ef0c1540 100644 --- a/library/src/main/java/com/readystatesoftware/chuck/internal/support/NotificationHelper.java +++ b/library/src/main/java/com/readystatesoftware/chuck/internal/support/NotificationHelper.java @@ -78,7 +78,7 @@ public synchronized void show(HttpTransaction transaction) { addToBuffer(transaction); if (!BaseChuckActivity.isInForeground()) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context) - .setContentIntent(PendingIntent.getActivity(context, 0, Chuck.getLaunchIntent(context), 0)) + .setContentIntent(PendingIntent.getActivity(context, 0, Chuck.getLaunchIntent(context), PendingIntent.FLAG_IMMUTABLE)) .setLocalOnly(true) .setSmallIcon(R.drawable.chuck_ic_notification_white_24dp) .setColor(ContextCompat.getColor(context, R.color.chuck_colorPrimary)) @@ -113,7 +113,7 @@ public synchronized void show(HttpTransaction transaction) { private NotificationCompat.Action getClearAction() { CharSequence clearTitle = context.getString(R.string.chuck_clear); Intent deleteIntent = new Intent(context, ClearTransactionsService.class); - PendingIntent intent = PendingIntent.getService(context, 11, deleteIntent, PendingIntent.FLAG_ONE_SHOT); + PendingIntent intent = PendingIntent.getService(context, 11, deleteIntent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_ONE_SHOT); return new NotificationCompat.Action(R.drawable.chuck_ic_delete_white_24dp, clearTitle, intent); } From 1f75fd68a773e82704f423f4ef50d69bad5eb794 Mon Sep 17 00:00:00 2001 From: James Tauzin Date: Fri, 29 Oct 2021 12:09:18 -0500 Subject: [PATCH 2/4] updated gradle files to more recent versions (tech debt) --- build.gradle | 7 ++++--- gradle/wrapper/gradle-wrapper.properties | 2 +- library-no-op/build.gradle | 2 +- library/build.gradle | 8 ++++---- sample/build.gradle | 14 +++++++------- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/build.gradle b/build.gradle index 7a82cc95..0772a288 100644 --- a/build.gradle +++ b/build.gradle @@ -3,9 +3,10 @@ buildscript { repositories { jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.3' + classpath 'com.android.tools.build:gradle:4.2.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -30,8 +31,8 @@ task clean(type: Delete) { ext { minSdkVersion = 16 - targetSdkVersion = 26 - compileSdkVersion = 26 + targetSdkVersion = 30 + compileSdkVersion = 30 buildToolsVersion = '26.0.1' supportLibVersion = '25.3.1' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5192af6d..08ca6349 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip diff --git a/library-no-op/build.gradle b/library-no-op/build.gradle index 8dea4692..f186f25c 100644 --- a/library-no-op/build.gradle +++ b/library-no-op/build.gradle @@ -10,7 +10,7 @@ android { } dependencies { - compile "com.squareup.okhttp3:okhttp:$okhttp3Version" + api "com.squareup.okhttp3:okhttp:$okhttp3Version" } apply from: rootProject.file('gradle/gradle-mvn-push.gradle') \ No newline at end of file diff --git a/library/build.gradle b/library/build.gradle index ed58a517..604c94c8 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -11,10 +11,10 @@ android { } dependencies { - compile 'com.google.code.gson:gson:2.8.0' - compile "com.squareup.okhttp3:okhttp:$okhttp3Version" - compile 'nl.qbusict:cupboard:2.2.0' - compile "com.android.support:design:$supportLibVersion" + api 'com.google.code.gson:gson:2.8.0' + api "com.squareup.okhttp3:okhttp:$okhttp3Version" + api 'nl.qbusict:cupboard:2.2.0' + api "com.android.support:design:$supportLibVersion" } apply from: rootProject.file('gradle/gradle-mvn-push.gradle') diff --git a/sample/build.gradle b/sample/build.gradle index 018e4fd6..e21e8288 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -25,11 +25,11 @@ android { } dependencies { - debugCompile project(':library') - releaseCompile project(':library-no-op') - compile "com.android.support:design:26.0.0" - compile "com.android.support:appcompat-v7:26.0.0" - compile "com.squareup.okhttp3:logging-interceptor:$okhttp3Version" - compile "com.squareup.retrofit2:retrofit:2.2.0" - compile "com.squareup.retrofit2:converter-gson:2.2.0" + debugImplementation project(':library') + releaseImplementation project(':library-no-op') + implementation "com.android.support:design:26.0.0" + implementation "com.android.support:appcompat-v7:26.0.0" + implementation "com.squareup.okhttp3:logging-interceptor:$okhttp3Version" + implementation "com.squareup.retrofit2:retrofit:2.2.0" + implementation "com.squareup.retrofit2:converter-gson:2.2.0" } From a1a062508a6c6a765b0e7d0a1b50a998c05bce28 Mon Sep 17 00:00:00 2001 From: James Tauzin Date: Fri, 29 Oct 2021 12:10:13 -0500 Subject: [PATCH 3/4] updated manifest to Android 12 (SDK 31 compatibility) --- sample/src/main/AndroidManifest.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index 89fd8c28..4911e524 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -25,7 +25,8 @@ android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> - + From 9533a303d69a410b560f8a88c27aea14770710f1 Mon Sep 17 00:00:00 2001 From: James Tauzin Date: Fri, 29 Oct 2021 12:19:23 -0500 Subject: [PATCH 4/4] added support to keep minimum SDK version at 16 (SDK 31 compatibility) --- .../internal/support/NotificationHelper.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/com/readystatesoftware/chuck/internal/support/NotificationHelper.java b/library/src/main/java/com/readystatesoftware/chuck/internal/support/NotificationHelper.java index ef0c1540..7c6655c6 100644 --- a/library/src/main/java/com/readystatesoftware/chuck/internal/support/NotificationHelper.java +++ b/library/src/main/java/com/readystatesoftware/chuck/internal/support/NotificationHelper.java @@ -76,13 +76,24 @@ public NotificationHelper(Context context) { public synchronized void show(HttpTransaction transaction) { addToBuffer(transaction); + NotificationCompat.Builder builder; if (!BaseChuckActivity.isInForeground()) { - NotificationCompat.Builder builder = new NotificationCompat.Builder(context) + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1){ + builder = new NotificationCompat.Builder(context) .setContentIntent(PendingIntent.getActivity(context, 0, Chuck.getLaunchIntent(context), PendingIntent.FLAG_IMMUTABLE)) .setLocalOnly(true) .setSmallIcon(R.drawable.chuck_ic_notification_white_24dp) .setColor(ContextCompat.getColor(context, R.color.chuck_colorPrimary)) .setContentTitle(context.getString(R.string.chuck_notification_title)); + } + else { + builder = new NotificationCompat.Builder(context) + .setContentIntent(PendingIntent.getActivity(context, 0, Chuck.getLaunchIntent(context), 0)) + .setLocalOnly(true) + .setSmallIcon(R.drawable.chuck_ic_notification_white_24dp) + .setColor(ContextCompat.getColor(context, R.color.chuck_colorPrimary)) + .setContentTitle(context.getString(R.string.chuck_notification_title)); + } NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); if (setChannelId != null) { try { setChannelId.invoke(builder, CHANNEL_ID); } catch (Exception ignored) {} @@ -113,7 +124,13 @@ public synchronized void show(HttpTransaction transaction) { private NotificationCompat.Action getClearAction() { CharSequence clearTitle = context.getString(R.string.chuck_clear); Intent deleteIntent = new Intent(context, ClearTransactionsService.class); - PendingIntent intent = PendingIntent.getService(context, 11, deleteIntent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_ONE_SHOT); + PendingIntent intent; + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1){ + intent = PendingIntent.getService(context, 11, deleteIntent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_ONE_SHOT); + } + else { + intent = PendingIntent.getService(context, 11, deleteIntent, PendingIntent.FLAG_ONE_SHOT); + } return new NotificationCompat.Action(R.drawable.chuck_ic_delete_white_24dp, clearTitle, intent); }