Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit c280ac5

Browse files
Merge pull request #520 from telerik/vladimirov/improve-android-devices-info
Improve getting device info for Android
2 parents deae3fa + ffceabf commit c280ac5

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

commands/device/list-devices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class ListDevicesCommand implements ICommand {
2828
} else {
2929
action = (device) => {
3030
return (() => {
31-
table.push([(index++).toString(), device.deviceInfo.displayName, device.deviceInfo.platform, device.deviceInfo.identifier]);
31+
table.push([(index++).toString(), device.deviceInfo.displayName || '', device.deviceInfo.platform || '', device.deviceInfo.identifier || '']);
3232
}).future<void>()();
3333
};
3434
}

mobile/android/android-device.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,19 @@ export class AndroidDevice implements Mobile.IAndroidDevice {
3535
this.applicationManager = this.$injector.resolve(applicationManagerPath.AndroidApplicationManager, { adb: this.adb, identifier: this.identifier });
3636
this.fileSystem = this.$injector.resolve(fileSystemPath.AndroidDeviceFileSystem, { adb: this.adb, identifier: this.identifier });
3737

38-
let details: IAndroidDeviceDetails = this.getDeviceDetails().wait();
38+
let details: IAndroidDeviceDetails;
39+
try {
40+
details = this.getDeviceDetails(["getprop"]).wait();
41+
} catch(err) {
42+
this.$logger.trace(`Error while calling getprop: ${err.message}`);
43+
}
44+
45+
if(!details || !details.name) {
46+
// In older CLI versions we are calling cat /system/build.prop to get details.
47+
// Keep this logic for compatibility and possibly for devices for which getprop is not working
48+
details = this.getDeviceDetails(["cat", "/system/build.prop"]).wait();
49+
}
50+
3951
this.deviceInfo = {
4052
identifier: this.identifier,
4153
displayName: details.name,
@@ -58,18 +70,22 @@ export class AndroidDevice implements Mobile.IAndroidDevice {
5870
this.$logcatHelper.start(this.identifier);
5971
}
6072

61-
private getDeviceDetails(): IFuture<IAndroidDeviceDetails> {
73+
private getDeviceDetails(shellCommandArgs: string[]): IFuture<IAndroidDeviceDetails> {
6274
return (() => {
63-
let details = this.adb.executeShellCommand(["cat", "/system/build.prop"]).wait();
75+
let details = this.adb.executeShellCommand(shellCommandArgs).wait();
76+
6477
let parsedDetails: any = {};
6578
details.split(/\r?\n|\r/).forEach((value: any) => {
66-
//sample line is "ro.build.version.release=4.4"
67-
let match = /(?:ro\.build\.version|ro\.product)\.(.+)=(.+)/.exec(value);
79+
// sample line is "ro.build.version.release=4.4" in /system/build.prop
80+
// sample line from getprop is: [ro.build.version.release]: [6.0]
81+
// NOTE: some props do not have value: [ro.build.version.base_os]: []
82+
let match = /(?:\[?ro\.build\.version|ro\.product)\.(.+?)]?(?:\:|=)(?:\s*?\[)?(.*?)]?$/.exec(value);
6883
if (match) {
6984
parsedDetails[match[1]] = match[2];
7085
}
7186
});
7287

88+
this.$logger.trace(parsedDetails);
7389
return parsedDetails;
7490
}).future<IAndroidDeviceDetails>()();
7591
}

0 commit comments

Comments
 (0)