How To Mount A Usb Drive On Android Things?
Solution 1:
ADB ONLY SOLUTION
Seem like as of now USB drives aren't mounted automatically. In order to make your code work I had to mount it manually.
As you can see (from /proc/partitions
) in the /proc
partition the USB drive is detected as sda
.
ADB mounting
Make a directory to mount to
mkdir /mnt/usb
Mount the device
mount -t vfat -o rw /dev/block/sda1 /mnt/usb
Now you should be able to list (and manage) the files on the USB drive both via ADB and from within the app (/mnt/usb
will also be logged).
Solution 2:
I think the only solution is to create a service in init.rc to be able to execute the script with root permisions on Boot. Apparently Android things doesnt have a solution right know. Something like:
on property:dev.bootcomplete=1
start bootcomplete_handler
service bootcomplete_handler /system/bin/sh /system/bin/bc_handler.sh
class late_start
user root
group root
disabled
oneshot
But dont know if this will work
Solution 3:
I have made an script that every 10 seconds if detects a usb storage units mounts it automatically, the only problem is to launch it on Boot, maybe this could help you, I have my post here: Execute Script on Boot Android Things
And the script:
whiletrue; doif [ "$( ls -l /dev/block/sd* | wc -l)" -ge 1 ];
thenecho"partition available"if [ "$( mount | grep "usbAlv" -c)" -ge 1 ]; #if partition not mountedthenecho" Unit Mounted"elseecho"not mounted"
//if folder where we mount the partition doesnt exist
if [ !"$( ls -l /sdcard/usbAlv | wc -l)" -ge 1 ];
thenmkdir /sdcard/usbAlv
fi
su root << EOSU
mount -t vfat -o rw /dev/block/sd* /sdcard/usbAlv
EOSUfielseecho"not partition available"fisleep 10;
done
Hope it helps, i guess now is the only posible way to do it programatically
Solution 4:
Working and discarded options
1. Use ADB (working)
As answerer by Onik in this post
2. Use USB API (working)
As Android API for USB allows bulkTransfer, you can code SCSI compatible commands.
You can also try existing libraries such as libaums, posted by Phaestion in response to this similar question
3. Inject shell commands at init.rc at boot.img (NOT working)
Shell commands can be injected to the init.rc file inside the boot.img (not the init.rc file that you can find in the /root directory). However, given the A-B boot nature of the AndroidThings compilation, I have been unable to make it work.
4. Add advanced app permissions (NOT working)
The following permissions seem promising to execute root commands from the app. However, permission denied error continues to block the root command execution.
<uses-permissionandroid:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"tools:ignore="ProtectedPermissions" /><uses-permissionandroid:name="android.permission.CALL_PRIVILEGED"tools:ignore="ProtectedPermissions" /><uses-permissionandroid:name="android.permission.MOUNT_FORMAT_FILESYSTEMS"tools:ignore="ProtectedPermissions" /><uses-permissionandroid:name="android.permission.MANAGE_DEVICE_ADMINS"tools:ignore="ProtectedPermissions" /><uses-permissionandroid:name="android.permission.MANAGE_USB"tools:ignore="ProtectedPermissions" />
I even tried to compile an AndroidThings distribution with an app with such permissions but the Android Things console does NOT allow to include the app to the compilation
5. White list the app (NOT working)
There is a white list for priviledged apps. However, this white list is placed in a priviledged directory and cannot be overwritten even from the shell command with root user
6. Install the app at a priviledged location (NOT working) Apps installed in priviledged directories can execute root commands. However, AndroidThings does NOT allow to install apps at such locations (even from the shell with root user)
Post a Comment for "How To Mount A Usb Drive On Android Things?"