Address PackageInfo and VersionCode deprecation warnings
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -25,7 +25,7 @@ data class Black(val packageName: String) {
|
||||
var displayName: String = String()
|
||||
var drawable: Drawable? = null
|
||||
var versionName: String = String()
|
||||
var versionCode: Int = 0
|
||||
var versionCode: Long = 0
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return packageName.hashCode()
|
||||
|
||||
@@ -21,52 +21,38 @@ package com.aurora.store.data.providers
|
||||
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import androidx.core.content.pm.PackageInfoCompat
|
||||
import com.aurora.store.util.PackageUtil.getPackageInfo
|
||||
|
||||
class NativeGsfVersionProvider(context: Context) {
|
||||
private var gsfVersionCode = 0
|
||||
private var vendingVersionCode = 0
|
||||
private var gsfVersionCode = 0L
|
||||
private var vendingVersionCode = 0L
|
||||
private var vendingVersionString = ""
|
||||
|
||||
init {
|
||||
try {
|
||||
gsfVersionCode =
|
||||
context.packageManager.getPackageInfo(GOOGLE_SERVICES_PACKAGE_ID, 0).versionCode
|
||||
val gsfPackageInfo = getPackageInfo(context, GOOGLE_SERVICES_PACKAGE_ID)
|
||||
gsfVersionCode = PackageInfoCompat.getLongVersionCode(gsfPackageInfo)
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
// com.google.android.gms not found
|
||||
}
|
||||
try {
|
||||
val packageInfo = context.packageManager.getPackageInfo(GOOGLE_VENDING_PACKAGE_ID, 0)
|
||||
vendingVersionCode = packageInfo.versionCode
|
||||
val packageInfo = getPackageInfo(context, GOOGLE_VENDING_PACKAGE_ID)
|
||||
vendingVersionCode = PackageInfoCompat.getLongVersionCode(packageInfo)
|
||||
vendingVersionString = packageInfo.versionName
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
// com.android.vending not found
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
try {
|
||||
gsfVersionCode =
|
||||
context.packageManager.getPackageInfo(GOOGLE_SERVICES_PACKAGE_ID, 0).versionCode
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
// com.google.android.gms not found
|
||||
}
|
||||
try {
|
||||
val packageInfo = context.packageManager.getPackageInfo(GOOGLE_VENDING_PACKAGE_ID, 0)
|
||||
vendingVersionCode = packageInfo.versionCode
|
||||
vendingVersionString = packageInfo.versionName
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
// com.android.vending not found
|
||||
}
|
||||
}
|
||||
|
||||
fun getGsfVersionCode(defaultIfNotFound: Boolean): Int {
|
||||
fun getGsfVersionCode(defaultIfNotFound: Boolean): Long {
|
||||
return if (defaultIfNotFound && gsfVersionCode < GOOGLE_SERVICES_VERSION_CODE)
|
||||
GOOGLE_SERVICES_VERSION_CODE
|
||||
else
|
||||
gsfVersionCode
|
||||
}
|
||||
|
||||
fun getVendingVersionCode(defaultIfNotFound: Boolean): Int {
|
||||
fun getVendingVersionCode(defaultIfNotFound: Boolean): Long {
|
||||
return if (defaultIfNotFound && vendingVersionCode < GOOGLE_VENDING_VERSION_CODE)
|
||||
GOOGLE_VENDING_VERSION_CODE
|
||||
else
|
||||
@@ -83,8 +69,8 @@ class NativeGsfVersionProvider(context: Context) {
|
||||
companion object {
|
||||
private const val GOOGLE_SERVICES_PACKAGE_ID = "com.google.android.gms"
|
||||
private const val GOOGLE_VENDING_PACKAGE_ID = "com.android.vending"
|
||||
private const val GOOGLE_SERVICES_VERSION_CODE = 203019037
|
||||
private const val GOOGLE_VENDING_VERSION_CODE = 82151710
|
||||
private const val GOOGLE_SERVICES_VERSION_CODE = 203019037L
|
||||
private const val GOOGLE_VENDING_VERSION_CODE = 82151710L
|
||||
private const val GOOGLE_VENDING_VERSION_STRING = "21.5.17-21 [0] [PR] 326734551"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import androidx.annotation.RequiresApi
|
||||
import com.aurora.extensions.isLAndAbove
|
||||
import com.aurora.store.util.PackageUtil.getPackageInfo
|
||||
import org.apache.commons.io.IOUtils
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
@@ -46,10 +47,7 @@ class ApkCopier(private val context: Context, private val packageName: String) {
|
||||
}
|
||||
}
|
||||
|
||||
val packageInfo: PackageInfo = context.packageManager.getPackageInfo(
|
||||
packageName,
|
||||
PackageManager.GET_META_DATA
|
||||
)
|
||||
val packageInfo = getPackageInfo(context, packageName, PackageManager.GET_META_DATA)
|
||||
|
||||
val baseApk = getBaseApk(packageInfo)
|
||||
val fileList: MutableList<File?> = mutableListOf()
|
||||
@@ -108,4 +106,4 @@ class ApkCopier(private val context: Context, private val packageName: String) {
|
||||
Log.e("ApkCopier : %s", e.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ package com.aurora.store.util
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import com.aurora.extensions.isPAndAbove
|
||||
import com.aurora.store.util.PackageUtil.getPackageInfo
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.InputStream
|
||||
import java.security.cert.CertificateFactory
|
||||
@@ -37,21 +38,13 @@ object CertUtil {
|
||||
packageName: String
|
||||
): List<X509Certificate> {
|
||||
val certificates: MutableList<X509Certificate> = mutableListOf()
|
||||
val packageManager = context.applicationContext.packageManager
|
||||
|
||||
try {
|
||||
|
||||
val packageInfo = if (isPAndAbove()) {
|
||||
packageManager.getPackageInfo(
|
||||
packageName,
|
||||
PackageManager.GET_SIGNING_CERTIFICATES
|
||||
)
|
||||
}
|
||||
else {
|
||||
packageManager.getPackageInfo(
|
||||
packageName,
|
||||
PackageManager.GET_SIGNATURES
|
||||
)
|
||||
getPackageInfo(context, packageName, PackageManager.GET_SIGNING_CERTIFICATES)
|
||||
} else {
|
||||
getPackageInfo(context, packageName, PackageManager.GET_SIGNATURES)
|
||||
}
|
||||
|
||||
val certificateFactory = CertificateFactory.getInstance("X509")
|
||||
@@ -96,4 +89,4 @@ object CertUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,15 +24,18 @@ import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.pm.PackageInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.pm.PackageManager.PackageInfoFlags
|
||||
import android.content.res.Configuration
|
||||
import android.os.Build
|
||||
import androidx.core.content.pm.PackageInfoCompat
|
||||
import com.aurora.extensions.isTAndAbove
|
||||
|
||||
|
||||
object PackageUtil {
|
||||
|
||||
fun isInstalled(context: Context, packageName: String): Boolean {
|
||||
return try {
|
||||
context.packageManager.getPackageInfo(packageName, PackageManager.GET_META_DATA)
|
||||
getPackageInfo(context, packageName, PackageManager.GET_META_DATA)
|
||||
true
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
false
|
||||
@@ -42,10 +45,7 @@ object PackageUtil {
|
||||
fun isInstalled(context: Context, packageName: String, versionCode: Int): Boolean {
|
||||
return try {
|
||||
val packageInfo = getPackageInfo(context, packageName)
|
||||
if (packageInfo != null) {
|
||||
return packageInfo.versionCode >= versionCode
|
||||
}
|
||||
true
|
||||
return PackageInfoCompat.getLongVersionCode(packageInfo) >= versionCode.toLong()
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
false
|
||||
}
|
||||
@@ -54,10 +54,7 @@ object PackageUtil {
|
||||
fun isUpdatable(context: Context, packageName: String, versionCode: Long): Boolean {
|
||||
return try {
|
||||
val packageInfo = getPackageInfo(context, packageName)
|
||||
if (packageInfo != null) {
|
||||
return versionCode > packageInfo.versionCode
|
||||
}
|
||||
true
|
||||
return versionCode > PackageInfoCompat.getLongVersionCode(packageInfo)
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
false
|
||||
}
|
||||
@@ -66,11 +63,7 @@ object PackageUtil {
|
||||
fun getInstalledVersion(context: Context, packageName: String): String {
|
||||
return try {
|
||||
val packageInfo = getPackageInfo(context, packageName)
|
||||
if (packageInfo != null) {
|
||||
"${packageInfo.versionName} (${packageInfo.versionCode})"
|
||||
} else {
|
||||
""
|
||||
}
|
||||
"${packageInfo.versionName} (${PackageInfoCompat.getLongVersionCode(packageInfo)})"
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
""
|
||||
}
|
||||
@@ -102,8 +95,15 @@ object PackageUtil {
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun getPackageInfo(context: Context, packageName: String?): PackageInfo? {
|
||||
return context.packageManager.getPackageInfo(packageName!!, 0)
|
||||
fun getPackageInfo(context: Context, packageName: String, flags: Int = 0): PackageInfo {
|
||||
return if (isTAndAbove()) {
|
||||
context.packageManager.getPackageInfo(
|
||||
packageName,
|
||||
PackageInfoFlags.of(flags.toLong())
|
||||
)
|
||||
} else {
|
||||
context.packageManager.getPackageInfo(packageName, flags)
|
||||
}
|
||||
}
|
||||
|
||||
fun getAllPackages(context: Context): List<PackageInfo> {
|
||||
@@ -181,4 +181,4 @@ object PackageUtil {
|
||||
}
|
||||
return flags
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ package com.aurora.store.viewmodel.all
|
||||
|
||||
import android.app.Application
|
||||
import android.content.pm.PackageManager
|
||||
import androidx.core.content.pm.PackageInfoCompat
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.aurora.store.data.RequestState
|
||||
@@ -65,7 +66,7 @@ class BlacklistViewModel(application: Application) : BaseAndroidViewModel(applic
|
||||
val black = Black(it.packageName).apply {
|
||||
displayName = packageManager.getApplicationLabel(it.applicationInfo)
|
||||
.toString()
|
||||
versionCode = it.versionCode
|
||||
versionCode = PackageInfoCompat.getLongVersionCode(it)
|
||||
versionName = it.versionName
|
||||
drawable = packageManager.getApplicationIcon(packageName)
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package com.aurora.store.viewmodel.all
|
||||
|
||||
import android.app.Application
|
||||
import androidx.core.content.pm.PackageInfoCompat
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
@@ -66,7 +67,7 @@ class UpdatesViewModel(application: Application) : BaseAppsViewModel(application
|
||||
subAppList.filter {
|
||||
val packageInfo = packageInfoMap[it.packageName]
|
||||
if (packageInfo != null) {
|
||||
it.versionCode > packageInfo.versionCode
|
||||
it.versionCode.toLong() > PackageInfoCompat.getLongVersionCode(packageInfo)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user