try version = new AndroidVersion( apiLevel ); String hashString = AndroidTargetHash.getPlatformHashString( version ); IAndroidTarget target = sdkManager.getAndroidTargetManager( progressIndicator )
FakeDevice( String serialNumber, DeviceState state, int sdkVersion, ImmutableList<String> abis, int density, ImmutableList<String> features, ImmutableMap<String, String> properties) { this.state = state; this.androidVersion = new AndroidVersion(sdkVersion); this.abis = abis; this.density = density; this.serialNumber = serialNumber; this.properties = properties; this.features = features; }
@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")); }
@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"); } }
@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(), (String) isNull()); }
@NonNull @Override public AndroidVersion getVersion() { return new AndroidVersion(mApiLevel, null); }
@NonNull @Override public AndroidVersion getVersion() { return new AndroidVersion(mApiLevel, null); }
@Nullable public static AndroidVersion getAddOnVersion(@NonNull String hashString) { List<String> parts = Splitter.on(':').splitToList(hashString); if (parts.size() != 3) { return null; } String apiLevelPart = parts.get(2); try { int apiLevel = Integer.parseInt(apiLevelPart); return new AndroidVersion(apiLevel, null); } catch (NumberFormatException e) { return null; } }
/** * Creates an {@link AndroidVersion} from {@link Properties}, with default values if the {@link * Properties} object doesn't contain the expected values. <p>The {@link Properties} is * expected to have been filled with the deleted * <code>saveProperties(AndroidVersion, Properties)</code>}. */ @NonNull public static AndroidVersion create(@Nullable Properties properties, int defaultApiLevel, @Nullable String defaultCodeName) { if (properties == null) { return new AndroidVersion(defaultApiLevel, defaultCodeName); } else { int api = Integer.parseInt(properties.getProperty(PkgProps.VERSION_API_LEVEL, Integer.toString(defaultApiLevel))); String codeName = properties.getProperty(PkgProps.VERSION_CODENAME, defaultCodeName); return new AndroidVersion(api, codeName); } }
sCurrentVersion = new AndroidVersion(sdkVersion, null);
@NonNull public AndroidVersion getAndroidVersion() { String apiStr = getProperties().get(AvdManager.AVD_INI_ANDROID_API); String codename = getProperties().get(AvdManager.AVD_INI_ANDROID_CODENAME); int api = 1; if (!Strings.isNullOrEmpty(apiStr)) { try { api = Integer.parseInt(apiStr); } catch (NumberFormatException e) { // continue with the default } } return new AndroidVersion(api, codename); }
/** * Returns the resource folders. * * @return a list of files pointing to the resource folders, which might be empty if the project * does not provide any resources. */ @NonNull public List<File> getResourceFolders() { if (resourceFolders == null) { List<File> folders = client.getResourceFolders(this); if (folders.size() == 1 && isAospFrameworksRelatedProject(dir)) { // No manifest file for this project: just init the manifest values here manifestMinSdk = manifestTargetSdk = new AndroidVersion(HIGHEST_KNOWN_API, null); File folder = new File(folders.get(0), RES_FOLDER); if (!folder.exists()) { folders = Collections.emptyList(); } } resourceFolders = folders; } return resourceFolders; }
/** * Creates an {@link AndroidVersion} from {@link Properties}. The properties must contain * android version information, or an exception will be thrown. * * @throws AndroidVersion.AndroidVersionException if no Android version information have been * found */ @NonNull public static AndroidVersion create(@NonNull Properties properties) throws AndroidVersion.AndroidVersionException { Exception error = null; String apiLevel = properties.getProperty(PkgProps.VERSION_API_LEVEL, null/*defaultValue*/); if (apiLevel != null) { try { int api = Integer.parseInt(apiLevel); String codeName = properties.getProperty(PkgProps.VERSION_CODENAME, null/*defaultValue*/); return new AndroidVersion(api, codeName); } catch (NumberFormatException e) { error = e; } } // reaching here means the Properties object did not contain the apiLevel which is required. throw new AndroidVersion.AndroidVersionException(PkgProps.VERSION_API_LEVEL + " not found!", error); } }
/** * Convenience method to create an {@link AndroidVersion} with the information from the given * {@link ApiDetailsType}. */ @NonNull default AndroidVersion getAndroidVersion() { return new AndroidVersion(getApiLevel(), getCodename()); }
@NonNull @Override public AndroidVersion getVersion() { if (mVersion != null) { return mVersion; } try { String buildApi = getProperty(PROP_BUILD_API_LEVEL); if (buildApi == null) { return AndroidVersion.DEFAULT; } int api = Integer.parseInt(buildApi); String codeName = getProperty(PROP_BUILD_CODENAME); mVersion = new AndroidVersion(api, codeName); return mVersion; } catch (Exception e) { return AndroidVersion.DEFAULT; } }
/** * 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); }
/** * 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 RemoteSourcePkgInfo(SdkSource source, Node packageNode, String nsUri, Map<String, String> licenses) { super(source, packageNode, nsUri, licenses); int apiLevel = RemotePackageParserUtils .getXmlInt(packageNode, SdkRepoConstants.NODE_API_LEVEL, 0); String codeName = RemotePackageParserUtils .getXmlString(packageNode, SdkRepoConstants.NODE_CODENAME); if (codeName.length() == 0) { codeName = null; } AndroidVersion version = new AndroidVersion(apiLevel, codeName); PkgDesc.Builder pkgDescBuilder = PkgDesc.Builder.newSource(version, getRevision()); pkgDescBuilder.setDescriptionShort( createShortDescription(mListDisplay, getRevision(), version, isObsolete())); pkgDescBuilder.setDescriptionUrl(getDescUrl()); pkgDescBuilder.setListDisplay(createListDescription(mListDisplay, version, isObsolete())); pkgDescBuilder.setIsObsolete(isObsolete()); pkgDescBuilder.setLicense(getLicense()); mPkgDesc = pkgDescBuilder.create(); }
/** * 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 RemoteDocPkgInfo(SdkSource source, Node packageNode, String nsUri, Map<String, String> licenses) { super(source, packageNode, nsUri, licenses); int apiLevel = RemotePackageParserUtils .getXmlInt(packageNode, SdkRepoConstants.NODE_API_LEVEL, 0); String codeName = RemotePackageParserUtils .getXmlString(packageNode, SdkRepoConstants.NODE_CODENAME); if (codeName.length() == 0) { codeName = null; } AndroidVersion version = new AndroidVersion(apiLevel, codeName); PkgDesc.Builder pkgDescBuilder = PkgDesc.Builder.newDoc(version, getRevision()); pkgDescBuilder.setDescriptionShort( createShortDescription(mListDisplay, getRevision(), version, isObsolete())); pkgDescBuilder.setDescriptionUrl(getDescUrl()); pkgDescBuilder.setListDisplay(createListDescription(mListDisplay, version, isObsolete())); pkgDescBuilder.setIsObsolete(isObsolete()); pkgDescBuilder.setLicense(getLicense()); mPkgDesc = pkgDescBuilder.create(); }
codeName = null; AndroidVersion version = new AndroidVersion(apiLevel, codeName);
codeName = null; AndroidVersion version = new AndroidVersion(apiLevel, codeName);