1 /* 2 * Copyright (C) 2016 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.build; 17 18 import com.android.tradefed.util.FileUtil; 19 20 import java.io.File; 21 import java.io.IOException; 22 23 /** 24 * An {@link OtaDeviceBuildInfo} that also contains an otatools directory. 25 */ 26 public class OtaToolsDeviceBuildInfo extends OtaDeviceBuildInfo { 27 private static final long serialVersionUID = BuildSerializedVersion.VERSION; 28 private File mOtaToolsDir; 29 30 /** 31 * Construct based on an {@link OtaDeviceBuildInfo}. 32 * @param parent 33 */ 34 public OtaToolsDeviceBuildInfo(OtaDeviceBuildInfo parent) { 35 setBaselineBuild(parent.mBaselineBuild); 36 setOtaBuild(parent.mOtaBuild); 37 } 38 39 public void setOtaTools(File otaTools) { 40 mOtaToolsDir = otaTools; 41 } 42 43 public File getOtaTools() { 44 return mOtaToolsDir; 45 } 46 47 // Allow the OTA package to be overwritten 48 @Override 49 public void setOtaPackageFile(File file, String version) { 50 ((DeviceBuildInfo)mBaselineBuild) 51 .getVersionedFileMap().put("ota", new VersionedFile(file, version)); 52 ((DeviceBuildInfo)mOtaBuild) 53 .getVersionedFileMap().put("ota", new VersionedFile(file, version)); 54 } 55 56 @Override 57 public void cleanUp() { 58 FileUtil.recursiveDelete(mOtaToolsDir); 59 super.cleanUp(); 60 } 61 62 @Override 63 public IBuildInfo clone() { 64 try { 65 OtaToolsDeviceBuildInfo clone = new OtaToolsDeviceBuildInfo( 66 (OtaDeviceBuildInfo)super.clone()); 67 File toolsCopy = FileUtil.createTempDir("otatools"); 68 FileUtil.recursiveHardlink(mOtaToolsDir, toolsCopy); 69 clone.setOtaTools(toolsCopy); 70 return clone; 71 } catch (IOException e) { 72 throw new RuntimeException(e); 73 } 74 } 75 } 76 77