1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.scopedstorage.cts.host; 18 19 import static org.junit.Assert.assertTrue; 20 21 import com.android.tradefed.device.ITestDevice; 22 23 import org.junit.AfterClass; 24 import org.junit.Before; 25 26 public class PublicVolumeCoreHostTest extends ScopedStorageCoreHostTest { 27 /* Used to clean up the virtual volume after the test */ 28 private static ITestDevice sDevice = null; 29 private boolean mIsPublicVolumeSetup = false; executeShellCommand(String cmd)30 String executeShellCommand(String cmd) throws Exception { 31 return getDevice().executeShellCommand(cmd); 32 } 33 setupNewPublicVolume()34 private void setupNewPublicVolume() throws Exception { 35 if (!mIsPublicVolumeSetup) { 36 assertTrue(runDeviceTests("android.scopedstorage.cts", 37 "android.scopedstorage.cts.PublicVolumeTestHelper", "setupNewPublicVolume")); 38 mIsPublicVolumeSetup = true; 39 } 40 } 41 setupDevice()42 private void setupDevice() { 43 if (sDevice == null) { 44 sDevice = getDevice(); 45 } 46 } 47 48 /** 49 * Runs the given phase of PublicVolumeTest by calling into the device. 50 * Throws an exception if the test phase fails. 51 */ 52 @Override runDeviceTest(String phase)53 void runDeviceTest(String phase) throws Exception { 54 assertTrue(runDeviceTests("android.scopedstorage.cts", 55 "android.scopedstorage.cts.PublicVolumeTest", phase)); 56 } 57 58 @Before setup()59 public void setup() throws Exception { 60 setupDevice(); 61 setupNewPublicVolume(); 62 super.setup(); 63 } 64 65 @AfterClass deletePublicVolumes()66 public static void deletePublicVolumes() throws Exception { 67 if (sDevice != null) { 68 sDevice.executeShellCommand("sm set-virtual-disk false"); 69 } 70 } 71 } 72