1#!/usr/bin/env python3.4
2#
3#   Copyright 2017 - The Android Open Source Project
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11#   Unless required by applicable law or agreed to in writing, software
12#   distributed under the License is distributed on an "AS IS" BASIS,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16
17import logging
18
19from acts.libs.ota.ota_tools.ota_tool import OtaTool
20
21# OTA Packages can be upwards of 1 GB. This may take some time to transfer over
22# USB 2.0.
23PUSH_TIMEOUT = 10 * 60
24
25
26class AdbSideloadOtaTool(OtaTool):
27    """Updates an AndroidDevice using adb sideload."""
28
29    def __init__(self, ignored_command):
30        # "command" is ignored. The ACTS adb version is used to prevent
31        # differing adb versions from constantly killing adbd.
32        super(AdbSideloadOtaTool, self).__init__(ignored_command)
33
34    def update(self, ota_runner):
35        logging.info('Rooting adb')
36        ota_runner.android_device.root_adb()
37        logging.info('Rebooting to sideload')
38        ota_runner.android_device.adb.reboot('sideload')
39        ota_runner.android_device.adb.wait_for_sideload()
40        logging.info('Sideloading ota package')
41        package_path = ota_runner.get_ota_package()
42        logging.info('Running adb sideload with package "%s"' % package_path)
43        ota_runner.android_device.adb.sideload(
44            package_path, timeout=PUSH_TIMEOUT)
45        logging.info('Sideload complete. Waiting for device to come back up.')
46        ota_runner.android_device.adb.wait_for_recovery()
47        ota_runner.android_device.reboot(stop_at_lock_screen=True)
48        logging.info('Device is up. Update complete.')
49