Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1402)

Unified Diff: devil/devil/android/tools/provision_devices.py

Issue 2734023002: Generalize the removal of system apps (Closed)
Patch Set: Address perezju@ comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: devil/devil/android/tools/provision_devices.py
diff --git a/devil/devil/android/tools/provision_devices.py b/devil/devil/android/tools/provision_devices.py
index ed435291d07975fc0749c5eb84dfd91734fa481b..4faba20d0105c327808075a24760d5766dd3256a 100755
--- a/devil/devil/android/tools/provision_devices.py
+++ b/devil/devil/android/tools/provision_devices.py
@@ -49,7 +49,8 @@ from devil.utils import timeout_retry
logger = logging.getLogger(__name__)
-_SYSTEM_WEBVIEW_PATHS = ['/system/app/webview', '/system/app/WebViewGoogle']
+_SYSTEM_APP_DIRECTORIES = ['/system/app/', '/system/priv-app/']
+_SYSTEM_WEBVIEW_NAMES = ['webview', 'WebViewGoogle']
_CHROME_PACKAGE_REGEX = re.compile('.*chrom.*')
_TOMBSTONE_REGEX = re.compile('tombstone.*')
@@ -84,10 +85,12 @@ def ProvisionDevices(
output_device_blacklist=None,
reboot_timeout=None,
remove_system_webview=False,
+ system_app_remove_list=None,
wipe=True):
blacklist = (device_blacklist.Blacklist(blacklist_file)
if blacklist_file
else None)
+ system_app_remove_list = system_app_remove_list or []
try:
devices = script_common.GetDevices(devices, blacklist)
except device_errors.NoDevicesError:
@@ -122,7 +125,11 @@ def ProvisionDevices(
lambda d: WaitForCharge(d, min_battery_level)))
if remove_system_webview:
- steps.append(ProvisionStep(RemoveSystemWebView))
+ system_app_remove_list.extend(_SYSTEM_WEBVIEW_NAMES)
+
+ if system_app_remove_list:
+ steps.append(ProvisionStep(
+ lambda d: RemoveSystemApps(d, system_app_remove_list)))
steps.append(ProvisionStep(SetDate))
steps.append(ProvisionStep(CheckExternalStorage))
@@ -343,28 +350,43 @@ def DisableSystemChrome(device):
check_return=True)
-def RemoveSystemWebView(device):
- if any(device.PathExists(p) for p in _SYSTEM_WEBVIEW_PATHS):
- logger.info('System WebView exists and needs to be removed')
- if device.HasRoot():
- # Disabled Marshmallow's Verity security feature
- if device.build_version_sdk >= version_codes.MARSHMALLOW:
- device.adb.DisableVerity()
- device.Reboot()
- device.WaitUntilFullyBooted()
- device.EnableRoot()
-
- # This is required, e.g., to replace the system webview on a device.
- device.adb.Remount()
- device.RunShellCommand(['stop'], check_return=True)
- device.RunShellCommand(['rm', '-rf'] + _SYSTEM_WEBVIEW_PATHS,
- check_return=True)
- device.RunShellCommand(['start'], check_return=True)
- else:
- logger.warning('Cannot remove system webview from a non-rooted device')
- else:
- logger.info('System WebView already removed')
+def _RemoveSystemApp(device, system_app):
+ found_paths = []
+ for directory in _SYSTEM_APP_DIRECTORIES:
+ path = os.path.join(directory, system_app)
+ if device.PathExists(path):
+ found_paths.append(path)
+ if not found_paths:
+ logger.warning('Could not find install location for system app %s',
+ system_app)
+ device.RemovePath(found_paths, force=True, recursive=True)
+
+def RemoveSystemApps(device, system_app_remove_list):
+ """Attempts to remove the provided system apps from the given device.
+
+ Arguments:
+ device: The device to remove the system apps from.
+ system_app_remove_list: A list of app names to remove, e.g.
+ ['WebViewGoogle', 'GoogleVrCore']
+ """
+ device.EnableRoot()
+ if device.HasRoot():
+ # Disable Marshmallow's Verity security feature
+ if device.build_version_sdk >= version_codes.MARSHMALLOW:
+ logger.info('Disabling Verity on %s', device.serial)
+ device.adb.DisableVerity()
+ device.Reboot()
+ device.WaitUntilFullyBooted()
+ device.EnableRoot()
+ device.adb.Remount()
+ device.RunShellCommand(['stop'], check_return=True)
+ for system_app in system_app_remove_list:
+ _RemoveSystemApp(device, system_app)
+ device.RunShellCommand(['start'], check_return=True)
+ else:
+ raise device_errors.CommandFailedError(
+ 'Failed to remove system apps from non-rooted device', str(device))
def _ConfigureLocalProperties(device, java_debug=True):
@@ -456,6 +478,7 @@ def SetDate(device):
_set_and_verify_date, wait_period=1, max_tries=2):
raise device_errors.CommandFailedError(
'Failed to set date & time.', device_serial=str(device))
+ device.EnableRoot()
device.BroadcastIntent(
intent.Intent(action='android.intent.action.TIME_SET'))
@@ -545,11 +568,14 @@ def main(raw_args):
' wait after each reboot '
'(default: %s)' % _DEFAULT_TIMEOUTS.HELP_TEXT)
parser.add_argument(
+ '--remove-system-apps', nargs='*', dest='system_app_remove_list',
+ help='the names of system apps to remove')
+ parser.add_argument(
'--remove-system-webview', action='store_true',
help='Remove the system webview from devices.')
parser.add_argument(
'--skip-wipe', action='store_true', default=False,
- help="don't wipe device data during provisioning")
+ help='do not wipe device data during provisioning')
parser.add_argument(
'-v', '--verbose', action='count', default=1,
help='Log more information.')
@@ -597,6 +623,7 @@ def main(raw_args):
output_device_blacklist=args.output_device_blacklist,
reboot_timeout=args.reboot_timeout,
remove_system_webview=args.remove_system_webview,
+ system_app_remove_list=args.system_app_remove_list,
wipe=not args.skip_wipe and not args.emulators)
except (device_errors.DeviceUnreachableError, device_errors.NoDevicesError):
logging.exception('Unable to provision local devices.')
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698