• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2019 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5from autotest_lib.client.common_lib import error
6from autotest_lib.client.common_lib import utils
7
8from autotest_lib.client.common_lib.cros import arc
9from autotest_lib.client.cros.enterprise import enterprise_policy_base
10
11
12class policy_ArcVideoCaptureAllowed(
13        enterprise_policy_base.EnterprisePolicyTest):
14    """
15    Test effect of the ArcVideoCaptureAllowed ChromeOS policy on ARC.
16
17    This test will launch the ARC container via the ArcEnabled policy, then
18    will check the behavior of the passthrough policy VideoCaptureAllowed.
19
20    When the policy is set to False, Video Capture is not allowed. To test
21    this, we will attemp to launch the ARC Camera, and check the logs to see
22    if the Camera was launched or not.
23
24    """
25    version = 1
26
27    def _test_Arc_cam_status(self, case):
28        """
29        Test if the Arc Camera has been opened, or not.
30
31        @param case: bool, value of the VideoCaptureAllowed policy.
32
33        """
34
35        #  The Camera can take a few seconds to respond, wait for it.
36        utils.poll_for_condition(
37            lambda: self.did_cam_app_respond(),
38            exception=error.TestFail('Camera APP did not respond.'),
39            timeout=10,
40            sleep_interval=1,
41            desc='Wait for Camera to respond.')
42
43        #  Once the Camera is open, get the status from logcat.
44        cam_device_resp, disabled_resp = self._check_cam_status()
45
46        if case or case is None:
47            if 'opened successfully' not in cam_device_resp or disabled_resp:
48                raise error.TestFail(
49                    'Camera did not launch when it should have.')
50        else:
51            if ('opened successfully' in cam_device_resp or
52                'disabled by policy' not in disabled_resp):
53                raise error.TestFail(
54                    'Camera did launch when it should not have.')
55
56    def _launch_Arc_Cam(self):
57        """Grant the Camera location permission, and launch the Camera app."""
58        arc.adb_shell('pm grant com.google.android.GoogleCameraArc android.permission.ACCESS_COARSE_LOCATION')
59        arc.adb_shell('am start -a android.media.action.IMAGE_CAPTURE')
60
61    def _check_cam_status(self):
62        """Returns the specified section from loggcat."""
63        return [arc.adb_shell("logcat -d | grep 'Camera device'"),
64                arc.adb_shell("logcat -d | grep 'CAMERA_DISABLED'")]
65
66    def did_cam_app_respond(self):
67        """
68        Check if the Camera app has responded to the start command via
69        data in the logs being populated.
70
71        @return: True/False, if the Camera has responded to the start command.
72
73        """
74
75        cam_logs = self._check_cam_status()
76        if cam_logs[0] or cam_logs[1]:
77            return True
78        return False
79
80    def run_once(self, case):
81        """
82        Setup and run the test configured for the specified test case.
83
84        @param case: Name of the test case to run.
85
86        """
87        pol = {'ArcEnabled': True,
88               'VideoCaptureAllowed': case}
89
90        self.setup_case(user_policies=pol,
91                        arc_mode='enabled',
92                        use_clouddpc_test=False)
93        self._launch_Arc_Cam()
94        self._test_Arc_cam_status(case)
95