feat: default storage for new installs, with USB/SDCARD/SSD detection (#1520)

* feat: choose default storage for new store installs

Store installs and the Epic Games Launcher can use internal storage, external storage, a folder picked through Choose folder..., or ask every time. The choice is stored in SessionPrefs and used by StoreInstallRoot; Storage > Default storage exposes it.

* fix: allow choosing any folder for default storage

The default storage choice can now hold an arbitrary folder path, not just internal or app-specific external storage. StoreInstallRoot resolves and validates picked folders, keeps a disconnected choice instead of silently falling back, and the folder picker stays available from Storage.

* fix: keep the Epic install folder when external storage is away

* test: use a unique missing folder for the Epic storage check

* fix: detect USB SSDs that the storage manager hides

List storage volumes that have no UUID instead of dropping them, keep volumes that are present but not yet mounted, and fall back to parsing /proc/mounts so USB OTG drives appear even when Android does not expose them as storage volumes or app directories. Prefer the system's volume description for removable drives. (Raw removable drives as move targets, the folder-picker fallback, and the unreadable-drive guidance follow with the move stack.)

* fix: compare mount paths as strings in StorageRootsTest

* fix: never drop a present storage volume from the drive list

Key volumes by description or index when they report no UUID and no directory, keep nofs/unmountable states so a plugged-in drive stays visible with guidance, only attach app directories on strict UUID matches, and accept any fstype under vold-managed locations plus usb-ish mounts directly under /mnt.

* fix: probe folder writes with a fresh temp file and keep Epic's folder unset while external storage is away

---------

Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
This commit is contained in:
ianandKurt Himebauch authored and GitHub committed 2026-10-25 16:38:06 -04:00
1 parent 38926b3157
commit ee3f32d31e
13 files changed
+526 -29

No files matched your search

@@ -1,5 +1,9 @@
package com.droiddeck.launcher.ui
import android.app.Activity
import android.widget.Toast
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.LocalIndication
@@ -51,6 +55,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
@@ -65,6 +70,7 @@ import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
@@ -74,6 +80,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import coil.compose.AsyncImage
import com.droiddeck.launcher.R
import com.droiddeck.launcher.files.InAppFilePicker
import com.droiddeck.launcher.session.SessionPrefs
import com.droiddeck.launcher.storage.Bucket
import com.droiddeck.launcher.storage.CleanItem
@@ -84,6 +91,8 @@ import com.droiddeck.launcher.storage.StorageState
import com.droiddeck.launcher.storage.ToolReason
import com.droiddeck.launcher.storage.ToolState
import com.droiddeck.launcher.storage.ToolUsage
import com.droiddeck.launcher.stores.StoreInstallRoot
import java.io.File
import java.text.DateFormat
import java.util.Date
@@ -144,6 +153,113 @@ internal fun StoragePanel(s: FrontEndState, a: FrontEndActions) {
}
}
@Composable
private fun DefaultStorageGroup() {
val ctx = LocalContext.current
var value by remember { mutableStateOf(SessionPrefs.defaultStorage(ctx)) }
var open by remember { mutableStateOf(false) }
var revision by remember { mutableIntStateOf(0) }
val customPath = SessionPrefs.defaultStorageFolder(ctx)
val customTarget = remember(customPath, revision) { StoreInstallRoot.customTarget(ctx) }
val detected = remember(customPath, revision) { StoreInstallRoot.detectedExternalTarget(ctx) }
val customLabel = SessionPrefs.defaultStorageFolderLabel(ctx).ifBlank {
customPath.takeIf { it.isNotBlank() }?.let { File(it).name }.orEmpty()
}
val pickFolder = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode != Activity.RESULT_OK) return@rememberLauncherForActivityResult
val path = InAppFilePicker.pickedPath(result.data) ?: return@rememberLauncherForActivityResult
val problem = StoreInstallRoot.prepareDefaultFolder(ctx, File(path))
if (problem != null) {
Toast.makeText(ctx, ctx.getString(R.string.main_storage_not_usable, problem), Toast.LENGTH_LONG).show()
return@rememberLauncherForActivityResult
}
SessionPrefs.setDefaultStorageFolder(ctx, path, StoreInstallRoot.folderLabel(ctx, File(path)))
SessionPrefs.setDefaultStorage(ctx, SessionPrefs.DEFAULT_STORAGE_EXTERNAL)
value = SessionPrefs.DEFAULT_STORAGE_EXTERNAL
revision++
open = false
}
fun chooseFolder() {
open = false
val initial = customPath.takeIf { it.isNotBlank() && File(it).isDirectory }
?: detected?.root?.parentFile?.takeIf { it.isDirectory }?.absolutePath
pickFolder.launch(InAppFilePicker.buildDirIntent(ctx, ctx.getString(R.string.storage_default_choose_folder), initial))
}
val title = stringResource(R.string.storage_default_title)
val chip = when (value) {
SessionPrefs.DEFAULT_STORAGE_INTERNAL -> stringResource(R.string.storage_default_internal)
SessionPrefs.DEFAULT_STORAGE_EXTERNAL -> when {
customPath.isNotBlank() -> customTarget?.label
?: "$customLabel · ${stringResource(R.string.storage_default_folder_missing)}"
detected != null -> detected.label
else -> stringResource(R.string.storage_default_external)
}
else -> stringResource(R.string.storage_default_ask)
}
fun pick(next: String) {
SessionPrefs.setDefaultStorage(ctx, next)
value = next
open = false
}
SettingsGroup(stringResource(R.string.storage_default_group)) {
SettingsRow(label = title, hint = stringResource(R.string.storage_default_hint)) {
Box {
ValueChip(chip, open, modifier = Modifier.testTag("setting-default-storage")) { open = !open }
AnchoredMenu(
open, onDismiss = { open = false }, title = title,
note = stringResource(R.string.storage_default_note),
) { firstItemFocus ->
MenuItem(
stringResource(R.string.storage_default_ask), value == SessionPrefs.DEFAULT_STORAGE_ASK,
detail = stringResource(R.string.storage_default_ask_detail),
focusRequester = firstItemFocus,
) { pick(SessionPrefs.DEFAULT_STORAGE_ASK) }
MenuItem(
stringResource(R.string.storage_default_internal), value == SessionPrefs.DEFAULT_STORAGE_INTERNAL,
) { pick(SessionPrefs.DEFAULT_STORAGE_INTERNAL) }
if (detected == null && customPath.isBlank()) {
MenuItem(
stringResource(R.string.storage_default_external), value == SessionPrefs.DEFAULT_STORAGE_EXTERNAL,
detail = stringResource(R.string.storage_default_choose_folder_detail),
) { chooseFolder() }
} else {
if (detected != null) {
MenuItem(
stringResource(R.string.storage_default_external),
value == SessionPrefs.DEFAULT_STORAGE_EXTERNAL && customPath.isBlank(),
detail = detected.let { target ->
val free = target.freeBytes
if (free >= 0) stringResource(R.string.storage_default_external_detail, target.label, gb(free))
else target.label
},
) {
SessionPrefs.clearDefaultStorageFolder(ctx)
pick(SessionPrefs.DEFAULT_STORAGE_EXTERNAL)
revision++
}
}
if (customPath.isNotBlank()) {
MenuItem(
stringResource(R.string.storage_default_folder, customLabel),
value == SessionPrefs.DEFAULT_STORAGE_EXTERNAL,
detail = customTarget?.let { target ->
val free = target.freeBytes
if (free >= 0) stringResource(R.string.storage_default_folder_free, gb(free))
else stringResource(R.string.storage_default_folder_missing)
} ?: stringResource(R.string.storage_default_folder_missing),
) { if (customTarget != null) pick(SessionPrefs.DEFAULT_STORAGE_EXTERNAL) else chooseFolder() }
}
MenuItem(
stringResource(R.string.storage_default_choose_folder), checked = false,
detail = stringResource(R.string.storage_default_choose_folder_detail),
) { chooseFolder() }
}
}
}
}
}
}
@OptIn(ExperimentalLayoutApi::class)
@Composable
private fun Overview(report: StorageReport, sessionRunning: Boolean, onCleanUp: () -> Unit, onOpen: (String) -> Unit) {
@@ -189,6 +305,7 @@ private fun Overview(report: StorageReport, sessionRunning: Boolean, onCleanUp:
Spacer(Modifier.height(8.dp))
Note(stringResource(R.string.storage_session_running))
}
DefaultStorageGroup()
SectionTitle(stringResource(R.string.storage_where), null)
val unused = report.unusedTools.sumOf { it.bytes }
val tiles = listOf<@Composable (Modifier) -> Unit>(