From 936bcee4fd3ab810bcd1efb3fd4821e0e77b0352 Mon Sep 17 00:00:00 2001 From: "Luis Guzman (AppDevForAll)" Date: Thu, 20 Aug 2026 22:15:18 -0600 Subject: [PATCH 1/2] ADFA-5225 fix(onboarding): grant storage permission on pre-Android-11 devices Onboarding hard-gated on a storage permission that could not be granted below Android 11: only MANAGE_EXTERNAL_STORAGE was declared, and the wizard's requestStorage() had no pre-R branch, so on a Samsung S9 (API <= 29) the toggle did nothing and Continue never enabled. - New StoragePermission helper centralizes the check + request, branching by OS version (R+ "All files access" screen; pre-R WRITE_EXTERNAL_STORAGE runtime). - WizardActivity and SetupSectionFragment delegate to it, removing the duplicated per-surface logic; WizardActivity gains the runtime launcher it was missing. - Manifest declares READ/WRITE_EXTERNAL_STORAGE with maxSdkVersion=29; R+ keeps MANAGE_EXTERNAL_STORAGE. No behaviour change on Android 11+. targetSdk unchanged (28). --- controller/app/src/main/AndroidManifest.xml | 5 ++ .../iiab/controller/SetupSectionFragment.java | 22 +----- .../permissions/StoragePermission.java | 68 +++++++++++++++++++ .../controller/redesign/WizardActivity.java | 21 ++---- 4 files changed, 83 insertions(+), 33 deletions(-) create mode 100644 controller/app/src/main/java/org/iiab/controller/permissions/StoragePermission.java 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..8931fe7a3 100644 --- a/controller/app/src/main/java/org/iiab/controller/SetupSectionFragment.java +++ b/controller/app/src/main/java/org/iiab/controller/SetupSectionFragment.java @@ -380,20 +380,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 +461,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..c14eee794 --- /dev/null +++ b/controller/app/src/main/java/org/iiab/controller/permissions/StoragePermission.java @@ -0,0 +1,68 @@ +package org.iiab.controller.permissions; + +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.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. + * + * @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) { + 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)); + } + } else { + runtimeLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE); + } + } +} 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..a60ea55bc 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,11 @@ 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()); + private final ActivityResultLauncher langPicker = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), r -> { if (r.getResultCode() == RESULT_OK && r.getData() != null) { @@ -293,9 +298,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 +316,7 @@ 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)); - } - } + org.iiab.controller.permissions.StoragePermission.request(this, permResult, storagePermResult); } private void requestBattery() { if (hasBattery()) return; From 857c8fbb35ba2423a78d024a294eeb6857ffc39f Mon Sep 17 00:00:00 2001 From: "Luis Guzman (AppDevForAll)" Date: Thu, 20 Aug 2026 23:03:25 -0600 Subject: [PATCH 2/2] ADFA-5225 fix(onboarding): route permanent pre-R storage denial to app settings The wizard's pre-R runtime request silently no-ops once the user picks "Don't ask again", re-stranding onboarding on a screen with no other path to Settings. requestOrOpenSettings() now detects that (rationale==false after a prior ask) and opens the app details settings instead. Also drops now-unused imports in SetupSectionFragment left over from centralizing the permission logic. --- .../iiab/controller/SetupSectionFragment.java | 3 - .../permissions/StoragePermission.java | 62 ++++++++++++++++--- .../controller/redesign/WizardActivity.java | 8 ++- 3 files changed, 61 insertions(+), 12 deletions(-) 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 8931fe7a3..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; 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 index c14eee794..ff504487c 100644 --- a/controller/app/src/main/java/org/iiab/controller/permissions/StoragePermission.java +++ b/controller/app/src/main/java/org/iiab/controller/permissions/StoragePermission.java @@ -1,5 +1,6 @@ package org.iiab.controller.permissions; +import android.app.Activity; import android.Manifest; import android.content.Context; import android.content.Intent; @@ -10,6 +11,7 @@ import android.provider.Settings; import androidx.activity.result.ActivityResultLauncher; +import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; /** @@ -44,6 +46,9 @@ public static boolean isGranted(Context ctx) { /** * 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) @@ -53,16 +58,57 @@ public static void request(Context ctx, ActivityResultLauncher runtimeLauncher) { if (isGranted(ctx)) 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:" + ctx.getPackageName())); - settingsLauncher.launch(i); - } catch (Exception e) { - settingsLauncher.launch(new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)); - } + 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 a60ea55bc..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 @@ -46,6 +46,9 @@ public class WizardActivity extends AppCompatActivity { // 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 -> { @@ -316,7 +319,10 @@ private void requestNotif() { } } private void requestStorage() { - org.iiab.controller.permissions.StoragePermission.request(this, permResult, storagePermResult); + // 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;