adbkit icon indicating copy to clipboard operation
adbkit copied to clipboard

implement backup & reboot functionality

Open fiws opened this issue 12 years ago • 1 comments

these features would be nice. A possible API:

Backup

client.backup(serial, options, callback) where the options could look like this:

{
  out: "backup.ab",
  apk: true,
  all: false,
  shared: false,
  system: true,
  packages: []
}
adb backup -f backup.ab -all (...)

Reboot

client.rebootRecovery(serial, callback) client.rebootBootloader(serial, callback)

adb reboot [bootloader|recovery]

I would like to contribute, but I can't get my head around coffescript.

fiws avatar Dec 24 '13 23:12 fiws

Reboot is a bit difficult as I'm not sure what to do about losing the connection to the device when the device reboots. Should the callback return when ADB reports success for the reboot command, or when the device becomes accessible again? Is ADB even available in recovery/bootloader mode?

Backup should also be doable, but it might take a while to implement it as we don't need it here at work right now...

Our code is CoffeeScript mainly because it makes writing callback-heavy code more enjoyable. But you're right, it takes a while to get used to it. If it helps, try running grunt coffee and reading the generated JS source code in the lib folder. You can also run grunt coffeelint to make sure there's nothing too obviosly wrong with your code (it won't catch everything however). And finally if grunt test succeeds, at least you will not have broken anything!

Personally I find that the biggest differences are that curly braces are always left out, parentheses can be omitted (e.g. foo(a, b, bar(c, d)) can be written as foo a, b, bar c, d), function(a, b) { foo } becomes (a, b) -> foo and the last expression in a function becomes its return value. After npm install -g coffee-script you can run any .coffee file via coffee foo.coffee, just like you'd do node foo.js normally. There's a small example over at https://github.com/CyberAgent/adbkit-logcat that might help illustrate a few of the differences. Also, CoffeeScripters are in high demand right now, couldn't hurt learning it ;)

Alternatively you could just write your additions in JavaScript, as .js files can be require()d normally from CoffeeScript. But I would really prefer if you didn't do that as it would make everything much more difficult to maintain.

As for implementing a new API method, aside from the complexities introduced by rebooting, the basic idea is that you create src/adb/command/host-transport/newcommand.coffee and then expose it via src/adb/client.coffee. Tests in test/adb/command/host-transport/newcommand.coffee would also be highly appreciated, but sometimes these things can be a bit difficult to test.

Anyway we'd really appreciate contributors so I hope you can look beyond the language!

sorccu avatar Dec 25 '13 07:12 sorccu