• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#  Copyright (C) 2025 The Android Open Source Project
2#
3#  Licensed under the Apache License, Version 2.0 (the "License");
4#  you may not use this file except in compliance with the License.
5#  You may obtain a copy of the License at
6#
7#       http://www.apache.org/licenses/LICENSE-2.0
8#
9#  Unless required by applicable law or agreed to in writing, software
10#  distributed under the License is distributed on an "AS IS" BASIS,
11#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12#  See the License for the specific language governing permissions and
13#  limitations under the License.
14
15import subprocess
16import os
17import logging
18
19from .types import DeviceType
20
21class DeviceSeahawk(DeviceType):
22
23  @staticmethod
24  def flash(serial, imagedir, wipe, hwVariant, b, diag, preserveKeys):
25    scriptName = 'fastboot_complete_seahawk.py'
26    flashScript = imagedir / scriptName
27    if not flashScript.exists():
28      print('Flashing script was not downloaded, therefore aborting. Try again to run '
29          + 'aae image pull')
30      sys.exit(-1)
31
32    args = ['python3', str(flashScript)]
33    os.environ['ANDROID_PRODUCT_OUT'] = str(imagedir)
34    os.environ['ANDROID_SERIAL'] = serial
35    args.append('2s')
36    if not wipe:
37      args.append('--no-wipe')
38    if not b:
39      args.append('--no-b')
40    if diag:
41      args.append('--enable-diag')
42    if preserveKeys:
43      args.append('--preserve-keys')
44    logging.info(args)
45    command = " ".join(str(x) for x in args)
46    try:
47      # Start the subprocess with Popen and stream the output
48      with subprocess.Popen(command, shell=True, executable='/bin/bash', stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) as proc:
49        logging.info('Flashing the device...')
50        # Stream the output line by line
51        for line in iter(proc.stdout.readline, ''):
52          logging.info(line.rstrip())  # Log the output lines in real-time
53        proc.wait()  # Wait for the subprocess to finish
54        if proc.returncode != 0:
55          raise subprocess.CalledProcessError(proc.returncode, command)
56    except subprocess.CalledProcessError as e:
57      logging.error('Flash command failed with return code %s', e.returncode)
58      raise
59