1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
from ppadb.plugins.device import batterystats_section as section_module
from ppadb.plugins import Plugin
from ppadb.utils.logger import AdbLogging
logger = AdbLogging.get_logger(__name__)
class BatteryStats(Plugin):
def get_battery_level(self):
battery = self.shell("dumpsys battery")
for line in battery.split('\n'):
tokens = line.split(":")
if tokens[0].strip() == "level" and len(tokens) == 2:
return int(tokens[1])
return None
def get_batterystats(self):
result = self.shell("dumpsys batterystats -c")
sections = {}
for line in result.split("\n"):
if not line.strip():
continue
tokens = line.split(",", 4)
if len(tokens) < 5:
continue
dummy, uid, mode, id, remaining_fields = tokens
print(dummy, uid, mode, id, remaining_fields)
SectionClass = section_module.get_section(id)
if not SectionClass:
logger.error("Unknown section {} in batterystats".format(id))
continue
if id not in sections:
sections[id] = []
sections[id].append(SectionClass(*remaining_fields.split(",")))
return sections
|