• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 package com.android.tradefed.testtype.suite.params;
17 
18 import com.android.tradefed.config.IConfiguration;
19 import com.android.tradefed.config.IDeviceConfiguration;
20 import com.android.tradefed.targetprep.ITargetPreparer;
21 import com.android.tradefed.targetprep.RunOnSdkSandboxTargetPreparer;
22 import com.android.tradefed.testtype.IRemoteTest;
23 import com.android.tradefed.testtype.ITestAnnotationFilterReceiver;
24 
25 import java.util.HashSet;
26 import java.util.List;
27 import java.util.Set;
28 
29 /** Handler for {@link ModuleParameters#RUN_ON_SDK_SANDBOX}. */
30 public class RunOnSdkSandboxHandler implements IModuleParameterHandler {
31 
32     /** {@inheritDoc} */
33     @Override
getParameterIdentifier()34     public String getParameterIdentifier() {
35         return "run-on-sdk-sandbox";
36     }
37 
38     /** {@inheritDoc} */
39     @Override
addParameterSpecificConfig(IConfiguration moduleConfiguration)40     public void addParameterSpecificConfig(IConfiguration moduleConfiguration) {
41         for (IDeviceConfiguration deviceConfig : moduleConfiguration.getDeviceConfig()) {
42             List<ITargetPreparer> preparers = deviceConfig.getTargetPreparers();
43             preparers.add(new RunOnSdkSandboxTargetPreparer());
44         }
45     }
46 
47     /** {@inheritDoc} */
48     @Override
applySetup(IConfiguration moduleConfiguration)49     public void applySetup(IConfiguration moduleConfiguration) {
50         for (IRemoteTest test : moduleConfiguration.getTests()) {
51             if (test instanceof ITestAnnotationFilterReceiver) {
52                 ITestAnnotationFilterReceiver filterTest = (ITestAnnotationFilterReceiver) test;
53                 Set<String> excludeAnnotations = new HashSet<>(filterTest.getExcludeAnnotations());
54                 // The sandbox is more restrictive than instant apps, ignore @AppModeFull tests.
55                 excludeAnnotations.add("android.platform.test.annotations.AppModeFull");
56                 // Ignore tests that are not applicable to the sandbox.
57                 excludeAnnotations.add("android.platform.test.annotations.AppModeNonSdkSandbox");
58 
59                 // Reset the annotations of the tests.
60                 filterTest.clearExcludeAnnotations();
61                 filterTest.addAllExcludeAnnotation(excludeAnnotations);
62             }
63         }
64     }
65 }
66