1717package androidx .test .internal .runner ;
1818
1919import android .app .Instrumentation ;
20+ import android .os .Build ;
2021import android .os .Bundle ;
2122import android .util .Log ;
2223import androidx .annotation .VisibleForTesting ;
2324import androidx .test .filters .AbstractFilter ;
2425import androidx .test .filters .CustomFilter ;
2526import androidx .test .filters .RequiresDevice ;
26- import androidx .test .filters .SdkSuppress ;
27+ import androidx .test .filters .SdkSuppressFilter ;
2728import androidx .test .filters .TestsRegExFilter ;
2829import androidx .test .internal .runner .ClassPathScanner .ChainedClassNameFilter ;
2930import androidx .test .internal .runner .ClassPathScanner .ExcludeClassNamesFilter ;
3031import androidx .test .internal .runner .ClassPathScanner .ExcludePackageNameFilter ;
3132import androidx .test .internal .runner .ClassPathScanner .ExternalClassNameFilter ;
3233import androidx .test .internal .runner .ClassPathScanner .InclusivePackageNamesFilter ;
33- import androidx .test .internal .util .Checks ;
3434import androidx .tracing .Trace ;
3535import java .io .IOException ;
3636import java .lang .annotation .Annotation ;
@@ -84,7 +84,6 @@ public class TestRequestBuilder {
8484 .intersect (new CustomFilters ());
8585 private List <Class <? extends RunnerBuilder >> customRunnerBuilderClasses = new ArrayList <>();
8686 private boolean skipExecution = false ;
87- private final DeviceBuild deviceBuild ;
8887 private long perTestTimeout = 0 ;
8988 private ClassLoader classLoader ;
9089
@@ -96,39 +95,6 @@ public class TestRequestBuilder {
9695 */
9796 private boolean ignoreSuiteMethods = false ;
9897
99- /**
100- * Accessor interface for retrieving device build properties.
101- *
102- * <p>Used so unit tests can mock calls
103- */
104- interface DeviceBuild {
105- /** Returns the SDK API level for current device. */
106- int getSdkVersionInt ();
107-
108- /** Returns the hardware type of the current device. */
109- String getHardware ();
110-
111- /** Returns the version code name of the current device. */
112- String getCodeName ();
113- }
114-
115- private static class DeviceBuildImpl implements DeviceBuild {
116- @ Override
117- public int getSdkVersionInt () {
118- return android .os .Build .VERSION .SDK_INT ;
119- }
120-
121- @ Override
122- public String getHardware () {
123- return android .os .Build .HARDWARE ;
124- }
125-
126- @ Override
127- public String getCodeName () {
128- return android .os .Build .VERSION .CODENAME ;
129- }
130- }
131-
13298 /** Filter that only runs tests whose method or class has been annotated with given filter. */
13399 private static class AnnotationInclusionFilter extends AbstractFilter {
134100
@@ -277,42 +243,6 @@ public String describe() {
277243 }
278244 }
279245
280- private class SdkSuppressFilter extends AbstractFilter {
281-
282- @ Override
283- protected boolean evaluateTest (Description description ) {
284- final SdkSuppress sdkSuppress = getAnnotationForTest (description );
285- if (sdkSuppress != null ) {
286- if ((getDeviceSdkInt () >= sdkSuppress .minSdkVersion ()
287- && getDeviceSdkInt () <= sdkSuppress .maxSdkVersion ()
288- && !isInExcludedSdks (sdkSuppress .excludedSdks ()))
289- || getDeviceCodeName ().equals (sdkSuppress .codeName ())) {
290- return true ; // run the test
291- }
292- return false ; // don't run the test
293- }
294- return true ; // no SdkSuppress, run the test
295- }
296-
297- private SdkSuppress getAnnotationForTest (Description description ) {
298- final SdkSuppress s = description .getAnnotation (SdkSuppress .class );
299- if (s != null ) {
300- return s ;
301- }
302- final Class <?> testClass = description .getTestClass ();
303- if (testClass != null ) {
304- return testClass .getAnnotation (SdkSuppress .class );
305- }
306- return null ;
307- }
308-
309- /** {@inheritDoc} */
310- @ Override
311- public String describe () {
312- return String .format ("skip tests annotated with SdkSuppress if necessary" );
313- }
314- }
315-
316246 /** Class that filters out tests annotated with {@link RequiresDevice} when running on emulator */
317247 @ VisibleForTesting
318248 class RequiresDeviceFilter extends AnnotationExclusionFilter {
@@ -335,7 +265,7 @@ class RequiresDeviceFilter extends AnnotationExclusionFilter {
335265 protected boolean evaluateTest (Description description ) {
336266 if (!super .evaluateTest (description )) {
337267 // annotation is present - check if device is an emulator
338- return !emulatorHardwareNames .contains (getDeviceHardware () );
268+ return !emulatorHardwareNames .contains (Build . HARDWARE );
339269 }
340270 return true ;
341271 }
@@ -536,18 +466,10 @@ public TestRequestBuilder(Instrumentation instr, Bundle bundle) {
536466
537467 /** Creates a TestRequestBuilder */
538468 public TestRequestBuilder () {
539- this (new DeviceBuildImpl ());
540- }
541-
542- /** Alternate TestRequestBuilder constructor that accepts a custom DeviceBuild */
543- @ VisibleForTesting
544- TestRequestBuilder (DeviceBuild deviceBuildAccessor ) {
545- deviceBuild = Checks .checkNotNull (deviceBuildAccessor );
546-
547469 maybeAddLegacySuppressFilter ();
548470 }
549471
550- // add legacy Suppress filer iff it is on classpath
472+ // add legacy Suppress filter iff it is on classpath
551473 private void maybeAddLegacySuppressFilter () {
552474 try {
553475 Class <? extends Annotation > legacySuppressClass =
@@ -929,25 +851,4 @@ private Class<? extends Annotation> loadAnnotationClass(String className) {
929851 }
930852 return null ;
931853 }
932-
933- private int getDeviceSdkInt () {
934- return deviceBuild .getSdkVersionInt ();
935- }
936-
937- private String getDeviceHardware () {
938- return deviceBuild .getHardware ();
939- }
940-
941- private String getDeviceCodeName () {
942- return deviceBuild .getCodeName ();
943- }
944-
945- private boolean isInExcludedSdks (int [] excludedSdks ) {
946- for (int sdk : excludedSdks ) {
947- if (sdk == getDeviceSdkInt ()) {
948- return true ;
949- }
950- }
951- return false ;
952- }
953854}
0 commit comments