Clemenz Portmann | f7f23ee | 2016-08-18 13:00:59 -0700 | [diff] [blame] | 1 | # 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 | |
| 15 | import os |
| 16 | import re |
| 17 | import subprocess |
| 18 | import sys |
| 19 | import time |
| 20 | |
Clemenz Portmann | 9b752ed | 2018-03-21 12:35:15 -0700 | [diff] [blame] | 21 | import numpy as np |
| 22 | |
Clemenz Portmann | f7f23ee | 2016-08-18 13:00:59 -0700 | [diff] [blame] | 23 | |
| 24 | def main(): |
| 25 | """Load charts on device and display.""" |
Clemenz Portmann | f7f23ee | 2016-08-18 13:00:59 -0700 | [diff] [blame] | 26 | scene = None |
| 27 | for s in sys.argv[1:]: |
| 28 | if s[:6] == 'scene=' and len(s) > 6: |
| 29 | scene = s[6:] |
| 30 | elif s[:7] == 'screen=' and len(s) > 7: |
| 31 | screen_id = s[7:] |
Clemenz Portmann | 8f07042 | 2017-11-27 16:06:33 -0800 | [diff] [blame] | 32 | elif s[:5] == 'dist=' and len(s) > 5: |
| 33 | chart_distance = float(re.sub('cm', '', s[5:])) |
| 34 | elif s[:4] == 'fov=' and len(s) > 4: |
| 35 | camera_fov = float(s[4:]) |
Clemenz Portmann | f7f23ee | 2016-08-18 13:00:59 -0700 | [diff] [blame] | 36 | |
| 37 | cmd = ('adb -s %s shell am force-stop com.google.android.apps.docs' % |
| 38 | screen_id) |
| 39 | subprocess.Popen(cmd.split()) |
| 40 | |
| 41 | if not scene: |
| 42 | print 'Error: need to specify which scene to load' |
| 43 | assert False |
| 44 | |
Clemenz Portmann | a9afdd2 | 2016-09-21 07:52:57 -0700 | [diff] [blame] | 45 | if not screen_id: |
| 46 | print 'Error: need to specify screen serial' |
| 47 | assert False |
| 48 | |
Clemenz Portmann | f7f23ee | 2016-08-18 13:00:59 -0700 | [diff] [blame] | 49 | remote_scene_file = '/sdcard/Download/%s.pdf' % scene |
| 50 | local_scene_file = os.path.join(os.environ['CAMERA_ITS_TOP'], 'tests', |
Clemenz Portmann | 8f07042 | 2017-11-27 16:06:33 -0800 | [diff] [blame] | 51 | scene) |
Clemenz Portmann | 9b752ed | 2018-03-21 12:35:15 -0700 | [diff] [blame] | 52 | if np.isclose(chart_distance, 20, rtol=0.1) and camera_fov < 90: |
Clemenz Portmann | 8f07042 | 2017-11-27 16:06:33 -0800 | [diff] [blame] | 53 | local_scene_file = os.path.join(local_scene_file, |
| 54 | scene+'_0.67_scaled.pdf') |
| 55 | else: |
| 56 | local_scene_file = os.path.join(local_scene_file, scene+'.pdf') |
| 57 | print 'Loading %s on %s' % (local_scene_file, screen_id) |
Clemenz Portmann | f7f23ee | 2016-08-18 13:00:59 -0700 | [diff] [blame] | 58 | cmd = 'adb -s %s push %s /mnt%s' % (screen_id, local_scene_file, |
| 59 | remote_scene_file) |
| 60 | subprocess.Popen(cmd.split()) |
| 61 | time.sleep(1) # wait-for-device doesn't always seem to work... |
| 62 | # The intent require PDF viewing app be installed on device. |
| 63 | # Also the first time such app is opened it might request some permission, |
| 64 | # so it's better to grant those permissions before using this script |
| 65 | cmd = ("adb -s %s wait-for-device shell am start -d 'file://%s'" |
| 66 | " -a android.intent.action.VIEW" % (screen_id, |
| 67 | remote_scene_file)) |
| 68 | subprocess.Popen(cmd.split()) |
| 69 | |
| 70 | if __name__ == '__main__': |
| 71 | main() |