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