use of com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator in project android by JetBrains.
the class InstallNdkHyperlink method execute.
@Override
protected void execute(@NotNull Project project) {
File path = getNdkPath(project);
if (path != null) {
// Try to install SDK in local.properties.
SelectNdkDialog dialog = new SelectNdkDialog(path.getPath(), false, true);
dialog.setModal(true);
if (dialog.showAndGet() && setNdkPath(project, dialog.getAndroidNdkPath())) {
// Saving NDK path is successful.
GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, null);
}
return;
}
// There is no path. Try installing from SDK.
AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
StudioLoggerProgressIndicator progressIndicator = new StudioLoggerProgressIndicator(getClass());
RepoManager sdkManager = sdkHandler.getSdkManager(progressIndicator);
StudioProgressRunner progressRunner = new StudioProgressRunner(false, /* backgroundable */
false, /* cancellable */
"Loading Remote SDK", true, /* in UI thread */
project);
RepoManager.RepoLoadedCallback onComplete = packages -> {
Map<String, RemotePackage> remotePackages = packages.getRemotePackages();
RemotePackage ndkPackage = remotePackages.get(FD_NDK);
if (ndkPackage != null) {
ModelWizardDialog dialog = createDialogForPaths(project, ImmutableList.of(ndkPackage.getPath()));
if (dialog != null && dialog.showAndGet()) {
GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, null);
}
return;
}
notifyNdkPackageNotFound(project);
};
Runnable onError = () -> notifyNdkPackageNotFound(project);
sdkManager.load(DEFAULT_EXPIRATION_PERIOD_MS, null, ImmutableList.of(onComplete), ImmutableList.of(onError), progressRunner, new StudioDownloader(), StudioSettingsController.getInstance(), false);
}
use of com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator in project android by JetBrains.
the class SdkQuickfixUtils method createDialog.
@VisibleForTesting
@Nullable
static ModelWizardDialog createDialog(@Nullable Project project, @Nullable Component parent, @Nullable Collection<String> requestedPaths, @Nullable Collection<UpdatablePackage> requestedPackages, @Nullable Collection<LocalPackage> requestedUninstalls, @Nullable AndroidSdkHandler sdkHandler, boolean backgroundable) {
if (sdkHandler == null) {
return null;
}
RepoManager mgr = sdkHandler.getSdkManager(REPO_LOGGER);
if (mgr.getLocalPath() == null) {
String title = "SDK Problem";
String msg = "<html>" + "Your Android SDK is missing or out of date." + "<br>" + "You can configure your SDK via <b>Configure | Project Defaults | Project Structure | SDKs</b></html>";
Messages.showErrorDialog(msg, title);
return null;
}
List<String> unknownPaths = new ArrayList<>();
List<UpdatablePackage> resolvedPackages;
mgr.loadSynchronously(0, new StudioLoggerProgressIndicator(SdkQuickfixUtils.class), new StudioDownloader(), StudioSettingsController.getInstance());
RepositoryPackages packages = mgr.getPackages();
if (requestedPackages == null) {
requestedPackages = new ArrayList<>();
}
requestedPackages.addAll(lookupPaths(requestedPaths, packages, unknownPaths));
try {
resolvedPackages = resolve(requestedPackages, packages);
} catch (PackageResolutionException e) {
Messages.showErrorDialog(e.getMessage(), "Error Resolving Packages");
return null;
}
Set<LocalPackage> resolvedUninstalls = new HashSet<>();
if (requestedUninstalls != null) {
resolvedUninstalls.addAll(requestedUninstalls);
// We don't want to uninstall something required by a package we're installing
resolvedPackages.forEach(updatable -> resolvedUninstalls.remove(updatable.getLocal()));
}
List<UpdatablePackage> unavailableDownloads = Lists.newArrayList();
verifyAvailability(resolvedPackages, unavailableDownloads);
// If there were requests we didn't understand or can't download, show an error.
if (!unknownPaths.isEmpty() || !unavailableDownloads.isEmpty()) {
String title = "Packages Unavailable";
HtmlBuilder builder = new HtmlBuilder();
builder.openHtmlBody().add(String.format("%1$s packages are not available for download!", resolvedPackages.isEmpty() ? "All" : "Some")).newline().newline().add("The following packages are not available:").beginList();
for (UpdatablePackage p : unavailableDownloads) {
builder.listItem().add(p.getRepresentative().getDisplayName());
}
for (String p : unknownPaths) {
builder.listItem().add("Package id " + p);
}
builder.endList().closeHtmlBody();
Messages.showErrorDialog(builder.getHtml(), title);
}
// If everything was removed, don't continue.
if (resolvedPackages.isEmpty() && resolvedUninstalls.isEmpty()) {
return null;
}
List<RemotePackage> installRequests = resolvedPackages.stream().map(UpdatablePackage::getRemote).collect(Collectors.toList());
ModelWizard.Builder wizardBuilder = new ModelWizard.Builder();
wizardBuilder.addStep(new LicenseAgreementStep(new LicenseAgreementModel(mgr.getLocalPath()), installRequests));
InstallSelectedPackagesStep installStep = new InstallSelectedPackagesStep(resolvedPackages, resolvedUninstalls, sdkHandler, backgroundable);
wizardBuilder.addStep(installStep);
ModelWizard wizard = wizardBuilder.build();
String title = "SDK Quickfix Installation";
return new StudioWizardDialogBuilder(wizard, title, parent).setProject(project).setModalityType(DialogWrapper.IdeModalityType.IDE).setCancellationPolicy(ModelWizardDialog.CancellationPolicy.CAN_CANCEL_UNTIL_CAN_FINISH).build();
}
use of com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator in project android by JetBrains.
the class SmwOldApiDirectInstall method startSdkInstallUsingNonSwtOldApi.
private void startSdkInstallUsingNonSwtOldApi() {
// Get the SDK instance.
final AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
if (sdkHandler.getLocation() == null) {
myErrorLabel.setText("Error: can't get SDK instance.");
myErrorLabel.setIcon(AllIcons.General.BalloonError);
return;
}
File androidSdkPath = IdeSdks.getInstance().getAndroidSdkPath();
if (androidSdkPath != null && androidSdkPath.exists() && !androidSdkPath.canWrite()) {
myErrorLabel.setText(String.format("SDK folder is read-only: '%1$s'", androidSdkPath.getPath()));
myErrorLabel.setIcon(AllIcons.General.BalloonError);
return;
}
myLabelSdkPath.setText(sdkHandler.getLocation().getPath());
final CustomLogger logger = new CustomLogger();
final com.android.repository.api.ProgressIndicator repoProgress = new StudioLoggerProgressIndicator(getClass());
RepoManager.RepoLoadedCallback onComplete = packages -> UIUtil.invokeLaterIfNeeded(() -> {
List<String> requestedChanges = myState.get(INSTALL_REQUESTS_KEY);
if (requestedChanges == null) {
assert false : "Shouldn't be in installer with no requests";
myInstallFinished = true;
invokeUpdate(null);
return;
}
Map<String, RemotePackage> remotes = packages.getRemotePackages();
List<RemotePackage> requestedPackages = Lists.newArrayList();
boolean notFound = false;
for (String path : requestedChanges) {
RemotePackage remotePackage = remotes.get(path);
if (remotePackage != null) {
requestedPackages.add(remotePackage);
} else {
notFound = true;
}
}
if (requestedPackages.isEmpty()) {
myInstallFinished = true;
invokeUpdate(null);
} else {
requestedPackages = InstallerUtil.computeRequiredPackages(requestedPackages, packages, repoProgress);
if (requestedPackages == null) {
notFound = true;
} else {
InstallTask task = new InstallTask(sdkHandler, requestedPackages, logger);
BackgroundableProcessIndicator indicator = new BackgroundableProcessIndicator(task);
logger.setIndicator(indicator);
ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, indicator);
}
}
if (notFound) {
myErrorLabel.setText("Problem: Some required packages could not be installed. Check internet connection.");
myErrorLabel.setIcon(AllIcons.General.BalloonError);
}
});
StudioProgressRunner runner = new StudioProgressRunner(false, false, "Updating SDK", false, null);
sdkHandler.getSdkManager(repoProgress).load(RepoManager.DEFAULT_EXPIRATION_PERIOD_MS, null, ImmutableList.of(onComplete), null, runner, new StudioDownloader(), StudioSettingsController.getInstance(), false);
}
use of com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator in project android by JetBrains.
the class AvdWizardUtils method emulatorSupportsWebp.
@VisibleForTesting
static boolean emulatorSupportsWebp(@NotNull AndroidSdkHandler sdkHandler) {
ProgressIndicator log = new StudioLoggerProgressIndicator(AvdWizardUtils.class);
LocalPackage sdkPackage = sdkHandler.getLocalPackage(FD_EMULATOR, log);
if (sdkPackage == null) {
sdkPackage = sdkHandler.getLocalPackage(FD_TOOLS, log);
}
if (sdkPackage != null) {
Revision version = sdkPackage.getVersion();
// >= 25.2.3?
if (version.getMajor() > 25 || version.getMajor() == 25 && (version.getMinor() > 2 || version.getMinor() == 2 && version.getMicro() >= 3)) {
return true;
}
}
return false;
}
use of com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator in project android by JetBrains.
the class SkinChooser method getSkins.
private List<File> getSkins() {
List<Device> devices = DeviceManagerConnection.getDefaultDeviceManagerConnection().getDevices();
Set<File> result = Sets.newTreeSet();
for (Device device : devices) {
File skinFile = AvdWizardUtils.resolveSkinPath(device.getDefaultHardware().getSkinFile(), null, FileOpUtils.create());
if (skinFile != null && skinFile.exists()) {
result.add(skinFile);
}
}
StudioLoggerProgressIndicator progress = new StudioLoggerProgressIndicator(SkinChooser.class);
AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
for (IAndroidTarget target : sdkHandler.getAndroidTargetManager(progress).getTargets(progress)) {
Arrays.stream(target.getSkins()).map(this::resolve).forEach(result::add);
}
for (ISystemImage img : sdkHandler.getSystemImageManager(progress).getImages()) {
Arrays.stream(img.getSkins()).map(this::resolve).forEach(result::add);
}
List<File> resultList = Lists.newArrayList();
resultList.add(NO_SKIN);
resultList.addAll(result);
return resultList;
}
Aggregations