Home | History | Annotate | Download | only in build
      1 /*
      2  * Copyright (C) 2010 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 
     17 package com.android.tradefed.build;
     18 
     19 import java.io.File;
     20 import java.io.IOException;
     21 
     22 /**
     23  * A {@link IBuildInfo} that represents a complete Android device build and (optionally) its tests.
     24  */
     25 public class DeviceBuildInfo extends BuildInfo implements IDeviceBuildInfo {
     26 
     27     private static final long serialVersionUID = BuildSerializedVersion.VERSION;
     28     private static final String DEVICE_IMAGE_NAME = "device";
     29     private static final String USERDATA_IMAGE_NAME = "userdata";
     30     private static final String TESTDIR_IMAGE_NAME = "testsdir";
     31     private static final String BASEBAND_IMAGE_NAME = "baseband";
     32     private static final String BOOTLOADER_IMAGE_NAME = "bootloader";
     33     private static final String OTA_IMAGE_NAME = "ota";
     34     private static final String MKBOOTIMG_IMAGE_NAME = "mkbootimg";
     35     private static final String RAMDISK_IMAGE_NAME = "ramdisk";
     36 
     37     public DeviceBuildInfo() {
     38         super();
     39     }
     40 
     41     public DeviceBuildInfo(String buildId, String buildTargetName) {
     42         super(buildId, buildTargetName);
     43     }
     44 
     45     /**
     46      * @deprecated use the constructor without test-tag instead. test-tag is no longer a mandatory
     47      * option for build info.
     48      */
     49     @Deprecated
     50     public DeviceBuildInfo(String buildId, String testTag, String buildTargetName) {
     51         super(buildId, testTag, buildTargetName);
     52     }
     53 
     54     public DeviceBuildInfo(BuildInfo buildInfo) {
     55         super(buildInfo);
     56     }
     57 
     58     /**
     59      * {@inheritDoc}
     60      *
     61      * @return {@link #getDeviceImageVersion()} if not {@code null}, else
     62      * {@link IBuildInfo#UNKNOWN_BUILD_ID}
     63      *
     64      * @see #getDeviceImageVersion()
     65      */
     66     @Override
     67     public String getDeviceBuildId() {
     68         String buildId = getDeviceImageVersion();
     69         return buildId == null ? UNKNOWN_BUILD_ID : buildId;
     70     }
     71 
     72     /**
     73      * {@inheritDoc}
     74      */
     75     @Override
     76     public String getDeviceBuildFlavor() {
     77         return getBuildFlavor();
     78     }
     79 
     80     /**
     81      * {@inheritDoc}
     82      */
     83     @Override
     84     public File getDeviceImageFile() {
     85         return getFile(DEVICE_IMAGE_NAME);
     86     }
     87 
     88     /**
     89      * {@inheritDoc}
     90      */
     91     @Override
     92     public String getDeviceImageVersion() {
     93         return getVersion(DEVICE_IMAGE_NAME);
     94     }
     95 
     96     /**
     97      * {@inheritDoc}
     98      */
     99     @Override
    100     public void setDeviceImageFile(File deviceImageFile, String version) {
    101         setFile(DEVICE_IMAGE_NAME, deviceImageFile, version);
    102     }
    103 
    104     /**
    105      * {@inheritDoc}
    106      */
    107     @Override
    108     public File getUserDataImageFile() {
    109         return getFile(USERDATA_IMAGE_NAME);
    110     }
    111 
    112     /**
    113      * {@inheritDoc}
    114      */
    115     @Override
    116     public String getUserDataImageVersion() {
    117         return getVersion(USERDATA_IMAGE_NAME);
    118     }
    119 
    120     /**
    121      * {@inheritDoc}
    122      */
    123     @Override
    124     public void setUserDataImageFile(File userDataFile, String version) {
    125         setFile(USERDATA_IMAGE_NAME, userDataFile, version);
    126     }
    127 
    128     /**
    129      * {@inheritDoc}
    130      */
    131     @Override
    132     public File getTestsDir() {
    133         return getFile(TESTDIR_IMAGE_NAME);
    134     }
    135 
    136     /**
    137      * {@inheritDoc}
    138      */
    139     @Override
    140     public String getTestsDirVersion() {
    141         return getVersion(TESTDIR_IMAGE_NAME);
    142     }
    143 
    144     /**
    145      * {@inheritDoc}
    146      */
    147     @Override
    148     public void setTestsDir(File testsDir, String version) {
    149         setFile(TESTDIR_IMAGE_NAME, testsDir, version);
    150     }
    151 
    152     /**
    153      * {@inheritDoc}
    154      */
    155     @Override
    156     public File getBasebandImageFile() {
    157         return getFile(BASEBAND_IMAGE_NAME);
    158     }
    159 
    160     /**
    161      * {@inheritDoc}
    162      */
    163     @Override
    164     public String getBasebandVersion() {
    165         return getVersion(BASEBAND_IMAGE_NAME);
    166     }
    167 
    168     /**
    169      * {@inheritDoc}
    170      */
    171     @Override
    172     public void setBasebandImage(File basebandFile, String version) {
    173         setFile(BASEBAND_IMAGE_NAME, basebandFile, version);
    174     }
    175 
    176     /**
    177      * {@inheritDoc}
    178      */
    179     @Override
    180     public File getBootloaderImageFile() {
    181         return getFile(BOOTLOADER_IMAGE_NAME);
    182     }
    183 
    184     /**
    185      * {@inheritDoc}
    186      */
    187     @Override
    188     public String getBootloaderVersion() {
    189         return getVersion(BOOTLOADER_IMAGE_NAME);
    190     }
    191 
    192     /**
    193      * {@inheritDoc}
    194      */
    195     @Override
    196     public void setBootloaderImageFile(File bootloaderImgFile, String version) {
    197         setFile(BOOTLOADER_IMAGE_NAME, bootloaderImgFile, version);
    198     }
    199 
    200     /**
    201      * {@inheritDoc}
    202      */
    203     @Override
    204     public File getOtaPackageFile() {
    205         return getFile(OTA_IMAGE_NAME);
    206     }
    207 
    208     /**
    209      * {@inheritDoc}
    210      */
    211     @Override
    212     public String getOtaPackageVersion() {
    213         return getVersion(OTA_IMAGE_NAME);
    214     }
    215 
    216     /**
    217      * {@inheritDoc}
    218      */
    219     @Override
    220     public void setOtaPackageFile(File otaFile, String version) {
    221         setFile(OTA_IMAGE_NAME, otaFile, version);
    222     }
    223 
    224     /**
    225      * {@inheritDoc}
    226      */
    227     @Override
    228     public File getMkbootimgFile() {
    229         return getFile(MKBOOTIMG_IMAGE_NAME);
    230     }
    231 
    232     /**
    233      * {@inheritDoc}
    234      */
    235     @Override
    236     public String getMkbootimgVersion() {
    237         return getVersion(MKBOOTIMG_IMAGE_NAME);
    238     }
    239 
    240     /**
    241      * {@inheritDoc}
    242      */
    243     @Override
    244     public void setMkbootimgFile(File mkbootimg, String version) {
    245         setFile(MKBOOTIMG_IMAGE_NAME, mkbootimg, version);
    246     }
    247 
    248     /**
    249      * {@inheritDoc}
    250      */
    251     @Override
    252     public File getRamdiskFile() {
    253         return getFile(RAMDISK_IMAGE_NAME);
    254     }
    255 
    256     /**
    257      * {@inheritDoc}
    258      */
    259     @Override
    260     public String getRamdiskVersion() {
    261         return getVersion(RAMDISK_IMAGE_NAME);
    262     }
    263 
    264     /**
    265      * {@inheritDoc}
    266      */
    267     @Override
    268     public void setRamdiskFile(File ramdisk, String version) {
    269         setFile(RAMDISK_IMAGE_NAME, ramdisk, version);
    270     }
    271 
    272     /**
    273      * {@inheritDoc}
    274      */
    275     @Override
    276     public IBuildInfo clone() {
    277         DeviceBuildInfo copy = new DeviceBuildInfo(getBuildId(), getBuildTargetName());
    278         copy.addAllBuildAttributes(this);
    279         try {
    280             copy.addAllFiles(this);
    281         } catch (IOException e) {
    282             throw new RuntimeException(e);
    283         }
    284         copy.setBuildBranch(getBuildBranch());
    285         copy.setBuildFlavor(getBuildFlavor());
    286 
    287         return copy;
    288     }
    289 }
    290