From 443ea0cd3612055cb63288507f255788bfe3fc6b Mon Sep 17 00:00:00 2001 From: bjoern Date: Sun, 30 Oct 2022 16:06:24 +0100 Subject: [PATCH] bump targetSdkVersion to 32 (#2407) * bump targetSdkVersion to 32 * explicitly set `android:exported` for `indent-filter` this is required since targetSdkVersion 31, https://developer.android.com/guide/components/intents-filters#Receiving as the default was `false` before, i just explicitly set `android:exported="false"` without looking in the details of each filter. * update to gradle 7.2.2; this might be needed to get warnings etc. * update androidx dependencies at least the update of androidx.sharetarget is required because of the missing `android:exported`; i took the chance to update all androidx depenencies. see https://developer.android.com/jetpack/androidx/releases/appcompat for a CHANGELOG of each dependency. * use explicit dependency instead of transitive ones; this fixes a weird duplicate error, see https://stackoverflow.com/questions/69817925/problem-duplicate-class-androidx-lifecycle-viewmodel-found-in-modules * work around google's poor design decision wrt FLAG_MUTABLE instead of setting a default behavior and logging a warning, google crashes the application when the flag is missing on newer androids. and setting the flag for older API seems to be undefined and therefore a lot of Build.VERSION.SDK_INT >= Build.VERSION_CODES.M would be required each time a PendingIntent object is constructed ... our Util returns either the new flag or zero, so that can just be used unconditionally on construction. * update dependencies but exoplayer to mitigate issues with FLAG_MUTABLE exoplayer needs more love and updating opens a can of worms; i tested, at least in the emulator, video and voice message playback works as usual, so let's update exoplayer if needed. --- AndroidManifest.xml | 15 ++++-- build.gradle | 52 ++++++++++--------- .../securesms/connect/KeepAliveService.java | 3 +- .../notifications/NotificationCenter.java | 9 ++-- .../service/GenericForegroundService.java | 3 +- .../securesms/util/IntentUtils.java | 10 ++++ 6 files changed, 57 insertions(+), 35 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index d3158559b..5a52d271a 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -63,7 +63,8 @@ android:launchMode="singleTask" android:taskAffinity="" android:windowSoftInputMode="stateHidden" - android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"> + android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize" + android:exported="false"> @@ -175,7 +176,8 @@ + android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize" + android:exported="false"> @@ -197,7 +199,8 @@ + android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize" + android:exported="false"> @@ -217,7 +220,8 @@ + android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize" + android:exported="false"> @@ -367,7 +371,8 @@ android:exported="false"> - + diff --git a/build.gradle b/build.gradle index 0157bd2dc..7a6d61a57 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:7.0.3' + classpath 'com.android.tools.build:gradle:7.2.2' } } @@ -22,23 +22,28 @@ repositories { } dependencies { - implementation 'androidx.sharetarget:sharetarget:1.1.0' - implementation 'androidx.webkit:webkit:1.4.0' + implementation 'androidx.sharetarget:sharetarget:1.2.0' + implementation 'androidx.webkit:webkit:1.5.0' implementation 'androidx.multidex:multidex:2.0.1' - implementation 'androidx.appcompat:appcompat:1.2.0' - implementation 'com.google.android.material:material:1.2.0' + implementation 'androidx.appcompat:appcompat:1.5.1' + implementation 'com.google.android.material:material:1.7.0' implementation 'androidx.legacy:legacy-support-v13:1.0.0' - implementation 'androidx.preference:preference:1.1.1' + implementation ('androidx.preference:preference:1.2.0') { + exclude group: 'androidx.lifecycle', module:'lifecycle-viewmodel' + exclude group: 'androidx.lifecycle', module:'lifecycle-viewmodel-ktx' + } implementation 'androidx.legacy:legacy-preference-v14:1.0.0' - implementation 'androidx.exifinterface:exifinterface:1.2.0' + implementation 'androidx.exifinterface:exifinterface:1.3.5' implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' - implementation 'androidx.lifecycle:lifecycle-common-java8:2.2.0' - implementation 'androidx.work:work-runtime:2.4.0' + implementation 'androidx.lifecycle:lifecycle-common-java8:2.5.1' + implementation 'androidx.lifecycle:lifecycle-viewmodel:2.5.1' + implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1' + implementation 'androidx.work:work-runtime:2.7.1' implementation 'com.google.android.exoplayer:exoplayer-core:2.9.6' // plays video and audio implementation 'com.google.android.exoplayer:exoplayer-ui:2.9.6' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'com.journeyapps:zxing-android-embedded:3.4.0' // QR Code scanner - implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.9.2' // used as JSON library + implementation 'com.fasterxml.jackson.core:jackson-databind:2.11.1' // used as JSON library implementation "me.leolin:ShortcutBadger:1.1.16" // display messagecount on the home screen icon. implementation 'com.jpardogo.materialtabstrip:library:1.0.9' // used in the emoji selector for the tab selection. implementation 'com.github.chrisbanes:PhotoView:2.1.3' // does the zooming on photos / media @@ -46,7 +51,7 @@ dependencies { implementation 'com.caverock:androidsvg-aar:1.4' // SVG support. implementation 'com.github.bumptech.glide:glide:4.12.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0' - annotationProcessor 'androidx.annotation:annotation:1.1.0' + annotationProcessor 'androidx.annotation:annotation:1.5.0' implementation 'com.makeramen:roundedimageview:2.1.0' // crops the avatars to circles implementation 'com.pnikosis:materialish-progress:1.5' // used only in the "Progress Wheel" in Share Activity. implementation 'com.soundcloud.android:android-crop:0.9.10@aar' // used in Group Select Avatar, should be unified with profie @@ -64,8 +69,7 @@ dependencies { exclude group: 'com.google.android.gms' } - testImplementation 'junit:junit:4.12' - testImplementation 'junit:junit:4.12' + testImplementation 'junit:junit:4.13.1' testImplementation 'org.assertj:assertj-core:1.7.1' testImplementation 'org.mockito:mockito-core:1.9.5' testImplementation 'org.powermock:powermock-api-mockito:1.6.1' @@ -73,12 +77,12 @@ dependencies { testImplementation 'org.powermock:powermock-module-junit4-rule:1.6.1' testImplementation 'org.powermock:powermock-classloading-xstream:1.6.1' - androidTestImplementation 'androidx.test:runner:1.2.0' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' - androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.3.0' - androidTestImplementation 'androidx.test:rules:1.2.0' - androidTestImplementation 'androidx.test.ext:junit:1.1.1' - androidTestImplementation 'com.android.support:support-annotations:24.0.0' + androidTestImplementation 'androidx.test:runner:1.4.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0' + androidTestImplementation 'androidx.test:rules:1.4.0' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'com.android.support:support-annotations:28.0.0' androidTestImplementation ('org.assertj:assertj-core:1.7.1') { exclude group: 'org.hamcrest', module: 'hamcrest-core' @@ -88,7 +92,7 @@ dependencies { android { flavorDimensions "none" - compileSdkVersion 30 + compileSdkVersion 32 useLibrary 'org.apache.http.legacy' defaultConfig { @@ -99,7 +103,7 @@ android { multiDexEnabled true minSdkVersion 16 - targetSdkVersion 30 + targetSdkVersion 32 vectorDrawables.useSupportLibrary = true @@ -210,10 +214,10 @@ android { java.srcDirs = ['androidTest'] } } - - lintOptions { + lint { abortOnError false } + } String buildConfigProperty(String name) { diff --git a/src/org/thoughtcrime/securesms/connect/KeepAliveService.java b/src/org/thoughtcrime/securesms/connect/KeepAliveService.java index 0db584116..9d2bda74a 100644 --- a/src/org/thoughtcrime/securesms/connect/KeepAliveService.java +++ b/src/org/thoughtcrime/securesms/connect/KeepAliveService.java @@ -18,6 +18,7 @@ import android.util.Log; import org.thoughtcrime.securesms.ConversationListActivity; import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.notifications.NotificationCenter; +import org.thoughtcrime.securesms.util.IntentUtils; import org.thoughtcrime.securesms.util.Prefs; public class KeepAliveService extends Service { @@ -92,7 +93,7 @@ public class KeepAliveService extends Service { private Notification createNotification() { Intent intent = new Intent(this, ConversationListActivity.class); - PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | IntentUtils.FLAG_MUTABLE()); // a notification _must_ contain a small icon, a title and a text, see https://developer.android.com/guide/topics/ui/notifiers/notifications.html#Required NotificationCompat.Builder builder = new NotificationCompat.Builder(this); diff --git a/src/org/thoughtcrime/securesms/notifications/NotificationCenter.java b/src/org/thoughtcrime/securesms/notifications/NotificationCenter.java index 6ea55e708..9e24ef483 100644 --- a/src/org/thoughtcrime/securesms/notifications/NotificationCenter.java +++ b/src/org/thoughtcrime/securesms/notifications/NotificationCenter.java @@ -37,6 +37,7 @@ import org.thoughtcrime.securesms.mms.GlideApp; import org.thoughtcrime.securesms.preferences.widgets.NotificationPrivacyPreference; import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.util.BitmapUtil; +import org.thoughtcrime.securesms.util.IntentUtils; import org.thoughtcrime.securesms.util.Prefs; import org.thoughtcrime.securesms.util.Util; @@ -103,7 +104,7 @@ public class NotificationCenter { private PendingIntent getOpenChatlistIntent() { Intent intent = new Intent(context, ConversationListActivity.class); intent.putExtra(ConversationListActivity.CLEAR_NOTIFICATIONS, true); - return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | IntentUtils.FLAG_MUTABLE()); } private PendingIntent getOpenChatIntent(int chatId) { @@ -112,7 +113,7 @@ public class NotificationCenter { intent.setData((Uri.parse("custom://"+System.currentTimeMillis()))); return TaskStackBuilder.create(context) .addNextIntentWithParentStack(intent) - .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); + .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT | IntentUtils.FLAG_MUTABLE()); } private PendingIntent getRemoteReplyIntent(int chatId) { @@ -121,7 +122,7 @@ public class NotificationCenter { intent.setData((Uri.parse("custom://"+System.currentTimeMillis()))); intent.putExtra(RemoteReplyReceiver.CHAT_ID_EXTRA, chatId); intent.setPackage(context.getPackageName()); - return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | IntentUtils.FLAG_MUTABLE()); } private PendingIntent getMarkAsReadIntent(int chatId, boolean markNoticed) { @@ -130,7 +131,7 @@ public class NotificationCenter { intent.setData((Uri.parse("custom://"+System.currentTimeMillis()))); intent.putExtra(MarkReadReceiver.CHAT_ID_EXTRA, chatId); intent.setPackage(context.getPackageName()); - return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | IntentUtils.FLAG_MUTABLE()); } diff --git a/src/org/thoughtcrime/securesms/service/GenericForegroundService.java b/src/org/thoughtcrime/securesms/service/GenericForegroundService.java index b1e692ee2..a77d32d3e 100644 --- a/src/org/thoughtcrime/securesms/service/GenericForegroundService.java +++ b/src/org/thoughtcrime/securesms/service/GenericForegroundService.java @@ -21,6 +21,7 @@ import androidx.core.content.ContextCompat; import org.thoughtcrime.securesms.DummyActivity; import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.notifications.NotificationCenter; +import org.thoughtcrime.securesms.util.IntentUtils; import java.util.Iterator; import java.util.LinkedHashMap; @@ -117,7 +118,7 @@ public final class GenericForegroundService extends Service { .setTicker(active.contentText) .setContentText(active.contentText) .setProgress(active.progressMax, active.progress, active.indeterminate) - .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, DummyActivity.class), 0)) + .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, DummyActivity.class), IntentUtils.FLAG_MUTABLE())) .build()); } diff --git a/src/org/thoughtcrime/securesms/util/IntentUtils.java b/src/org/thoughtcrime/securesms/util/IntentUtils.java index ba20ca062..19ecb4caa 100644 --- a/src/org/thoughtcrime/securesms/util/IntentUtils.java +++ b/src/org/thoughtcrime/securesms/util/IntentUtils.java @@ -1,10 +1,13 @@ package org.thoughtcrime.securesms.util; +import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.pm.ResolveInfo; import android.net.Uri; +import android.os.Build; + import androidx.annotation.NonNull; import java.util.List; @@ -21,4 +24,11 @@ public class IntentUtils { context.startActivity(browserIntent); } + public static int FLAG_MUTABLE() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + return PendingIntent.FLAG_MUTABLE; + } else { + return 0; + } + } }