]> glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/helpers/props.py
Add Android Market Protocol Handler
[waydroid.git] / tools / helpers / props.py
1 # Copyright 2021 Oliver Smith
2 # SPDX-License-Identifier: GPL-3.0-or-later
3 from shutil import which
4 import subprocess
5 import logging
6 import os
7 import tools.helpers.run
8 from tools.interfaces import IPlatform
9
10
11 def host_get(args, prop):
12 if which("getprop") is not None:
13 command = ["getprop", prop]
14 return subprocess.run(command, stdout=subprocess.PIPE).stdout.decode('utf-8').strip()
15 else:
16 return ""
17
18 def host_set(args, prop, value):
19 if which("setprop") is not None:
20 command = ["setprop", prop, value]
21 tools.helpers.run.user(args, command)
22
23 def get(args, prop):
24 if os.path.exists(tools.config.session_defaults["config_path"]):
25 session_cfg = tools.config.load_session()
26 if session_cfg["session"]["state"] == "RUNNING":
27 platformService = IPlatform.get_service(args)
28 if platformService:
29 return platformService.getprop(prop, "")
30 else:
31 logging.error("Failed to access IPlatform service")
32 else:
33 logging.error("WayDroid container is {}".format(
34 session_cfg["session"]["state"]))
35 else:
36 logging.error("WayDroid session is stopped")
37
38 def set(args, prop, value):
39 if os.path.exists(tools.config.session_defaults["config_path"]):
40 session_cfg = tools.config.load_session()
41 if session_cfg["session"]["state"] == "RUNNING":
42 platformService = IPlatform.get_service(args)
43 if platformService:
44 platformService.setprop(prop, value)
45 else:
46 logging.error("Failed to access IPlatform service")
47 else:
48 logging.error("WayDroid container is {}".format(
49 session_cfg["session"]["state"]))
50 else:
51 logging.error("WayDroid session is stopped")
52
53 def file_get(args, file, prop):
54 with open(file) as build_prop:
55 for line in build_prop:
56 line = line.strip()
57 if len(line) == 0 or line[0] == "#":
58 continue
59 k,v = line.partition("=")[::2]
60 if k == prop:
61 return v;
62 return ""