Simplify permission request strategy
This commit is contained in:
committed by
Aayush Gupta
parent
46078338f1
commit
7d25f4a3ed
@@ -62,9 +62,9 @@ class PermissionProvider(private val fragment: Fragment) :
|
||||
}
|
||||
|
||||
PermissionType.POST_NOTIFICATIONS -> {
|
||||
if (isTAndAbove) {
|
||||
permissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
|
||||
}
|
||||
if (isTAndAbove) {
|
||||
permissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
@@ -93,7 +93,7 @@ class PermissionProvider(private val fragment: Fragment) :
|
||||
return when (permissionType) {
|
||||
PermissionType.EXTERNAL_STORAGE,
|
||||
PermissionType.STORAGE_MANAGER -> {
|
||||
context.isExternalStorageAccessible() && PathUtil.canReadWriteOBB()
|
||||
context.isExternalStorageAccessible() && PathUtil.canReadWriteOBB(context)
|
||||
}
|
||||
|
||||
PermissionType.INSTALL_UNKNOWN_APPS -> PackageUtil.canRequestPackageInstalls(context)
|
||||
|
||||
@@ -34,6 +34,7 @@ import android.util.Log
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.content.pm.PackageInfoCompat
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import com.aurora.extensions.isHuawei
|
||||
import com.aurora.extensions.isOAndAbove
|
||||
import com.aurora.extensions.isPAndAbove
|
||||
import com.aurora.extensions.isTAndAbove
|
||||
@@ -139,11 +140,18 @@ object PackageUtil {
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.R)
|
||||
fun getStorageManagerIntent(context: Context): Intent {
|
||||
val intent = Intent(
|
||||
var intent = Intent(
|
||||
Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION,
|
||||
Uri.parse("package:${BuildConfig.APPLICATION_ID}")
|
||||
)
|
||||
|
||||
if (isHuawei) {
|
||||
intent = Intent(
|
||||
Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
|
||||
Uri.parse("package:${BuildConfig.APPLICATION_ID}")
|
||||
)
|
||||
}
|
||||
|
||||
// Check if the intent can be resolved
|
||||
val packageManager = context.packageManager
|
||||
val isIntentAvailable = packageManager.queryIntentActivities(
|
||||
|
||||
@@ -106,14 +106,14 @@ object PathUtil {
|
||||
return file
|
||||
}
|
||||
|
||||
fun canReadWriteOBB(): Boolean {
|
||||
return canReadWriteDir(
|
||||
Environment.getExternalStorageDirectory().toString() + "/Android/obb/"
|
||||
)
|
||||
}
|
||||
fun canReadWriteOBB(context: Context): Boolean {
|
||||
val obbDir = context.obbDir.parentFile
|
||||
|
||||
private fun canReadWriteDir(dir: String): Boolean {
|
||||
return File(dir).let { it.exists() && it.canRead() && it.canWrite() }
|
||||
if (obbDir != null) {
|
||||
return obbDir.exists() && obbDir.canRead() && obbDir.canWrite()
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -573,7 +573,7 @@ class AppDetailsFragment : BaseFragment<FragmentDetailsBinding>() {
|
||||
viewModel.download(app)
|
||||
} else {
|
||||
permissionProvider.request(PermissionType.STORAGE_MANAGER) {
|
||||
if (it) viewModel.download(app)
|
||||
if (it) viewModel.download(app) else flip(0)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -665,18 +665,8 @@ class AppDetailsFragment : BaseFragment<FragmentDetailsBinding>() {
|
||||
} else if (app.versionCode == 0) {
|
||||
toast(R.string.toast_app_unavailable)
|
||||
} else {
|
||||
if (app.fileList.requiresObbDir() && permissionProvider.isGranted(
|
||||
PermissionType.STORAGE_MANAGER)) {
|
||||
permissionProvider.request(PermissionType.STORAGE_MANAGER) {
|
||||
if (it) {
|
||||
btn.setText(R.string.download_metadata)
|
||||
startDownload()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
btn.setText(R.string.download_metadata)
|
||||
startDownload()
|
||||
}
|
||||
btn.setText(R.string.download_metadata)
|
||||
startDownload()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user