tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

boot_device.py (1586B)


      1 # Copyright 2023 The Chromium Authors
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 """Functionalities to reliably reboot the device."""
      5 
      6 import enum
      7 
      8 from typing import Optional
      9 
     10 class BootMode(enum.Enum):
     11    """Specifies boot mode for device."""
     12    REGULAR = enum.auto()
     13    RECOVERY = enum.auto()
     14    BOOTLOADER = enum.auto()
     15 
     16 
     17 class StateTransitionError(Exception):
     18    """Raised when target does not transition to desired state."""
     19 
     20 
     21 def boot_device(target_id: Optional[str],
     22                mode: BootMode,
     23                serial_num: Optional[str] = None,
     24                must_boot: bool = False) -> None:
     25    """Boot device into desired mode.
     26 
     27    Args:
     28        target_id: Optional target_id of device.
     29        mode: Desired boot mode.
     30        must_boot: Forces device to boot, regardless of current state.
     31    Raises:
     32        StateTransitionError: When final state of device is not desired.
     33    """
     34    # Avoid cycle dependency.
     35    # This file will be replaced with serial_boot_device quite soon, later one
     36    # should be much more reliable comparing to ffx target list and ssh. So
     37    # changing the file structure is not necessary in the current situation.
     38    # pylint: disable=cyclic-import, import-outside-toplevel
     39    # pylint: disable=wrong-import-position
     40    import serial_boot_device
     41    if not serial_boot_device.boot_device(target_id, serial_num, mode,
     42                                          must_boot):
     43        raise StateTransitionError(
     44            f'Could not get device to desired state {mode}.')