Home | History | Annotate | Download | only in ota_tools
      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 
     17 import logging
     18 import os
     19 import shutil
     20 import tempfile
     21 
     22 from acts.libs.ota.ota_tools import ota_tool
     23 from acts.libs.proc import job
     24 from acts import utils
     25 
     26 # OTA Packages can be upwards of 1 GB. This may take some time to transfer over
     27 # USB 2.0. A/B devices must also complete the update in the background.
     28 UPDATE_TIMEOUT = 20 * 60
     29 UPDATE_LOCATION = '/data/ota_package/update.zip'
     30 
     31 
     32 class UpdateDeviceOtaTool(ota_tool.OtaTool):
     33     """Runs an OTA Update with system/update_engine/scripts/update_device.py."""
     34 
     35     def __init__(self, command):
     36         super(UpdateDeviceOtaTool, self).__init__(command)
     37 
     38         self.unzip_path = tempfile.mkdtemp()
     39         utils.unzip_maintain_permissions(self.command, self.unzip_path)
     40 
     41         self.command = os.path.join(self.unzip_path, 'update_device.py')
     42 
     43     def update(self, ota_runner):
     44         logging.info('Forcing adb to be in root mode.')
     45         ota_runner.android_device.root_adb()
     46         update_command = 'python2.7 %s -s %s %s' % (
     47             self.command, ota_runner.serial, ota_runner.get_ota_package())
     48         logging.info('Running %s' % update_command)
     49         result = job.run(update_command, timeout=UPDATE_TIMEOUT)
     50         logging.info('Output: %s' % result.stdout)
     51 
     52         logging.info('Rebooting device for update to go live.')
     53         ota_runner.android_device.reboot(stop_at_lock_screen=True)
     54         logging.info('Reboot sent.')
     55 
     56     def __del__(self):
     57         """Delete the unzipped update_device folder before ACTS exits."""
     58         shutil.rmtree(self.unzip_path)
     59