Search in sources :

Example 31 with AndroidVersion

use of com.android.sdklib.AndroidVersion in project kotlin by JetBrains.

the class PermissionRequirement method appliesTo.

/**
     * Returns false if this permission does not apply given the specified minimum and
     * target sdk versions
     *
     * @param minSdkVersion the minimum SDK version
     * @param targetSdkVersion the target SDK version
     * @return true if this permission requirement applies for the given versions
     */
/**
     * Returns false if this permission does not apply given the specified minimum and target
     * sdk versions
     *
     * @param available   the permission holder which also knows the min and target versions
     * @return true if this permission requirement applies for the given versions
     */
protected boolean appliesTo(@NonNull PermissionHolder available) {
    if (firstApi == 0) {
        // initialized?
        // initialized, not specified
        firstApi = -1;
        // Not initialized
        String range = getAnnotationStringValue(annotation, "apis");
        if (range != null) {
            // Currently only support the syntax "a..b" where a and b are inclusive end points
            // and where "a" and "b" are optional
            int index = range.indexOf("..");
            if (index != -1) {
                try {
                    if (index > 0) {
                        firstApi = Integer.parseInt(range.substring(0, index));
                    } else {
                        firstApi = 1;
                    }
                    if (index + 2 < range.length()) {
                        lastApi = Integer.parseInt(range.substring(index + 2));
                    } else {
                        lastApi = Integer.MAX_VALUE;
                    }
                } catch (NumberFormatException ignore) {
                }
            }
        }
    }
    if (firstApi != -1) {
        AndroidVersion minSdkVersion = available.getMinSdkVersion();
        if (minSdkVersion.getFeatureLevel() > lastApi) {
            return false;
        }
        AndroidVersion targetSdkVersion = available.getTargetSdkVersion();
        if (targetSdkVersion.getFeatureLevel() < firstApi) {
            return false;
        }
    }
    return true;
}
Also used : AndroidVersion(com.android.sdklib.AndroidVersion)

Example 32 with AndroidVersion

use of com.android.sdklib.AndroidVersion in project kotlin by JetBrains.

the class ApiDetector method getMinSdk.

protected int getMinSdk(Context context) {
    if (mMinApi == -1) {
        AndroidVersion minSdkVersion = context.getMainProject().getMinSdkVersion();
        mMinApi = minSdkVersion.getFeatureLevel();
    }
    return mMinApi;
}
Also used : AndroidVersion(com.android.sdklib.AndroidVersion)

Example 33 with AndroidVersion

use of com.android.sdklib.AndroidVersion in project android by JetBrains.

the class AndroidSdksTest method createTargetWithApiLevel.

@NotNull
private static IAndroidTarget createTargetWithApiLevel(int apiLevel) {
    AndroidVersion version = new AndroidVersion(apiLevel, null);
    IAndroidTarget target = mock(IAndroidTarget.class);
    when(target.getVersion()).thenReturn(version);
    return target;
}
Also used : IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidVersion(com.android.sdklib.AndroidVersion) NotNull(org.jetbrains.annotations.NotNull)

Example 34 with AndroidVersion

use of com.android.sdklib.AndroidVersion in project android by JetBrains.

the class SdkComponentSource method getStatuses.

@NotNull
@Override
public Collection<? extends Pair<String, String>> getStatuses() {
    Revision toolsRevision = null;
    LocalPackage toolsPackage = getRepoManager().getPackages().getLocalPackages().get(SdkConstants.FD_TOOLS);
    if (toolsPackage != null) {
        toolsRevision = toolsPackage.getVersion();
    }
    Revision platformRevision = null;
    AndroidVersion platformVersion = null;
    for (LocalPackage info : getRepoManager().getPackages().getLocalPackagesForPrefix(SdkConstants.FD_PLATFORMS)) {
        if (info.getTypeDetails() instanceof DetailsTypes.PlatformDetailsType) {
            DetailsTypes.PlatformDetailsType details = (DetailsTypes.PlatformDetailsType) info.getTypeDetails();
            AndroidVersion testVersion = new AndroidVersion(details.getApiLevel(), details.getCodename());
            if (platformVersion == null || platformVersion.compareTo(testVersion) < 0) {
                platformRevision = info.getVersion();
                platformVersion = testVersion;
            }
        }
    }
    List<Pair<String, String>> result = Lists.newArrayList();
    if (toolsRevision != null) {
        result.add(Pair.create("Android SDK Tools:", toolsRevision.toString()));
    }
    if (platformVersion != null) {
        result.add(Pair.create("Android Platform Version:", String.format("%1$s revision %2$s", platformVersion.getCodename() != null ? platformVersion.getCodename() : SdkVersionInfo.getAndroidName(platformVersion.getApiLevel()), platformRevision)));
    }
    return result;
}
Also used : Revision(com.android.repository.Revision) DetailsTypes(com.android.sdklib.repository.meta.DetailsTypes) AndroidVersion(com.android.sdklib.AndroidVersion) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 35 with AndroidVersion

use of com.android.sdklib.AndroidVersion in project android by JetBrains.

the class ApiLevelColumnInfo method valueOf.

@Nullable
@Override
public String valueOf(UpdaterTreeNode node) {
    AndroidVersion version;
    if (node instanceof DetailsTreeNode) {
        DetailsTypes.ApiDetailsType details = (DetailsTypes.ApiDetailsType) ((DetailsTreeNode) node).getPackage().getTypeDetails();
        version = new AndroidVersion(details.getApiLevel(), details.getCodename());
    } else if (node instanceof SummaryTreeNode) {
        version = ((SummaryTreeNode) node).getVersion();
    } else {
        return "";
    }
    if (version != null) {
        return version.getApiString();
    } else {
        return "Unknown";
    }
}
Also used : DetailsTypes(com.android.sdklib.repository.meta.DetailsTypes) AndroidVersion(com.android.sdklib.AndroidVersion) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AndroidVersion (com.android.sdklib.AndroidVersion)89 Test (org.junit.Test)21 NotNull (org.jetbrains.annotations.NotNull)14 IAndroidTarget (com.android.sdklib.IAndroidTarget)12 IDevice (com.android.ddmlib.IDevice)11 Nullable (org.jetbrains.annotations.Nullable)9 MockPlatformTarget (com.android.sdklib.internal.androidTarget.MockPlatformTarget)8 Module (com.intellij.openapi.module.Module)8 File (java.io.File)8 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)8 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)8 DetailsTypes (com.android.sdklib.repository.meta.DetailsTypes)6 Project (com.intellij.openapi.project.Project)5 Abi (com.android.sdklib.devices.Abi)4 InstantRunGradleSupport (com.android.tools.idea.fd.gradle.InstantRunGradleSupport)4 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)4 OutputFile (com.android.build.OutputFile)3 TypeDetails (com.android.repository.impl.meta.TypeDetails)3 AvdInfo (com.android.sdklib.internal.avd.AvdInfo)3 ModelWizardDialog (com.android.tools.idea.wizard.model.ModelWizardDialog)3