use of com.android.sdklib.AndroidVersion in project android by JetBrains.
the class MultiUserUtilsTest method createMockDevice.
@NotNull
private static IDevice createMockDevice(@NotNull String pmListUsersOutput, @NotNull String amCurrentUserOutput) throws Exception {
IDevice device = mock(IDevice.class);
when(device.getVersion()).thenReturn(new AndroidVersion(23, null));
doAnswer(invocation -> {
String cmd = (String) invocation.getArguments()[0];
String answer = null;
if (cmd.equals("pm list users")) {
answer = pmListUsersOutput;
} else if (cmd.equals("am get-current-user")) {
answer = amCurrentUserOutput;
} else {
fail("Mock device does not support shell command: " + cmd);
}
byte[] bytes = answer.getBytes(Charsets.UTF_8);
IShellOutputReceiver receiver = (IShellOutputReceiver) invocation.getArguments()[1];
receiver.addOutput(bytes, 0, bytes.length);
receiver.flush();
return null;
}).when(device).executeShellCommand(anyString(), anyObject());
return device;
}
use of com.android.sdklib.AndroidVersion in project android by JetBrains.
the class InstantRunBuilderTest method fullBuildIfAppNotRunningOnApiBelow21.
@Test
public void fullBuildIfAppNotRunningOnApiBelow21() throws Exception {
myDumpsysPackageOutput = DUMPSYS_PACKAGE_EXISTS;
myDeviceBuildTimetamp = "100";
myAppInForeground = false;
when(myDevice.getVersion()).thenReturn(new AndroidVersion(20, null));
setUpDeviceForHotSwap();
myBuilder.build(myTaskRunner, Collections.emptyList());
assertEquals("gradlew -Pandroid.optional.compilation=INSTANT_DEV,FULL_APK -Pandroid.injected.coldswap.mode=MULTIAPK :app:assemble", myTaskRunner.getBuilds());
}
use of com.android.sdklib.AndroidVersion in project android by JetBrains.
the class AndroidVersionsInfoTest method withPreviewAndroidTarget.
/**
* For preview Android target versions, the Build API should be the same as the preview
*/
@Test
public void withPreviewAndroidTarget() {
MockPlatformTarget androidTarget = new MockPlatformTarget(PREVIEW_VERSION, 0) {
@NonNull
@Override
public AndroidVersion getVersion() {
return new AndroidVersion(PREVIEW_VERSION - 1, "TEST_CODENAME");
}
};
AndroidVersionsInfo.VersionItem versionItem = myMockAndroidVersionsInfo.new VersionItem(androidTarget);
assertEquals(PREVIEW_VERSION, versionItem.getApiLevel());
assertEquals(PREVIEW_VERSION, versionItem.getBuildApiLevel());
}
use of com.android.sdklib.AndroidVersion in project kotlin by JetBrains.
the class Project method initialize.
protected void initialize() {
// Default initialization: Use ADT/ant style project.properties file
try {
// Read properties file and initialize library state
Properties properties = new Properties();
File propFile = new File(mDir, PROJECT_PROPERTIES);
if (propFile.exists()) {
BufferedInputStream is = new BufferedInputStream(new FileInputStream(propFile));
try {
properties.load(is);
String value = properties.getProperty(ANDROID_LIBRARY);
mLibrary = VALUE_TRUE.equals(value);
String proguardPath = properties.getProperty(PROGUARD_CONFIG);
if (proguardPath != null) {
mProguardPath = proguardPath;
}
mMergeManifests = VALUE_TRUE.equals(properties.getProperty(//$NON-NLS-1$
"manifestmerger.enabled"));
//$NON-NLS-1$
String target = properties.getProperty("target");
if (target != null) {
int index = target.lastIndexOf('-');
if (index == -1) {
index = target.lastIndexOf(':');
}
if (index != -1) {
String versionString = target.substring(index + 1);
try {
mBuildSdk = Integer.parseInt(versionString);
} catch (NumberFormatException nufe) {
mClient.log(Severity.WARNING, null, "Unexpected build target format: %1$s", target);
}
}
}
for (int i = 1; i < 1000; i++) {
String key = String.format(ANDROID_LIBRARY_REFERENCE_FORMAT, i);
String library = properties.getProperty(key);
if (library == null || library.isEmpty()) {
// No holes in the numbering sequence is allowed
break;
}
File libraryDir = new File(mDir, library).getCanonicalFile();
if (mDirectLibraries == null) {
mDirectLibraries = new ArrayList<Project>();
}
// Adjust the reference dir to be a proper prefix path of the
// library dir
File libraryReferenceDir = mReferenceDir;
if (!libraryDir.getPath().startsWith(mReferenceDir.getPath())) {
// Symlinks etc might have been resolved, so do those to
// the reference dir as well
libraryReferenceDir = libraryReferenceDir.getCanonicalFile();
if (!libraryDir.getPath().startsWith(mReferenceDir.getPath())) {
File file = libraryReferenceDir;
while (file != null && !file.getPath().isEmpty()) {
if (libraryDir.getPath().startsWith(file.getPath())) {
libraryReferenceDir = file;
break;
}
file = file.getParentFile();
}
}
}
try {
Project libraryPrj = mClient.getProject(libraryDir, libraryReferenceDir);
mDirectLibraries.add(libraryPrj);
// By default, we don't report issues in inferred library projects.
// The driver will set report = true for those library explicitly
// requested.
libraryPrj.setReportIssues(false);
} catch (CircularDependencyException e) {
e.setProject(this);
e.setLocation(Location.create(propFile));
throw e;
}
}
} finally {
try {
Closeables.close(is, true);
} catch (IOException e) {
// cannot happen
}
}
}
} catch (IOException ioe) {
mClient.log(ioe, "Initializing project state");
}
if (mDirectLibraries != null) {
mDirectLibraries = Collections.unmodifiableList(mDirectLibraries);
} else {
mDirectLibraries = Collections.emptyList();
}
if (isAospBuildEnvironment()) {
if (isAospFrameworksRelatedProject(mDir)) {
// No manifest file for this project: just init the manifest values here
mManifestMinSdk = mManifestTargetSdk = new AndroidVersion(HIGHEST_KNOWN_API, null);
} else if (mBuildSdk == -1) {
// only set BuildSdk for projects other than frameworks and
// the ones that don't have one set in project.properties.
mBuildSdk = getClient().getHighestKnownApiLevel();
}
}
}
Aggregations