AppInstaller: Rework and extend silent install logic check

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2024-10-07 18:36:58 +05:30
parent 6ea0cda277
commit 9a49ccc727
10 changed files with 130 additions and 38 deletions

View File

@@ -1,6 +1,9 @@
package com.aurora.extensions
import android.content.pm.PackageManager
import android.os.Build
import androidx.annotation.RequiresApi
import com.aurora.store.BuildConfig
fun PackageManager.getInstallerPackageNameCompat(packageName: String): String? {
return if (isRAndAbove()) {
@@ -10,3 +13,17 @@ fun PackageManager.getInstallerPackageNameCompat(packageName: String): String? {
return getInstallerPackageName(packageName)
}
}
@RequiresApi(Build.VERSION_CODES.S)
fun PackageManager.getUpdateOwnerPackageNameCompat(packageName: String): String? {
// https://developer.android.com/reference/android/content/pm/PackageInstaller.SessionParams#setRequireUserAction(int)
val installSourceInfo = getInstallSourceInfo(packageName)
return when {
isUAndAbove() -> {
// If update ownership is null, we can still silently update it if we installed it
installSourceInfo.updateOwnerPackageName ?: installSourceInfo.installingPackageName
}
isSAndAbove() -> installSourceInfo.installingPackageName
else -> if (packageName == BuildConfig.APPLICATION_ID) BuildConfig.APPLICATION_ID else null
}
}