top of page
admin

Android Shell Tricks: Using Mass Provisioning as an Example, Part 3


Settings

Say you have 400 devices to provision before deployment--how do you configure them all? And how can you guarantee that they’re all configured correctly? Automate it!

adb shell settings put global airplane_mode_on 1
adb shell settings put global adb_enabled 0
adb shell settings put global install_non_market_apps 1
adb shell settings put global usb_mass_storage_enabled 0
adb shell settings put global data_roaming 1

Note that changing these settings does not result in the respective functionality being enabled immediately; rather, the setting is stored and the change becomes effective upon reboot, at the latest.

There are lots of knobs; see Settings.java for a list of available settings. For some of the settings you’ll have to dig around in the source code in order to figure out what values to set.


Backup and Restore

Full backups are easy using adb:

adb backup -apk -shared -obb -all -f mybackup.ab

Restoring from a full backup is easy too:

adb restore mybackup.ab

Another backup tool called rawbu only backs up the /data partition, which is often more appropriate for provisioning. Rawbu stops Android, backs up /data, and then restarts Android.

This is perfect for provisioning. First you configure one device with all the right settings, then backup /data with rawbu. Now you can use that backup as a template for preconfiguring any number of devices with a single command. For example:

# Configure a device and retrieve the backup:
adb shell rawbu backup /sdcard/provision.dat
adb pull /sdcard/provision.dat provision.dat

# Push the backup to a new device and restore /data from it.
adb push provision.dat /sdcard/provision.dat
adb shell rawbu restore /sdcard/provision.dat
adb shell reboot

Note that not all devices ship with rawbu installed. Also, read the usage for rawbu because it spells out some important restrictions regarding the backup path.

rawbu

Stops Android, does the backup or restore, restarts.

rawbu backup /sdcard/backup.dat
rawbu restore /sdcard/backup.dat

Usage: rawbu COMMAND [options] [backup-file-path]
commands are:
  help            Show this help text.
  backup          Perform a backup of /data.
  restore         Perform a restore of /data.
options include:
  -h              Show this help text.
  -a              Backup all files.

 backup-file-path Defaults to /sdcard/backup.dat .
                  On devices that emulate the sdcard, you will need to
                  explicitly specify the directory it is mapped to,
                  to avoid recursive backup or deletion of the backup file
                  during restore.

                  Eg. /data/media/0/backup.dat

The rawbu command allows you to perform low-level
backup and restore of the /data partition.  This is
where all user data is kept, allowing for a fairly
complete restore of a device's state.  Note that
because this is low-level, it will only work across
builds of the same (or very similar) device software.


Conclusion

These are some of our favorite Android shell utilities, and there are many more besides. As you can see, the Android shell utilities can be quite powerful and useful. We would enjoy hearing from you on some of your favorites. Just tweet us at @sdgsys or on Google+. Need some help with your Android development? Our team of engineers has been working with Android since 2009. Please contact us to see how we can help.

614 views0 comments

댓글


bottom of page