mirror of
https://github.com/whyorean/AuroraStore.git
synced 2026-06-16 11:42:16 -04:00
Do a manual check for OBB directory R/W access before attempting to download apps with OBB files
This commit is contained in:
committed by
Aayush Gupta
parent
5bdddac9d6
commit
a6760b45d5
@@ -27,6 +27,7 @@ import com.aurora.store.PermissionType
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.util.Log
|
||||
import com.aurora.store.util.PackageUtil
|
||||
import com.aurora.store.util.PathUtil
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
class PermissionProvider : ActivityResultCallback<ActivityResult> {
|
||||
@@ -96,10 +97,13 @@ class PermissionProvider : ActivityResultCallback<ActivityResult> {
|
||||
else -> {
|
||||
val intent = knownPermissions()[permissionType] ?: return
|
||||
|
||||
if (permissionType == PermissionType.STORAGE_MANAGER
|
||||
&& !isGranted(PermissionType.INSTALL_UNKNOWN_APPS)
|
||||
) {
|
||||
context.toast(R.string.toast_permission_installer_required)
|
||||
if (permissionType == PermissionType.STORAGE_MANAGER) {
|
||||
if (!isGranted(PermissionType.INSTALL_UNKNOWN_APPS)) {
|
||||
context.toast(R.string.toast_permission_installer_required)
|
||||
} else {
|
||||
context.toast(R.string.toast_permission_esm_caution)
|
||||
intentLauncher.launch(intent)
|
||||
}
|
||||
} else {
|
||||
intentLauncher.launch(intent)
|
||||
}
|
||||
@@ -115,7 +119,7 @@ class PermissionProvider : ActivityResultCallback<ActivityResult> {
|
||||
fun isGranted(permissionType: PermissionType): Boolean {
|
||||
return when (permissionType) {
|
||||
PermissionType.EXTERNAL_STORAGE,
|
||||
PermissionType.STORAGE_MANAGER -> context.isExternalStorageAccessible()
|
||||
PermissionType.STORAGE_MANAGER -> context.isExternalStorageAccessible() && PathUtil.canReadWriteOBB()
|
||||
|
||||
PermissionType.POST_NOTIFICATIONS -> context.checkManifestPermission(Manifest.permission.POST_NOTIFICATIONS)
|
||||
PermissionType.INSTALL_UNKNOWN_APPS -> PackageUtil.canRequestPackageInstalls(context)
|
||||
|
||||
@@ -69,7 +69,7 @@ object PathUtil {
|
||||
file: GPlayFile,
|
||||
sharedLibPackageName: String? = null
|
||||
): File {
|
||||
val downloadDir = if (!sharedLibPackageName.isNullOrBlank()) {
|
||||
val downloadDir = if (!sharedLibPackageName.isNullOrBlank()) {
|
||||
getLibDownloadDir(context, packageName, versionCode, sharedLibPackageName)
|
||||
} else {
|
||||
File(getPackageDirectory(context, packageName), versionCode.toString())
|
||||
@@ -109,5 +109,15 @@ object PathUtil {
|
||||
file.createNewFile()
|
||||
return file
|
||||
}
|
||||
|
||||
fun canReadWriteOBB(): Boolean {
|
||||
return canReadWriteDir(
|
||||
Environment.getExternalStorageDirectory().toString() + "/Android/obb/"
|
||||
)
|
||||
}
|
||||
|
||||
private fun canReadWriteDir(dir: String): Boolean {
|
||||
return File(dir).let { it.exists() && it.canRead() && it.canWrite() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,11 @@ object Preferences {
|
||||
return getPrefs(context).getString(key, default).toString()
|
||||
}
|
||||
|
||||
fun getStringSet(context: Context, key: String, default: Set<String> = emptySet()): Set<String> {
|
||||
fun getStringSet(
|
||||
context: Context,
|
||||
key: String,
|
||||
default: Set<String> = emptySet()
|
||||
): Set<String> {
|
||||
return getPrefs(context).getStringSet(key, default) ?: emptySet()
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ import com.aurora.extensions.share
|
||||
import com.aurora.extensions.show
|
||||
import com.aurora.extensions.toast
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
import com.aurora.gplayapi.data.models.File
|
||||
import com.aurora.gplayapi.data.models.Review
|
||||
import com.aurora.gplayapi.data.models.StreamBundle
|
||||
import com.aurora.gplayapi.data.models.StreamCluster
|
||||
@@ -639,8 +640,13 @@ class AppDetailsFragment : BaseFragment<FragmentDetailsBinding>() {
|
||||
} else if (app.versionCode == 0) {
|
||||
toast(R.string.toast_app_unavailable)
|
||||
} else {
|
||||
btn.setText(R.string.download_metadata)
|
||||
startDownload()
|
||||
val hasOBB = app.fileList.any { it.type == File.FileType.OBB }
|
||||
if (hasOBB && !PathUtil.canReadWriteOBB()) {
|
||||
permissionProvider.request(PermissionType.STORAGE_MANAGER)
|
||||
} else {
|
||||
btn.setText(R.string.download_metadata)
|
||||
startDownload()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -310,6 +310,7 @@
|
||||
<string name="toast_developer_setting_failed">Turn on developer settings from the device settings to open them.</string>
|
||||
<string name="toast_permission_granted">"Permission granted"</string>
|
||||
<string name="toast_permission_installer_required">"You need to grant Installer Permission first"</string>
|
||||
<string name="toast_permission_esm_caution">"You may have to re-grant the permission due to bug in Storage Access Framework"</string>
|
||||
<string name="toast_spoof_applied">Device spoof applied.</string>
|
||||
<string name="toast_purchase_blocked">"App purchases not available on Anonymous accounts."</string>
|
||||
<string name="toast_manual_unavailable">"The version code you are requesting is unavailable."</string>
|
||||
|
||||
Reference in New Issue
Block a user