-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(android): catch api issues for --list
This commit catches errors related to unsuitable API installations. Without system images, AVDs cannot be listed as valid targets. fixes #23
- Loading branch information
Showing
2 changed files
with
69 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import * as Debug from 'debug'; | ||
|
||
import { Target } from '../../utils/list'; | ||
|
||
import { Device, getDevices } from './adb'; | ||
import { AVD, getDefaultAVD, getInstalledAVDs } from './avd'; | ||
import { SDK } from './sdk'; | ||
|
||
const modulePrefix = 'native-run:android:utils:list'; | ||
|
||
export async function getDeviceTargets(sdk: SDK): Promise<Target[]> { | ||
const debug = Debug(`${modulePrefix}:${getDeviceTargets.name}`); | ||
|
||
try { | ||
return (await getDevices(sdk)) | ||
.filter(device => device.type === 'hardware') | ||
.map(deviceToTarget); | ||
} catch (e) { | ||
debug('Error getting device targets: %O', e); | ||
} | ||
|
||
return []; | ||
} | ||
|
||
export async function getVirtualTargets(sdk: SDK): Promise<Target[]> { | ||
const debug = Debug(`${modulePrefix}:${getVirtualTargets.name}`); | ||
|
||
try { | ||
const avds = await getInstalledAVDs(sdk); | ||
const defaultAvd = await getDefaultAVD(sdk, avds); | ||
|
||
if (!avds.includes(defaultAvd)) { | ||
avds.push(defaultAvd); | ||
} | ||
|
||
return avds.map(avdToTarget); | ||
} catch (e) { | ||
debug('Error getting virtual targets: %O', e); | ||
} | ||
|
||
return []; | ||
} | ||
|
||
export function deviceToTarget(device: Device): Target { | ||
return { | ||
platform: 'android', | ||
model: `${device.manufacturer} ${device.model}`, | ||
sdkVersion: device.sdkVersion, | ||
id: device.serial, | ||
format() { | ||
return `${this.model} (API ${this.sdkVersion}) ${this.id}`; | ||
}, | ||
}; | ||
} | ||
|
||
export function avdToTarget(avd: AVD): Target { | ||
return { | ||
platform: 'android', | ||
name: avd.name, | ||
sdkVersion: avd.sdkVersion, | ||
id: avd.id, | ||
format() { | ||
return `${this.name} (API ${this.sdkVersion}) ${this.id}`; | ||
}, | ||
}; | ||
} |