Skip to content
Snippets Groups Projects
Commit 7a2b74f1 authored by Nicolas Pomepuy's avatar Nicolas Pomepuy
Browse files

Fix getPackageInfo deprecation

parent 014f7dff
No related branches found
No related tags found
1 merge request!1603Cleanup a lot of compilation warnings
Pipeline #283190 passed with stage
in 21 minutes and 40 seconds
......@@ -21,10 +21,8 @@
package org.videolan.resources
import android.annotation.TargetApi
import android.app.UiModeManager
import android.content.Context
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.net.Uri
import android.os.Build
import android.os.Build.VERSION_CODES
......@@ -35,6 +33,7 @@ import android.view.MotionEvent
import androidx.core.content.getSystemService
import androidx.core.net.toUri
import org.videolan.libvlc.util.AndroidUtil
import org.videolan.resources.util.getPackageInfoCompat
import org.videolan.tools.containsName
import org.videolan.tools.getFileNameFromPath
import org.videolan.tools.startsWith
......@@ -167,7 +166,7 @@ object AndroidDevices {
private fun hasPlayServices(pm: PackageManager): Boolean {
try {
pm.getPackageInfo("com.google.android.gsf", PackageManager.GET_SERVICES)
pm.getPackageInfoCompat("com.google.android.gsf", PackageManager.GET_SERVICES)
return true
} catch (ignored: PackageManager.NameNotFoundException) {
}
......
......@@ -3,6 +3,8 @@ package org.videolan.resources.util
import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.os.Build.VERSION.SDK_INT
import android.os.Bundle
import android.os.Parcelable
......@@ -182,4 +184,15 @@ inline fun <reified T : Parcelable> Bundle.parcelableArray(key: String): Array<T
fun Service.stopForegroundCompat(removeNotification:Boolean = true) = when {
SDK_INT >= 24 -> stopForeground(if (removeNotification) Service.STOP_FOREGROUND_REMOVE else Service.STOP_FOREGROUND_DETACH)
else -> @Suppress("DEPRECATION") stopForeground(removeNotification)
}
\ No newline at end of file
}
@Suppress("DEPRECATION")
fun PackageManager.getPackageInfoCompat(packageName: String, vararg flagArgs: Int): PackageInfo {
var flags = 0
flagArgs.forEach { flag -> flags = flags or flag }
return if (SDK_INT >= 33) {
getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(flags.toLong()))
} else {
getPackageInfo(packageName, flags)
}
}
......@@ -101,7 +101,7 @@ class VLCCrashHandler : UncaughtExceptionHandler {
val bw = BufferedWriter(output)
val version = try {
val pInfo: PackageInfo = AppContextProvider.appContext.packageManager.getPackageInfo(AppContextProvider.appContext.packageName, 0)
val pInfo: PackageInfo = AppContextProvider.appContext.packageManager.getPackageInfoCompat(AppContextProvider.appContext.packageName, 0)
pInfo.versionName
} catch (e: PackageManager.NameNotFoundException) {
e.printStackTrace()
......
......@@ -31,16 +31,6 @@ import android.os.StatFs
@Suppress("DEPRECATION")
object AppUtils {
fun getVersionName(context: Context): String {
return context.packageManager.getPackageInfo(context.packageName, 0).versionName
}
fun getVersionCode(context: Context): Long {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
context.packageManager.getPackageInfo(context.packageName, 0).longVersionCode
else context.packageManager.getPackageInfo(context.packageName, 0).versionCode.toLong()
}
fun totalMemory(): Long {
val statFs = StatFs(Environment.getRootDirectory().absolutePath)
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
......@@ -54,17 +44,4 @@ object AppUtils {
statFs.availableBlocksLong * statFs.blockSizeLong
else (statFs.availableBlocks * statFs.blockSize).toLong()
}
fun busyMemory(): Long {
val statFs = StatFs(Environment.getRootDirectory().absolutePath)
val total = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
statFs.blockCountLong * statFs.blockSizeLong
else (statFs.blockCount * statFs.blockSize).toLong()
val free = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
statFs.availableBlocksLong * statFs.blockSizeLong
else (statFs.availableBlocks * statFs.blockSize).toLong()
return total - free
}
}
\ No newline at end of file
......@@ -30,6 +30,7 @@ import kotlinx.coroutines.withContext
import org.json.JSONArray
import org.json.JSONObject
import org.videolan.resources.AppContextProvider
import org.videolan.resources.util.getPackageInfoCompat
import org.videolan.vlc.R
import java.security.MessageDigest
import java.security.NoSuchAlgorithmException
......@@ -133,7 +134,7 @@ object AccessControl {
@Suppress("deprecation")
private fun getSignature(ctx: Context, callingPackage: String): String? {
try {
val packageInfo = ctx.packageManager.getPackageInfo(callingPackage, PackageManager.GET_SIGNATURES)
val packageInfo = ctx.packageManager.getPackageInfoCompat(callingPackage, PackageManager.GET_SIGNATURES)
if (packageInfo.signatures != null && packageInfo.signatures.size == 1) {
return genSigSha256(packageInfo.signatures[0].toByteArray())
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment