xref: /aosp_15_r20/external/angle/build/android/update_verification.py (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker#!/usr/bin/env vpython3
2*8975f5c5SAndroid Build Coastguard Worker#
3*8975f5c5SAndroid Build Coastguard Worker# Copyright 2013 The Chromium Authors
4*8975f5c5SAndroid Build Coastguard Worker# Use of this source code is governed by a BSD-style license that can be
5*8975f5c5SAndroid Build Coastguard Worker# found in the LICENSE file.
6*8975f5c5SAndroid Build Coastguard Worker
7*8975f5c5SAndroid Build Coastguard Worker"""Runs semi-automated update testing on a non-rooted device.
8*8975f5c5SAndroid Build Coastguard Worker
9*8975f5c5SAndroid Build Coastguard WorkerThis script will help verify that app data is preserved during an update.
10*8975f5c5SAndroid Build Coastguard WorkerTo use this script first run it with the create_app_data option.
11*8975f5c5SAndroid Build Coastguard Worker
12*8975f5c5SAndroid Build Coastguard Worker./update_verification.py create_app_data --old-apk <path> --app-data <path>
13*8975f5c5SAndroid Build Coastguard Worker
14*8975f5c5SAndroid Build Coastguard WorkerThe script will then install the old apk, prompt you to create some app data
15*8975f5c5SAndroid Build Coastguard Worker(bookmarks, etc.), and then save the app data in the path you gave it.
16*8975f5c5SAndroid Build Coastguard Worker
17*8975f5c5SAndroid Build Coastguard WorkerNext, once you have some app data saved, run this script with the test_update
18*8975f5c5SAndroid Build Coastguard Workeroption.
19*8975f5c5SAndroid Build Coastguard Worker
20*8975f5c5SAndroid Build Coastguard Worker./update_verification.py test_update --old-apk <path> --new-apk <path>
21*8975f5c5SAndroid Build Coastguard Worker--app-data <path>
22*8975f5c5SAndroid Build Coastguard Worker
23*8975f5c5SAndroid Build Coastguard WorkerThis will install the old apk, load the saved app data, install the new apk,
24*8975f5c5SAndroid Build Coastguard Workerand ask the user to verify that all of the app data was preserved.
25*8975f5c5SAndroid Build Coastguard Worker"""
26*8975f5c5SAndroid Build Coastguard Worker
27*8975f5c5SAndroid Build Coastguard Workerimport argparse
28*8975f5c5SAndroid Build Coastguard Workerimport logging
29*8975f5c5SAndroid Build Coastguard Workerimport sys
30*8975f5c5SAndroid Build Coastguard Worker
31*8975f5c5SAndroid Build Coastguard Workerimport devil_chromium
32*8975f5c5SAndroid Build Coastguard Worker
33*8975f5c5SAndroid Build Coastguard Workerfrom devil.android import apk_helper
34*8975f5c5SAndroid Build Coastguard Workerfrom devil.android import device_denylist
35*8975f5c5SAndroid Build Coastguard Workerfrom devil.android import device_errors
36*8975f5c5SAndroid Build Coastguard Workerfrom devil.android import device_utils
37*8975f5c5SAndroid Build Coastguard Workerfrom devil.utils import run_tests_helper
38*8975f5c5SAndroid Build Coastguard Worker
39*8975f5c5SAndroid Build Coastguard Worker
40*8975f5c5SAndroid Build Coastguard Workerdef CreateAppData(device, old_apk, app_data, package_name):
41*8975f5c5SAndroid Build Coastguard Worker  device.Install(old_apk)
42*8975f5c5SAndroid Build Coastguard Worker  input('Set the application state. Once ready, press enter and '
43*8975f5c5SAndroid Build Coastguard Worker        'select "Backup my data" on the device.')
44*8975f5c5SAndroid Build Coastguard Worker  device.adb.Backup(app_data, packages=[package_name])
45*8975f5c5SAndroid Build Coastguard Worker  logging.critical('Application data saved to %s', app_data)
46*8975f5c5SAndroid Build Coastguard Worker
47*8975f5c5SAndroid Build Coastguard Workerdef TestUpdate(device, old_apk, new_apk, app_data, package_name):
48*8975f5c5SAndroid Build Coastguard Worker  device.Install(old_apk)
49*8975f5c5SAndroid Build Coastguard Worker  device.adb.Restore(app_data)
50*8975f5c5SAndroid Build Coastguard Worker  # Restore command is not synchronous
51*8975f5c5SAndroid Build Coastguard Worker  input('Select "Restore my data" on the device. Then press enter to '
52*8975f5c5SAndroid Build Coastguard Worker        'continue.')
53*8975f5c5SAndroid Build Coastguard Worker  if not device.IsApplicationInstalled(package_name):
54*8975f5c5SAndroid Build Coastguard Worker    raise Exception('Expected package %s to already be installed. '
55*8975f5c5SAndroid Build Coastguard Worker                    'Package name might have changed!' % package_name)
56*8975f5c5SAndroid Build Coastguard Worker
57*8975f5c5SAndroid Build Coastguard Worker  logging.info('Verifying that %s can be overinstalled.', new_apk)
58*8975f5c5SAndroid Build Coastguard Worker  device.adb.Install(new_apk, reinstall=True)
59*8975f5c5SAndroid Build Coastguard Worker  logging.critical('Successfully updated to the new apk. Please verify that '
60*8975f5c5SAndroid Build Coastguard Worker                   'the application data is preserved.')
61*8975f5c5SAndroid Build Coastguard Worker
62*8975f5c5SAndroid Build Coastguard Workerdef main():
63*8975f5c5SAndroid Build Coastguard Worker  parser = argparse.ArgumentParser(
64*8975f5c5SAndroid Build Coastguard Worker      description="Script to do semi-automated upgrade testing.")
65*8975f5c5SAndroid Build Coastguard Worker  parser.add_argument('-v', '--verbose', action='count',
66*8975f5c5SAndroid Build Coastguard Worker                      help='Print verbose log information.')
67*8975f5c5SAndroid Build Coastguard Worker  parser.add_argument('--denylist-file', help='Device denylist JSON file.')
68*8975f5c5SAndroid Build Coastguard Worker  command_parsers = parser.add_subparsers(dest='command')
69*8975f5c5SAndroid Build Coastguard Worker
70*8975f5c5SAndroid Build Coastguard Worker  subparser = command_parsers.add_parser('create_app_data')
71*8975f5c5SAndroid Build Coastguard Worker  subparser.add_argument('--old-apk', required=True,
72*8975f5c5SAndroid Build Coastguard Worker                         help='Path to apk to update from.')
73*8975f5c5SAndroid Build Coastguard Worker  subparser.add_argument('--app-data', required=True,
74*8975f5c5SAndroid Build Coastguard Worker                         help='Path to where the app data backup should be '
75*8975f5c5SAndroid Build Coastguard Worker                           'saved to.')
76*8975f5c5SAndroid Build Coastguard Worker  subparser.add_argument('--package-name',
77*8975f5c5SAndroid Build Coastguard Worker                         help='Chrome apk package name.')
78*8975f5c5SAndroid Build Coastguard Worker
79*8975f5c5SAndroid Build Coastguard Worker  subparser = command_parsers.add_parser('test_update')
80*8975f5c5SAndroid Build Coastguard Worker  subparser.add_argument('--old-apk', required=True,
81*8975f5c5SAndroid Build Coastguard Worker                         help='Path to apk to update from.')
82*8975f5c5SAndroid Build Coastguard Worker  subparser.add_argument('--new-apk', required=True,
83*8975f5c5SAndroid Build Coastguard Worker                         help='Path to apk to update to.')
84*8975f5c5SAndroid Build Coastguard Worker  subparser.add_argument('--app-data', required=True,
85*8975f5c5SAndroid Build Coastguard Worker                         help='Path to where the app data backup is saved.')
86*8975f5c5SAndroid Build Coastguard Worker  subparser.add_argument('--package-name',
87*8975f5c5SAndroid Build Coastguard Worker                         help='Chrome apk package name.')
88*8975f5c5SAndroid Build Coastguard Worker
89*8975f5c5SAndroid Build Coastguard Worker  args = parser.parse_args()
90*8975f5c5SAndroid Build Coastguard Worker  run_tests_helper.SetLogLevel(args.verbose)
91*8975f5c5SAndroid Build Coastguard Worker
92*8975f5c5SAndroid Build Coastguard Worker  devil_chromium.Initialize()
93*8975f5c5SAndroid Build Coastguard Worker
94*8975f5c5SAndroid Build Coastguard Worker  denylist = (device_denylist.Denylist(args.denylist_file)
95*8975f5c5SAndroid Build Coastguard Worker              if args.denylist_file else None)
96*8975f5c5SAndroid Build Coastguard Worker
97*8975f5c5SAndroid Build Coastguard Worker  devices = device_utils.DeviceUtils.HealthyDevices(denylist)
98*8975f5c5SAndroid Build Coastguard Worker  if not devices:
99*8975f5c5SAndroid Build Coastguard Worker    raise device_errors.NoDevicesError()
100*8975f5c5SAndroid Build Coastguard Worker  device = devices[0]
101*8975f5c5SAndroid Build Coastguard Worker  logging.info('Using device %s for testing.', str(device))
102*8975f5c5SAndroid Build Coastguard Worker
103*8975f5c5SAndroid Build Coastguard Worker  package_name = (args.package_name if args.package_name
104*8975f5c5SAndroid Build Coastguard Worker                  else apk_helper.GetPackageName(args.old_apk))
105*8975f5c5SAndroid Build Coastguard Worker  if args.command == 'create_app_data':
106*8975f5c5SAndroid Build Coastguard Worker    CreateAppData(device, args.old_apk, args.app_data, package_name)
107*8975f5c5SAndroid Build Coastguard Worker  elif args.command == 'test_update':
108*8975f5c5SAndroid Build Coastguard Worker    TestUpdate(
109*8975f5c5SAndroid Build Coastguard Worker        device, args.old_apk, args.new_apk, args.app_data, package_name)
110*8975f5c5SAndroid Build Coastguard Worker  else:
111*8975f5c5SAndroid Build Coastguard Worker    raise Exception('Unknown test command: %s' % args.command)
112*8975f5c5SAndroid Build Coastguard Worker
113*8975f5c5SAndroid Build Coastguard Workerif __name__ == '__main__':
114*8975f5c5SAndroid Build Coastguard Worker  sys.exit(main())
115