1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php 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.sdk; 18 19 import com.android.annotations.NonNull; 20 import com.android.manifmerger.ICallback; 21 import com.android.manifmerger.ManifestMerger; 22 import com.android.sdklib.AndroidTargetHash; 23 import com.android.sdklib.AndroidVersion; 24 import com.android.sdklib.IAndroidTarget; 25 26 /** 27 * A {@link ManifestMerger} {@link ICallback} that returns the 28 * proper API level for known API codenames. 29 */ 30 public class AdtManifestMergeCallback implements ICallback { 31 @Override queryCodenameApiLevel(@onNull String codename)32 public int queryCodenameApiLevel(@NonNull String codename) { 33 Sdk sdk = Sdk.getCurrent(); 34 if (sdk != null) { 35 try { 36 AndroidVersion version = new AndroidVersion(codename); 37 String hashString = AndroidTargetHash.getPlatformHashString(version); 38 IAndroidTarget t = sdk.getTargetFromHashString(hashString); 39 if (t != null) { 40 return t.getVersion().getApiLevel(); 41 } 42 } catch (AndroidVersion.AndroidVersionException ignore) {} 43 } 44 return ICallback.UNKNOWN_CODENAME; 45 } 46 } 47