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. 4from autotest_lib.client.common_lib import error 5from autotest_lib.client.common_lib import utils 6 7from autotest_lib.client.common_lib.cros import arc 8from autotest_lib.client.cros.enterprise import enterprise_policy_base 9 10 11class policy_ArcDisableScreenshots( 12 enterprise_policy_base.EnterprisePolicyTest): 13 """ 14 Test effect of policy_ArcDisableScreenshots policy on the ARC++ container 15 within ChromeOS. 16 17 """ 18 version = 1 19 20 POLICY_NAME = 'ArcPolicy' 21 22 def verify_policy(self, case): 23 """ 24 Verify the policy was properly set 25 26 @param case: bool, value of the policy setting 27 28 """ 29 if case: 30 e_msg = 'ARC++ Screenshot Taken when it should not have been' 31 else: 32 e_msg = 'ARC++ Screenshot was blocked when it should not have been' 33 34 # Give the ARC container time to setup and configure its policy. 35 utils.poll_for_condition( 36 lambda: self.check_screenshot(case), 37 exception=error.TestFail(e_msg), 38 timeout=30, 39 sleep_interval=1, 40 desc='Checking for screenshot file size') 41 42 def check_screenshot(self, case): 43 """ 44 Take a sceenshot and check its size, to see if the policy was set 45 correctly. 46 47 @param case: bool, value of the policy setting 48 49 @Returns True if the screenshot setting was correct, False otherwise. 50 51 """ 52 # Remove any lingering possible screenshots 53 arc.adb_shell('rm -f /sdcard/test.png', ignore_status=True) 54 55 # Take a screenshot, then check its size 56 arc.adb_shell('screencap > /sdcard/test.png', ignore_status=True) 57 screenshotsize = arc.adb_shell('du -s /sdcard/test.png', 58 ignore_status=True).split()[0] 59 60 # Some devices screenshot may contain metadata that would be up to 8b 61 if case and int(screenshotsize) > 8: 62 return False 63 # No screenshot should be under 100b 64 elif not case and int(screenshotsize) < 100: 65 return False 66 67 return True 68 69 def run_once(self, case): 70 """ 71 @param case: bool, value of the policy setting 72 73 """ 74 pol = {'ArcEnabled': True, 75 'DisableScreenshots': case} 76 self.setup_case(user_policies=pol, 77 arc_mode='enabled', 78 use_clouddpc_test=False) 79 80 self.verify_policy(case) 81