com.android.prefs.AndroidLocation Java Examples

The following examples show how to use com.android.prefs.AndroidLocation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SettingsController.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Load settings from the settings file.
 */
public void loadSettings() {

    String path = null;
    try {
        String folder = AndroidLocation.getFolder();
        File f = new File(folder, SETTINGS_FILENAME);
        path = f.getPath();

        Properties props = mFileOp.loadProperties(f);
        mSettings.mProperties.clear();
        mSettings.mProperties.putAll(props);

        // Properly reformat some settings to enforce their default value when missing.
        setShowUpdateOnly(mSettings.getShowUpdateOnly());
        setSetting(ISettingsPage.KEY_ASK_ADB_RESTART, mSettings.getAskBeforeAdbRestart());
        setSetting(ISettingsPage.KEY_USE_DOWNLOAD_CACHE, mSettings.getUseDownloadCache());

    } catch (Exception e) {
        if (mSdkLog != null) {
            mSdkLog.error(e,
                    "Failed to load settings from .android folder. Path is '%1$s'.",
                    path);
        }
    }
}
 
Example #2
Source File: BaseComponentModelPlugin.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Defaults
public void configureAndroidModel(
        AndroidConfig androidModel,
        ServiceRegistry serviceRegistry) {
    Instantiator instantiator = serviceRegistry.get(Instantiator.class);
    AndroidConfigHelper.configure(androidModel, instantiator);

    androidModel.getSigningConfigs().create(DEBUG, new Action<SigningConfig>() {
        @Override
        public void execute(SigningConfig signingConfig) {
            try {
                signingConfig.setStoreFile(KeystoreHelper.defaultDebugKeystoreLocation());
                signingConfig.setStorePassword(DefaultSigningConfig.DEFAULT_PASSWORD);
                signingConfig.setKeyAlias(DefaultSigningConfig.DEFAULT_ALIAS);
                signingConfig.setKeyPassword(DefaultSigningConfig.DEFAULT_PASSWORD);
                signingConfig.setStoreType(KeyStore.getDefaultType());
            } catch (AndroidLocation.AndroidLocationException e) {
                throw new RuntimeException(e);
            }
        }
    });
}
 
Example #3
Source File: SettingsController.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Load settings from the settings file.
 */
public void loadSettings() {

    String path = null;
    try {
        String folder = AndroidLocation.getFolder();
        File f = new File(folder, SETTINGS_FILENAME);
        path = f.getPath();

        Properties props = mFileOp.loadProperties(f);
        mSettings.mProperties.clear();
        mSettings.mProperties.putAll(props);

        // Properly reformat some settings to enforce their default value when missing.
        setShowUpdateOnly(mSettings.getShowUpdateOnly());
        setSetting(ISettingsPage.KEY_USE_DOWNLOAD_CACHE, mSettings.getUseDownloadCache());
        setSetting(ISettingsPage.KEY_ENABLE_PREVIEWS, mSettings.getEnablePreviews());

    } catch (Exception e) {
        if (mSdkLog != null) {
            mSdkLog.error(e,
                    "Failed to load settings from .android folder. Path is '%1$s'.",
                    path);
        }
    }
}
 
Example #4
Source File: CreateAvdVisualPanel3.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
public List<AvdInfo> getAvds(boolean forceRefresh) {
    if (forceRefresh) {
        try {
            avdManager.reloadAvds(new NullLogger());
        } catch (AndroidLocation.AndroidLocationException e) {
            Exceptions.printStackTrace(e);
        }
    }
    ArrayList<AvdInfo> avdInfos = Lists.newArrayList(avdManager.getAllAvds());
    boolean needsRefresh = false;
    for (AvdInfo info : avdInfos) {
        if (info.getStatus() == AvdInfo.AvdStatus.ERROR_DEVICE_CHANGED) {
            updateDeviceChanged(info);
            needsRefresh = true;
        }
    }
    if (needsRefresh) {
        return getAvds(true);
    } else {
        return avdInfos;
    }
}
 
Example #5
Source File: SettingsController.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Saves settings to the settings file.
 */
public void saveSettings() {

    String path = null;
    try {
        String folder = AndroidLocation.getFolder();
        File f = new File(folder, SETTINGS_FILENAME);
        path = f.getPath();
        mFileOp.saveProperties(f, mSettings.mProperties, "## Settings for Android Tool");  //$NON-NLS-1$

    } catch (Exception e) {
        if (mSdkLog != null) {
            // This is important enough that we want to really nag the user about it
            String reason = null;

            if (e instanceof FileNotFoundException) {
                reason = "File not found";
            } else if (e instanceof AndroidLocationException) {
                reason = ".android folder not found, please define ANDROID_SDK_HOME";
            } else if (e.getMessage() != null) {
                reason = String.format("%1$s: %2$s",
                        e.getClass().getSimpleName(),
                        e.getMessage());
            } else {
                reason = e.getClass().getName();
            }

            mSdkLog.error(e, "Failed to save settings file '%1$s': %2$s", path, reason);
        }
    }
}
 
Example #6
Source File: DebugKeyProvider.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the OS path to the default debug keystore.
 *
 * @return The OS path to the default debug keystore.
 * @throws KeytoolException
 * @throws AndroidLocationException
 */
public static String getDefaultKeyStoreOsPath()
        throws KeytoolException, AndroidLocationException {
    String folder = AndroidLocation.getFolder();
    if (folder == null) {
        throw new KeytoolException("Failed to get HOME directory!\n");
    }
    String osKeyStorePath = folder + "debug.keystore";

    return osKeyStorePath;
}
 
Example #7
Source File: KeystoreHelper.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the location of the default debug keystore.
 *
 * @return The location of the default debug keystore.
 * @throws AndroidLocationException if the location cannot be computed
 */
@NonNull
public static String defaultDebugKeystoreLocation() throws AndroidLocationException {
    //this is guaranteed to either return a non null value (terminated with a platform
    // specific separator), or throw.
    String folder = AndroidLocation.getFolder();
    return folder + "debug.keystore";
}
 
Example #8
Source File: SigningConfig.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a SigningConfig with a given name.
 *
 * @param name the name of the signingConfig.
 */
public SigningConfig(@NonNull String name) {
    super(name);

    if (BuilderConstants.DEBUG.equals(name)) {
        try {
            initDebug();
        } catch (AndroidLocation.AndroidLocationException e) {
            throw new BuildException("Failed to get default debug keystore location", e);
        }
    }
}
 
Example #9
Source File: ValidateSigningTask.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@TaskAction
public void validate() throws AndroidLocation.AndroidLocationException, KeytoolException {
    File storeFile = signingConfig.getStoreFile();
    if (storeFile == null) {
        throw new IllegalArgumentException(
                "Keystore file not set for signing config " + signingConfig.getName());
    }
    if (!storeFile.exists()) {
        if (KeystoreHelper.defaultDebugKeystoreLocation().equals(storeFile.getAbsolutePath())) {
            checkState(signingConfig.isSigningReady(), "Debug signing config not ready.");

            getLogger().info(
                    "Creating default debug keystore at {}",
                    storeFile.getAbsolutePath());

            //noinspection ConstantConditions - isSigningReady() called above
            if (!KeystoreHelper.createDebugStore(
                    signingConfig.getStoreType(), signingConfig.getStoreFile(),
                    signingConfig.getStorePassword(), signingConfig.getKeyPassword(),
                    signingConfig.getKeyAlias(), getILogger())) {
                throw new BuildException("Unable to recreate missing debug keystore.", null);
            }
        } else {
            throw new IllegalArgumentException(
                    String.format(
                            "Keystore file %s not found for signing config '%s'.",
                            storeFile.getAbsolutePath(),
                            signingConfig.getName()));
        }
    }
}
 
Example #10
Source File: SettingsController.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Saves settings to the settings file.
 */
public void saveSettings() {

    String path = null;
    try {
        String folder = AndroidLocation.getFolder();
        File f = new File(folder, SETTINGS_FILENAME);
        path = f.getPath();
        mFileOp.saveProperties(f, mSettings.mProperties, "## Settings for Android Tool");  //$NON-NLS-1$

    } catch (Exception e) {
        if (mSdkLog != null) {
            // This is important enough that we want to really nag the user about it
            String reason = null;

            if (e instanceof FileNotFoundException) {
                reason = "File not found";
            } else if (e instanceof AndroidLocationException) {
                reason = ".android folder not found, please define ANDROID_SDK_HOME";
            } else if (e.getMessage() != null) {
                reason = String.format("%1$s: %2$s",
                        e.getClass().getSimpleName(),
                        e.getMessage());
            } else {
                reason = e.getClass().getName();
            }

            mSdkLog.error(e, "Failed to save settings file '%1$s': %2$s", path, reason);
        }
    }
}
 
Example #11
Source File: DebugKeyProvider.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the OS path to the default debug keystore.
 *
 * @return The OS path to the default debug keystore.
 * @throws KeytoolException
 * @throws AndroidLocationException
 */
public static String getDefaultKeyStoreOsPath()
        throws KeytoolException, AndroidLocationException {
    String folder = AndroidLocation.getFolder();
    if (folder == null) {
        throw new KeytoolException("Failed to get HOME directory!\n");
    }
    String osKeyStorePath = folder + "debug.keystore";

    return osKeyStorePath;
}
 
Example #12
Source File: KeystoreHelper.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the location of the default debug keystore.
 *
 * @return The location of the default debug keystore.
 * @throws AndroidLocationException if the location cannot be computed
 */
@NonNull
public static String defaultDebugKeystoreLocation() throws AndroidLocationException {
    //this is guaranteed to either return a non null value (terminated with a platform
    // specific separator), or throw.
    String folder = AndroidLocation.getFolder();
    return folder + "debug.keystore";
}
 
Example #13
Source File: AvdManager.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
private void refreshAvds() {
    try {
        avdManager.reloadAvds(new NullLogger());
    } catch (AndroidLocation.AndroidLocationException ex) {
        Exceptions.printStackTrace(ex);
    }
    AvdInfo[] validAvds = avdManager.getValidAvds();
    model = new ExistingDevicesTableModel(validAvds);
    table.setModel(model);
}
 
Example #14
Source File: AndroidExtension.java    From javafxmobile-plugin with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public AndroidExtension(Project project, ToolingModelBuilderRegistry registry) {
    this.project = project;

    this.extraModelInfo = new ExtraModelInfo(new ProjectOptions(project), project.getLogger());

    this.signingConfig = project.getExtensions().create("signingConfig", SigningConfig.class, "signing");
    this.packagingOptions = project.getExtensions().create("packagingOptions", PackagingOptions.class);
    this.dexOptions = project.getExtensions().create("dexOptions", DexOptions.class, extraModelInfo);

    try {
        this.buildCache = FileCache.getInstanceWithMultiProcessLocking(new File(AndroidLocation.getFolder(), "build-cache"));
    } catch (AndroidLocation.AndroidLocationException e) {
        throw new RuntimeException(e);
    }

    LoggerWrapper loggerWrapper = new LoggerWrapper(project.getLogger());

    this.sdkHandler = new SdkHandler(project, loggerWrapper);
    this.androidBuilder = new AndroidBuilder(
            project == project.getRootProject() ? project.getName() : project.getPath(),
            "JavaFX Mobile",
            new GradleProcessExecutor(project),
            new GradleJavaProcessExecutor(project),
            extraModelInfo,
            loggerWrapper,
            false);

    this.androidTaskRegistry = new AndroidTaskRegistry();
    this.taskFactory = new TaskContainerAdaptor(project.getTasks());

    installDirectory = new File(project.getBuildDir(), "javafxports/android");
    project.getLogger().info("Android install directory: " + installDirectory);

    temporaryDirectory = new File(project.getBuildDir(), "javafxports/tmp/android");
    project.getLogger().info("Android temporary output directory: " + temporaryDirectory);

    resourcesDirectory = new File(temporaryDirectory, "resources");
    resourcesDirectory.mkdirs();
    project.getLogger().info("Resources directory: " + resourcesDirectory);

    multidexOutputDirectory = new File(temporaryDirectory, "multi-dex");
    multidexOutputDirectory.mkdirs();
    project.getLogger().info("Multi-dex output directory: " + multidexOutputDirectory);

    dexOutputDirectory = new File(temporaryDirectory, "dex");
    dexOutputDirectory.mkdirs();
    project.getLogger().info("Dex output directory: " + dexOutputDirectory);
}
 
Example #15
Source File: CreateAvdWizardIterator.java    From NBANDROID-V2 with Apache License 2.0 4 votes vote down vote up
@Override
public Set<?> instantiate() throws IOException {
    // TODO return set of FileObject (or DataObject) you have created

    //path /home/arsi/.android/avd/Nexus_5_API_27.avd
    //avd name Nexus_5_API_27
    //skinFolder /jetty/android-studio-sdk/skins/nexus_5
    //skinname null
    //sdcard 512M
    //
    //hw.dPad => no  x
    //hw.lcd.height => 1920 x
    //fastboot.chosenSnapshotFile => 
    //runtime.network.speed => full
    //hw.accelerometer => yes x
    //hw.device.name => Nexus 5 x
    //vm.heapSize => 128
    //skin.dynamic => yes
    //hw.device.manufacturer => Google x
    //hw.lcd.width => 1080 x
    //skin.path => /jetty/android-studio-sdk/skins/nexus_5
    //hw.gps => yes x
    //hw.initialOrientation => Portrait
    //hw.audioInput => yes x
    //showDeviceFrame => yes
    //hw.camera.back => emulated
    //hw.mainKeys => no x
    //AvdId => Nexus_5_API_27
    //hw.lcd.density => 480 x
    //hw.camera.front => emulated
    //avd.ini.displayname => Nexus 5 API 27
    //hw.gpu.mode => auto/host/software
    //hw.device.hash2 => MD5:1c925b9117dd9f33c5128dac289a0d68 x
    //fastboot.forceChosenSnapshotBoot => no
    //fastboot.forceFastBoot => yes
    //hw.trackBall => no x
    //hw.ramSize => 1536
    //hw.battery => yes x
    //fastboot.forceColdBoot => no
    //hw.cpu.ncore => 4
    //hw.sdCard => yes xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    //runtime.network.latency => none
    //hw.keyboard => yes
    //hw.sensors.proximity => yes x
    //hw.sensors.orientation => yesx
    //disk.dataPartition.size => 2G
    //hw.gpu.enabled => yes
    //
    //dev has playstore true
    //create snapshot false
    //removeprev false
    //editExisting true
    AndroidSdk defaultSdk = (AndroidSdk) wizard.getProperty(ANDROID_SDK);
    AvdManager avdManager = (AvdManager) wizard.getProperty(AVD_MANAGER);
    Device selectedDevice = (Device) wizard.getProperty(DEVICE_SELECTED);
    SystemImageDescription selectedImage = (SystemImageDescription) wizard.getProperty(SYSTEM_IMAGE);
    String displayName = (String) wizard.getProperty(AVD_DISPLAY_NAME);
    String avdId = (String) wizard.getProperty(AVD_ID_NAME);
    Map<String, String> hardwareProperties = DeviceManager.getHardwareProperties(selectedDevice);
    Map<String, String> userHardwareProperties = (Map<String, String>) wizard.getProperty(AVD_USER_HW_CONFIG);
    hardwareProperties.putAll(userHardwareProperties);
    String skinPath = hardwareProperties.get("skin.path");
    String sdcard = (String) wizard.getProperty(AVD_SDCARD);
    try {
        String avdPath = avdManager.getBaseAvdFolder().getAbsoluteFile().getAbsolutePath() + File.separator + avdId + ".avd";
        avdManager.createAvd(new File(avdPath), avdId, selectedImage.getSystemImage(),
                new File(skinPath), null, sdcard, hardwareProperties, selectedDevice.getBootProps(), selectedDevice.hasPlayStore()&&selectedImage.getSystemImage().hasPlayStore(), false, false, true, new StdLogger(StdLogger.Level.INFO));
    } catch (AndroidLocation.AndroidLocationException androidLocationException) {
    }
    changeListener.stateChanged(null);
    return Collections.emptySet();
}
 
Example #16
Source File: EmulatorLauncher.java    From NBANDROID-V2 with Apache License 2.0 4 votes vote down vote up
public Future<IDevice> launchEmulator(AvdInfo avdInfo, LaunchConfiguration launchCfg) {
    final String cookie = Long.toString(System.currentTimeMillis());
    ExecutionDescriptor descriptor = new ExecutionDescriptor()
            .frontWindow(true).postExecution(new Runnable() {
        @Override
        public void run() {
            cancel = true;
            semaphore.release();
        }
    });

    ProcessBuilder processBuilder = ProcessBuilder.getLocal();
    processBuilder.setExecutable(getEmulatorBinaryPath());
    List<String> arguments = new ArrayList<>();
    arguments.add(FLAG_AVD);
    arguments.add(avdInfo.getName());
    arguments.add(FLAG_PROP);
    arguments.add(LAUNCH_COOKIE + "=" + cookie);
    if(SelectDeviceAction.wipeData.isSelected()){
        arguments.add(FLAG_WIPE_DATA);
    }
    for (String arg : Splitter.on(' ').omitEmptyStrings().split(launchCfg.getEmulatorOptions())) {
        arguments.add(arg);
    }
    processBuilder.setArguments(arguments);
    AndroidSdk defaultSdk = AndroidSdkProvider.getDefaultSdk();
    if (defaultSdk != null) {
        try {
            AvdManager avdManager = AvdManager.getInstance(defaultSdk.getAndroidSdkHandler(), new NullLogger());
            if (avdManager != null) {
                File baseAvdFolder = avdManager.getBaseAvdFolder();
                processBuilder.getEnvironment().setVariable("ANDROID_AVD_HOME", baseAvdFolder.getAbsolutePath());
            }
        } catch (AndroidLocation.AndroidLocationException ex) {
            Exceptions.printStackTrace(ex);
        }
    }

    ExecutionService service = ExecutionService.newService(
            processBuilder, descriptor, "Android emulator");
    final Future<Integer> taskStatus = service.run();
    return EXECUTOR.submit(new Callable<IDevice>() {

        @Override
        public IDevice call() throws Exception {

            ProgressHandle handle = ProgressHandle.createHandle("Emulator starting", new Cancellable() {
                @Override
                public boolean cancel() {
                    cancel = true;
                    semaphore.release();
                    return true;
                }
            });
            handle.start();
            while (true) {
                Map<String, IDevice> runningEmulators = AdbUtils.getRunningEmulators();
                IDevice device = runningEmulators.get(avdInfo.getName());
                if (device != null && device.isOnline()) {
                    handle.finish();
                    LOG.log(Level.INFO, "Started emulator device connected.");
                    return device;
                } else if (cancel) {
                    handle.finish();
                    LOG.log(Level.INFO, "Emulator start canceled");
                    return null;
                }
                semaphore.tryAcquire(2, TimeUnit.SECONDS);
            }
        }

    });
}