]> glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/helpers/props.py
Revert "All AppArmor profiles have been switched to the "enforce" mode."
[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 platformService = IPlatform.get_service(args)
25 if platformService:
26 return platformService.getprop(prop, "")
27 else:
28 logging.error("Failed to access IPlatform service")
29
30 def set(args, prop, value):
31 platformService = IPlatform.get_service(args)
32 if platformService:
33 platformService.setprop(prop, value)
34 else:
35 logging.error("Failed to access IPlatform service")
36
37 def file_get(args, file, prop):
38 with open(file) as build_prop:
39 for line in build_prop:
40 line = line.strip()
41 if len(line) == 0 or line[0] == "#":
42 continue
43 k,v = line.partition("=")[::2]
44 if k == prop:
45 return v
46 return ""