Search in sources :

Example 36 with Revision

use of com.android.repository.Revision in project android by JetBrains.

the class PatchInstallerFactoryTest method cantHandleNoPatchOnWindowsWithNoPatcher.

@Test
public void cantHandleNoPatchOnWindowsWithNoPatcher() {
    myFileOp.setIsWindows(true);
    FakeRemotePackage remote = new FakeRemotePackage("foo");
    remote.setRevision(new Revision(2));
    FakeLocalPackage local = new FakeLocalPackage("foo");
    local.setRevision(new Revision(1));
    myRepositoryPackages.setLocalPkgInfos(ImmutableList.of(local));
    myRepositoryPackages.setRemotePkgInfos(ImmutableList.of(remote));
    assertFalse(myInstallerFactory.canHandlePackage(remote, myRepoManager, myFileOp));
}
Also used : FakeRemotePackage(com.android.repository.testframework.FakePackage.FakeRemotePackage) FakeLocalPackage(com.android.repository.testframework.FakePackage.FakeLocalPackage) Revision(com.android.repository.Revision) Test(org.junit.Test)

Example 37 with Revision

use of com.android.repository.Revision in project kotlin by JetBrains.

the class ApiDetector method visitAttribute.

@Override
public void visitAttribute(@NonNull XmlContext context, @NonNull Attr attribute) {
    if (mApiDatabase == null) {
        return;
    }
    int attributeApiLevel = -1;
    if (ANDROID_URI.equals(attribute.getNamespaceURI())) {
        String name = attribute.getLocalName();
        if (!(name.equals(ATTR_LAYOUT_WIDTH) && !(name.equals(ATTR_LAYOUT_HEIGHT)) && !(name.equals(ATTR_ID)))) {
            //$NON-NLS-1$
            String owner = "android/R$attr";
            attributeApiLevel = mApiDatabase.getFieldVersion(owner, name);
            int minSdk = getMinSdk(context);
            if (attributeApiLevel > minSdk && attributeApiLevel > context.getFolderVersion() && attributeApiLevel > getLocalMinSdk(attribute.getOwnerElement()) && !isBenignUnusedAttribute(name) && !isAlreadyWarnedDrawableFile(context, attribute, attributeApiLevel)) {
                if (RtlDetector.isRtlAttributeName(name) || ATTR_SUPPORTS_RTL.equals(name)) {
                    // the resources differently.
                    if (name.equals(ATTR_PADDING_START)) {
                        BuildToolInfo buildToolInfo = context.getProject().getBuildTools();
                        Revision buildTools = buildToolInfo != null ? buildToolInfo.getRevision() : null;
                        boolean isOldBuildTools = buildTools != null && (buildTools.getMajor() < 23 || buildTools.getMajor() == 23 && buildTools.getMinor() == 0 && buildTools.getMicro() == 0);
                        if ((buildTools == null || isOldBuildTools) && viewMayExtendTextView(attribute.getOwnerElement())) {
                            Location location = context.getLocation(attribute);
                            String message = String.format("Attribute `%1$s` referenced here can result in a crash on " + "some specific devices older than API %2$d " + "(current min is %3$d)", attribute.getLocalName(), attributeApiLevel, minSdk);
                            //noinspection VariableNotUsedInsideIf
                            if (buildTools != null) {
                                message = String.format("Upgrade `buildToolsVersion` from " + "`%1$s` to at least `23.0.1`; if not, ", buildTools.toShortString()) + Character.toLowerCase(message.charAt(0)) + message.substring(1);
                            }
                            context.report(UNSUPPORTED, attribute, location, message);
                        }
                    }
                } else {
                    Location location = context.getLocation(attribute);
                    String message = String.format("Attribute `%1$s` is only used in API level %2$d and higher " + "(current min is %3$d)", attribute.getLocalName(), attributeApiLevel, minSdk);
                    context.report(UNUSED, attribute, location, message);
                }
            }
        }
        // since this will work just fine. See issue 67440 for more.
        if (name.equals("divider")) {
            return;
        }
    }
    String value = attribute.getValue();
    String owner = null;
    String name = null;
    String prefix;
    if (value.startsWith(ANDROID_PREFIX)) {
        prefix = ANDROID_PREFIX;
    } else if (value.startsWith(ANDROID_THEME_PREFIX)) {
        prefix = ANDROID_THEME_PREFIX;
        if (context.getResourceFolderType() == ResourceFolderType.DRAWABLE) {
            int api = 21;
            int minSdk = getMinSdk(context);
            if (api > minSdk && api > context.getFolderVersion() && api > getLocalMinSdk(attribute.getOwnerElement())) {
                Location location = context.getLocation(attribute);
                String message;
                message = String.format("Using theme references in XML drawables requires API level %1$d " + "(current min is %2$d)", api, minSdk);
                context.report(UNSUPPORTED, attribute, location, message);
                // API level 11
                return;
            }
        }
    } else if (value.startsWith(PREFIX_ANDROID) && ATTR_NAME.equals(attribute.getName()) && TAG_ITEM.equals(attribute.getOwnerElement().getTagName()) && attribute.getOwnerElement().getParentNode() != null && TAG_STYLE.equals(attribute.getOwnerElement().getParentNode().getNodeName())) {
        //$NON-NLS-1$
        owner = "android/R$attr";
        name = value.substring(PREFIX_ANDROID.length());
        prefix = null;
    } else if (value.startsWith(PREFIX_ANDROID) && ATTR_PARENT.equals(attribute.getName()) && TAG_STYLE.equals(attribute.getOwnerElement().getTagName())) {
        //$NON-NLS-1$
        owner = "android/R$style";
        name = getResourceFieldName(value.substring(PREFIX_ANDROID.length()));
        prefix = null;
    } else {
        return;
    }
    if (owner == null) {
        // Convert @android:type/foo into android/R$type and "foo"
        int index = value.indexOf('/', prefix.length());
        if (index != -1) {
            owner = //$NON-NLS-1$
            "android/R$" + value.substring(prefix.length(), index);
            name = getResourceFieldName(value.substring(index + 1));
        } else if (value.startsWith(ANDROID_THEME_PREFIX)) {
            //$NON-NLS-1$
            owner = "android/R$attr";
            name = value.substring(ANDROID_THEME_PREFIX.length());
        } else {
            return;
        }
    }
    int api = mApiDatabase.getFieldVersion(owner, name);
    int minSdk = getMinSdk(context);
    if (api > minSdk && api > context.getFolderVersion() && api > getLocalMinSdk(attribute.getOwnerElement())) {
        // used only for designtime previews
        if (TOOLS_URI.equals(attribute.getNamespaceURI())) {
            return;
        }
        //noinspection StatementWithEmptyBody
        if (attributeApiLevel >= api) {
        // The attribute will only be *read* on platforms >= attributeApiLevel.
        // If this isn't lower than the attribute reference's API level, it
        // won't be a problem
        } else if (attributeApiLevel > minSdk) {
            String attributeName = attribute.getLocalName();
            Location location = context.getLocation(attribute);
            String message = String.format("`%1$s` requires API level %2$d (current min is %3$d), but note " + "that attribute `%4$s` is only used in API level %5$d " + "and higher", name, api, minSdk, attributeName, attributeApiLevel);
            context.report(UNSUPPORTED, attribute, location, message);
        } else {
            Location location = context.getLocation(attribute);
            String message = String.format("`%1$s` requires API level %2$d (current min is %3$d)", value, api, minSdk);
            context.report(UNSUPPORTED, attribute, location, message);
        }
    }
}
Also used : Revision(com.android.repository.Revision) BuildToolInfo(com.android.sdklib.BuildToolInfo)

Aggregations

Revision (com.android.repository.Revision)37 Test (org.junit.Test)11 FakeRemotePackage (com.android.repository.testframework.FakePackage.FakeRemotePackage)10 FakeLocalPackage (com.android.repository.testframework.FakePackage.FakeLocalPackage)9 File (java.io.File)8 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)6 UpdatableExternalComponent (com.intellij.ide.externalComponents.UpdatableExternalComponent)6 Nullable (org.jetbrains.annotations.Nullable)6 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 LocalPackage (com.android.repository.api.LocalPackage)4 BuildToolInfo (com.android.sdklib.BuildToolInfo)4 StudioProgressIndicatorAdapter (com.android.tools.idea.sdk.progress.StudioProgressIndicatorAdapter)4 NotNull (org.jetbrains.annotations.NotNull)4 Installer (com.android.repository.api.Installer)3 FakeDownloader (com.android.repository.testframework.FakeDownloader)3 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)3 ExternalUpdate (com.intellij.openapi.updateSettings.impl.ExternalUpdate)3 UpdateSettings (com.intellij.openapi.updateSettings.impl.UpdateSettings)3 VisibleForTesting (com.android.annotations.VisibleForTesting)2 GradleVersion (com.android.ide.common.repository.GradleVersion)2