Switch to compat methods wherever possible
* Introduce custom compat methods with DEPRECATION suppressed if not present in public library Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -40,3 +40,13 @@ inline fun <reified T : Context> Context.newIntent(flags: Int, extras: Bundle):
|
||||
intent.putExtras(extras)
|
||||
return intent
|
||||
}
|
||||
|
||||
fun Intent.applyUninstallActionCompat() {
|
||||
if (isPAndAbove()) {
|
||||
action = Intent.ACTION_DELETE
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
action = Intent.ACTION_UNINSTALL_PACKAGE
|
||||
putExtra(Intent.EXTRA_RETURN_RESULT, true)
|
||||
}
|
||||
}
|
||||
|
||||
12
app/src/main/java/com/aurora/extensions/PackageManager.kt
Normal file
12
app/src/main/java/com/aurora/extensions/PackageManager.kt
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.aurora.extensions
|
||||
|
||||
import android.content.pm.PackageManager
|
||||
|
||||
fun PackageManager.getInstallerPackageNameCompat(packageName: String): String? {
|
||||
return if (isRAndAbove()) {
|
||||
getInstallSourceInfo(packageName).installingPackageName
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
return getInstallerPackageName(packageName)
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,8 @@ package com.aurora.store.data.installer
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import androidx.core.content.FileProvider
|
||||
import com.aurora.extensions.applyUninstallActionCompat
|
||||
import com.aurora.store.AuroraApplication
|
||||
import com.aurora.store.BuildConfig
|
||||
import com.aurora.store.data.event.InstallerEvent
|
||||
@@ -50,13 +50,7 @@ abstract class InstallerBase(protected var context: Context) : IInstaller {
|
||||
val intent = Intent().apply {
|
||||
data = uri
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
|
||||
intent.action = Intent.ACTION_DELETE
|
||||
} else {
|
||||
intent.action = Intent.ACTION_UNINSTALL_PACKAGE
|
||||
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true)
|
||||
applyUninstallActionCompat()
|
||||
}
|
||||
|
||||
context.startActivity(intent)
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.app.Service
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageInstaller
|
||||
import android.os.IBinder
|
||||
import androidx.core.content.IntentCompat
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.data.event.InstallerEvent
|
||||
import com.aurora.store.util.Log
|
||||
@@ -45,7 +46,8 @@ class InstallerService : Service() {
|
||||
}
|
||||
|
||||
private fun promptUser(intent: Intent) {
|
||||
val confirmationIntent: Intent? = intent.getParcelableExtra(Intent.EXTRA_INTENT)
|
||||
val confirmationIntent =
|
||||
IntentCompat.getParcelableExtra(intent, Intent.EXTRA_INTENT, Intent::class.java)
|
||||
|
||||
confirmationIntent?.let {
|
||||
it.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true)
|
||||
|
||||
@@ -6,10 +6,10 @@ import android.os.Build
|
||||
import android.os.IBinder
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.ServiceCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.lifecycle.LifecycleService
|
||||
import com.aurora.Constants
|
||||
import com.aurora.extensions.isNAndAbove
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
import com.aurora.gplayapi.data.models.File
|
||||
import com.aurora.store.BuildConfig
|
||||
@@ -87,11 +87,7 @@ class SelfUpdateService : LifecycleService() {
|
||||
private fun destroyService() {
|
||||
Log.d("Self-update service destroyed")
|
||||
fetch.removeListener(fetchListener)
|
||||
if (isNAndAbove()) {
|
||||
stopForeground(STOP_FOREGROUND_REMOVE)
|
||||
} else {
|
||||
stopForeground(true)
|
||||
}
|
||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||
stopSelf()
|
||||
}
|
||||
|
||||
|
||||
@@ -5,11 +5,11 @@ import android.content.Intent
|
||||
import android.os.*
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.ServiceCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.lifecycle.LifecycleService
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.aurora.Constants
|
||||
import com.aurora.extensions.isNAndAbove
|
||||
import com.aurora.extensions.isOAndAbove
|
||||
import com.aurora.extensions.stackTraceToString
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
@@ -56,11 +56,10 @@ class UpdateService: LifecycleService() {
|
||||
if (!data && isEmptyInstalling() && fetchListeners.isEmpty() && appMetadataListeners.isEmpty()) {
|
||||
Handler(Looper.getMainLooper()).postDelayed ({
|
||||
if (isEmptyInstalling() && fetchListeners.isEmpty() && appMetadataListeners.isEmpty()) {
|
||||
if (isNAndAbove()) {
|
||||
stopForeground(STOP_FOREGROUND_REMOVE)
|
||||
} else {
|
||||
stopForeground(true)
|
||||
}
|
||||
ServiceCompat.stopForeground(
|
||||
this@UpdateService,
|
||||
ServiceCompat.STOP_FOREGROUND_REMOVE
|
||||
)
|
||||
stopSelf()
|
||||
}
|
||||
}, 5 * 1000)
|
||||
@@ -599,11 +598,10 @@ class UpdateService: LifecycleService() {
|
||||
fetch.hasActiveDownloads(true) { hasActiveDownloads ->
|
||||
if (!hasActiveDownloads && isEmptyInstalling() && fetchListeners.isEmpty() && appMetadataListeners.isEmpty()) {
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
if (isNAndAbove()) {
|
||||
stopForeground(STOP_FOREGROUND_REMOVE)
|
||||
} else {
|
||||
stopForeground(true)
|
||||
}
|
||||
ServiceCompat.stopForeground(
|
||||
this@UpdateService,
|
||||
ServiceCompat.STOP_FOREGROUND_REMOVE
|
||||
)
|
||||
stopSelf()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import android.content.pm.SharedLibraryInfo
|
||||
import android.content.res.Configuration
|
||||
import android.os.Build
|
||||
import androidx.core.content.pm.PackageInfoCompat
|
||||
import com.aurora.extensions.getInstallerPackageNameCompat
|
||||
import com.aurora.extensions.isOAndAbove
|
||||
import com.aurora.extensions.isTAndAbove
|
||||
|
||||
@@ -191,7 +192,7 @@ object PackageUtil {
|
||||
if (isAuroraOnlyUpdateEnabled) {
|
||||
packageInfoList = packageInfoList
|
||||
.filter {
|
||||
val packageInstaller = packageManager.getInstallerPackageName(it.packageName)
|
||||
val packageInstaller = packageManager.getInstallerPackageNameCompat(it.packageName)
|
||||
listOf(
|
||||
"com.aurora.store",
|
||||
"com.aurora.store.nightly",
|
||||
@@ -208,7 +209,7 @@ object PackageUtil {
|
||||
if (isFDroidFilterEnabled) {
|
||||
packageInfoList = packageInfoList
|
||||
.filter {
|
||||
val packageInstaller = packageManager.getInstallerPackageName(it.packageName)
|
||||
val packageInstaller = packageManager.getInstallerPackageNameCompat(it.packageName)
|
||||
!listOf(
|
||||
"org.fdroid.fdroid",
|
||||
"org.fdroid.fdroid.privileged"
|
||||
|
||||
Reference in New Issue
Block a user