From f83d26df58c719544636d4b323a513d7a403e779 Mon Sep 17 00:00:00 2001 From: Oliver Scott Date: Wed, 10 Nov 2021 15:14:05 -0500 Subject: [PATCH] Android 12 updates * Updated gradle version and dependencies * Bumped compileSdkVersion and targetSdkVersion to 31 * Added support for updates without user action * Bumped versionCode and versionName Changes required by API level 31: * Added explicit exported tags to activities and receivers * Added explicit IMMUTABLE|MUTABLE flags to PendingIntents --- app/build.gradle | 17 +++++----- app/src/main/AndroidManifest.xml | 13 +++++--- .../java/com/aurora/extensions/Context.kt | 4 ++- .../java/com/aurora/extensions/Platform.kt | 4 +++ .../store/data/installer/SessionInstaller.kt | 10 +++++- .../store/data/service/NotificationService.kt | 31 +++++++++++++++---- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 8 files changed, 60 insertions(+), 23 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d4af7fff3..347f3fe11 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -23,16 +23,15 @@ apply plugin: 'kotlin-kapt' apply plugin: "androidx.navigation.safeargs.kotlin" android { - compileSdkVersion 30 - buildToolsVersion "30.0.3" + compileSdkVersion 31 defaultConfig { applicationId "com.aurora.store" minSdkVersion 19 - targetSdkVersion 30 + targetSdkVersion 31 - versionCode 38 - versionName "4.0.7" + versionCode 39 + versionName "4.1.0" vectorDrawables.useSupportLibrary = true multiDexEnabled true @@ -82,8 +81,8 @@ buildscript { fetch2 : "3.1.6", fuel : "2.3.0", glide : "4.11.0", - lifecycle : "2.3.1", - navigation: "2.3.4", + lifecycle : '2.4.0', + navigation: '2.3.5', epoxy : "4.3.1", libsu : "3.0.2" ] @@ -108,12 +107,12 @@ dependencies { implementation("org.apache.commons:commons-text:1.8") //Google's Goodies - implementation("com.google.android.material:material:1.3.0") + implementation("com.google.android.material:material:1.4.0") implementation("com.google.android:flexbox:2.0.1") implementation("com.google.code.gson:gson:2.8.6") //AndroidX - implementation("androidx.core:core-ktx:1.3.2") + implementation("androidx.core:core-ktx:1.7.0") implementation("androidx.viewpager2:viewpager2:1.0.0") implementation("androidx.vectordrawable:vectordrawable:1.1.0") implementation("androidx.preference:preference-ktx:1.1.1") diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f7a741ad2..37fd17abc 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -41,6 +41,7 @@ tools:ignore="ProtectedPermissions" /> + - + @@ -88,7 +90,8 @@ android:name=".MainActivity" android:launchMode="singleTask" /> - + @@ -120,7 +123,8 @@ - + @@ -173,7 +177,8 @@ android:resource="@xml/paths" /> - + diff --git a/app/src/main/java/com/aurora/extensions/Context.kt b/app/src/main/java/com/aurora/extensions/Context.kt index ea9397755..fd6fffd16 100644 --- a/app/src/main/java/com/aurora/extensions/Context.kt +++ b/app/src/main/java/com/aurora/extensions/Context.kt @@ -96,11 +96,13 @@ fun Context.open(className: Class, newTask: Boolean = false) { } fun Context.restartApp() { + val flags = if (isMAndAbove()) PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE + else PendingIntent.FLAG_CANCEL_CURRENT val pendingIntent = PendingIntent.getActivity( this, 1337, Intent(this, MainActivity::class.java), - PendingIntent.FLAG_CANCEL_CURRENT + flags ) val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager diff --git a/app/src/main/java/com/aurora/extensions/Platform.kt b/app/src/main/java/com/aurora/extensions/Platform.kt index 21e7375d8..f568f37cf 100644 --- a/app/src/main/java/com/aurora/extensions/Platform.kt +++ b/app/src/main/java/com/aurora/extensions/Platform.kt @@ -52,6 +52,10 @@ fun isRAndAbove(): Boolean { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.R } +fun isSAndAbove(): Boolean { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S +} + fun isMIUI(): Boolean { return getSystemProperty("ro.miui.ui.version.name").isNotEmpty() } diff --git a/app/src/main/java/com/aurora/store/data/installer/SessionInstaller.kt b/app/src/main/java/com/aurora/store/data/installer/SessionInstaller.kt index c4fc4a857..f25265f69 100644 --- a/app/src/main/java/com/aurora/store/data/installer/SessionInstaller.kt +++ b/app/src/main/java/com/aurora/store/data/installer/SessionInstaller.kt @@ -27,7 +27,9 @@ import android.net.Uri import android.os.Build import androidx.annotation.RequiresApi import androidx.core.content.FileProvider +import com.aurora.extensions.isMAndAbove import com.aurora.extensions.isNAndAbove +import com.aurora.extensions.isSAndAbove import com.aurora.store.BuildConfig import com.aurora.store.util.Log import org.apache.commons.io.IOUtils @@ -63,6 +65,9 @@ class SessionInstaller(context: Context) : InstallerBase(context) { if (isNAndAbove()) { setOriginatingUid(android.os.Process.myUid()) } + if (isSAndAbove()) { + setRequireUserAction(SessionParams.USER_ACTION_NOT_REQUIRED) + } } val sessionId = packageInstaller.createSession(sessionParams) val session = packageInstaller.openSession(sessionId) @@ -87,11 +92,14 @@ class SessionInstaller(context: Context) : InstallerBase(context) { } val callBackIntent = Intent(context, InstallerService::class.java) + val flags = if (isSAndAbove()) + PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE else + PendingIntent.FLAG_UPDATE_CURRENT; val pendingIntent = PendingIntent.getService( context, sessionId, callBackIntent, - PendingIntent.FLAG_UPDATE_CURRENT + flags ) Log.i("Starting install session for $packageName") diff --git a/app/src/main/java/com/aurora/store/data/service/NotificationService.kt b/app/src/main/java/com/aurora/store/data/service/NotificationService.kt index 421f9218d..935bd21a4 100644 --- a/app/src/main/java/com/aurora/store/data/service/NotificationService.kt +++ b/app/src/main/java/com/aurora/store/data/service/NotificationService.kt @@ -32,6 +32,7 @@ import androidx.core.content.ContextCompat import com.aurora.Constants import com.aurora.extensions.getStyledAttributeColor import com.aurora.extensions.isLAndAbove +import com.aurora.extensions.isMAndAbove import com.aurora.gplayapi.data.models.App import com.aurora.store.R import com.aurora.store.data.downloader.DownloadManager @@ -331,45 +332,63 @@ class NotificationService : Service() { private fun getPauseIntent(groupId: Int): PendingIntent { val intent = Intent(this, DownloadPauseReceiver::class.java) intent.putExtra(Constants.FETCH_GROUP_ID, groupId) - return PendingIntent.getBroadcast(this, groupId, intent, PendingIntent.FLAG_UPDATE_CURRENT) + val flags = if (isMAndAbove()) + PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE + else PendingIntent.FLAG_CANCEL_CURRENT + return PendingIntent.getBroadcast(this, groupId, intent, flags) } private fun getResumeIntent(groupId: Int): PendingIntent { val intent = Intent(this, DownloadResumeReceiver::class.java) intent.putExtra(Constants.FETCH_GROUP_ID, groupId) - return PendingIntent.getBroadcast(this, groupId, intent, PendingIntent.FLAG_UPDATE_CURRENT) + val flags = if (isMAndAbove()) + PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE + else PendingIntent.FLAG_CANCEL_CURRENT + return PendingIntent.getBroadcast(this, groupId, intent, flags) } private fun getCancelIntent(groupId: Int): PendingIntent { val intent = Intent(this, DownloadCancelReceiver::class.java) intent.putExtra(Constants.FETCH_GROUP_ID, groupId) - return PendingIntent.getBroadcast(this, groupId, intent, PendingIntent.FLAG_UPDATE_CURRENT) + val flags = if (isMAndAbove()) + PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE + else PendingIntent.FLAG_CANCEL_CURRENT + return PendingIntent.getBroadcast(this, groupId, intent, flags) } private fun getContentIntentForDetails(app: App?): PendingIntent { val intent = Intent(this, AppDetailsActivity::class.java) intent.putExtra(Constants.STRING_EXTRA, gson.toJson(app)) + val flags = if (isMAndAbove()) + PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE + else PendingIntent.FLAG_CANCEL_CURRENT return PendingIntent.getActivity( this, packageName.hashCode(), intent, - PendingIntent.FLAG_UPDATE_CURRENT + flags ) } private fun getContentIntentForDownloads(): PendingIntent { val intent = Intent(this, DownloadActivity::class.java) - return PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) + val flags = if (isMAndAbove()) + PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE + else PendingIntent.FLAG_CANCEL_CURRENT + return PendingIntent.getActivity(this, 0, intent, flags) } private fun getInstallIntent(packageName: String, versionCode: String): PendingIntent { val intent = Intent(this, InstallReceiver::class.java) intent.putExtra(Constants.STRING_EXTRA, packageName) + val flags = if (isMAndAbove()) + PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE + else PendingIntent.FLAG_CANCEL_CURRENT return PendingIntent.getBroadcast( this, packageName.hashCode(), intent, - PendingIntent.FLAG_UPDATE_CURRENT + flags ) } diff --git a/build.gradle b/build.gradle index f02d3c0d8..c4fc97778 100644 --- a/build.gradle +++ b/build.gradle @@ -32,7 +32,7 @@ buildscript { ext.navigation= "2.3.4" dependencies { - classpath ("com.android.tools.build:gradle:4.1.3") + classpath ('com.android.tools.build:gradle:7.0.3') classpath ("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin") classpath ("androidx.navigation:navigation-safe-args-gradle-plugin:$navigation") } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 6a0f54918..a6e275633 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -22,4 +22,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip