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.compatibility.common.tradefed.targetprep; 17 18 import com.android.compatibility.common.tradefed.build.CompatibilityBuildHelper; 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 Compatibility repository. 29 */ 30 @OptionClass(alias="apk-installer") 31 public class ApkInstaller extends TestAppInstallSetup { 32 33 private CompatibilityBuildHelper mBuildHelper = null; 34 getTestsDir(IBuildInfo buildInfo)35 protected File getTestsDir(IBuildInfo buildInfo) throws FileNotFoundException { 36 if (mBuildHelper == null) { 37 mBuildHelper = new CompatibilityBuildHelper(buildInfo); 38 } 39 return mBuildHelper.getTestsDir(); 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 File apkFile = null; 49 try { 50 apkFile = new File(getTestsDir(buildInfo), apkFileName); 51 if (!apkFile.isFile()) { 52 throw new FileNotFoundException(); 53 } 54 } catch (FileNotFoundException e) { 55 throw new TargetSetupError(String.format("%s not found", apkFileName), e); 56 } 57 return apkFile; 58 } 59 } 60