Skip to content
This repository has been archived by the owner on Apr 2, 2021. It is now read-only.

Commit

Permalink
re-enable charging and more (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
aerickson committed Aug 22, 2019
1 parent a3ca05f commit 053ac62
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ RUN cd /tmp && \
tar xzf /builds/worker/Downloads/android-sdk_r24.3.4-linux.tgz --directory=/builds/worker || true && \
unzip -qq -n /builds/worker/Downloads/sdk-tools-linux-4333796.zip -d /builds/worker/android-sdk-linux/ || true && \
/builds/worker/android-sdk-linux/tools/bin/sdkmanager platform-tools "build-tools;28.0.3" && \
pip install mozdevice==3.0.3 && \
pip install mozdevice==3.0.5 && \
pip install google-cloud-logging && \
rm -rf /tmp/* && \
rm -rf /var/lib/apt/lists/* && \
Expand Down
74 changes: 72 additions & 2 deletions taskcluster/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
import subprocess
import sys

from distutils.dir_util import copy_tree
from glob import glob

from mozdevice import ADBAndroid, ADBHost, ADBError
from mozdevice import ADBAndroid, ADBHost, ADBError, ADBTimeoutError


MAX_NETWORK_ATTEMPTS = 3
Expand All @@ -32,6 +31,70 @@ def fatal(message):
print('TEST-UNEXPECTED-FAIL | bitbar | {}'.format(message))
sys.exit(TBPL_RETRY_EXIT_STATUS)


def get_device_type(device):
timeout = 10
device_type = device.shell_output("getprop ro.product.model", timeout=timeout)
if device_type == "Pixel 2":
pass
elif device_type == "Moto G (5)":
pass
else:
print(
"TEST-UNEXPECTED-FAIL | bitbar | Unknown device ('%s')! Contact Android Relops immediately."
% device_type
)
sys.exit(1)
return device_type


def enable_charging(device, device_type):
rc = 0
timeout = 10
p2_path = "/sys/class/power_supply/battery/input_suspend"
g5_path = "/sys/class/power_supply/battery/charging_enabled"

try:
if device_type == "Pixel 2":
p2_charging_disabled = (
device.shell_output(
"cat %s 2>/dev/null" % p2_path, timeout=timeout
).strip()
== "1"
)
if p2_charging_disabled:
print("Enabling charging...")
device.shell_bool(
"echo %s > %s" % (0, p2_path), root=True, timeout=timeout
)
elif device_type == "Moto G (5)":
g5_charging_disabled = (
device.shell_output(
"cat %s 2>/dev/null" % g5_path, timeout=timeout
).strip()
== "0"
)
if g5_charging_disabled:
print("Enabling charging...")
device.shell_bool(
"echo %s > %s" % (1, g5_path), root=True, timeout=timeout
)
else:
print(
"TEST-UNEXPECTED-FAIL | bitbar | Unknown device ('%s')! Contact Android Relops immediately."
% device_type
)
rc = 1
except (ADBTimeoutError, ADBError) as e:
print(
"TEST-UNEXPECTED-FAIL | bitbar | Failed to enable charging. Contact Android Relops immediately."
)
print("{}: {}".format(e.__class__.__name__, e))
rc = 1

return rc


def main():
parser = argparse.ArgumentParser(
usage='%(prog)s [options] <test command> (<test command option> ...)',
Expand Down Expand Up @@ -74,6 +137,7 @@ def main():
env['DEVICE_SERIAL'] = scriptvarsenv['DEVICE_SERIAL']
env['HOST_IP'] = scriptvarsenv['HOST_IP']
env['DEVICE_IP'] = scriptvarsenv['DEVICE_IP']
env['DOCKER_IMAGE_VERSION'] = scriptvarsenv['DOCKER_IMAGE_VERSION']

if 'HOME' not in env:
env['HOME'] = '/builds/worker'
Expand Down Expand Up @@ -109,6 +173,8 @@ def main():
print('Connecting to Android device {}'.format(env['DEVICE_SERIAL']))
try:
device = ADBAndroid(device=env['DEVICE_SERIAL'])
# this can explode if an unknown device, explode now vs in an hour...
device_type = get_device_type(device)

# clean up the device.
device.rm('/data/local/tests', recursive=True, force=True, root=True)
Expand Down Expand Up @@ -136,6 +202,10 @@ def main():
sys.stdout.write(line)
rc = proc.poll()

# enable charging on device if it is disabled
# see https://bugzilla.mozilla.org/show_bug.cgi?id=1565324
rc = enable_charging(device, device_type) + rc

try:
if env['DEVICE_SERIAL'].endswith(':5555'):
device.command_output(["usb"])
Expand Down

0 comments on commit 053ac62

Please sign in to comment.