1 /*
2  * Copyright (C) 2016 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.appsecurity.cts;
18 
19 import android.compat.cts.CompatChangeGatingTestCase;
20 
21 import com.android.compatibility.common.tradefed.build.CompatibilityBuildHelper;
22 import com.android.tradefed.device.DeviceNotAvailableException;
23 import com.android.tradefed.testtype.IAbi;
24 import com.android.tradefed.testtype.IAbiReceiver;
25 
26 /**
27  * Base class for {@link android.provider.DocumentsContract} and related test cases.
28  */
29 abstract class DocumentsTestCase extends CompatChangeGatingTestCase implements IAbiReceiver {
30     protected static final String CLIENT_PKG = "com.android.cts.documentclient";
31     protected static final String CLIENT_APK = "CtsDocumentClient.apk";
32 
33     protected IAbi mAbi;
34 
35     @Override
setAbi(IAbi abi)36     public void setAbi(IAbi abi) {
37         mAbi = abi;
38     }
39 
40     @Override
setUp()41     protected void setUp() throws Exception {
42         super.setUp();
43 
44         Utils.prepareSingleUser(getDevice());
45         assertNotNull(mAbi);
46 
47         reinstallClientPackage();
48     }
49 
50     @Override
tearDown()51     protected void tearDown() throws Exception {
52         super.tearDown();
53 
54         getDevice().uninstallPackage(CLIENT_PKG);
55     }
56 
runDeviceTests(String packageName, String testClassName, String testMethodName)57     public void runDeviceTests(String packageName, String testClassName, String testMethodName)
58             throws DeviceNotAvailableException {
59         Utils.runDeviceTests(getDevice(), packageName, testClassName, testMethodName,
60                 getDevice().getCurrentUser());
61     }
62 
reinstallClientPackage()63     protected void reinstallClientPackage() throws Exception {
64         getDevice().uninstallPackage(CLIENT_PKG);
65         CompatibilityBuildHelper buildHelper = new CompatibilityBuildHelper(mCtsBuild);
66         assertNull(getDevice().installPackage(buildHelper.getTestFile(CLIENT_APK), false));
67     }
68 }
69