blob: 1dc96923e80d52b4fd8c6fa9783d36313239908d [file] [log] [blame]
Borjan Tchakaloffa4bdae12017-11-21 14:58:12 +01001#!/usr/bin/env python3
2
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +01003import os
Borjan Tchakaloffa4bdae12017-11-21 14:58:12 +01004import time
5from uiautomator import Device
Franz-Xaver Geigerb0f55422018-04-17 10:33:37 +02006import re
Borjan Tchakaloffa4bdae12017-11-21 14:58:12 +01007import sys
8import subprocess
9import pathlib
10
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +010011
Borjan Tchakaloffd8445d32018-04-18 18:01:20 +020012VWS_CREDENTIALS = {
13 'user': 'fairphonetesting@gmail.com',
14 'password': 'aish3echi:uwaiSh'
15}
16
17
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +010018PREBUILTS_PATH = '../../vendor/smartviser/viser/prebuilts/apk'
19
Borjan Tchakaloffd4ce8072018-05-16 18:20:13 +020020PREBUILT_PROXY_APK_PATTERN = (
21 'com.lunarlabs.panda.proxy-latest-sdk{sdk}-{flavour}.apk')
Franz-Xaver Geigerb3f7c982018-04-12 09:29:32 +020022
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +010023PREBUILT_APKS = [
Borjan Tchakaloffd4ce8072018-05-16 18:20:13 +020024 'com.smartviser.demogame-latest.apk',
25 'com.lunarlabs.panda-latest.apk',
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +010026]
27
Borjan Tchakaloff74d962a2018-04-11 17:47:14 +020028FAIRPHONE_WIFI_NETWORKS = {
29 'Fairphone Guest': {'security': 'WPA/WPA2 PSK', 'password': 'fairwifi'},
30 'Fairphone DEV (2.4 GHz)': {
31 'security': 'WPA/WPA2 PSK', 'password': 'fdev@adm'},
32 'Fairphone DEV (5 GHz)': {
33 'security': 'WPA/WPA2 PSK', 'password': 'fdev@adm'},
34}
35
Franz-Xaver Geigerb0f55422018-04-17 10:33:37 +020036ADB_DEVICES_PATTERN = re.compile(r'^([a-z0-9-]+)\s+device$', flags=re.M)
37
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +010038
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +020039class HostCommandError(BaseException):
40 """An error happened while issuing a command on the host."""
41 def __init__(self, command, error_message):
42 self.command = command
43 self.error_message = error_message
44 message = 'Command `{}` failed: {}'.format(command, error_message)
45 super(HostCommandError, self).__init__(message)
46
47
48class DeviceCommandError(BaseException):
49 """An error happened while sending a command to a device."""
50 def __init__(self, serial, command, error_message):
51 self.serial = serial
52 self.command = command
53 self.error_message = error_message
54 message = 'Command `{}` failed on {}: {}'.format(
55 command, serial, error_message)
56 super(DeviceCommandError, self).__init__(message)
57
58
59def adb(*args, serial = None, raise_on_error = True):
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +010060 """Run ADB command attached to serial.
61
62 Example:
63 >>> process = adb('shell', 'getprop', 'ro.build.fingerprint', serial='cc60c021')
64 >>> process.returncode
65 0
66 >>> process.stdout.strip()
67 'Fairphone/FP2/FP2:6.0.1/FP2-gms-18.02.0/FP2-gms-18.02.0:user/release-keys'
68
69 :param *args:
70 List of options to ADB (including command).
71 :param str serial:
72 Identifier for ADB connection to device.
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +020073 :param raise_on_error bool:
74 Whether to raise a DeviceCommandError exception if the return code is
75 less than 0.
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +010076 :returns subprocess.CompletedProcess:
77 Completed process.
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +020078 :raises DeviceCommandError:
79 If the command failed.
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +010080 """
81
82 # Make sure the adb server is started to avoid the infamous "out of date"
83 # message that pollutes stdout.
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +020084 ret = subprocess.run(
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +010085 ['adb', 'start-server'], stdout=subprocess.PIPE, stderr=subprocess.PIPE,
86 universal_newlines=True)
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +020087 if ret.returncode < 0:
88 if raise_on_error:
89 raise DeviceCommandError(
90 serial if serial else '??', str(args), ret.stderr)
91 else:
92 return None
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +010093
94 command = ['adb']
95 if serial:
96 command += ['-s', serial]
97 if args:
98 command += list(args)
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +020099 ret = subprocess.run(
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +0100100 command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
101 universal_newlines=True)
102
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200103 if raise_on_error and ret.returncode < 0:
104 raise DeviceCommandError(
105 serial if serial else '??', str(args), ret.stderr)
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +0100106
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200107 return ret
108
109
Franz-Xaver Geigerb0f55422018-04-17 10:33:37 +0200110def list_devices():
111 """List serial numbers of devices attached to adb.
112
113 Raises:
114 DeviceCommandError: If the underlying adb command failed.
115 """
116 process = adb('devices')
117 return ADB_DEVICES_PATTERN.findall(process.stdout)
118
119
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200120def aapt(*args, raise_on_error = True):
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +0100121 """Run an AAPT command.
122
123 :param *args:
124 The AAPT command with its options.
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200125 :param raise_on_error bool:
126 Whether to raise a DeviceCommandError exception if the return code is
127 less than 0.
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +0100128 :returns subprocess.CompletedProcess:
129 Completed process.
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200130 :raises HostCommandError:
131 If the command failed.
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +0100132 """
133 command = ['aapt']
134 if args:
135 command += list(args)
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200136 ret = subprocess.run(
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +0100137 command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
138 universal_newlines=True)
139
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200140 if raise_on_error and ret.returncode < 0:
141 raise HostCommandError(str(args), ret.stderr)
142
143 return ret
144
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +0100145
Borjan Tchakaloff64ec42b2018-02-07 11:33:15 -0800146def force_awake(serial, always=True):
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200147 """Force the device to stay awake.
148
149 Raises:
150 DeviceCommandError: If the underlying adb command failed.
151 """
152 adb('shell', 'svc power stayon {}'.format(
Borjan Tchakaloff64ec42b2018-02-07 11:33:15 -0800153 'true' if always else 'false'), serial=serial)
154
155
Borjan Tchakaloffd4ce8072018-05-16 18:20:13 +0200156def unlock(dut):
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200157 """Wake-up the device and unlock it.
158
159 Raises:
160 DeviceCommandError: If the underlying adb commands failed.
161 """
Borjan Tchakaloffd4ce8072018-05-16 18:20:13 +0200162 if not dut.info['screenOn']:
163 adb('shell', 'input keyevent KEYCODE_POWER', serial=dut.serial)
164 time.sleep(1)
165 # The KEYCODE_MENU input is enough to unlock a "swipe up to unlock"
166 # lockscreen on Android 6, but unfortunately not Android 7. So we use a
167 # swipe up (that depends on the screen resolution) instead.
168 adb('shell', 'input touchscreen swipe 930 880 930 380', serial=dut.serial)
Borjan Tchakaloff64ec42b2018-02-07 11:33:15 -0800169 time.sleep(1)
Borjan Tchakaloffd4ce8072018-05-16 18:20:13 +0200170 adb('shell', 'input keyevent KEYCODE_HOME', serial=dut.serial)
Borjan Tchakaloff64ec42b2018-02-07 11:33:15 -0800171
172
Franz-Xaver Geigerb3f7c982018-04-12 09:29:32 +0200173def getprop(serial, key):
174 """Get system property of device.
175
176 Example:
177 >>> getprop('167eb6e8', 'ro.build.id')
178 'FP2-gms-18.02.0'
179
180 :param str serial:
181 Identifier for ADB connection to device.
182 :param str key:
183 Key of property to get.
184 :returns str:
185 Value of system property.
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200186 :raise DeviceCommandError: If the underlying adb command failed.
Franz-Xaver Geigerb3f7c982018-04-12 09:29:32 +0200187 """
188 process = adb('shell', 'getprop', key, serial=serial)
189 return process.stdout.strip()
190
191
192def is_gms_device(serial):
193 """Test if device runs GMS or sibon.
194
195 Example:
196 >>> is_gms_device('167eb6e8')
197 True
198
199 :param str serial:
200 Identifier for ADB connection to device.
201 :returns bool:
202 True if device runs GMS, false otherwise.
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200203 :raise DeviceCommandError: If the underlying adb command failed.
Franz-Xaver Geigerb3f7c982018-04-12 09:29:32 +0200204 """
Borjan Tchakaloffd4ce8072018-05-16 18:20:13 +0200205 return (
206 getprop(serial, 'ro.build.id').startswith('FP2-gms-')
207 or getprop(serial, 'ro.build.version.incremental').startswith('gms-'))
Franz-Xaver Geigerb3f7c982018-04-12 09:29:32 +0200208
209
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +0100210def uninstall_apk(serial, filename, prebuilts_dir):
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200211 """Uninstall apk from prebuilts_dir on device.
212
213 Raises:
214 ValueError: If the package name could not be read from the apk.
215 DeviceCommandError: If the uninstall command failed.
216 """
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +0100217 ret = aapt('dump', 'badging', '{}/{}'.format(prebuilts_dir, filename))
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200218 package = None
219 for line in ret.stdout.splitlines():
220 if line.startswith('package'):
221 for token in line.split(' '):
222 if token.startswith('name='):
223 # Extract the package name out of the token
224 # (name='some.package.name')
225 package = token[6:-1]
226 break
227 if not package:
228 raise ValueError('Could not find package of app `{}`'.format(
229 filename))
230
231 adb('uninstall', package, serial=serial)
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +0100232
233
234def install_apk(serial, filename, prebuilts_dir):
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200235 """Install apk from prebuilts_dir on device.
236
237 Raises:
238 DeviceCommandError: If the install command failed.
239 """
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +0100240 path = os.path.join(prebuilts_dir, filename)
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200241 adb('install', '-r', path, serial=serial)
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +0100242
243
Borjan Tchakaloff74d962a2018-04-11 17:47:14 +0200244def configure_wifi_networks(dut, networks):
245 """Configure Wi-Fi networks.
246
247 The `networks` parameters is a list of networks to configure hashed by
248 their SSID. Each network value should have the following format:
249 - security (str): The security value as can be found in the Wi-Fi
250 settings dialog. Common values are 'None' and 'WPA/WPA2 PSK'.
251 - password (str, optional): The network password if the security is
252 'WPA/WPA2 PSK'.
253
254 Parameters:
255 dut (Device): The device object.
256 networks (dict(dict(str))): The list of networks to configure.
257 Raises:
258 DeviceCommandError: If the UI automation fails.
259 """
260 # Open the Wi-Fi settings
261 adb('shell', ('am start -a android.settings.WIFI_SETTINGS '
262 '--activity-clear-task'), serial=dut.serial)
263
264 # Make sure Wi-Fi is enabled
265 wifi_enabler = dut(text='OFF',
266 resourceId='com.android.settings:id/switch_widget')
267 if wifi_enabler.exists:
268 wifi_enabler.click()
269
270 # Check for registered networks
271 registered_networks = set()
272 dut(description='More options').click()
273 time.sleep(1)
274 saved_networks = dut(text='Saved networks')
275 if saved_networks.exists:
276 saved_networks.click()
277 for ssid in networks.keys():
278 if dut(text=ssid).exists:
279 registered_networks.add(ssid)
280 dut.press.back()
281
282 missing_networks = networks.keys() - registered_networks
283
284 for ssid in registered_networks:
285 print('Ignoring `{}` Wi-Fi network, already configured.'.format(ssid))
286
287 for ssid in missing_networks:
288 print('Configuring `{}` Wi-Fi network…'.format(ssid))
289
290 dut(description='More options').click()
291 dut(text='Add network').click()
292 dut(resourceId='com.android.settings:id/ssid') \
293 .set_text(ssid)
294 dut(resourceId='com.android.settings:id/security') \
295 .click()
296 dut(text=networks[ssid]['security']) \
297 .click()
298 password_field = dut(resourceId='com.android.settings:id/password')
299 if 'password' in networks[ssid] and networks[ssid]['password']:
300 if not password_field.exists:
301 dut(text='Cancel').click()
302 raise DeviceCommandError(dut, 'UI: add Wi-Fi',
303 'missing password field')
304 password_field.set_text(networks[ssid]['password'])
305 elif password_field.exists:
306 dut(text='Cancel').click()
307 raise DeviceCommandError(dut, 'UI: add Wi-Fi',
308 'missing password data')
309 save_button = dut(text='Save')
310 if not save_button.click():
311 dut(text='Cancel').click()
312 raise DeviceCommandError(dut, 'UI: add Wi-Fi',
313 'could not save network')
314
315 # Force the Wi-Fi on and off to pick the best network available
316 dut(text='ON', resourceId='com.android.settings:id/switch_widget').click()
317 dut(text='OFF', resourceId='com.android.settings:id/switch_widget').click()
318
319 # Leave the settings
320 dut.press.back()
321
322
Borjan Tchakaloffd4ce8072018-05-16 18:20:13 +0200323def get_proxy_apk(android_sdk, flavour):
324 if android_sdk >= 24:
325 return PREBUILT_PROXY_APK_PATTERN.format(sdk=24, flavour=flavour)
326 else:
327 return PREBUILT_PROXY_APK_PATTERN.format(sdk=19, flavour=flavour)
328
Borjan Tchakaloffa4bdae12017-11-21 14:58:12 +0100329# Prepare the DUT
Borjan Tchakaloffd4ce8072018-05-16 18:20:13 +0200330def prepare_dut(dut, scenarios_dir, data_dir, prebuilts_dir):
331 flavour = 'gms' if is_gms_device(dut.serial) else 'sibon'
332 proxy_apk = get_proxy_apk(dut.sdk, flavour)
Franz-Xaver Geigerb3f7c982018-04-12 09:29:32 +0200333
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +0100334 # Uninstall the smartviser apps
Borjan Tchakaloffd4ce8072018-05-16 18:20:13 +0200335 for app in PREBUILT_APKS + [proxy_apk]:
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200336 print('Uninstalling `{}`…'.format(app))
Borjan Tchakaloffd4ce8072018-05-16 18:20:13 +0200337 uninstall_apk(dut.serial, app, prebuilts_dir)
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +0100338
Borjan Tchakaloffa4bdae12017-11-21 14:58:12 +0100339 # Copy the scenarios
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200340 print('Pushing scenarios from `{}`…'.format(scenarios_dir))
Borjan Tchakaloffd4ce8072018-05-16 18:20:13 +0200341 adb('push', scenarios_dir, '/sdcard/viser', serial=dut.serial)
Borjan Tchakaloffa4bdae12017-11-21 14:58:12 +0100342
343 # Copy the scenarios data
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200344 print('Pushing scenarios data from `{}`…'.format(data_dir))
Borjan Tchakaloffd4ce8072018-05-16 18:20:13 +0200345 adb('push', data_dir, '/sdcard/viser/data', serial=dut.serial)
Borjan Tchakaloffa4bdae12017-11-21 14:58:12 +0100346
Franz-Xaver Geigerb3f7c982018-04-12 09:29:32 +0200347 # Install the smartviser apps (starting with the proxy app)
Borjan Tchakaloffd4ce8072018-05-16 18:20:13 +0200348 for app in [proxy_apk] + PREBUILT_APKS:
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200349 print('Installing `{}`…'.format(app))
Borjan Tchakaloffd4ce8072018-05-16 18:20:13 +0200350 install_apk(dut.serial, app, prebuilts_dir)
Franz-Xaver Geigerb28348e2018-02-19 14:41:40 +0100351
Borjan Tchakaloffa4bdae12017-11-21 14:58:12 +0100352
353# Grant the permissions through the UI
354def configure_perms(dut):
Borjan Tchakaloff6dad85d2018-04-11 13:55:25 +0200355 dut() \
Borjan Tchakaloffa4bdae12017-11-21 14:58:12 +0100356 .child_by_text('You need to grant access for the Permissions Group '
357 'Calendar Camera Contacts Microphone SMS Storage Telephone Location',
Borjan Tchakaloff6dad85d2018-04-11 13:55:25 +0200358 resourceId='android:id/content') \
359 .child(text='OK', className='android.widget.Button') \
360 .click()
Borjan Tchakaloffa4bdae12017-11-21 14:58:12 +0100361
362 # Accept any permission that is asked for
363 prompt = dut(resourceId='com.android.packageinstaller:id/permission_allow_button',
364 className='android.widget.Button')
365 while prompt.exists:
366 prompt.click()
367
368 # Input the credentials
369 dut(resourceId='android:id/content') \
370 .child(text='Username') \
371 .child(className='android.widget.EditText') \
Borjan Tchakaloffd8445d32018-04-18 18:01:20 +0200372 .set_text(VWS_CREDENTIALS['user'])
Borjan Tchakaloffa4bdae12017-11-21 14:58:12 +0100373 dut(resourceId='android:id/content') \
374 .child(text='Password') \
375 .child(className='android.widget.EditText') \
Borjan Tchakaloffd8445d32018-04-18 18:01:20 +0200376 .set_text(VWS_CREDENTIALS['password'])
Borjan Tchakaloffa4bdae12017-11-21 14:58:12 +0100377
378 # Sign in
Borjan Tchakaloffd4ce8072018-05-16 18:20:13 +0200379 signin_label = 'SIGN IN' if dut.sdk >= 24 else 'Sign in'
Borjan Tchakaloffa4bdae12017-11-21 14:58:12 +0100380 dut(resourceId='android:id/content') \
Borjan Tchakaloffd4ce8072018-05-16 18:20:13 +0200381 .child(text=signin_label, className='android.widget.Button') \
Borjan Tchakaloffa4bdae12017-11-21 14:58:12 +0100382 .click()
383
384def configure_sms(dut):
385 # TODO wait for the connection to be established and time-out
386 prompt = dut(resourceId='android:id/content') \
387 .child(text='Viser must be your SMS app to send messages')
388 while not prompt.exists:
389 time.sleep(1)
390
391 # Make viser the default SMS app
392 dut(resourceId='android:id/content') \
393 .child_by_text('Viser must be your SMS app to send messages',
394 className='android.widget.LinearLayout') \
395 .child(text='OK', className='android.widget.Button') \
396 .click()
397
398 dut(resourceId='android:id/content') \
399 .child_by_text('Change SMS app?', className='android.widget.LinearLayout') \
400 .child(text='Yes', className='android.widget.Button') \
401 .click()
402
403def configure_settings(dut):
404 # Set the e-mail account
405 dut(text='Settings', className='android.widget.TextView') \
406 .click()
407 dut(resourceId='android:id/list') \
408 .child_by_text('User settings', className='android.widget.LinearLayout') \
409 .click()
410 dut(resourceId='android:id/list') \
411 .child_by_text('Email account', className='android.widget.LinearLayout') \
412 .click()
413 prompt = dut(resourceId='android:id/content') \
414 .child_by_text('Email account', className='android.widget.LinearLayout')
415 prompt.child(resourceId='android:id/edit') \
416 .set_text('fairphone.viser@gmail.com')
417 prompt.child(text='OK', className='android.widget.Button') \
418 .click()
419 dut(resourceId='android:id/list') \
420 .child_by_text('Email password', className='android.widget.LinearLayout') \
421 .click()
422 dut(text='Password :') \
423 .child(className='android.widget.EditText') \
424 .set_text('fairphoneviser2017')
425 dut(description='OK', className='android.widget.TextView') \
426 .click()
427 dut.press.back()
428 dut.press.back()
429
Borjan Tchakaloffa4bdae12017-11-21 14:58:12 +0100430
Franz-Xaver Geigerd1079e22018-02-19 14:34:15 +0100431def deploy():
432 serials = []
Borjan Tchakaloffa4bdae12017-11-21 14:58:12 +0100433
Franz-Xaver Geigerd1079e22018-02-19 14:34:15 +0100434 if len(sys.argv) > 1:
435 serials.append(sys.argv[1])
436 else:
Franz-Xaver Geigerb0f55422018-04-17 10:33:37 +0200437 serials = list_devices()
Borjan Tchakaloffa4bdae12017-11-21 14:58:12 +0100438
Franz-Xaver Geigerd1079e22018-02-19 14:34:15 +0100439 for serial in serials:
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200440 print('Configuring device {}…'.format(serial))
Borjan Tchakaloffa4bdae12017-11-21 14:58:12 +0100441
Franz-Xaver Geigerd1079e22018-02-19 14:34:15 +0100442 dut = Device(serial)
Borjan Tchakaloff74d962a2018-04-11 17:47:14 +0200443 # Work around the not-so-easy Device class
444 dut.serial = serial
Borjan Tchakaloffd4ce8072018-05-16 18:20:13 +0200445 # Cache the Android SDK version (dut.info fetches system properties)
446 dut.sdk = dut.info['sdkInt']
Borjan Tchakaloffa4bdae12017-11-21 14:58:12 +0100447
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200448 try:
449 # Make sure the screen stays on - we're going to use UI automation
450 force_awake(serial)
Borjan Tchakaloffd4ce8072018-05-16 18:20:13 +0200451 unlock(dut)
Borjan Tchakaloff64ec42b2018-02-07 11:33:15 -0800452
Borjan Tchakaloff74d962a2018-04-11 17:47:14 +0200453 # Configure common Fairphone Wi-Fi networks
Borjan Tchakaloffd4ce8072018-05-16 18:20:13 +0200454 if dut.sdk < 24:
455 configure_wifi_networks(dut, FAIRPHONE_WIFI_NETWORKS)
456 else:
457 print('Uh oh, the device is running Android SDK {} on which we '
458 'do not deploy Wi-Fi networks yet.'.format(dut.sdk))
Borjan Tchakaloff74d962a2018-04-11 17:47:14 +0200459
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200460 # Push the scenarios, their data, and install the apps
461 prepare_dut(
Borjan Tchakaloffd4ce8072018-05-16 18:20:13 +0200462 dut, '../scenarios', '../scenarios-data', PREBUILTS_PATH)
Borjan Tchakaloffa4bdae12017-11-21 14:58:12 +0100463
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200464 # Start the viser app
465 adb(
Franz-Xaver Geiger223ae752018-02-19 14:54:08 +0100466 'shell', 'monkey', '-p', 'com.lunarlabs.panda', '-c',
467 'android.intent.category.LAUNCHER', '1', serial=serial)
Borjan Tchakaloffa4bdae12017-11-21 14:58:12 +0100468
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200469 configure_perms(dut)
Borjan Tchakaloffa4bdae12017-11-21 14:58:12 +0100470
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200471 # TODO DO NOT DO THE FOLLOWING IF NO SIM CARD IS IN THE DUT
472 # time.sleep(10)
473 # configure_sms(dut)
Franz-Xaver Geigerd1079e22018-02-19 14:34:15 +0100474
Borjan Tchakaloffde9fa0f2018-04-12 12:05:48 +0200475 configure_settings(dut)
476 except (HostCommandError, DeviceCommandError) as e:
477 print('ERROR {}'.format(e), file=sys.stderr)
478 finally:
479 try:
480 # Leave the device alone now
481 force_awake(serial, always=False)
482 except DeviceCommandError as e:
483 print('WARNING {}'.format(e), file=sys.stderr)
Borjan Tchakaloff64ec42b2018-02-07 11:33:15 -0800484
Franz-Xaver Geigerd1079e22018-02-19 14:34:15 +0100485
486if __name__ == '__main__':
487 deploy()