/* * Copyright (C) 2015 The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.databinding.tool.reflection; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import android.databinding.tool.util.L; import android.databinding.tool.util.Preconditions; import java.io.File; import java.io.InputStream; import java.util.HashMap; import java.util.Map; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; /** * Class that is used for SDK related stuff. *
* Must be initialized with the sdk location to work properly
*/
public class SdkUtil {
static ApiChecker sApiChecker;
static int sMinSdk;
public static void initialize(int minSdk, File sdkPath) {
sMinSdk = minSdk;
sApiChecker = new ApiChecker(new File(sdkPath.getAbsolutePath()
+ "/platform-tools/api/api-versions.xml"));
L.d("SdkUtil init, minSdk: %s", minSdk);
}
public static int getMinApi(ModelClass modelClass) {
return sApiChecker.getMinApi(modelClass.getJniDescription(), null);
}
public static int getMinApi(ModelMethod modelMethod) {
ModelClass declaringClass = modelMethod.getDeclaringClass();
Preconditions.checkNotNull(sApiChecker, "should've initialized api checker");
while (declaringClass != null) {
String classDesc = declaringClass.getJniDescription();
String methodDesc = modelMethod.getJniDescription();
int result = sApiChecker.getMinApi(classDesc, methodDesc);
L.d("checking method api for %s, class:%s method:%s. result: %d", modelMethod.getName(),
classDesc, methodDesc, result);
if (result > 0) {
return result;
}
declaringClass = declaringClass.getSuperclass();
}
return 1;
}
static class ApiChecker {
private Map