1 /* 2 * Copyright (C) 2015 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.cts.tradefed.targetprep; 17 18 import com.android.cts.tradefed.build.CtsBuildHelper; 19 import com.android.tradefed.build.IBuildInfo; 20 import com.android.tradefed.config.OptionClass; 21 import com.android.tradefed.targetprep.TargetSetupError; 22 import com.android.tradefed.targetprep.TestAppInstallSetup; 23 24 import java.io.File; 25 import java.io.FileNotFoundException; 26 27 /** 28 * Installs specified apks from CTS test case repository 29 */ 30 @OptionClass(alias="cts-apk-installer") 31 public class CtsApkInstaller extends TestAppInstallSetup { 32 33 private CtsBuildHelper mBuildHelper = null; 34 getCtsBuildHelper(IBuildInfo buildInfo)35 protected CtsBuildHelper getCtsBuildHelper(IBuildInfo buildInfo) { 36 if (mBuildHelper == null) { 37 mBuildHelper = CtsBuildHelper.createBuildHelper(buildInfo); 38 } 39 return mBuildHelper; 40 } 41 42 /** 43 * {@inheritDoc} 44 */ 45 @Override getLocalPathForFilename(IBuildInfo buildInfo, String apkFileName)46 protected File getLocalPathForFilename(IBuildInfo buildInfo, String apkFileName) 47 throws TargetSetupError { 48 try { 49 return getCtsBuildHelper(buildInfo).getTestApp(apkFileName); 50 } catch (FileNotFoundException e) { 51 throw new TargetSetupError(String.format("apk not found: %s", apkFileName), e); 52 } 53 } 54 } 55