com.android.sdklib.AndroidVersion Java Examples

The following examples show how to use com.android.sdklib.AndroidVersion. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocalSdk.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Try to find a docs package at the given location.
 * Returns null if not found.
 */
private LocalDocPkgInfo scanDoc(File docFolder) {
    // Can we find some properties?
    Properties props = parseProperties(new File(docFolder, SdkConstants.FN_SOURCE_PROP));
    MajorRevision rev = PackageParserUtils.getPropertyMajor(props, PkgProps.PKG_REVISION);
    if (rev == null) {
        return null;
    }

    try {
        AndroidVersion vers = new AndroidVersion(props);
        LocalDocPkgInfo info = new LocalDocPkgInfo(this, docFolder, props, vers, rev);

        // To start with, a doc folder should have an "index.html" to be acceptable.
        // We don't actually check the content of the file.
        if (!mFileOp.isFile(new File(docFolder, "index.html"))) {
            info.appendLoadError("Missing index.html");
        }
        return info;

    } catch (AndroidVersionException e) {
        return null; // skip invalid or missing android version.
    }
}
 
Example #2
Source File: DdmlibDeviceTest.java    From bundletool with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void allowDowngrade_postL() throws Exception {
  when(mockDevice.getVersion()).thenReturn(new AndroidVersion(VersionCodes.LOLLIPOP));
  DdmlibDevice ddmlibDevice = new DdmlibDevice(mockDevice);

  ddmlibDevice.installApks(
      ImmutableList.of(APK_PATH), InstallOptions.builder().setAllowDowngrade(true).build());

  ArgumentCaptor<List<String>> extraArgsCaptor = ArgumentCaptor.forClass((Class) List.class);
  verify(mockDevice)
      .installPackages(
          eq(ImmutableList.of(APK_PATH.toFile())),
          anyBoolean(),
          extraArgsCaptor.capture(),
          anyLong(),
          any(TimeUnit.class));

  assertThat(extraArgsCaptor.getValue()).contains("-d");
}
 
Example #3
Source File: LocalSdk.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Retrieves information on a package identified by an {@link AndroidVersion}.
 * <p>
 * Note: don't use this for {@link PkgType#PKG_SYS_IMAGE} since there can be more than
 * one ABI and this method only returns a single package per filter type.
 *
 * @param filter  {@link PkgType#PKG_PLATFORM}, {@link PkgType#PKG_SAMPLE}
 *                or {@link PkgType#PKG_SOURCE}.
 * @param version The {@link AndroidVersion} specific for this package type.
 * @return An existing package information or null if not found.
 */
@Nullable
public LocalPkgInfo getPkgInfo(@NonNull PkgType filter, @NonNull AndroidVersion version) {
    assert filter == PkgType.PKG_PLATFORM ||
            filter == PkgType.PKG_SAMPLE ||
            filter == PkgType.PKG_SOURCE;

    for (LocalPkgInfo pkg : getPkgsInfos(filter)) {
        IPkgDesc d = pkg.getDesc();
        if (d.hasAndroidVersion() && d.getAndroidVersion().equals(version)) {
            return pkg;
        }
    }

    return null;
}
 
Example #4
Source File: SourcePackage.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@VisibleForTesting(visibility=Visibility.PRIVATE)
protected SourcePackage(
        SdkSource source,
        AndroidVersion platformVersion,
        int revision,
        Properties props,
        String localOsPath) {
    super(  source,                     //source
            props,                      //properties
            revision,                   //revision
            null,                       //license
            null,                       //description
            null,                       //descUrl
            localOsPath                 //archiveOsPath
            );
    mVersion = platformVersion;

    mPkgDesc = setDescriptions(PkgDesc.Builder.newSource(mVersion, (MajorRevision) getRevision())).create();
}
 
Example #5
Source File: SourcePackage.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new source package from the attributes and elements of the given XML node.
 * This constructor should throw an exception if the package cannot be created.
 *
 * @param source The {@link SdkSource} where this is loaded from.
 * @param packageNode The XML element being parsed.
 * @param nsUri The namespace URI of the originating XML document, to be able to deal with
 *          parameters that vary according to the originating XML schema.
 * @param licenses The licenses loaded from the XML originating document.
 */
public SourcePackage(
        SdkSource source,
        Node packageNode,
        String nsUri,
        Map<String,String> licenses) {
    super(source, packageNode, nsUri, licenses);

    int apiLevel =
        PackageParserUtils.getXmlInt(packageNode, SdkRepoConstants.NODE_API_LEVEL, 0);
    String codeName =
        PackageParserUtils.getXmlString(packageNode, SdkRepoConstants.NODE_CODENAME);
    if (codeName.isEmpty()) {
        codeName = null;
    }
    mVersion = new AndroidVersion(apiLevel, codeName);

    mPkgDesc = setDescriptions(PkgDesc.Builder.newSource(mVersion, (MajorRevision)getRevision())).create();
}
 
Example #6
Source File: LocalSdk.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
private void scanSources(File collectionDir, Collection<LocalPkgInfo> outCollection) {
    // The build-tool root folder contains a list of per-revision folders.
    for (File platformDir : mFileOp.listFiles(collectionDir)) {
        if (!shouldVisitDir(PkgType.PKG_SOURCE, platformDir)) {
            continue;
        }

        Properties props = parseProperties(new File(platformDir, SdkConstants.FN_SOURCE_PROP));
        MajorRevision rev = PackageParserUtils.getPropertyMajor(props, PkgProps.PKG_REVISION);
        if (rev == null) {
            continue; // skip, no revision
        }

        try {
            AndroidVersion vers = new AndroidVersion(props);

            LocalSourcePkgInfo pkgInfo =
                new LocalSourcePkgInfo(this, platformDir, props, vers, rev);
            outCollection.add(pkgInfo);
        } catch (AndroidVersionException e) {
            continue; // skip invalid or missing android version.
        }
    }
}
 
Example #7
Source File: AvdUISelector.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
public final void setAvdInfos(AvdInfo[] infos) {
    avdInfos = infos;
    DefaultTableModel tableModel = getTableModel();
    tableModel.setRowCount(0);
    for (AvdInfo info : infos) {
        AndroidVersion target = info.getAndroidVersion();
        if (target != null) {
            tableModel.addRow(new Object[]{
                info.getName(), target.getApiLevel(), target.getCodename(), target.getFeatureLevel()
            });
        } else {
            LOG.log(Level.INFO, "Not valid AvdInfo {0}", info);
        }
    }
    if (infos.length > 0) {
        avdsTable.setRowSelectionInterval(0, 0); // pre-select 1st row
    }
}
 
Example #8
Source File: AndroidVersionNode.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }

    if (obj instanceof AndroidVersionNode) {
        if (Objects.equals(this.version, ((AndroidVersionNode) obj).getVersion())) {
            return true;
        }
    }

    if (obj instanceof AndroidVersion) {
        if (version.equals(obj)) {
            return true;
        }
    }
    return false;
}
 
Example #9
Source File: PkgDesc.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new doc package descriptor.
 *
 * @param revision The revision of the doc package.
 * @return A {@link PkgDesc} describing this doc package.
 */
@NonNull
public static Builder newDoc(@NonNull AndroidVersion version,
                             @NonNull MajorRevision revision) {
    Builder p = new Builder(PkgType.PKG_DOC);
    p.mAndroidVersion = version;
    p.mMajorRevision = revision;
    p.mCustomIsUpdateFor = new IIsUpdateFor() {
        @Override
        public boolean isUpdateFor(PkgDesc thisPkgDesc, IPkgDesc existingDesc) {
            if (existingDesc == null ||
                    !thisPkgDesc.getType().equals(existingDesc.getType())) {
                return false;
            }

            // This package is unique in the SDK. It's an update if the API is newer
            // or the revision is newer for the same API.
            int diff = thisPkgDesc.getAndroidVersion().compareTo(
                      existingDesc.getAndroidVersion());
            return diff > 0 ||
                   (diff == 0 && thisPkgDesc.getMajorRevision().compareTo(
                                existingDesc.getMajorRevision()) > 0);
        }
    };
    return p;
}
 
Example #10
Source File: Project.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the resource folder.
 *
 * @return a file pointing to the resource folder, or null if the project
 *         does not contain any resources
 */
@NonNull
public List<File> getResourceFolders() {
    if (mResourceFolders == null) {
        List<File> folders = mClient.getResourceFolders(this);

        if (folders.size() == 1 && isAospFrameworksProject(mDir)) {
            // No manifest file for this project: just init the manifest values here
            mManifestMinSdk = mManifestTargetSdk = new AndroidVersion(HIGHEST_KNOWN_API, null);
            File folder = new File(folders.get(0), RES_FOLDER);
            if (!folder.exists()) {
                folders = Collections.emptyList();
            }
        }

        mResourceFolders = folders;
    }

    return mResourceFolders;

}
 
Example #11
Source File: SamplePackage.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new sample package from the attributes and elements of the given XML node.
 * This constructor should throw an exception if the package cannot be created.
 *
 * @param source The {@link SdkSource} where this is loaded from.
 * @param packageNode The XML element being parsed.
 * @param nsUri The namespace URI of the originating XML document, to be able to deal with
 *          parameters that vary according to the originating XML schema.
 * @param licenses The licenses loaded from the XML originating document.
 */
public SamplePackage(SdkSource source,
        Node packageNode,
        String nsUri,
        Map<String,String> licenses) {
    super(source, packageNode, nsUri, licenses);

    int apiLevel =
        PackageParserUtils.getXmlInt   (packageNode, SdkRepoConstants.NODE_API_LEVEL, 0);
    String codeName =
        PackageParserUtils.getXmlString(packageNode, SdkRepoConstants.NODE_CODENAME);
    if (codeName.isEmpty()) {
        codeName = null;
    }
    mVersion = new AndroidVersion(apiLevel, codeName);

    mMinApiLevel = PackageParserUtils.getXmlInt(packageNode,
                SdkRepoConstants.NODE_MIN_API_LEVEL,
                MIN_API_LEVEL_NOT_SPECIFIED);

    mPkgDesc = setDescriptions(PkgDesc.Builder
            .newSample(mVersion, (MajorRevision) getRevision(), getMinToolsRevision()))
            .create();
}
 
Example #12
Source File: DocPackage.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new doc package from the attributes and elements of the given XML node.
 * This constructor should throw an exception if the package cannot be created.
 *
 * @param source The {@link SdkSource} where this is loaded from.
 * @param packageNode The XML element being parsed.
 * @param nsUri The namespace URI of the originating XML document, to be able to deal with
 *          parameters that vary according to the originating XML schema.
 * @param licenses The licenses loaded from the XML originating document.
 */
public DocPackage(SdkSource source,
        Node packageNode,
        String nsUri,
        Map<String,String> licenses) {
    super(source, packageNode, nsUri, licenses);

    int apiLevel =
        PackageParserUtils.getXmlInt   (packageNode, SdkRepoConstants.NODE_API_LEVEL, 0);
    String codeName =
        PackageParserUtils.getXmlString(packageNode, SdkRepoConstants.NODE_CODENAME);
    if (codeName.isEmpty()) {
        codeName = null;
    }
    mVersion = new AndroidVersion(apiLevel, codeName);

    mPkgDesc = setDescriptions(
            PkgDesc.Builder.newDoc(mVersion, (MajorRevision) getRevision()))
            .create();
}
 
Example #13
Source File: SourcePackage.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting(visibility=Visibility.PRIVATE)
protected SourcePackage(
        SdkSource source,
        AndroidVersion platformVersion,
        int revision,
        Properties props,
        String localOsPath) {
    super(  source,                     //source
            props,                      //properties
            revision,                   //revision
            null,                       //license
            null,                       //description
            null,                       //descUrl
            localOsPath                 //archiveOsPath
            );
    mVersion = platformVersion;

    mPkgDesc = PkgDesc.Builder
            .newSource(mVersion,
                       (MajorRevision) getRevision())
            .setDescriptions(this)
            .create();
}
 
Example #14
Source File: LintGradleProject.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
@NonNull
public AndroidVersion getTargetSdkVersion() {
    if (mTargetSdkVersion == null) {
        ApiVersion targetSdk = mVariant.getMergedFlavor().getTargetSdkVersion();
        if (targetSdk == null) {
            ProductFlavor flavor = mProject.getDefaultConfig().getProductFlavor();
            targetSdk = flavor.getTargetSdkVersion();
        }
        if (targetSdk != null) {
            mTargetSdkVersion = LintUtils.convertVersion(targetSdk, mClient.getTargets());
        } else {
            mTargetSdkVersion = super.getTargetSdkVersion(); // from manifest
        }
    }

    return mTargetSdkVersion;
}
 
Example #15
Source File: SourcePackage.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new source package from the attributes and elements of the given XML node.
 * This constructor should throw an exception if the package cannot be created.
 *
 * @param source The {@link SdkSource} where this is loaded from.
 * @param packageNode The XML element being parsed.
 * @param nsUri The namespace URI of the originating XML document, to be able to deal with
 *          parameters that vary according to the originating XML schema.
 * @param licenses The licenses loaded from the XML originating document.
 */
public SourcePackage(
        SdkSource source,
        Node packageNode,
        String nsUri,
        Map<String,String> licenses) {
    super(source, packageNode, nsUri, licenses);

    int apiLevel =
        PackageParserUtils.getXmlInt(packageNode, SdkRepoConstants.NODE_API_LEVEL, 0);
    String codeName =
        PackageParserUtils.getXmlString(packageNode, SdkRepoConstants.NODE_CODENAME);
    if (codeName.length() == 0) {
        codeName = null;
    }
    mVersion = new AndroidVersion(apiLevel, codeName);

    mPkgDesc = PkgDesc.Builder
            .newSource(mVersion,
                       (MajorRevision) getRevision())
            .setDescriptions(this)
            .create();
}
 
Example #16
Source File: LintGradleProject.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
@NonNull
public AndroidVersion getMinSdkVersion() {
    if (mMinSdkVersion == null) {
        ApiVersion minSdk = mVariant.getMergedFlavor().getMinSdkVersion();
        if (minSdk == null) {
            ProductFlavor flavor = mProject.getDefaultConfig().getProductFlavor();
            minSdk = flavor.getMinSdkVersion();
        }
        if (minSdk != null) {
            mMinSdkVersion = LintUtils.convertVersion(minSdk, mClient.getTargets());
        } else {
            mMinSdkVersion = super.getMinSdkVersion(); // from manifest
        }
    }

    return mMinSdkVersion;
}
 
Example #17
Source File: PkgDesc.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new platform package descriptor.
 *
 * @param version The android version of the platform package.
 * @param revision The revision of the extra package.
 * @param minToolsRev An optional {@code min-tools-rev}.
 *                    Use {@link FullRevision#NOT_SPECIFIED} to indicate
 *                    there is no requirement.
 * @return A {@link PkgDesc} describing this platform package.
 */
@NonNull
public static Builder newPlatform(@NonNull AndroidVersion version,
                                  @NonNull MajorRevision revision,
                                  @NonNull FullRevision minToolsRev) {
    Builder p = new Builder(PkgType.PKG_PLATFORM);
    p.mAndroidVersion = version;
    p.mMajorRevision = revision;
    p.mMinToolsRev = minToolsRev;
    p.mCustomPath = new IGetPath() {
        @Override
        public String getPath(PkgDesc thisPkgDesc) {
            /** The "path" of a Platform is its Target Hash. */
            return AndroidTargetHash.getPlatformHashString(thisPkgDesc.getAndroidVersion());
        }
    };
    return p;
}
 
Example #18
Source File: SamplePackage.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
private SamplePackage(String archiveOsPath, Properties props) throws AndroidVersionException {
    super(null,                                   //source
          props,                                  //properties
          0,                                      //revision will be taken from props
          null,                                   //license
          null,                                   //description
          null,                                   //descUrl
          archiveOsPath                           //archiveOsPath
          );

    mVersion = new AndroidVersion(props);

    mMinApiLevel = getPropertyInt(props, PkgProps.SAMPLE_MIN_API_LEVEL,
                                         MIN_API_LEVEL_NOT_SPECIFIED);

    mPkgDesc = PkgDesc.Builder
            .newSample(mVersion,
                       (MajorRevision) getRevision(),
                       getMinToolsRevision())
            .setDescriptions(this)
            .create();
}
 
Example #19
Source File: LocalAddonSysImgPkgInfo.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public LocalAddonSysImgPkgInfo(@NonNull LocalSdk localSdk,
                          @NonNull File localDir,
                          @NonNull Properties sourceProps,
                          @NonNull AndroidVersion version,
                          @Nullable IdDisplay addonVendor,
                          @Nullable IdDisplay addonName,
                          @NonNull String abi,
                          @NonNull MajorRevision revision) {
    super(localSdk, localDir, sourceProps);
    mDesc = PkgDesc.Builder.newAddonSysImg(version, addonVendor, addonName, abi, revision)
                           .create();
}
 
Example #20
Source File: PkgDesc.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new platform system-image package descriptor.
 * <p/>
 * For system-images, {@link PkgDesc#getPath()} returns the ABI.
 *
 * @param version The android version of the system-image package.
 * @param tag The tag of the system-image package.
 * @param abi The ABI of the system-image package.
 * @param revision The revision of the system-image package.
 * @return A {@link PkgDesc} describing this system-image package.
 */
@NonNull
public static Builder newSysImg(@NonNull AndroidVersion version,
                                @NonNull IdDisplay tag,
                                @NonNull String abi,
                                @NonNull MajorRevision revision) {
    Builder p = new Builder(PkgType.PKG_SYS_IMAGE);
    p.mAndroidVersion = version;
    p.mMajorRevision  = revision;
    p.mTag            = tag;
    p.mPath           = abi;
    p.mVendor         = null;
    return p;
}
 
Example #21
Source File: DdmlibDeviceTest.java    From bundletool with Apache License 2.0 5 votes vote down vote up
@Test
public void allowTestOnly() throws Exception {
  when(mockDevice.getVersion()).thenReturn(new AndroidVersion(VersionCodes.KITKAT));
  DdmlibDevice ddmlibDevice = new DdmlibDevice(mockDevice);

  ddmlibDevice.installApks(
      ImmutableList.of(APK_PATH), InstallOptions.builder().setAllowTestOnly(true).build());

  verify(mockDevice).installPackage(eq(APK_PATH.toString()), anyBoolean(), eq("-t"));
}
 
Example #22
Source File: DdmlibDevice.java    From bundletool with Apache License 2.0 5 votes vote down vote up
@Override
public void installApks(ImmutableList<Path> apks, InstallOptions installOptions) {
  ImmutableList<File> apkFiles = apks.stream().map(Path::toFile).collect(toImmutableList());
  ImmutableList.Builder<String> extraArgs = ImmutableList.builder();
  if (installOptions.getAllowDowngrade()) {
    extraArgs.add("-d");
  }
  if (installOptions.getAllowTestOnly()) {
    extraArgs.add("-t");
  }

  try {
    if (getVersion()
        .isGreaterOrEqualThan(AndroidVersion.ALLOW_SPLIT_APK_INSTALLATION.getApiLevel())) {
      device.installPackages(
          apkFiles,
          installOptions.getAllowReinstall(),
          extraArgs.build(),
          installOptions.getTimeout().toMillis(),
          TimeUnit.MILLISECONDS);
    } else {
      device.installPackage(
          Iterables.getOnlyElement(apkFiles).toString(),
          installOptions.getAllowReinstall(),
          extraArgs.build().toArray(new String[0]));
    }
  } catch (InstallException e) {
    throw CommandExecutionException.builder()
        .withCause(e)
        .withInternalMessage("Installation of the app failed.")
        .build();
  }
}
 
Example #23
Source File: DocPackage.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Consider doc packages to be the same if they cover the same API level,
 * regardless of their revision number.
 */
@Override
public boolean sameItemAs(Package pkg) {
    if (pkg instanceof DocPackage) {
        AndroidVersion rev2 = ((DocPackage) pkg).getAndroidVersion();
        return this.getAndroidVersion().equals(rev2);
    }

    return false;
}
 
Example #24
Source File: PlatformPackage.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new platform package from the attributes and elements of the given XML node.
 * This constructor should throw an exception if the package cannot be created.
 *
 * @param source The {@link SdkSource} where this is loaded from.
 * @param packageNode The XML element being parsed.
 * @param nsUri The namespace URI of the originating XML document, to be able to deal with
 *          parameters that vary according to the originating XML schema.
 * @param licenses The licenses loaded from the XML originating document.
 */
public PlatformPackage(
        SdkSource source,
        Node packageNode,
        String nsUri,
        Map<String,String> licenses) {
    super(source, packageNode, nsUri, licenses);

    mVersionName =
        PackageParserUtils.getXmlString(packageNode, SdkRepoConstants.NODE_VERSION);

    int apiLevel =
        PackageParserUtils.getXmlInt   (packageNode, SdkRepoConstants.NODE_API_LEVEL, 0);
    String codeName =
        PackageParserUtils.getXmlString(packageNode, SdkRepoConstants.NODE_CODENAME);
    if (codeName.length() == 0) {
        codeName = null;
    }
    mVersion = new AndroidVersion(apiLevel, codeName);

    mIncludedAbi = PackageParserUtils.getOptionalXmlString(packageNode,
                                    SdkRepoConstants.NODE_ABI_INCLUDED);

    mLayoutlibVersion = new LayoutlibVersionMixin(packageNode);

    mPkgDesc = PkgDesc.Builder
            .newPlatform(mVersion,
                         (MajorRevision) getRevision(),
                         getMinToolsRevision())
            .setDescriptions(this)
            .create();
}
 
Example #25
Source File: DocPackage.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * <hr>
 * Doc packages are a bit different since there can only be one doc installed at
 * the same time.
 * <p/>
 * We now consider that docs for different APIs are NOT updates, e.g. doc for API N+1
 * is no longer considered an update for doc API N.
 * However docs that have the same API version (API level + codename) are considered
 * updates if they have a higher revision number (so 15 rev 2 is an update for 15 rev 1,
 * but is not an update for 14 rev 1.)
 */
@Override
public UpdateInfo canBeUpdatedBy(Package replacementPackage) {
    // check they are the same kind of object
    if (!(replacementPackage instanceof DocPackage)) {
        return UpdateInfo.INCOMPATIBLE;
    }

    DocPackage replacementDoc = (DocPackage)replacementPackage;

    AndroidVersion replacementVersion = replacementDoc.getAndroidVersion();

    // Check if they're the same exact (api and codename)
    if (replacementVersion.equals(mVersion)) {
        // exact same version, so check the revision level
        if (replacementPackage.getRevision().compareTo(this.getRevision()) > 0) {
            return UpdateInfo.UPDATE;
        }
    } else {
        // not the same version? we check if they have the same api level and the new one
        // is a preview, in which case it's also an update (since preview have the api level
        // of the _previous_ version.)
        if (replacementVersion.getApiLevel() == mVersion.getApiLevel() &&
                replacementVersion.isPreview()) {
            return UpdateInfo.UPDATE;
        }
    }

    // not an upgrade but not incompatible either.
    return UpdateInfo.NOT_UPDATE;
}
 
Example #26
Source File: PlatformPackage.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new platform package from the attributes and elements of the given XML node.
 * This constructor should throw an exception if the package cannot be created.
 *
 * @param source The {@link SdkSource} where this is loaded from.
 * @param packageNode The XML element being parsed.
 * @param nsUri The namespace URI of the originating XML document, to be able to deal with
 *          parameters that vary according to the originating XML schema.
 * @param licenses The licenses loaded from the XML originating document.
 */
public PlatformPackage(
        SdkSource source,
        Node packageNode,
        String nsUri,
        Map<String,String> licenses) {
    super(source, packageNode, nsUri, licenses);

    mVersionName =
        PackageParserUtils.getXmlString(packageNode, SdkRepoConstants.NODE_VERSION);

    int apiLevel =
        PackageParserUtils.getXmlInt   (packageNode, SdkRepoConstants.NODE_API_LEVEL, 0);
    String codeName =
        PackageParserUtils.getXmlString(packageNode, SdkRepoConstants.NODE_CODENAME);
    if (codeName.isEmpty()) {
        codeName = null;
    }
    mVersion = new AndroidVersion(apiLevel, codeName);

    mIncludedAbi = PackageParserUtils.getOptionalXmlString(packageNode,
            SdkRepoConstants.NODE_ABI_INCLUDED);

    mLayoutlibVersion = new LayoutlibVersionMixin(packageNode);

    mPkgDesc = setDescriptions(PkgDesc.Builder
            .newPlatform(mVersion, (MajorRevision) getRevision(), getMinToolsRevision()))
            .create();
}
 
Example #27
Source File: LintUtils.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Convert an {@link com.android.builder.model.ApiVersion} to a {@link
 * com.android.sdklib.AndroidVersion}. The chief problem here is that the {@link
 * com.android.builder.model.ApiVersion}, when using a codename, will not encode the
 * corresponding API level (it just reflects the string entered by the user in the gradle file)
 * so we perform a search here (since lint really wants to know the actual numeric API level)
 *
 * @param api     the api version to convert
 * @param targets if known, the installed targets (used to resolve platform codenames, only
 *                needed to resolve platforms newer than the tools since {@link
 *                com.android.sdklib.SdkVersionInfo} knows the rest)
 * @return the corresponding version
 */
@NonNull
public static AndroidVersion convertVersion(
        @NonNull ApiVersion api,
        @Nullable IAndroidTarget[] targets) {
    String codename = api.getCodename();
    if (codename != null) {
        AndroidVersion version = SdkVersionInfo.getVersion(codename, targets);
        if (version != null) {
            return version;
        }
        return new AndroidVersion(api.getApiLevel(), codename);
    }
    return new AndroidVersion(api.getApiLevel(), null);
}
 
Example #28
Source File: DdmlibDeviceTest.java    From bundletool with Apache License 2.0 5 votes vote down vote up
@Test
public void allowDowngrade_preL() throws Exception {
  when(mockDevice.getVersion()).thenReturn(new AndroidVersion(VersionCodes.KITKAT));
  DdmlibDevice ddmlibDevice = new DdmlibDevice(mockDevice);

  ddmlibDevice.installApks(
      ImmutableList.of(APK_PATH), InstallOptions.builder().setAllowDowngrade(true).build());

  verify(mockDevice).installPackage(eq(APK_PATH.toString()), anyBoolean(), eq("-d"));
}
 
Example #29
Source File: DdmlibDeviceTest.java    From bundletool with Apache License 2.0 5 votes vote down vote up
@Test
public void doesNotAllowDowngrade() throws Exception {
  when(mockDevice.getVersion()).thenReturn(new AndroidVersion(VersionCodes.KITKAT));
  DdmlibDevice ddmlibDevice = new DdmlibDevice(mockDevice);

  ddmlibDevice.installApks(
      ImmutableList.of(APK_PATH), InstallOptions.builder().setAllowDowngrade(false).build());

  // "-d" should *not* be passed as extra arg.
  verify(mockDevice).installPackage(eq(APK_PATH.toString()), anyBoolean() /*, no extra args */);
}
 
Example #30
Source File: LocalSourcePkgInfo.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public LocalSourcePkgInfo(@NonNull LocalSdk localSdk,
                          @NonNull File localDir,
                          @NonNull Properties sourceProps,
                          @NonNull AndroidVersion version,
                          @NonNull MajorRevision revision) {
    super(localSdk, localDir, sourceProps);
    mDesc = PkgDesc.Builder.newSource(version, revision).create();
}