• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.dynamicmime.cts;
18 
19 import com.android.tradefed.device.DeviceNotAvailableException;
20 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
21 import com.android.tradefed.util.RunUtil;
22 
23 /**
24  * Reboot test case Base
25  *
26  * The base class provides the basic methods to reuse existing test cases from
27  * {@link android.dynamicmime.testapp.ComplexFilterTest} and
28  * {@link android.dynamicmime.testapp.SingleAppTest} by "inserting" device reboot between
29  * setup part (MIME group commands) and verification part (MIME group assertions) in each test case
30  *
31  * @see android.dynamicmime.testapp.reboot.PreRebootSingleAppTest
32  * @see android.dynamicmime.testapp.reboot.PostRebootSingleAppTest
33  * @see #runTestWithReboot(String, String)
34  */
35 
36 public class RebootTestCaseBase extends BaseHostJUnit4Test {
37     private static final String PACKAGE_TEST_APP = "android.dynamicmime.testapp";
38     private static final String PACKAGE_REBOOT_TESTS = PACKAGE_TEST_APP + ".reboot";
39 
40     private static final int SETTINGS_WRITE_TIMEOUT_MS = 10_000;
41 
runTestWithReboot(String testClassName, String testMethodName)42     protected void runTestWithReboot(String testClassName, String testMethodName)
43             throws DeviceNotAvailableException {
44         runPreReboot(testClassName, testMethodName);
45         waitForSettingsWrite();
46         getDevice().reboot();
47         runPostReboot(testClassName, testMethodName);
48     }
49 
runPostReboot(String testClassName, String testMethodName)50     protected void runPostReboot(String testClassName, String testMethodName)
51             throws DeviceNotAvailableException {
52         runDeviceTests(PACKAGE_TEST_APP, PACKAGE_REBOOT_TESTS + ".PostReboot" + testClassName,
53                 testMethodName);
54     }
55 
waitForSettingsWrite()56     protected void waitForSettingsWrite() {
57         RunUtil.getDefault().sleep(SETTINGS_WRITE_TIMEOUT_MS);
58     }
59 
runPreReboot(String testClassName, String testMethodName)60     protected void runPreReboot(String testClassName, String testMethodName)
61             throws DeviceNotAvailableException {
62         runDeviceTests(PACKAGE_TEST_APP, PACKAGE_REBOOT_TESTS + ".PreReboot" + testClassName,
63                 testMethodName);
64     }
65 }
66