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.cros import arc 6from autotest_lib.client.cros.enterprise import enterprise_policy_base 7 8 9class policy_ArcExternalStorageDisabled( 10 enterprise_policy_base.EnterprisePolicyTest): 11 version = 1 12 13 POLICY_NAME = 'ExternalStorageDisabled' 14 TEST_CASES = { 15 'True_Block': True, 16 'False_Allow': False, 17 'NotSet_Allow': None 18 } 19 20 def _test_arc_external_storage(self, policy_value): 21 """ 22 Verify the behavior of the ExternalStorageDisabled policy on ARC. 23 24 Check the /storage directory and verify that it is empty if the 25 policy disables access to external storage, or not empty if external 26 storage is allowed. 27 28 @param policy_value: policy value for this case. 29 30 @raises error.TestFail: If the contents of the /media/removable 31 directory do not match the policy behavior. 32 33 """ 34 35 arc_dirs = set(arc.adb_shell('ls /storage').split()) 36 37 base_dirs = set(['emulated', 'self', 'MyFiles']) 38 39 usb_parts = arc_dirs - base_dirs 40 if policy_value: 41 if usb_parts: 42 raise error.TestFail('External storage was disabled but ' 43 'external storage detected') 44 elif not usb_parts: 45 raise error.TestFail('External storage enabled but external ' 46 'storage not found') 47 48 def run_once(self, case): 49 """ 50 Setup and run the test configured for the specified test case. 51 52 @param case: Name of the test case to run. 53 54 """ 55 case_value = self.TEST_CASES[case] 56 pol = {'ArcEnabled': True, 57 'ExternalStorageDisabled': case_value} 58 self.setup_case(user_policies=pol, 59 arc_mode='enabled', 60 use_clouddpc_test=False) 61 self._test_arc_external_storage(case_value) 62