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