Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Android preferences root path on Windows #558

Merged
merged 15 commits into from
Nov 26, 2020
39 changes: 17 additions & 22 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -848,35 +848,30 @@ function toAvdLocaleArgs (language, country) {
* @returns {?string} The full path to the folder or `null` if the folder cannot be found
*/
async function getAndroidPrefsRoot () {
// https://gerrit.pixelexperience.org/plugins/gitiles/development/+/5c11852110eeb03dc5a69111354b383f98d15336/tools/androidprefs/src/com/android/prefs/AndroidLocation.java
let location = null;
if (system.isWindows()) {
let localAppData = process.env.LOCALAPPDATA;
if (!localAppData) {
localAppData = process.env.USERPROFILE;
if (localAppData) {
localAppData = path.resolve(localAppData, 'Local Settings', 'Application Data');
}
}
if (localAppData) {
location = path.resolve(localAppData, 'Android');
}
} else {
const home = process.env.HOME;
let location = process.env.ANDROID_EMULATOR_HOME;
jpkleemans marked this conversation as resolved.
Show resolved Hide resolved
if (location && !await fs.exists(location)) {
jpkleemans marked this conversation as resolved.
Show resolved Hide resolved
log.debug(`Value of $ANDROID_EMULATOR_HOME '${location}' does not exist`);
return null;
jpkleemans marked this conversation as resolved.
Show resolved Hide resolved
}

if (!location) {
jpkleemans marked this conversation as resolved.
Show resolved Hide resolved
const home = process.env.HOME || process.env.USERPROFILE;
if (home) {
location = path.resolve(home, '.android');
}
}

if (location && await fs.exists(location)) {
if (!(await fs.stat(location)).isDirectory()) {
log.debug(`Android config root '${location}' is not a directory`);
return null;
}
return location;
if (!location || !await fs.exists(location)) {
log.debug(`Android config root '${location}' does not exist`);
return null;
}

if (!(await fs.stat(location)).isDirectory()) {
log.debug(`Android config root '${location}' is not a directory`);
return null;
}

return null;
return location;
}

export {
Expand Down
18 changes: 14 additions & 4 deletions lib/tools/adb-emu-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,24 @@ emuMethods.SENSORS = {
* @returns {Array<EmuInfo>}
*/
async function listEmulators () {
// https://android.googlesource.com/platform/sdk/+/33f330d963c1bf24667eddb891531abcce9fb4de/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java
const prefsRoot = await getAndroidPrefsRoot();
if (!prefsRoot) {
let avdsRoot = process.env.ANDROID_AVD_HOME;
if (avdsRoot && !await fs.exists(avdsRoot)) {
log.debug(`Value of $ANDROID_AVD_HOME '${location}' does not exist`);
return [];
jpkleemans marked this conversation as resolved.
Show resolved Hide resolved
}

const avdsRoot = path.resolve(prefsRoot, 'avd');
if (!avdsRoot) {
// https://android.googlesource.com/platform/sdk/+/33f330d963c1bf24667eddb891531abcce9fb4de/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java
const prefsRoot = await getAndroidPrefsRoot();
if (!prefsRoot) {
return [];
}

avdsRoot = path.resolve(prefsRoot, 'avd');
}

if (!await fs.exists(avdsRoot)) {
log.debug(`Virtual devices config root '${avdsRoot}' does not exist`);
return [];
}

Expand Down