diff --git a/commons/src/main/kotlin/org/fossify/commons/activities/BaseSimpleActivity.kt b/commons/src/main/kotlin/org/fossify/commons/activities/BaseSimpleActivity.kt
index c1906678e6..f391eb812e 100644
--- a/commons/src/main/kotlin/org/fossify/commons/activities/BaseSimpleActivity.kt
+++ b/commons/src/main/kotlin/org/fossify/commons/activities/BaseSimpleActivity.kt
@@ -751,12 +751,12 @@ abstract class BaseSimpleActivity : AppCompatActivity() {
}
}
- fun handleAndroidSAFDialog(path: String, callback: (success: Boolean) -> Unit): Boolean {
+ fun handleAndroidSAFDialog(path: String, openInSystemAppAllowed: Boolean = false, callback: (success: Boolean) -> Unit): Boolean {
hideKeyboard()
return if (!packageName.startsWith("org.fossify")) {
callback(true)
false
- } else if (isShowingAndroidSAFDialog(path)) {
+ } else if (isShowingAndroidSAFDialog(path, openInSystemAppAllowed)) {
funAfterSAFPermission = callback
true
} else {
diff --git a/commons/src/main/kotlin/org/fossify/commons/extensions/Activity.kt b/commons/src/main/kotlin/org/fossify/commons/extensions/Activity.kt
index b9c3f0b094..fecb542989 100644
--- a/commons/src/main/kotlin/org/fossify/commons/extensions/Activity.kt
+++ b/commons/src/main/kotlin/org/fossify/commons/extensions/Activity.kt
@@ -226,31 +226,29 @@ fun BaseSimpleActivity.isShowingSAFCreateDocumentDialogSdk30(path: String): Bool
}
}
-fun BaseSimpleActivity.isShowingAndroidSAFDialog(path: String): Boolean {
+fun BaseSimpleActivity.isShowingAndroidSAFDialog(path: String, openInSystemAppAllowed: Boolean = false): Boolean {
return if (isRestrictedSAFOnlyRoot(path) && (getAndroidTreeUri(path).isEmpty() || !hasProperStoredAndroidTreeUri(path))) {
runOnUiThread {
if (!isDestroyed && !isFinishing) {
- ConfirmationAdvancedDialog(this, "", R.string.confirm_storage_access_android_text, R.string.ok, R.string.cancel) { success ->
- if (success) {
- Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply {
- putExtra(EXTRA_SHOW_ADVANCED, true)
- putExtra(DocumentsContract.EXTRA_INITIAL_URI, createAndroidDataOrObbUri(path))
- try {
- startActivityForResult(this, OPEN_DOCUMENT_TREE_FOR_ANDROID_DATA_OR_OBB)
- checkedDocumentPath = path
- return@apply
- } catch (e: Exception) {
- type = "*/*"
- }
-
- try {
- startActivityForResult(this, OPEN_DOCUMENT_TREE_FOR_ANDROID_DATA_OR_OBB)
- checkedDocumentPath = path
- } catch (e: ActivityNotFoundException) {
- toast(R.string.system_service_disabled, Toast.LENGTH_LONG)
- } catch (e: Exception) {
- toast(R.string.unknown_error_occurred)
- }
+ if (!openInSystemAppAllowed) {
+ ConfirmationDialog(
+ this,
+ "",
+ R.string.confirm_storage_access_restricted_text,
+ positive = android.R.string.ok,
+ negative = 0
+ ) {}
+ } else {
+ ConfirmationAdvancedDialog(
+ this,
+ "",
+ R.string.confirm_storage_access_restricted_text,
+ R.string.confirm_storage_access_restricted_text_open_system,
+ R.string.cancel
+ ) { success ->
+ if (success) {
+ val uri = createAndroidDataOrObbUri(path)
+ launchSystemFileManager(uri)
}
}
}
@@ -262,6 +260,62 @@ fun BaseSimpleActivity.isShowingAndroidSAFDialog(path: String): Boolean {
}
}
+/**
+ * Launch system file manager by testing different possible intents depending on the device
+ * Each intent is tested in a OR condition which allows to stop at the first successful one
+ */
+fun BaseSimpleActivity.launchSystemFileManager(uri: Uri) {
+ if (
+ startIntentForUriAction(
+ uri,
+ "android.intent.action.VIEW",
+ ComponentName("com.google.android.documentsui", "com.android.documentsui.files.FilesActivity")
+ ) ||
+ startIntentForUriAction(
+ uri,
+ "android.intent.action.VIEW",
+ ComponentName("com.android.documentsui", "com.android.documentsui.files.FilesActivity")
+ ) ||
+ startIntentForUriAction(
+ uri,
+ "android.intent.action.VIEW",
+ ComponentName("com.android.documentsui", "com.android.documentsui.FilesActivity")
+ ) ||
+ startIntentForUriAction(uri, "android.intent.action.VIEW", null) ||
+ startIntentForUriAction(uri, "android.provider.action.BROWSE", null) ||
+ startIntentForUriAction(uri, "android.provider.action.BROWSE_DOCUMENT_ROOT", null)
+ ) {
+ return
+ } else {
+ toast(R.string.confirm_storage_access_restricted_text_not_found)
+ }
+}
+
+/**
+ * Start the intent
+ * @param uri URI to pass to the intent
+ * @param action Action of the intent
+ * @param componentName Optional ComponentName
+ * @return true if the intent was successful
+ */
+fun BaseSimpleActivity.startIntentForUriAction(
+ uri: Uri,
+ action: String,
+ componentName: ComponentName?
+): Boolean {
+ val intent = Intent(action, uri)
+ if (componentName != null) {
+ intent.setComponent(componentName)
+ }
+ return try {
+ startActivity(intent)
+ true
+ } catch (e: java.lang.Exception) {
+ e.printStackTrace()
+ false
+ }
+}
+
fun BaseSimpleActivity.isShowingOTGDialog(path: String): Boolean {
return if (!isRPlus() && isPathOnOTG(path) && (baseConfig.OTGTreeUri.isEmpty() || !hasProperStoredTreeUri(true))) {
showOTGPermissionDialog(path)
diff --git a/commons/src/main/res/values/strings.xml b/commons/src/main/res/values/strings.xml
index f49d70800a..2a892e816a 100644
--- a/commons/src/main/res/values/strings.xml
+++ b/commons/src/main/res/values/strings.xml
@@ -290,6 +290,9 @@
If you don\'t see the SD card, try this
Please allow the app accessing the selected storage on the next screen by pressing \'Use this folder\' at the bottom.
Please allow access to \'<b>%s</b>\' on the next screen by pressing \'<b>Use this folder</b>\' at the bottom.
+ Due to system restrictions, this folder is not available.
+ Open in system app
+ A system file manager app could not be found.
Please press \'<b>Save</b>\' at the bottom of the next screen to create the new folder.
Confirm selection
Loading…