Skip to content

Commit 8742a64

Browse files
committed
Add /sdcard bind mount to terminal proot session
The terminal builds its own proot args in Dart (terminal_service.dart) separately from ProcessManager.kt. Added /storage and /sdcard bind mounts to buildProotArgs() so the terminal shell also has access to shared storage when permission is granted. Co-Authored-By: Mithun Gowda B <mithungowda.b7411@gmail.com>
1 parent be277c0 commit 8742a64

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

flutter_app/lib/services/terminal_service.dart

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/services.dart';
22
import '../constants.dart';
3+
import 'native_bridge.dart';
34

45
/// Provides proot shell configuration for the terminal and onboarding screens.
56
/// Must match ProcessManager.kt's gateway mode (command_login) exactly.
@@ -24,6 +25,8 @@ class TerminalService {
2425
final prootPath = '$nativeLibDir/libproot.so';
2526
final libDir = '$filesDir/lib';
2627

28+
final storageGranted = await NativeBridge.hasStoragePermission();
29+
2730
return {
2831
'executable': prootPath,
2932
'rootfsDir': rootfsDir,
@@ -32,6 +35,7 @@ class TerminalService {
3235
'homeDir': homeDir,
3336
'libDir': libDir,
3437
'nativeLibDir': nativeLibDir,
38+
'storageGranted': storageGranted.toString(),
3539
// Host-side proot env — ONLY proot-specific vars.
3640
// Do NOT set PROOT_NO_SECCOMP (proot-distro doesn't set it).
3741
// Do NOT set HOME/TERM/LANG here (those go in guest env via env -i).
@@ -62,7 +66,7 @@ class TerminalService {
6266
final kernelRelease = '\\Linux\\localhost\\$_fakeKernelRelease'
6367
'\\$_fakeKernelVersion\\$machine\\localdomain\\-1\\';
6468

65-
return [
69+
final args = <String>[
6670
// proot-distro command_login style
6771
'--change-id=0:0',
6872
'--sysvipc',
@@ -97,6 +101,17 @@ class TerminalService {
97101
// App-specific binds
98102
'--bind=${config['configDir']}/resolv.conf:/etc/resolv.conf',
99103
'--bind=${config['homeDir']}:/root/home',
104+
];
105+
106+
// Bind-mount shared storage if permission is granted (Termux-style)
107+
if (config['storageGranted'] == 'true') {
108+
args.addAll([
109+
'--bind=/storage:/storage',
110+
'--bind=/storage/emulated/0:/sdcard',
111+
]);
112+
}
113+
114+
args.addAll([
100115
// Clean guest environment via env -i (matching proot-distro).
101116
// This prevents Android JVM vars (LD_PRELOAD, CLASSPATH, DEX2OAT,
102117
// ANDROID_ROOT, etc.) from leaking into the proot guest.
@@ -112,7 +127,9 @@ class TerminalService {
112127
'NODE_OPTIONS=--require /root/.openclaw/bionic-bypass.js',
113128
'/bin/bash',
114129
'-l',
115-
];
130+
]);
131+
132+
return args;
116133
}
117134

118135
/// Host-side environment map for Pty.start().

0 commit comments

Comments
 (0)