blob: 97b6eadedff0d228f42c1c5d2e1604b8df7fd4ba [file] [log] [blame]
Clemenz Portmannf7f23ee2016-08-18 13:00:59 -07001# Copyright 2016 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import os
16import re
17import subprocess
18import sys
19import time
Leslie Shawd73c9342020-09-01 00:56:38 +000020
Clemenz Portmannd4408952018-10-12 08:51:49 -070021import its.cv2image
Clemenz Portmann9b752ed2018-03-21 12:35:15 -070022import numpy as np
23
Clemenz Portmann7a3f7eb2019-08-01 13:08:50 -070024LOAD_SCENE_DELAY = 2 # seconds
25
Clemenz Portmannf7f23ee2016-08-18 13:00:59 -070026
27def main():
28 """Load charts on device and display."""
Clemenz Portmannf7f23ee2016-08-18 13:00:59 -070029 scene = None
30 for s in sys.argv[1:]:
31 if s[:6] == 'scene=' and len(s) > 6:
32 scene = s[6:]
33 elif s[:7] == 'screen=' and len(s) > 7:
34 screen_id = s[7:]
Clemenz Portmann8f070422017-11-27 16:06:33 -080035 elif s[:5] == 'dist=' and len(s) > 5:
36 chart_distance = float(re.sub('cm', '', s[5:]))
37 elif s[:4] == 'fov=' and len(s) > 4:
38 camera_fov = float(s[4:])
Clemenz Portmannf7f23ee2016-08-18 13:00:59 -070039
40 cmd = ('adb -s %s shell am force-stop com.google.android.apps.docs' %
41 screen_id)
42 subprocess.Popen(cmd.split())
Leslie Shawd73c9342020-09-01 00:56:38 +000043
Clemenz Portmannf7f23ee2016-08-18 13:00:59 -070044 if not scene:
45 print 'Error: need to specify which scene to load'
46 assert False
47
Clemenz Portmanna9afdd22016-09-21 07:52:57 -070048 if not screen_id:
49 print 'Error: need to specify screen serial'
50 assert False
51
Clemenz Portmannd4408952018-10-12 08:51:49 -070052 src_scene_path = os.path.join(os.environ['CAMERA_ITS_TOP'], 'tests', scene)
53 dst_scene_file = '/sdcard/Download/%s.pdf' % scene
54 chart_scaling = its.cv2image.calc_chart_scaling(chart_distance, camera_fov)
55 if np.isclose(chart_scaling, its.cv2image.SCALE_TELE_IN_WFOV_BOX, atol=0.01):
Clemenz Portmann31ea19b2019-04-10 13:55:20 -070056 file_name = '%s_%sx_scaled.pdf' % (
Clemenz Portmannd4408952018-10-12 08:51:49 -070057 scene, str(its.cv2image.SCALE_TELE_IN_WFOV_BOX))
58 elif np.isclose(chart_scaling, its.cv2image.SCALE_RFOV_IN_WFOV_BOX, atol=0.01):
Clemenz Portmann31ea19b2019-04-10 13:55:20 -070059 file_name = '%s_%sx_scaled.pdf' % (
Clemenz Portmannb1c43b02018-11-20 13:49:05 -080060 scene, str(its.cv2image.SCALE_RFOV_IN_WFOV_BOX))
Clemenz Portmann8f070422017-11-27 16:06:33 -080061 else:
Clemenz Portmannd4408952018-10-12 08:51:49 -070062 file_name = '%s.pdf' % scene
63 src_scene_file = os.path.join(src_scene_path, file_name)
64 print 'Loading %s on %s' % (src_scene_file, screen_id)
65 cmd = 'adb -s %s push %s /mnt%s' % (screen_id, src_scene_file,
66 dst_scene_file)
Clemenz Portmannf7f23ee2016-08-18 13:00:59 -070067 subprocess.Popen(cmd.split())
Clemenz Portmann7a3f7eb2019-08-01 13:08:50 -070068 time.sleep(LOAD_SCENE_DELAY) # wait-for-device doesn't always seem to work
Clemenz Portmannf7f23ee2016-08-18 13:00:59 -070069 # The intent require PDF viewing app be installed on device.
70 # Also the first time such app is opened it might request some permission,
71 # so it's better to grant those permissions before using this script
72 cmd = ("adb -s %s wait-for-device shell am start -d 'file://%s'"
Clemenz Portmannd4408952018-10-12 08:51:49 -070073 " -a android.intent.action.VIEW" % (screen_id, dst_scene_file))
Clemenz Portmannf7f23ee2016-08-18 13:00:59 -070074 subprocess.Popen(cmd.split())
75
Clemenz Portmannf7f23ee2016-08-18 13:00:59 -070076if __name__ == '__main__':
77 main()