Comment 0 for bug 1359622

Revision history for this message
Martin Pitt (pitti) wrote : Add functionality to reset device to factory state with keeping network connections

For running tests on the device it should be reset to a known pristine state before each test, to avoid tests influencing each other. For that, autopkgtest's adb setup script currently saves the network connections, resets to factory state, and restores the network connections:

    echo "Performing factory reset, this will take a minute..." >&2

    # save current network connections
    local network_tar=$(mktemp)
    adb $ADBOPTS shell tar cPpf /run/netconf.tar /etc/NetworkManager/system-connections
    adb pull /run/netconf.tar $network_tar

    # reset to factory state
    adb $ADBOPTS shell 'echo format data > /cache/recovery/ubuntu_command'
    adb $ADBOPTS reboot recovery
    adb $ADBOPTS wait-for-device

    # restore network connections
    adb push $network_tar /run/netconf.tar
    adb shell 'tar xPpf /run/netconf.tar && rm /run/netconf.tar'

Doing that is a lot faster than having to re-flash the device from scratch every time. It allows us to manually set up a device once (i. e. pick network and type passphrase), and then just use it noninteractively.

It would be good to move this to phablet-tools, which is a more appropriate place as it contains all the other phone specific knowledge.