Add a safeguard to ESM/ESA access prompt

This commit is contained in:
Rahul Patel
2024-07-25 01:22:32 +05:30
parent 02e1c9845a
commit 894e7a629f
4 changed files with 26 additions and 14 deletions

View File

@@ -124,11 +124,15 @@ object PackageUtil {
} }
@RequiresApi(Build.VERSION_CODES.R) @RequiresApi(Build.VERSION_CODES.R)
fun getStorageManagerIntent(): Intent { fun getStorageManagerIntent(safe: Boolean = false): Intent {
return Intent( return if (safe) {
Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION, Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)
Uri.parse("package:${BuildConfig.APPLICATION_ID}") } else {
) Intent(
Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION,
Uri.parse("package:${BuildConfig.APPLICATION_ID}")
)
}
} }
@Throws(Exception::class) @Throws(Exception::class)

View File

@@ -562,9 +562,11 @@ class AppDetailsFragment : BaseFragment<FragmentDetailsBinding>() {
if (PathUtil.needsStorageManagerPerm(app.fileList)) { if (PathUtil.needsStorageManagerPerm(app.fileList)) {
if (isRAndAbove()) { if (isRAndAbove()) {
if (!Environment.isExternalStorageManager()) { if (!Environment.isExternalStorageManager()) {
startForStorageManagerResult.launch( try {
PackageUtil.getStorageManagerIntent() startForStorageManagerResult.launch(PackageUtil.getStorageManagerIntent())
) } catch (_: ActivityNotFoundException) {
startForStorageManagerResult.launch(PackageUtil.getStorageManagerIntent(true))
}
} else { } else {
viewModel.download(app) viewModel.download(app)
} }

View File

@@ -21,6 +21,7 @@
package com.aurora.store.view.ui.onboarding package com.aurora.store.view.ui.onboarding
import android.Manifest import android.Manifest
import android.content.ActivityNotFoundException
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
@@ -216,9 +217,11 @@ class PermissionsFragment : BaseFragment<FragmentOnboardingPermissionsBinding>()
private fun requestStorageManagerPermission() { private fun requestStorageManagerPermission() {
if (isRAndAbove()) { if (isRAndAbove()) {
if (canInstallPackages()) { if (canInstallPackages()) {
startForStorageManagerResult.launch( try {
PackageUtil.getStorageManagerIntent() startForStorageManagerResult.launch(PackageUtil.getStorageManagerIntent())
) } catch (_: ActivityNotFoundException) {
startForStorageManagerResult.launch(PackageUtil.getStorageManagerIntent(true))
}
} else { } else {
toast(R.string.toast_permission_installer_required) toast(R.string.toast_permission_installer_required)
} }

View File

@@ -20,6 +20,7 @@
package com.aurora.store.view.ui.updates package com.aurora.store.view.ui.updates
import android.Manifest import android.Manifest
import android.content.ActivityNotFoundException
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.os.Bundle import android.os.Bundle
import android.os.Environment import android.os.Environment
@@ -205,9 +206,11 @@ class UpdatesFragment : BaseFragment<FragmentUpdatesBinding>() {
if (PathUtil.needsStorageManagerPerm(update.fileList)) { if (PathUtil.needsStorageManagerPerm(update.fileList)) {
if (isRAndAbove()) { if (isRAndAbove()) {
if (!Environment.isExternalStorageManager()) { if (!Environment.isExternalStorageManager()) {
startForStorageManagerResult.launch( try {
PackageUtil.getStorageManagerIntent() startForStorageManagerResult.launch(PackageUtil.getStorageManagerIntent())
) } catch (_: ActivityNotFoundException) {
startForStorageManagerResult.launch(PackageUtil.getStorageManagerIntent(true))
}
} else { } else {
viewModel.download(update) viewModel.download(update)
} }