use of com.android.sdklib.AndroidVersion in project android by JetBrains.
the class LaunchTaskRunner method run.
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setText(getTitle());
indicator.setIndeterminate(false);
LaunchStatus launchStatus = new ProcessHandlerLaunchStatus(myProcessHandler);
ConsolePrinter consolePrinter = new ProcessHandlerConsolePrinter(myProcessHandler);
List<ListenableFuture<IDevice>> listenableDeviceFutures = myDeviceFutures.get();
AndroidVersion androidVersion = myDeviceFutures.getDevices().size() == 1 ? myDeviceFutures.getDevices().get(0).getVersion() : null;
DebugConnectorTask debugSessionTask = myLaunchTasksProvider.getConnectDebuggerTask(launchStatus, androidVersion);
if (debugSessionTask != null && listenableDeviceFutures.size() != 1) {
launchStatus.terminateLaunch("Cannot launch a debug session on more than 1 device.");
}
if (debugSessionTask != null) {
// we need to copy over console output from the first console to the debug console once it is established
AndroidProcessText.attach(myProcessHandler);
}
DateFormat dateFormat = new SimpleDateFormat("MM/dd HH:mm:ss");
consolePrinter.stdout("\n" + dateFormat.format(new Date()) + ": Launching " + myConfigName);
for (ListenableFuture<IDevice> deviceFuture : listenableDeviceFutures) {
indicator.setText("Waiting for target device to come online");
IDevice device = waitForDevice(deviceFuture, indicator, launchStatus);
if (device == null) {
return;
}
List<LaunchTask> launchTasks = null;
try {
launchTasks = myLaunchTasksProvider.getTasks(device, launchStatus, consolePrinter);
} catch (com.intellij.execution.ExecutionException e) {
launchStatus.terminateLaunch(e.getMessage());
return;
} catch (IllegalStateException e) {
launchStatus.terminateLaunch(e.getMessage());
Logger.getInstance(LaunchTaskRunner.class).error(e);
return;
}
int totalDuration = listenableDeviceFutures.size() * getTotalDuration(launchTasks, debugSessionTask);
int elapsed = 0;
for (LaunchTask task : launchTasks) {
// perform each task
indicator.setText(task.getDescription());
if (!task.perform(device, launchStatus, consolePrinter)) {
myError = "Error " + task.getDescription();
launchStatus.terminateLaunch("Error while " + task.getDescription());
return;
}
// update progress
elapsed += task.getDuration();
indicator.setFraction((double) elapsed / totalDuration);
// check for cancellation via progress bar
if (indicator.isCanceled()) {
launchStatus.terminateLaunch("User cancelled launch");
return;
}
// check for cancellation via stop button
if (launchStatus.isLaunchTerminated()) {
return;
}
}
if (debugSessionTask != null) {
debugSessionTask.perform(myLaunchInfo, device, (ProcessHandlerLaunchStatus) launchStatus, (ProcessHandlerConsolePrinter) consolePrinter);
} else {
// we only need to inform the process handler if certain scenarios
if (// we are not doing a hot swap (in which case we are creating a new process)
myLaunchTasksProvider.createsNewProcess() && myProcessHandler instanceof AndroidProcessHandler) {
// we aren't debugging (in which case its a DebugProcessHandler)
((AndroidProcessHandler) myProcessHandler).addTargetDevice(device);
}
}
}
}
use of com.android.sdklib.AndroidVersion in project android by JetBrains.
the class ResourceTypeInspection method checkApiLevel.
private static void checkApiLevel(@NotNull PsiCall methodCall, @NotNull PsiMethod method, @NotNull ProblemsHolder holder, @NotNull PsiAnnotation annotation, @NotNull PsiAnnotation[] allMethodAnnotations, @NonNull PsiAnnotation[] allClassAnnotations) {
// Don't inherit these annotations; see for example b/32952309
PsiAnnotationOwner owner = annotation.getOwner();
if (owner == null || !(method.getModifierList().equals(owner) || method.getContainingClass() != null && owner.equals(method.getContainingClass().getModifierList()))) {
return;
}
// if there is another annotation specified on the method.
if (containsAnnotation(allClassAnnotations, annotation) && containsAnnotation(allMethodAnnotations, REQUIRES_API_ANNOTATION)) {
return;
}
AndroidFacet facet = AndroidFacet.getInstance(methodCall);
// already checked early on in the inspection visitor
assert facet != null;
AndroidVersion minSdkVersion = AndroidModuleInfo.get(facet).getMinSdkVersion();
PsiAnnotationMemberValue apiValue = annotation.findAttributeValue(ATTR_VALUE);
if (apiValue == null || (int) getLongValue(apiValue, 1) == 1) {
// Look for both value= and api= (they are aliases, though value of 1 is meaningless)
apiValue = annotation.findAttributeValue("api");
}
int api = (int) getLongValue(apiValue, 1);
if (api <= 1) {
return;
}
int minSdk = minSdkVersion.getFeatureLevel();
if (api <= minSdk) {
return;
}
int target = ApiDetector.getTargetApi(methodCall);
if (target != -1) {
if (api <= target) {
return;
}
}
if (LintIdeUtils.isSuppressed(methodCall, UNSUPPORTED)) {
return;
}
if (VersionChecks.isWithinVersionCheckConditional(methodCall, api)) {
return;
}
if (VersionChecks.isPrecededByVersionCheckExit(methodCall, api)) {
return;
}
PsiClass containingClass = method.getContainingClass();
String fqcn = containingClass != null ? containingClass.getQualifiedName() : "";
// Keep in sync with guessLintIssue
String message = String.format("Call requires API level %1$d (current min is %2$d): %3$s", api, minSdk, fqcn + '#' + method.getName());
LocalQuickFix versionCheck = new AndroidLintQuickFix.LocalFixWrapper(new AddTargetVersionCheckQuickFix(api), methodCall, methodCall);
LocalQuickFix addTargetApiQuickFix = new AndroidLintQuickFix.LocalFixWrapper(new AddTargetApiQuickFix(api, false, methodCall), methodCall, methodCall);
LocalQuickFix addRequiresApiQuickFix = new AndroidLintQuickFix.LocalFixWrapper(new AddTargetApiQuickFix(api, true, methodCall), methodCall, methodCall);
registerProblem(holder, UNSUPPORTED, methodCall, message, versionCheck, addRequiresApiQuickFix, addTargetApiQuickFix);
}
use of com.android.sdklib.AndroidVersion in project android by JetBrains.
the class AndroidSdkUtilsTest method testGetTargetLabel.
public void testGetTargetLabel() throws Exception {
IAndroidTarget platformTarget = new MockPlatformTarget(18, 2);
assertEquals("API 18: Android 4.3 (Jelly Bean)", AndroidSdkUtils.getTargetLabel(platformTarget));
IAndroidTarget unknownTarget = new MockPlatformTarget(-1, 1);
assertEquals("API -1", AndroidSdkUtils.getTargetLabel(unknownTarget));
IAndroidTarget anotherUnknownTarget = new MockPlatformTarget(100, 1);
assertEquals("API 100", AndroidSdkUtils.getTargetLabel(anotherUnknownTarget));
IAndroidTarget platformPreviewTarget = new MockPlatformTarget(100, 1) {
@NonNull
@Override
public AndroidVersion getVersion() {
return new AndroidVersion(100, "Z");
}
};
assertEquals("API 100+: platform r100", AndroidSdkUtils.getTargetLabel(platformPreviewTarget));
}
use of com.android.sdklib.AndroidVersion in project android by JetBrains.
the class AvdSummaryAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
AvdInfo info = getAvdInfo();
if (info == null) {
return;
}
HtmlBuilder htmlBuilder = new HtmlBuilder();
htmlBuilder.openHtmlBody();
htmlBuilder.addHtml("<br>Name: ").add(info.getName());
htmlBuilder.addHtml("<br>CPU/ABI: ").add(AvdInfo.getPrettyAbiType(info));
htmlBuilder.addHtml("<br>Path: ").add(info.getDataFolderPath());
if (info.getStatus() != AvdInfo.AvdStatus.OK) {
htmlBuilder.addHtml("<br>Error: ").add(info.getErrorMessage());
} else {
AndroidVersion version = info.getAndroidVersion();
htmlBuilder.addHtml("<br>Target: ").add(String.format("%1$s (API level %2$s)", info.getTag(), version.getApiString()));
// display some extra values.
Map<String, String> properties = info.getProperties();
String skin = properties.get(AvdManager.AVD_INI_SKIN_NAME);
if (skin != null) {
htmlBuilder.addHtml("<br>Skin: ").add(skin);
}
String sdcard = properties.get(AvdManager.AVD_INI_SDCARD_SIZE);
if (sdcard == null) {
sdcard = properties.get(AvdManager.AVD_INI_SDCARD_PATH);
}
if (sdcard != null) {
htmlBuilder.addHtml("<br>SD Card: ").add(sdcard);
}
String snapshot = properties.get(AvdManager.AVD_INI_SNAPSHOT_PRESENT);
if (snapshot != null) {
htmlBuilder.addHtml("<br>Snapshot: ").add(snapshot);
}
// display other hardware
HashMap<String, String> copy = new HashMap<String, String>(properties);
// remove stuff we already displayed (or that we don't want to display)
copy.remove(AvdManager.AVD_INI_ABI_TYPE);
copy.remove(AvdManager.AVD_INI_CPU_ARCH);
copy.remove(AvdManager.AVD_INI_SKIN_NAME);
copy.remove(AvdManager.AVD_INI_SKIN_PATH);
copy.remove(AvdManager.AVD_INI_SDCARD_SIZE);
copy.remove(AvdManager.AVD_INI_SDCARD_PATH);
copy.remove(AvdManager.AVD_INI_IMAGES_2);
if (copy.size() > 0) {
for (Map.Entry<String, String> entry : copy.entrySet()) {
htmlBuilder.addHtml("<br>").add(entry.getKey()).add(": ").add(entry.getValue());
}
}
}
htmlBuilder.closeHtmlBody();
String[] options = { "Copy to Clipboard and Close", "Close" };
int i = Messages.showDialog((Project) null, htmlBuilder.getHtml(), "Details for " + info.getName(), options, 0, AllIcons.General.InformationDialog);
if (i == 0) {
CopyPasteManager.getInstance().setContents(new StringSelection(StringUtil.stripHtml(htmlBuilder.getHtml(), true)));
}
}
use of com.android.sdklib.AndroidVersion in project android by JetBrains.
the class LayoutPullParserFactory method prefCapableTargetInstalled.
/**
* Returns if a target capable of rendering preferences file is found.
*/
private static boolean prefCapableTargetInstalled(@NotNull PsiFile file) {
Module module = ModuleUtilCore.findModuleForPsiElement(file);
if (module != null) {
AndroidPlatform platform = AndroidPlatform.getInstance(module);
if (platform != null) {
IAndroidTarget[] targets = platform.getSdkData().getTargets();
for (int i = targets.length - 1; i >= 0; i--) {
IAndroidTarget target = targets[i];
if (target.isPlatform()) {
AndroidVersion version = target.getVersion();
int featureLevel = version.getFeatureLevel();
if (featureLevel >= PREFERENCES_MIN_API) {
return true;
}
}
}
}
}
return false;
}
Aggregations