• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 com.android.sts.common;
18 
19 import static com.google.common.truth.Truth.assertWithMessage;
20 
21 import com.android.tradefed.device.DeviceNotAvailableException;
22 import com.android.tradefed.device.ITestDevice;
23 import com.android.tradefed.targetprep.TargetSetupError;
24 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
25 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
26 
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 
31 /** Unit tests for {@link LockSettingsUtil}. */
32 @RunWith(DeviceJUnit4ClassRunner.class)
33 public class LockSettingsUtilDeviceTestWrapper extends BaseHostJUnit4Test {
34     private ITestDevice mDevice;
35 
36     @Before
setUp()37     public void setUp() throws Exception {
38         mDevice = getDevice();
39     }
40 
41     @Test
testLockSettingsUtilNonRoot()42     public void testLockSettingsUtilNonRoot() throws Exception {
43         assertWithMessage("Must be able to unroot the device")
44                 .that(mDevice.disableAdbRoot())
45                 .isTrue();
46 
47         installAndRunDeviceTests();
48 
49         assertWithMessage("Device should not implicitly root to cleanup")
50                 .that(mDevice.isAdbRoot())
51                 .isFalse();
52     }
53 
54     @Test
testLockSettingsUtilRoot()55     public void testLockSettingsUtilRoot() throws Exception {
56         assertWithMessage("Must test with rootable device").that(mDevice.enableAdbRoot()).isTrue();
57 
58         installAndRunDeviceTests();
59 
60         assertWithMessage("Device should still be root after cleanup if started with root")
61                 .that(mDevice.isAdbRoot())
62                 .isTrue();
63     }
64 
installAndRunDeviceTests()65     private void installAndRunDeviceTests() throws TargetSetupError, DeviceNotAvailableException {
66         final String testPkg = "com.android.sts.common.util.tests";
67         installPackage("StsCommonUtilDeviceTests.apk");
68         runDeviceTests(testPkg, testPkg + ".LockSettingsUtilTest");
69     }
70 }
71