1 /* 2 * Copyright (C) 2012 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.ide.eclipse.adt.internal.launch; 18 19 import com.android.sdklib.AndroidVersion; 20 import com.android.sdklib.IAndroidTarget; 21 import com.android.sdklib.internal.avd.AvdInfo; 22 23 public class AvdCompatibility { 24 public enum Compatibility { 25 YES, 26 NO, 27 UNKNOWN, 28 }; 29 30 /** 31 * Returns whether the specified AVD can run the given project that is built against 32 * a particular SDK and has the specified minApiLevel. 33 * @param avd AVD to check compatibility for 34 * @param projectTarget project build target 35 * @param minApiVersion project min api level 36 * @return whether the given AVD can run the given application 37 */ 38 public static Compatibility canRun(AvdInfo avd, IAndroidTarget projectTarget, 39 AndroidVersion minApiVersion) { 40 if (avd == null) { 41 return Compatibility.UNKNOWN; 42 } 43 44 IAndroidTarget avdTarget = avd.getTarget(); 45 if (avdTarget == null) { 46 return Compatibility.UNKNOWN; 47 } 48 49 // for platform targets, we only need to check the min api version 50 if (projectTarget.isPlatform()) { 51 return avdTarget.getVersion().canRun(minApiVersion) ? 52 Compatibility.YES : Compatibility.NO; 53 } 54 55 // for add-on targets, delegate to the add on target to check for compatibility 56 return projectTarget.canRunOn(avdTarget) ? Compatibility.YES : Compatibility.NO; 57 } 58 } 59