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

Extend device plugin #3244

Merged
merged 6 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.content.pm.ApplicationInfo;
import android.os.BatteryManager;
import android.os.Environment;
import android.os.StatFs;
Expand Down Expand Up @@ -32,6 +33,8 @@ public void getInfo(PluginCall call) {
r.put("osVersion", android.os.Build.VERSION.RELEASE);
r.put("appVersion", getAppVersion());
r.put("appBuild", getAppBuild());
r.put("appId", getAppBundleId());
r.put("appName", getAppName());
r.put("platform", getPlatform());
r.put("manufacturer", android.os.Build.MANUFACTURER);
r.put("uuid", getUuid());
Expand Down Expand Up @@ -91,6 +94,25 @@ private String getAppBuild() {
}
}

private String getAppBundleId() {
try {
PackageInfo pinfo = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), 0);
return pinfo.packageName;
} catch(Exception ex) {
return "";
}
}

private String getAppName() {
try {
ApplicationInfo applicationInfo = getContext().getApplicationInfo();
int stringId = applicationInfo.labelRes;
return stringId == 0 ? applicationInfo.nonLocalizedLabel.toString() : getContext().getString(stringId);
} catch(Exception ex) {
return "";
}
}

private String getPlatform() {
return "android";
}
Expand Down
8 changes: 8 additions & 0 deletions core/src/core-plugin-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,14 @@ export interface DeviceInfo {
* The current bundle build of the app
*/
appBuild: string;
/**
* The bundle id of the app
*/
appId: string;
/**
* The display name of the app
*/
appName: string;
/**
* The operating system of the device
*/
Expand Down
2 changes: 2 additions & 0 deletions core/src/web/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export class DevicePluginWeb extends WebPlugin implements DevicePlugin {
platform: <'web'> 'web',
appVersion: '',
appBuild: '',
appId: '',
appName: '',
operatingSystem: uaFields.operatingSystem,
osVersion: uaFields.osVersion,
manufacturer: navigator.vendor,
Expand Down
2 changes: 2 additions & 0 deletions electron/src/electron/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export class DevicePluginElectron extends WebPlugin implements DevicePlugin {
platform: <'electron'> 'electron',
appVersion: app.getVersion(),
appBuild: '',
appId: '',
appName: '',
operatingSystem: info.operatingSystem,
osVersion: info.osVersion,
manufacturer: navigator.vendor,
Expand Down
2 changes: 2 additions & 0 deletions ios/Capacitor/Capacitor/Plugins/Device.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class CAPDevicePlugin: CAPPlugin {
"osVersion": UIDevice.current.systemVersion,
"appVersion": Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "",
"appBuild": Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "",
"appId": Bundle.main.infoDictionary?["CFBundleIdentifier"] as? String ?? "",
"appName": Bundle.main.infoDictionary?["CFBundleDisplayName"] as? String ?? "",
"platform": "ios",
"manufacturer": "Apple",
"uuid": UIDevice.current.identifierForVendor!.uuidString,
Expand Down