0

I am transfering files to an android device using adb push. I am able to push the files to the SD card, and the commandline tells me the transfer rate, file size, and time elapsed, e.g:

C:\Users\some_guy\Pictures>adb -d push wilford.jpg /sdcard/wilford.jpg
2558 KB/s (13104 bytes in 0.005s)

I'm looking to create an app or service that can subscribe to events through a broadcast receiver to get updates on when the adb push starts, finishes, and includes the current file transfer rate while the transfer is in progress. So, as the file gets written from adb, it would notify my applicatoin of its current % complete and transfer rate. Is this possible? What permissions are required and how would the application subscribe to the updates? I've looked around at the list of permissions and other resources and can't figure out a way to do this.

Another possibility would be to simply monitor the SD card file system for incoming files, but I'm not sure what that would give me beyond monitoring when new files are written fully.

Stealth Rabbi
  • 10,156
  • 22
  • 100
  • 176

2 Answers2

1

I had a very similar issue a while back, and I believe I exhausted all options to no avail. There's no broadcast as part of the adb push process. However, you can create your own broadcasts before and after each push using adb shell am broadcast ... and even send extras (such as filename or transfer rate).

This will be easier if you use bash or python to script your adb transfers, rather than windows batch files -- I wound up using the jython implementation for MonkeyRunner included with the SDK tools, and only had to drop out to the shell to do the actual file push, as MonkeyRunner doesn't provide that.

323go
  • 14,143
  • 6
  • 33
  • 41
1

You can detect at least the creation of new files using the Linux kernel inotify mechanism on the target directory.

Android exposes this functionality through the FileObserver class:

Monitors files (using inotify) to fire an event after files are accessed or changed by by any process on the device (including this one). FileObserver is an abstract class; subclasses must implement the event handler onEvent(int, String).

Each FileObserver instance monitors a single file or directory. If a directory is monitored, events will be triggered for all files and subdirectories inside the monitored directory.

see http://developer.android.com/reference/android/os/FileObserver.html

Note that the mechanism is not recursive in that monitoring a directory monitors only entires in that directory, not entries in its subdirectories. This question discusses some recursive possibilities.

Community
  • 1
  • 1
Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
  • I'm not sure if this notifies you as the file is being written. Would this be the MODIFY mask? Also, it doesn't give you anything about the amount written, or the speed in which it is written. – Stealth Rabbi Dec 18 '13 at 17:08
  • I'm not exactly sure how the underlying filesystem will handle in progress writes, but it's possible that once you see the directory created, you could try monitoring the file size periodically. Remember though that ADB is not a tool intended for end-users. If you really want to involve an app, you could forward a unix-domain or tcp socket through adb, send the data to your monitoring app via that, and have it write the file. – Chris Stratton Dec 18 '13 at 17:12
  • Using a file browser app, I can see that the file is written to the SD card beofre teh transfer completes, and that it grows in size as time passes. I may have to artificially get the transfer speed by polling the file size periodically (until the file writing has completed), and dividing by the time elapsed. Edit: Sorry, just noticed your recent comment. Yeah, perhaps a socket would be simpler, which would eliminate the need to enable debug privs. As you say, it is not intended for end users. – Stealth Rabbi Dec 18 '13 at 17:17
  • No, a socket forward via ADB would still requires debugging to be enabled for ADB to work at all. Something piggybacked on tethering, or via wifi would not, but those have their own issues. – Chris Stratton Dec 18 '13 at 17:21