• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.TestAppInstallSetup;
22 import com.android.tradefed.testtype.IRemoteTest;
23 import com.android.tradefed.testtype.ITestAnnotationFilterReceiver;
24 
25 import java.util.HashSet;
26 import java.util.Set;
27 
28 /** Handler for {@link ModuleParameters#INSTANT_APP}. */
29 public class InstantAppHandler implements IModuleParameterHandler {
30 
31     public static final String INSTANT_APP_ID = "instant";
32 
33     /** {@inheritDoc} */
34     @Override
getParameterIdentifier()35     public String getParameterIdentifier() {
36         return INSTANT_APP_ID;
37     }
38 
39     /** {@inheritDoc} */
40     @Override
applySetup(IConfiguration moduleConfiguration)41     public void applySetup(IConfiguration moduleConfiguration) {
42         // First, force target_preparers if they support it to install app in instant mode.
43         for (IDeviceConfiguration deviceConfig : moduleConfiguration.getDeviceConfig()) {
44             for (ITargetPreparer preparer : deviceConfig.getTargetPreparers()) {
45                 if (preparer instanceof TestAppInstallSetup) {
46                     ((TestAppInstallSetup) preparer).setInstantMode(true);
47                 }
48             }
49         }
50         // TODO: Second, notify HostTest that instant mode might be needed for apks.
51 
52         // Third, add filter to exclude @FullAppMode and allow @AppModeInstant
53         for (IRemoteTest test : moduleConfiguration.getTests()) {
54             if (test instanceof ITestAnnotationFilterReceiver) {
55                 ITestAnnotationFilterReceiver filterTest = (ITestAnnotationFilterReceiver) test;
56                 // Retrieve the current set of excludeAnnotations to maintain for after the
57                 // clearing/reset of the annotations.
58                 Set<String> excludeAnnotations = new HashSet<>(filterTest.getExcludeAnnotations());
59                 // Remove any global filter on AppModeInstant so instant mode tests can run.
60                 excludeAnnotations.remove("android.platform.test.annotations.AppModeInstant");
61                 // Prevent full mode tests from running.
62                 excludeAnnotations.add("android.platform.test.annotations.AppModeFull");
63                 // Reset the annotations of the tests
64                 filterTest.clearExcludeAnnotations();
65                 filterTest.addAllExcludeAnnotation(excludeAnnotations);
66             }
67         }
68     }
69 }
70