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 com.google.common.truth.Truth.assertThat; 20 21 import com.android.tradefed.device.ITestDevice; 22 23 import org.junit.AfterClass; 24 import org.junit.Before; 25 26 public class PublicVolumeHostTest extends ScopedStorageHostTest { 27 /** Used to clean up the virtual volume after the test */ 28 private static ITestDevice sDevice; 29 private boolean mIsPublicVolumeSetup; 30 setupNewPublicVolume()31 private void setupNewPublicVolume() throws Exception { 32 if (!mIsPublicVolumeSetup) { 33 assertThat(runDeviceTests("android.scopedstorage.cts", 34 "android.scopedstorage.cts.PublicVolumeTestHelper", "setupNewPublicVolume")) 35 .isTrue(); 36 mIsPublicVolumeSetup = true; 37 } 38 } 39 setupDevice()40 private void setupDevice() { 41 if (sDevice == null) { 42 sDevice = getDevice(); 43 } 44 } 45 46 /** 47 * Runs the given phase of PublicVolumeTest by calling into the device. 48 * Throws an exception if the test phase fails. 49 */ 50 @Override runDeviceTest(String phase)51 void runDeviceTest(String phase) throws Exception { 52 assertThat(runDeviceTests("android.scopedstorage.cts", 53 "android.scopedstorage.cts.PublicVolumeTest", phase)).isTrue(); 54 } 55 56 @Before setup()57 public void setup() throws Exception { 58 setupDevice(); 59 setupNewPublicVolume(); 60 super.setup(); 61 } 62 63 @AfterClass deletePublicVolumes()64 public static void deletePublicVolumes() throws Exception { 65 if (sDevice != null) { 66 sDevice.executeShellCommand("sm set-virtual-disk false"); 67 } 68 } 69 } 70