1 /*
2  * Copyright (C) 2021 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.bedstead.harrier;
18 
19 import com.android.queryable.annotations.Query;
20 
21 import org.junit.rules.TestRule;
22 
23 /** A @Rule used on device by Harrier. */
24 // Annotating this class with @Query as a workaround to add this as a data type to a field
25 // in annotations that are called upon by @AutoAnnotation (for e.g. EnsureHasWorkProfile).
26 // @AutoAnnotation is not able to set default value for a field with an annotated data type,
27 // so we try to pass the default value explicitly that is accessed via reflection through this
28 // class.
29 @Query
30 public abstract class HarrierRule implements TestRule {
31     /** Sets that we should skip tearing down between tests. */
setSkipTestTeardown(boolean skipTestTeardown)32     abstract void setSkipTestTeardown(boolean skipTestTeardown);
33     /** Sets that we are using the BedsteadJUnit4 test runner. */
setUsingBedsteadJUnit4(boolean usingBedsteadJUnit4)34     abstract void setUsingBedsteadJUnit4(boolean usingBedsteadJUnit4);
35     /** Queries if the current device is using headless system user mode. */
isHeadlessSystemUserMode()36     abstract boolean isHeadlessSystemUserMode();
37 
38     /**
39      * Release resources.
40      * <br><br>
41      * Since this is a ClassRule and thereby static, we explicitly release all expensive resources
42      * it holds after the test class is executed.
43      */
releaseResources()44     protected abstract void releaseResources();
45 }
46