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