Want to build a FxOS backup tool or a FxOS upgrade tool within Firefox Desktop?
As an addon or as a builtin feature?
It's now very simple with our ADB wrapper.
~~~
Part of our work in the Firefox DevTools team was to make connections
with a FxOS devices easy.
To do so, we did 2 things:
- auto-install the ADB binaries when the user starts the FxOS devtools on Firefox Desktop
- wrap ADB commands into JS methods
ADB binaries are wrapped in an Addon that we maintain [1].
There are plenty of examples of how we instrument ADB from the devtools in
WebIDE. See source code [2].
For example, we added buttons to root the device and change some files (prefs.js).
Let me describe what we do in WebIDE [3], and know that you can do that for any tool
within Firefox Desktop:
- when WebIDE starts, we auto install ADB:
// Autoinstall ADB, seamless to the user:
const {Devices} = Cu.import("resource://gre/modules/devtools/Devices.jsm");
const {GetAvailableAddons} = require("devtools/webide/addons");
if (!Devices.helperAddonInstalled) {
GetAvailableAddons().then(addons => {
addons.adb.install();
}, console.error);
}
// Devices.on("addon-status-updated", AddonInstalledOrUninstalled);
// Devices.on("register", ADeviceAsBeenPlugged)
// Devices.on("unregister", ADeviceAsBeenUnPlugged)
- to talk to the device through ADB:
Devices.available; // an array of available devices (list of ids)
let device = Devices.getByName(id);
device.isRoot(); // will tell you if ADB is root or user
device.summontRoot(); // will restart ADB in root (if device is unlocked)
device.shell("ls /").then(function(stdout) {
// result of the shell command
});
We can add more features upon request.
[1]:
https://github.com/mozilla/adbhelper
[2]:
http://mxr.mozilla.org/mozilla-central/source/browser/devtools/webide/
[3]:
https://developer.mozilla.org/en-US/docs/Tools/WebIDE
-- Paul