diff --git a/controller/app/src/main/AndroidManifest.xml b/controller/app/src/main/AndroidManifest.xml
index 17c1af7c8..7e78799af 100644
--- a/controller/app/src/main/AndroidManifest.xml
+++ b/controller/app/src/main/AndroidManifest.xml
@@ -19,6 +19,11 @@
+
+
+
diff --git a/controller/app/src/main/java/org/iiab/controller/SetupSectionFragment.java b/controller/app/src/main/java/org/iiab/controller/SetupSectionFragment.java
index 96d5393dc..9e13571cf 100644
--- a/controller/app/src/main/java/org/iiab/controller/SetupSectionFragment.java
+++ b/controller/app/src/main/java/org/iiab/controller/SetupSectionFragment.java
@@ -1,14 +1,11 @@
package org.iiab.controller;
-import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
-import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
-import android.os.Environment;
import android.os.PowerManager;
import android.provider.Settings;
import android.view.LayoutInflater;
@@ -380,20 +377,8 @@ private void setupListeners() {
return;
}
if (switchStorage.isChecked()) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
- try {
- Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
- intent.addCategory("android.intent.category.DEFAULT");
- intent.setData(Uri.parse(String.format("package:%s", requireContext().getPackageName())));
- storageLauncher.launch(intent);
- } catch (Exception e) {
- Intent intent = new Intent();
- intent.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
- storageLauncher.launch(intent);
- }
- } else {
- requestPermissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE);
- }
+ org.iiab.controller.permissions.StoragePermission.request(
+ requireContext(), storageLauncher, requestPermissionLauncher);
}
switchStorage.setChecked(false);
});
@@ -473,11 +458,7 @@ private boolean hasNotifPermission() {
}
private boolean hasStoragePermission() {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
- return Environment.isExternalStorageManager();
- }
- return ContextCompat.checkSelfPermission(requireContext(),
- Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
+ return org.iiab.controller.permissions.StoragePermission.isGranted(requireContext());
}
private boolean hasBatteryPermission() {
diff --git a/controller/app/src/main/java/org/iiab/controller/permissions/StoragePermission.java b/controller/app/src/main/java/org/iiab/controller/permissions/StoragePermission.java
new file mode 100644
index 000000000..ff504487c
--- /dev/null
+++ b/controller/app/src/main/java/org/iiab/controller/permissions/StoragePermission.java
@@ -0,0 +1,114 @@
+package org.iiab.controller.permissions;
+
+import android.app.Activity;
+import android.Manifest;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.net.Uri;
+import android.os.Build;
+import android.os.Environment;
+import android.provider.Settings;
+
+import androidx.activity.result.ActivityResultLauncher;
+import androidx.core.app.ActivityCompat;
+import androidx.core.content.ContextCompat;
+
+/**
+ * ADFA-5225: single source of truth for the app's "broad storage access" permission.
+ *
+ *
The permission model differs by OS version, and each onboarding surface used to branch on
+ * that independently — which is how a Samsung S9 (API <= 29) ended up blocked: the wizard only
+ * handled the Android 11+ path, so on older devices the grant simply never happened and onboarding
+ * could not advance. Centralizing the check and the request keeps every surface consistent on
+ * every OS.
+ *
+ *
+ * - Android 11+ (API 30, R): "All files access" (MANAGE_EXTERNAL_STORAGE), granted from
+ * a system Settings screen.
+ * - Android 10 and below (API <= 29): the legacy WRITE_EXTERNAL_STORAGE runtime
+ * permission, which under legacy-storage mode (targetSdk 28) grants broad shared-storage
+ * access — enough for the {@code /sdcard} bind into the proot environment.
+ *
+ */
+public final class StoragePermission {
+
+ private StoragePermission() {}
+
+ /** True when the app currently has broad storage access on this OS version. */
+ public static boolean isGranted(Context ctx) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
+ return Environment.isExternalStorageManager();
+ }
+ return ContextCompat.checkSelfPermission(ctx, Manifest.permission.WRITE_EXTERNAL_STORAGE)
+ == PackageManager.PERMISSION_GRANTED;
+ }
+
+ /**
+ * Trigger the correct grant flow for this OS version. No-op if the permission is already held.
+ * Use this from a surface that already offers its own "open app settings" escape hatch (e.g. the
+ * settings shell's "Manage all" button); the wizard, which has none, should use
+ * {@link #requestOrOpenSettings} instead so a permanent pre-R denial can't dead-end onboarding.
+ *
+ * @param settingsLauncher launches the R+ "All files access" Settings screen (Intent contract)
+ * @param runtimeLauncher requests the pre-R WRITE_EXTERNAL_STORAGE runtime permission (String contract)
+ */
+ public static void request(Context ctx,
+ ActivityResultLauncher settingsLauncher,
+ ActivityResultLauncher runtimeLauncher) {
+ if (isGranted(ctx)) return;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
+ launchAllFilesSettings(ctx, settingsLauncher);
+ } else {
+ runtimeLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE);
+ }
+ }
+
+ /**
+ * Like {@link #request}, but on pre-R it falls back to the app's details settings when the
+ * runtime permission has been permanently denied ("Don't ask again"). Without this the second
+ * tap would silently no-op and re-strand the user — the exact ADFA-5225 symptom, on a screen
+ * (the wizard) that has no other route to Settings.
+ *
+ * @param alreadyAsked whether the runtime permission has been requested before this call
+ * @return the value the caller should store back as its "already asked" flag
+ */
+ public static boolean requestOrOpenSettings(Activity activity,
+ ActivityResultLauncher settingsLauncher,
+ ActivityResultLauncher runtimeLauncher,
+ boolean alreadyAsked) {
+ if (isGranted(activity)) return alreadyAsked;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
+ launchAllFilesSettings(activity, settingsLauncher);
+ return alreadyAsked;
+ }
+ // Pre-R: a prior denial with rationale==false means "Don't ask again" — the dialog will
+ // never show again, so send the user to app settings instead of firing a no-op request.
+ boolean permanentlyDenied = alreadyAsked && !ActivityCompat
+ .shouldShowRequestPermissionRationale(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);
+ if (permanentlyDenied) {
+ settingsLauncher.launch(appDetailsSettings(activity));
+ } else {
+ runtimeLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE);
+ }
+ return true;
+ }
+
+ /** The app's own "App info" settings page, where the user can toggle a denied permission. */
+ public static Intent appDetailsSettings(Context ctx) {
+ Intent i = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
+ i.setData(Uri.parse("package:" + ctx.getPackageName()));
+ return i;
+ }
+
+ private static void launchAllFilesSettings(Context ctx, ActivityResultLauncher settingsLauncher) {
+ try {
+ Intent i = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
+ i.addCategory("android.intent.category.DEFAULT");
+ i.setData(Uri.parse("package:" + ctx.getPackageName()));
+ settingsLauncher.launch(i);
+ } catch (Exception e) {
+ settingsLauncher.launch(new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION));
+ }
+ }
+}
diff --git a/controller/app/src/main/java/org/iiab/controller/redesign/WizardActivity.java b/controller/app/src/main/java/org/iiab/controller/redesign/WizardActivity.java
index f5bd0d1ff..7161596bf 100644
--- a/controller/app/src/main/java/org/iiab/controller/redesign/WizardActivity.java
+++ b/controller/app/src/main/java/org/iiab/controller/redesign/WizardActivity.java
@@ -42,6 +42,14 @@ public class WizardActivity extends AppCompatActivity {
private final ActivityResultLauncher permResult =
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), r -> render());
+ // ADFA-5225: pre-R storage is a runtime permission (not a Settings screen), so it needs its own
+ // String-contract launcher. StoragePermission picks which launcher to use per OS version.
+ private final ActivityResultLauncher storagePermResult =
+ registerForActivityResult(new ActivityResultContracts.RequestPermission(), r -> render());
+ // ADFA-5225: tracks whether the pre-R runtime permission was already requested, so a later
+ // "Don't ask again" denial can be detected and routed to app settings.
+ private boolean storageAsked = false;
+
private final ActivityResultLauncher langPicker =
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), r -> {
if (r.getResultCode() == RESULT_OK && r.getData() != null) {
@@ -293,9 +301,7 @@ private boolean hasNotif() {
return true;
}
private boolean hasStorage() {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) return android.os.Environment.isExternalStorageManager();
- return ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
- == android.content.pm.PackageManager.PERMISSION_GRANTED;
+ return org.iiab.controller.permissions.StoragePermission.isGranted(this);
}
private boolean hasBattery() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
@@ -313,17 +319,10 @@ private void requestNotif() {
}
}
private void requestStorage() {
- if (hasStorage()) return;
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
- try {
- Intent i = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
- i.addCategory("android.intent.category.DEFAULT");
- i.setData(Uri.parse("package:" + getPackageName()));
- permResult.launch(i);
- } catch (Exception e) {
- permResult.launch(new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION));
- }
- }
+ // ADFA-5225: requestOrOpenSettings (not request) so a permanent pre-R denial routes to app
+ // settings instead of a silent no-op — the wizard has no other path to Settings.
+ storageAsked = org.iiab.controller.permissions.StoragePermission
+ .requestOrOpenSettings(this, permResult, storagePermResult, storageAsked);
}
private void requestBattery() {
if (hasBattery()) return;