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 package com.android.tradefed.testtype.suite.params; 17 18 import com.android.tradefed.config.IConfiguration; 19 import com.android.tradefed.device.DeviceFoldableState; 20 21 import java.util.ArrayList; 22 import java.util.Collections; 23 import java.util.List; 24 import java.util.Set; 25 26 /** 27 * A {@link IModuleParameterHandler} expanding into more for each non-primary foldable 28 * configuration. 29 */ 30 public class FoldableExpandingHandler implements IModuleParameterHandler { 31 32 @Override getParameterIdentifier()33 public String getParameterIdentifier() { 34 throw new UnsupportedOperationException("Should never be called"); 35 } 36 37 @Override applySetup(IConfiguration moduleConfiguration)38 public void applySetup(IConfiguration moduleConfiguration) { 39 throw new UnsupportedOperationException("Should never be called"); 40 } 41 expandHandler(Set<DeviceFoldableState> states)42 public List<IModuleParameterHandler> expandHandler(Set<DeviceFoldableState> states) { 43 List<DeviceFoldableState> foldableList = new ArrayList<>(states); 44 Collections.sort(foldableList); 45 46 List<IModuleParameterHandler> foldableStateToRun = new ArrayList<>(); 47 // If there is no or only one foldable state, there is no need to parameterize. 48 if (foldableList.isEmpty() || foldableList.size() == 1) { 49 return foldableStateToRun; 50 } 51 // Consider the lowest identifier the 'primary state' 52 for (int i = 1; i < foldableList.size(); i++) { 53 foldableStateToRun.add(new FoldableHandler( 54 foldableList.get(i).toString(), foldableList.get(i).getIdentifier())); 55 } 56 return foldableStateToRun; 57 } 58 } 59