From 5fdcbfd41d151c3897df463dfed00c2467facbee Mon Sep 17 00:00:00 2001 From: Manuel Date: Mon, 13 Jul 2020 07:20:17 +0200 Subject: [PATCH 1/5] Add appName and appId to device info for android --- .../java/com/getcapacitor/plugin/Device.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/Device.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/Device.java index 9858f974b3..093e5c8bb4 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/Device.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/Device.java @@ -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; @@ -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()); @@ -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"; } From 081dbadcaddaccce9c131242eaec3985d1ac473c Mon Sep 17 00:00:00 2001 From: Manuel Date: Mon, 13 Jul 2020 07:47:34 +0200 Subject: [PATCH 2/5] Add appName and appId to device info for ios --- ios/Capacitor/Capacitor/Plugins/Device.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ios/Capacitor/Capacitor/Plugins/Device.swift b/ios/Capacitor/Capacitor/Plugins/Device.swift index c120a74e99..76aac469cd 100644 --- a/ios/Capacitor/Capacitor/Plugins/Device.swift +++ b/ios/Capacitor/Capacitor/Plugins/Device.swift @@ -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, From d599039a3cd4a54740cf336efc1d54fccb18b5cc Mon Sep 17 00:00:00 2001 From: Manuel Date: Mon, 13 Jul 2020 07:51:47 +0200 Subject: [PATCH 3/5] Extend DeviceInfo definition --- core/src/core-plugin-definitions.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/src/core-plugin-definitions.ts b/core/src/core-plugin-definitions.ts index c9b6a6efa7..de8f92ced1 100644 --- a/core/src/core-plugin-definitions.ts +++ b/core/src/core-plugin-definitions.ts @@ -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 */ From 04861fc9a234442acd1ae1622d91ee78814a6d75 Mon Sep 17 00:00:00 2001 From: Manuel Date: Mon, 13 Jul 2020 07:57:01 +0200 Subject: [PATCH 4/5] Update DevicePluginWeb --- core/src/web/device.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/web/device.ts b/core/src/web/device.ts index 4889b5808d..ca3eead93f 100644 --- a/core/src/web/device.ts +++ b/core/src/web/device.ts @@ -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, From 8d9dddc5b331030c9f8d228cc94c4e1ce1e60f1a Mon Sep 17 00:00:00 2001 From: Manuel Date: Mon, 13 Jul 2020 08:53:18 +0200 Subject: [PATCH 5/5] Update DevicePluginElectron --- electron/src/electron/device.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/electron/src/electron/device.ts b/electron/src/electron/device.ts index 6bd5ee2dcc..dd9583ba80 100644 --- a/electron/src/electron/device.ts +++ b/electron/src/electron/device.ts @@ -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,