1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-01-31 10:10:46 +00:00

utils/android: Add grant_app_permissions

This is mostly useful to avoid having to manually click/tap
on the permission requests that may pop up when opening apps,
which would ruin automation
This commit is contained in:
Valentin Schneider 2017-09-13 11:47:51 +01:00
parent ee153210c6
commit 24d5630e54

View File

@ -445,6 +445,23 @@ def adb_command(device, command, timeout=None,adb_server=None):
output, _ = check_output(full_command, timeout, shell=True)
return output
def grant_app_permissions(target, package):
"""
Grant an app all the permissions it may ask for
"""
dumpsys = target.execute('dumpsys package {}'.format(package))
permissions = re.search(
'requested permissions:\s*(?P<permissions>(android.permission.+\s*)+)', dumpsys
)
permissions = permissions.group('permissions').replace(" ", "").splitlines()
for permission in permissions:
try:
target.execute('pm grant {} {}'.format(package, permission))
except TargetError:
logger.debug('Cannot grant {}'.format(permission))
# Messy environment initialisation stuff...