Skip to content

Commit

Permalink
fix: correct restricted version for com.android.documentsui
Browse files Browse the repository at this point in the history
  • Loading branch information
aliernfrog committed Sep 15, 2024
1 parent d635bf0 commit 2bfd27d
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,26 @@ import java.util.Locale

class GeneralUtil {
companion object {
private const val DOCUMENTS_UI_PACKAGE = "com.android.documentsui"
private const val GOOGLE_DOCUMENTS_UI_PACKAGE = "com.google.android.documentsui"

fun documentsUIRestrictsAndroidData(context: Context): Boolean {
if (!hasAndroidDataRestrictions) return false
val documentsUIPackage = getDocumentsUIPackage(context)
return documentsUIPackage?.longVersionCode?.let {
it >= 340916000
return documentsUIPackage?.let {
it.longVersionCode >= when (it.packageName) {
DOCUMENTS_UI_PACKAGE -> 14
GOOGLE_DOCUMENTS_UI_PACKAGE -> 340916000
else -> Long.MAX_VALUE
}
} ?: false
}

fun getDocumentsUIPackage(context: Context) = try {
context.packageManager.getPackageInfo("com.google.android.documentsui", 0)
context.packageManager.getPackageInfo(GOOGLE_DOCUMENTS_UI_PACKAGE, 0)
} catch (_: Exception) {
try {
context.packageManager.getPackageInfo("com.android.documentsui", 0)
context.packageManager.getPackageInfo(DOCUMENTS_UI_PACKAGE, 0)
} catch (_: Exception) {
null
}
Expand Down

0 comments on commit 2bfd27d

Please sign in to comment.