I am building this app on android things. I want to be able to give it access to media files on a USB stick or maybe even the raspberry pi's SDcard. I don't know what I'll have it do with those files yet but I just wanna know if its possible. If it isn't that's fine I have other solutions but I figured I would start with the obvious approach first.
I'm didn't try it, but seems it's possible by the same way as in normal Android OS. To do this You should mount Your USB dongle into the filesystem somewhere e.g. in new folder /mnt/usb like in this answer of Onik or that project of Keval Patel:
Mount USB drive:
Plug you USB drive at any of the USB port in your Raspberry Pi.
Open adb shell by typing below command in terminal (Make sure your raspberry pi is connected via adb):
adb shell
Mount the USB drive by running below command in adb shell (Your USB drive should be formatted in FAT file system):
su mkdir /mnt/usb
mount -t vfat -o rw /dev/block/sda1 /mnt/usb
where
sda1 is the first partition of the first disk (sdb1 is the first partition of the second disk, etc.) and /mnt/usb - new folder for mounted USB dongle.
Then You can access to mounted USB dongle something like this way:
File usbDongleRoot = new File("/mnt/usb");
(or something like this).
Also take a look at this answer of JBA and that repo of Shaka Huang.
Related
Is there any tool to install multiple apps(4 apps) as a system apps on android rooted device directly.
I done it using ES File Explorer but the problem is, how to install those apps as system apps in more devices (1000 or 10000 devices) quickly.
Is there any tool to do that kind of situation.
Finally I found the solution,
Connect device to PC using USB cable and enable USB debugging
Creating .bat file with these commands.
Save bat file where .apk file located and double click .bat file and execute.
adb remount
adb push apk-filename-here /system/app/
adb shell chmod 644 /system/app/apk-filename-here
adb reboot
I have a smartphone without the possibility to insert an SD-card.
I would like to make a dump of the biggest partition (cause I lost files and I'd like to use a dump to recover them).
The partition is 10GB.
I was looking for an ADB command to pull using dd but nothing...
I tried to use Carliv touch recovery with a 32GB usb key by OTG but the USB key didn't mount ... Then I couldn't use "dd" directly on the phone using Aroma file manager and a terminal emulation.
Thank you!
I don't understand why they closed a question that has already an accepted answer by linking a completely different question. Copying a file and copying a partition are 2 different things.
As said in comment, adb pull /dev/block/mmcblk0 mmcblk0.img worked for me. A "DD image" is only a binary image file of the device.
You want to copy a disk from your android device to your computer (preferably on your fastest drive) for faster and lossless analysis/recovery.
This is short step-by-step guide in windows (linux: scroll down) to achieve it using the linux tool dd intended for precise, bit-wise copies of data. Credits go to scandium on xda for the code, see his post for more details.
Prerequisites
make sure your device is rooted and busybox is installed
Windows:
install cygwin. During install, add netcat (under Net) and pv (under util-linux) packages; the standard install is located in C:\ so make sure you have enough disk space beforehand;
install adb e.g. through Android Studio. Make sure to add adb.exe executable file to the path variable to access it properly (guide).
Open two cygwin consoles/terminals (one sending data, one receiving data) and enter in one of the terminals to enter the device:
# terminal 1
adb forward tcp:5555 tcp:5555 # forward data over tcp connection
adb shell # open a connection
su # gain root access
BUSYBOX=/system/xbin/busybox # default location for most bb installers
# note: adapt the variable `BUSYBOX` to point to your install directory
# the TWRP default is `BUSYBOX=/sbin/busybox` (in case of bricked device)
Decide what partition to copy, the /dev/block/mmcblk0 partition is usually the one containing the data you typically would want.
In the following code, adapt the partition name according to 4. and quickly one after another type in terminal 1 and terminal 2:
# terminal 1
$BUSYBOX nc -l -p 5555 -e $BUSYBOX dd if=/dev/block/mmcblk0
# terminal 2
nc 127.0.0.1 5555 | pv -i 0.5 > $HOME/mmcblk0.raw
This saves the partition in the cygwin home directory (in a nutshell: it sends/receives output of dd over a tcp connection)
Look at the files / analysis
To mount the partition in Windows you can use (OSFmount).
To analyze the files I recommend Active# Undelete but there are tons of alternatives. With that program you can also directly load all partitions from the file (without mounting it, so step 5 is redundant in this case).
Guide for GNU/Linux users: install netcat and pv (step 1), use the Disks utility to analyze
Run as root:
adb root
Use dd to output content into stdout and write file on your computer:
adb shell 'dd if=/dev/block/platform/msm_sdcc.1/by-name/XXXXXX 2>/dev/null' > XXXXXX.img
Or all (see cat /proc/partitions)
adb shell 'dd if=/dev/block/mmcblk0 2>/dev/null' > mmcblk0.img
I am trying to make a backup (a direct dd image of the partitions of my built-in memory card of my phone to my PC. I am using Linux and my phone is a Nexus 4.
Don't install TWRP
Instead:
Install android-platform-tools or android-sdk onto your computer.
Download TWRP to your computer.
Hold the volume down and volume up buttons and turn on your phone to start up the bootloader screen. Make sure your phone is plugged into your computer's USB port.
Boot TWRP by running fastboot boot twrp-3.1.0.0.img. (No need to flash your recovery partition this way.)
In TWRP, select Advanced, then Terminal, which will open a shell. Type mount and press [ENTER] to see the partitions. You're looking for the /data and possibly /sdcard mounts.
Let's say your /data partition maps to /dev/mmcblk0p28. Just run adb pull /dev/block/mmcblk0p28 data.img on your computer and it will copy the partition. Expect this process to take a while since it is copying the entire partition, regardless of how many files are stored in it.
Here another better answer:
Requirements: adb must be already installed
Download insecure boot.img to your PC from https://www.androidfilehost.com/?fid=9390169635556426389
Reboot your phone into fastboot mode by powering it off and then pressing and holding volume-down and power buttons.
From your Linux PC in the folder where boot.img is located type:
$ fastboot boot boot.img
To copy the image of the mmcblk0 partition type:
$ adb pull /dev/block/mmcblk0 mmcblk0.img
Edit: Hongo's answer has fewer steps.
Install TWRP.
Choose your device on the TWRP page and follow the installation instructions there.
Boot into Recovery
You may have to find the key combination specific to your device in order to react the bootloader menu. If you flashed TWRP using fastboot (fastboot flash recovery twrp.img), then you can try fastboot reboot-bootloader, then select Recovery.
Mount partitions in TWRP
You should now be in TWRP. From there, choose Mount. Make sure your data partition in mounted. Make sure your system partition is mounted, as you'll need some executables that reside there.
Connect adb
Install adb if you haven't already. Connect your phone to your computer by USB cable. Type adb devices. If you see a device listed, then you're connected.
Forward a port adb forward tcp:33333 tcp:33333
We need to enable TCP access to your phone. This command listens on the computer's port 33333 (the first argument) and forwards all connections to port 33333 on your phone. You can pick any port. Ports lower than 1024 on the PC require root access. Make sure the port you pick isn't already being used. The two numbers don't need to match.
Locate the partition you want to backup adb shell mount
Locate the partition that you want to backup and get the device name. [EDIT: if the partition that you need to backup looks like /dev/block/dm-0, it's part of a logical volume (LVM) and this is probably not the right way to back it up]
Forward the raw partition from your phone
adb shell
Try dd if=/dev/block/dm-0 bs=64k | gzip | nc -l -p 33333
This /dev/block/dm-0 with the the device that you found from the mount command, earlier.
Replace 33333 with the phone port that you picked above
If any commands can't be found, you can try to prepend them with /system/bin/toybox or /system/bin/busybox.
This command block copies from the specified device (if=) and, using a block size of 64k (bs=64k - you can specify any, or omit this argument entirely, but small values will likely slow the process down. Values larger than 64k will generally not speed the process up), dumps this to stdout, which is piped into gzip to compress it, then piped into netcat, which is listening (-l) on port 33333 (-p 33333).
Dump the data on your computer
From a new terminal, do nc localhost 33333 | pv -i 0.5 --size 54g > dm-0.raw.gz
Replace 33333 with the computer port that you picked above
Replace dm-0.raw.gz with any file name
Replace 54g with the size of your partition (see below)
This command connects to port 33333 on the localhost (your computer) and dumps to stdout, pipes that to pv, which updates the transfer progress every half second (-i 0.5) with an estimated size of 54 gigs (--size 54g - you can omit this argument but it's necessary for the transfer progress to be accurate), then into a file named dm-0.raw.gz
Requirements: adb must be already installed
Download insecure boot.img to your PC from https://www.androidfilehost.com/?fid=9390169635556426389
Reboot your phone into fastboot mode by powering it off and then pressing and holding volume-down and power buttons.
From your Linux PC in the folder where boot.img is located type:
$ fastboot boot boot.img
To make an image of the mmcblk0p23 partition type:
$ adb shell 'stty raw && dd if=/dev/block/mmcblk0p23' > ~/userdata.img
Useful Links:
How to you identify the partition of interest:
http://forum.xda-developers.com/showthread.php?t=2450045
If stty raw is not used all LF will be translated to CRLF:
android.stackexchange.com/questions/69434/is-it-possible-to-cat-a-file-to-an-android-phone-and-dd-to-dev-xxx-on-the-fly-w
How to root phone and use insecure boot.img:
www.addictivetips.com/android/root-google-nexus-4-install-clockworkmod-recovery/
Transferring binary data over ADB shell (how to use stty raw):
stackoverflow.com/questions/11689511/transferring-binary-data-over-adb-shell-ie-fast-file-transfer-using-tar
I've search and searched here, and no topics come close to answering the question.
Mounting and unmounting a USB stick from within a rooted APK. I've been successful in doing it from the command line via adb as follows:
prompt>> mount -t vfat -o rw /dev/block/sda1 /sdcard/usb
After this command, I can "cd /sdcard/usb" and can see the contents of the USB stick.
If I try this in code using the Process class, I can't see anything there from the command line in adb, a file explorer on the device, etc:
proc = Runtime.getRuntime().exec(new String[]{"/system/xbin/su", "-c", "mount -t vfat -o rw /dev/block/sdb1 /sdcard/usb"});
proc.waitFor();
This is a sandbox problem. It's driving me nuts. Here's what I think is going on, and I have no idea how to solve it: When the Process class invokes su, it does so in a completely new userspace -- it's own sandbox. The mount succeeds (I can see that from some debugging), then the process dies and returns to the app, which is in a different sandbox. Because of that, not only can I not see the mount, it unmounted with the su process going away.
I need to be able to mount a USB stick from my application, read/write to a file, then unmount it before it is removed (otherwise risk data corruption).
I've looked and looked for an android or java interface to the Linux mount(2) and umount(2) commands and have come up empty. There must be some way to do this!!
you must read that carefully. mounting and unmounting should be done using that
http://developer.android.com/guide/topics/connectivity/usb/host.html
Hope this isn't too much of an amateur/moron question: I'm trying to replace most ringtones and alarms (Dell Streak 5 (2.2.2 rooted)) with a few of my own pet sounds.
For reasons I won't bother you with, I can't use an SD card, so my .ogg replacements need be transferred straight from my PC to their respective default folders under /system/media/audio/ .
ADB push and pull commands don't seem to accept widlcards (which is a pain) but anyway, despite setting the system folder to rw, I get 'permission denied' when I tediously attempt to pull or push files one by one.
But I should be able to rm and cp interactively from ADB's shell # prompt, with simple Unix commands to transfer groups of files between the /system/media/audio folders and my Windows PC. But to do this I presumably need to mount my PC source folder, and I have no idea how to do this.
I'd be grateful for any info or ideas...
You need to have root access on the phone. My advice as a programmer would be to
1) Write a program to do this...
or just do it the easy way haha. Try this (your device must be rooted):
adb shell into your device using $> adb shell
move to the local folder using $> cd /data/local
Now create a directory for your tones with $> mkdir my_tones - this shouldn't require su
Next you must push your .ogg files from your computer to the /data/local/my_tones folder
Now you can become su user with $> su
Now you should be able to copy the files from the /data/local/my_tones directory to where ever it is you would like them.
Hope this helps.