/** Callback called when the window shell is disposed. */ private void onAndroidSdkUpdaterDispose() { if (mUpdaterData != null) { ImageFactory imgFactory = mUpdaterData.getImageFactory(); if (imgFactory != null) { imgFactory.dispose(); } } }
/** Creates the icon of the window shell. */ private void setWindowImage(Shell androidSdkUpdater) { String imageName = "android_icon_16.png"; // $NON-NLS-1$ if (SdkConstants.currentPlatform() == SdkConstants.PLATFORM_DARWIN) { imageName = "android_icon_128.png"; // $NON-NLS-1$ } if (mUpdaterData != null) { ImageFactory imgFactory = mUpdaterData.getImageFactory(); if (imgFactory != null) { mAndroidSdkUpdater.setImage(imgFactory.getImageByName(imageName)); } } }
/** * Creates an UpdateNoWindow object that will update using the given SDK root and outputs to the * given SDK logger. * * @param osSdkRoot The OS path of the SDK folder to update. * @param sdkManager An existing SDK manager to list current platforms and addons. * @param sdkLog A logger object, that should ideally output to a write-only console. * @param force The reply to any question asked by the update process. Currently this will be * yes/no for ability to replace modified samples or restart ADB. * @param useHttp True to force using HTTP instead of HTTPS for downloads. * @param proxyPort An optional HTTP/HTTPS proxy port. Can be null. * @param proxyHost An optional HTTP/HTTPS proxy host. Can be null. */ public SdkUpdaterNoWindow( String osSdkRoot, SdkManager sdkManager, ISdkLog sdkLog, boolean force, boolean useHttp, String proxyHost, String proxyPort) { mSdkLog = sdkLog; mForce = force; mUpdaterData = new UpdaterData(osSdkRoot, sdkLog); // Read and apply settings from settings file, so that http/https proxy is set // and let the command line args override them as necessary. SettingsController settingsController = mUpdaterData.getSettingsController(); settingsController.loadSettings(); settingsController.applySettings(); setupProxy(proxyHost, proxyPort); // Change the in-memory settings to force the http/https mode settingsController.setSetting(ISettingsPage.KEY_FORCE_HTTP, useHttp); // Use a factory that only outputs to the given ISdkLog. mUpdaterData.setTaskFactory(new ConsoleTaskFactory()); // Check that the AVD Manager has been correctly initialized. This is done separately // from the constructor in the GUI-based UpdaterWindowImpl to give time to the UI to // initialize before displaying a message box. Since we don't have any GUI here // we can call it whenever we want. if (mUpdaterData.checkIfInitFailed()) { return; } // Setup the default sources including the getenv overrides. mUpdaterData.setupDefaultSources(); mUpdaterData.getLocalSdkParser().parseSdk(osSdkRoot, sdkManager, new NullTaskMonitor(sdkLog)); }
/** * Initializes settings. This must be called after addExtraPages(), which created a settings page. * Iterate through all the pages to find the first (and supposedly unique) setting page, and use * it to load and apply these settings. */ private void initializeSettings() { SettingsController c = mUpdaterData.getSettingsController(); c.loadSettings(); c.applySettings(); for (Object page : mPages) { if (page instanceof ISettingsPage) { ISettingsPage settingsPage = (ISettingsPage) page; c.setSettingsPage(settingsPage); break; } } }
/** * Adds all extra pages. For each page, instantiates an instance of the {@link Composite} using * the constructor that takes a single {@link Composite} argument and then adds it to the page * list. */ @SuppressWarnings("unchecked") private void addExtraPages() { if (mExtraPages == null) { return; } for (Object[] extraPage : mExtraPages) { String title = (String) extraPage[0]; Class<? extends Composite> clazz = (Class<? extends Composite>) extraPage[1]; // We want the constructor that takes a single Composite as parameter Constructor<? extends Composite> cons; try { cons = clazz.getConstructor(new Class<?>[] {Composite.class}); Composite instance = cons.newInstance(new Object[] {mPagesRootComposite}); addPage(instance, title); } catch (NoSuchMethodException e) { // There is no such constructor. mUpdaterData .getSdkLog() .error( e, "Failed to add extra page %1$s. Constructor args must be (Composite parent).", //$NON-NLS-1$ clazz.getSimpleName()); } catch (Exception e) { // Log this instead of crashing the whole app. mUpdaterData .getSdkLog() .error( e, "Failed to add extra page %1$s.", //$NON-NLS-1$ clazz.getSimpleName()); } } }
/** * Once the UI has been created, initializes the content. This creates the pages, selects the * first one, setup sources and scan for local folders. * * <p>Returns true if we should show the window. */ private boolean postCreate() { mUpdaterData.setWindowShell(getShell()); mTaskFactory = new ProgressTaskFactory(getShell()); mUpdaterData.setTaskFactory(mTaskFactory); mUpdaterData.setImageFactory(new ImageFactory(getShell().getDisplay())); setWindowImage(mAndroidSdkUpdater); addPage(mAvdManagerPage, "Virtual devices"); addPage(mLocalPackagePage, "Installed packages"); addPage(mRemotePackagesPage, "Available packages"); addExtraPages(); int pageIndex = 0; int i = 0; for (Composite p : mPages) { if (p.getClass().equals(mInitialPage)) { pageIndex = i; break; } i++; } displayPage(pageIndex); mPageList.setSelection(pageIndex); setupSources(); initializeSettings(); if (mUpdaterData.checkIfInitFailed()) { return false; } mUpdaterData.broadcastOnSdkLoaded(); if (mRequestAutoUpdate) { mUpdaterData.updateOrInstallAll_WithGUI( null /*selectedArchives*/, false /* includeObsoletes */); } return true; }
/** Used to initialize the sources. */ private void setupSources() { mUpdaterData.setupDefaultSources(); mRemotePackagesPage.onSdkReload(); }
/** Called by the main loop when the window has been disposed. */ private void dispose() { mUpdaterData.getSources().saveUserAddons(mUpdaterData.getSdkLog()); }
/** * Removes a new listener to be notified anymore when a change is made to the content of the SDK. */ public void removeListener(ISdkChangeListener listener) { mUpdaterData.removeListener(listener); }
/** Adds a new listener to be notified when a change is made to the content of the SDK. */ public void addListener(ISdkChangeListener listener) { mUpdaterData.addListeners(listener); }
/** * Lists remote packages available for install using 'android update sdk --no-ui'. * * @param includeObsoletes True to also list and install obsolete packages. * @param extendedOutput True to display more details on each package. */ public void listRemotePackages(boolean includeObsoletes, boolean extendedOutput) { mUpdaterData.listRemotePackages_NoGUI(includeObsoletes, extendedOutput); }
/** * Performs the actual update. * * @param pkgFilter A list of {@link SdkRepoConstants#NODES} to limit the type of packages we can * update. A null or empty list means to update everything possible. * @param includeObsoletes True to also list and install obsolete packages. * @param dryMode True to check what would be updated/installed but do not actually download or * install anything. */ public void updateAll(ArrayList<String> pkgFilter, boolean includeObsoletes, boolean dryMode) { mUpdaterData.updateOrInstallAll_NoGUI(pkgFilter, includeObsoletes, dryMode); }