]> glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/services/hardware_manager.py
hardware_manager: Validate upgrade zips against the saved ota channel
[waydroid.git] / tools / services / hardware_manager.py
1 # Copyright 2021 Erfan Abdi
2 # SPDX-License-Identifier: GPL-3.0-or-later
3 import logging
4 import threading
5 import os
6 import tools.actions.container_manager
7 import tools.actions.session_manager
8 import tools.config
9 from tools import helpers
10 from tools.interfaces import IHardware
11
12 stopping = False
13
14 def start(args):
15 def enableNFC(enable):
16 logging.debug("Function enableNFC not implemented")
17
18 def enableBluetooth(enable):
19 logging.debug("Function enableBluetooth not implemented")
20
21 def suspend():
22 cfg = tools.config.load(args)
23 if cfg["waydroid"]["suspend_action"] == "stop":
24 tools.actions.session_manager.stop(args)
25 else:
26 tools.actions.container_manager.freeze(args)
27
28 def reboot():
29 helpers.lxc.stop(args)
30 helpers.lxc.start(args)
31
32 def upgrade(system_zip, system_time, vendor_zip, vendor_time):
33 if os.path.exists(system_zip) and not helpers.images.validate(args, "system_ota", system_zip):
34 logging.warning("Not upgrading because system.img comes from an unverified source")
35 return
36 if os.path.exists(vendor_zip) and not helpers.images.validate(args, "vendor_ota", vendor_zip):
37 logging.warning("Not upgrading because vendor.img comes from an unverified source")
38 return
39 helpers.lxc.stop(args)
40 helpers.images.umount_rootfs(args)
41 helpers.images.replace(args, system_zip, system_time,
42 vendor_zip, vendor_time)
43 args.session["background_start"] = "false"
44 helpers.images.mount_rootfs(args, args.images_path, args.session)
45 helpers.protocol.set_aidl_version(args)
46 helpers.lxc.start(args)
47
48 def service_thread():
49 while not stopping:
50 IHardware.add_service(
51 args, enableNFC, enableBluetooth, suspend, reboot, upgrade)
52
53 global stopping
54 stopping = False
55 args.hardware_manager = threading.Thread(target=service_thread)
56 args.hardware_manager.start()
57
58 def stop(args):
59 global stopping
60 stopping = True
61 try:
62 if args.hardwareLoop:
63 args.hardwareLoop.quit()
64 except AttributeError:
65 logging.debug("Hardware service is not even started")