How to decrypt files on the fly when transferring via USB? - android

In my Android app I store encrypted files on the SD card and only my app is able to access and decipher them.
However, I need to make those files available for clear transfer to a PC or Mac via the USB connexion.
The idea would be that the user can activate the transfer mode on the app secured by authentication and PIN code. When activated, I would like to create a fake folder tree and files matching the encrypted content on the SD card.
And when the user will try to copy them on his computer, I thought about catching the event and decipher the original file on the fly to allow him to retrieve the original file on his computer's file system.
Does anyone know if that is even technically possible on non-rooted phones?

You could use a USB connection from Android to a computer and then have a client program on the PC and your app on Android talk to each other (no file-system): Android USB-API
This way, you could transfer the encrypted files and decrypt them on the PC.
Pay attention to the hardware requirements though:
USB accessory and host modes are directly supported in Android 3.1
(API level 12) or newer platforms. USB accessory mode is also
backported to Android 2.3.4 (API level 10) as an add-on library to support a broader range of devices. Device manufacturers can choose
whether or not to include the add-on library on the device's system
image.
Note: Support for USB host and accessory modes are ultimately
dependant on the device's hardware, regardless of platform level. You
can filter for devices that support USB host and accessory through a
<uses-feature> element. See the USB accessory and host documentation
for more details.
This would be a low-level implementation.

Related

Can't find usb devices using Android app

I'm going to run Android app on Chromebook directly to access connected usb devices, not from ARC Welder.
I want to use ES File Explorer to access my usb devices.
Plugin a USB OTG wire and run ES File Explorer on normal Android devices, it can detect connected USB devices as expected.
However, if I run the same ES File Explorer Android app on Chromebook, it can not detect connected USB devices. Looks in this case, Chromebook intercepts USB low level data packages. Because I can use Chromebook built-in File Explorer(which is not an Android app) to access connected USB devices.
By the way, I'm using USB storage to do the test.
So my question is, how can an Android app access connected USB devices on Chromebook? Is current behavior by design? Is there any plan to add USB support for Android apps in the future?
Based on the following Chromium bug report:
https://bugs.chromium.org/p/chromium/issues/detail?id=660189
Summary:
It appears that access to external/USB storage (read and write) for container based Android Apps on ChromeOS (container ARC) is a known issue, appears to be on the roadmap, but behind other priorities.
Update 2017-11-30:
The Chromium team has implemented USB On-The-Go access for the SD card on ChromeOS 62 (Chromium M-61?) or higher. What this means is that developers who expect their apps to work with the SD card as if it was under the battery in their phone will be disappointed. This is due to the fact that a 'hot swappable' SD card such as those found on a Chromebook isn't considered Adoptable Storage by the Android Framework.
Additionally if you want to use the MediaStore APIs to access it, you are still out of luck as the Android Framework does not support access to removable hardware. The Chromium team is aware and considering options:
Old issue ticket: https://bugs.chromium.org/p/chromium/issues/detail?id=789045&desc=3
So what to do?
Use: Android Storage Access Framework
See this Commonware's post on Removable Storage for further details.
Update 2019-09-04
ChromeOS 72 onward is supporting Android's MediaStore API, and direct '/storage' support for accessing content on SD card.
See: https://bugs.chromium.org/p/chromium/issues/detail?id=789045#c98
Issue ticket for supporting Android's Adoptable Storage:
https://bugs.chromium.org/p/chromium/issues/detail?id=917451

Android USB Host API taking away ttyACM file

I have a custom build of AOSP (based on kitkat 4.4). I am controlling an arduino board via Android's USB Host API. I also am running a kernel that supports the CDC-ACM module.
I want to be able to flash new hex files onto the board. I have seen ArduinoDroid do this in his app. I have been able to flash using avrdude and the /dev/ttyACM* file that is created using the CDC-ACM driver.
However, when I grant permission for my app to communicate with the arduino board, the /dev/ttyACM* file disappears. Which makes sense because I am now controlling it via Android's USB host api. I am looking for either a way to restore the /dev/ttyACM* file or allow avrdude to use the /dev/bus/usb/#/# file in order to flash a new hex file onto the board. It doesn't appear that there is a revokePermission method in the USBManager.
The /dev/ttyACM* device file does not appear even after closing the device. I am running the following code to close the device.
connection.releaseInterface(device.getInterface(1));
connection.close();
I guess my real question is that there a way to get the kernel driver back after releasing the USB connection.
Because I am using a custom build of AOSP, I do not have google play and I cannot install ArduinoDroid on the tablet. However, I can run my app as a system level app if needed.
Ultimately I solved this, but it does seem like a bit of a hack.
Before taking control of the device (on a reboot of the tablet), I checked to see if any /dev/ttyACM* files existed. If they did, I then checked the /sys/ file system to check to see they were the correct device. I essentially checked the vendor of the usb device and matched it against the known device. Once that was confirmed, I knew it was safe to try and upload a new hex file to the device.

Can I connect two Android devices directly using USB?

I need to write a program that will alow an Android device (running version 2.2) to send data (a simple String) to another device (also running version 2.2) via a USB connection. Are there any libraries to do that?
I believe those devices would have to support USB host mode in hardware. And then one of them would need to be out in storage media mode, then you'd use standard filesystem access functions. But the hardware side needs to be dealt with first. I would check out special USB host cables to see what can be done. Not all Android devices can be put into USB host mode.

Software based Android accessory on Windows

I would like to turn my computer into an Android accessory using my application. So instead of a specialized hardware this will be just PC that will switch the phone into accessory mode, thus launching some Java app on the phone associated with the host hardware and create a communication channel.
I've found a sample code (plus some Java Android app) to do this on Linux using libusb. It works by "opening" the phone using the standard VID and PID. Then it sends a command to turn on the accessory mode, along with the metadata like model, version etc.
If the phone supports accessory mode it'll then disconnect and reenumerate with a different PID. The sample code then checks if it did and opens the new device.
However, I'm trying to get this running on Windows. I've found a few USB libraries, like LibUsbDotNet, but they all seem to require the device using a WinUSB/libusb driver. I've used a tool in LibUsbDotNet to generate a libusb driver for my phone, installing it over the old generic removable drive one. But this means I now can't access the phone as a removable drive when I want to, so this is not a solution.
Is there a way (preferably a library) that can open any connected USB device based on VID and PID, and then send a few raw commands to it?
After that the device will reenumerate with a different PID, which I can use to create my own WinUSB driver, so that is not an issue. I just need to inject some commands through/around the default driver to turn the accessory mode on.
(I would prefer .NET solution, but anything Windows is fine and I can write my own interop wrapper)
I am also searching for a similar solution. I tried the Linux version, with libusb, with little hickups, was able to communicate with the device.
While searching for the solutions on windows I tried many hacks.
If need to communicate with device in ADK mode, I need to send several Vendor Commands, now this I need to do while its connected in Mass Storage mode. This is impossible using Mass Storage driver. I tried to get the Node handle of connected USB device to see if could send vendor command, but there I could only file Get Descriptor requests. So I went ugly method, replaced mass storage driver with libusb-win32, to see it could do the same, YES, it worked, but not at all a good solution.
Still searching..

Can Android's internal memory be mapped to a drive letter on PC?

When an Android device is plugged in to a PC (through USB?), is the internal file system mapped to a drive letter on the PC? So that one can copy files to and from the Android under Windows?
And, can Emulator simulate the situation when it's plugged in? How?
Thank you in advance!
Yes, it CAN be mapped to a drive letter. It was much easier with something like a Droid X (Android 2.3), since it would show up as a mass storage device (disconnecting the card from your phone in the meantime), but it's also possible on newer phones such as the LG G3 if you're willing to install 2 free programs, which you probably would like to have anyway.
ES File Explorer - Remote Manager (FTP Server)
First, you need a file manager, not only because the built-in one is useless, but also because you need an FTP server. Install "ES File Explorer" on your Android Device. Then in the options, turn on the "Remote Manager" option, which will activate the FTP server and show you its local address like "192.168.1.3:3721. You can now access your phone as an FTP site from your computer when on your local WiFi network.
Net Drive - Remote Drive Mapping Utility
Next, all you have to do is install NetDrive: http://netdrive.net/ It's freeware and seems to be used by a lot of companies, because it lets you map cloud storage to local drives. That will allow you to map your FTP server on your phone as a local drive.
Don't bother trying to map an FTP site with explorer. First, you may run into a problem that's apparently caused by Chrome, where you can't even add an FTP network location. You'll get an unexpected error telling you the path format is invalid. Interestingly, that is solved by opening the registry editor, then under [HKEY_CLASSES_ROOT\ftp] add a key named "ShellFolder" with string value "{E436EBB6-524F-11CE-9F53-0020AF0BA770}". The error will immediately cease occurring, with no restart or any other action required. Just go back in and add the ftp network location. That, however, still does not allow you to map it to a drive letter, which is why you need NetDrive.
As of Android 4, the wise ones have removed USB Mass Storage support for accessing the internal phone memory. So you no-longer get direct block-access (or a driver letter in windows). You can usually choose on the phone between MTP, or PTP (Media / Photo Transfer protocols) for whichever your OS supports better.
If your device has removable storage it should still support USBMS (with a drive letter) for that partition. At least Android still supports that, but your Manufacturer or Carrier-ware may still fail you here.
However, when it comes to the phone memory, there was a trade-off made in Honeycomb. Unified storage prevents wasted space (no more separate storage for phone / data, and having one fill up first and having confused frustrated users trying to move apps to SD, etc). The trade-off requires that:
Android can no longer ever yield up the storage for the host PC to
molest directly over USB.
Initially for Mac and Linux where support for MTP/PTP has been slower, You can use an FTP app on your phone. But now there is an increasing number of Desktop (PC/Mac/Linux) apps that understand and support the MTP or PTP protocols. You just don't get block access and so you can't get a drive letter without some hackery / third party software.
There have been hacks over the years to make FTP or WebDav or some other protocol work behind a windows drive letter, and something like could still work work for these MTP/PTP protocols, but I have yet to see any such consumer usable software for windows.
If your Linux distro doesn't include MTP support, gMTP seems pretty popular.
You can mount the device via USB but (in Win7 at least) it doesn't appear to have its own drive letter; rather it's treated like a camera or another media device. It doesn't mount automatically; you generally need to "opt-in" in the notification area with something like "Turn on USB storage"
Don't know about emulators.
Using Eclipse you can push and pull files to the emulator using the DDMS perspective. Doing similar on a real device, iirc will require root access to the device, at least to get to the 'sensitive' areas.
The SDK tools will also provide a way of push and pull via the command line.
possible with https://github.com/billziss-gh/sshfs-win
difficult finding good sshservers for android, know that at least one works but doesn't autostart at wifi and have to manually restarted, which it was possible to "come home from work, drive is connected"
this server seams to work fine
https://play.google.com/store/apps/details?id=net.xnano.android.sshserver.tv&hl=en_US
Wanted to backup(incremental) android device using Areca backup utility which requires src and dest to have drive paths.
After trying various methods like adb-sync, Syncthing, webDAV, etc. Got it working with ftp sharing.
Download any ftp server app. I used "WiFi FTP Server" by Medha Apps on Playstore to create a ftp server something like this- ftp://username:*#xxx.xxx.xxx.xxx:yyyy where username can be set in app settings and xxx is i.p. with yyyy as port number.
Map ftp URL to drive path by using free app- "DirectNet Drive"
Use the drive as if it's in your own system, though it will be slow being wireless.

Categories

Resources