From 87370b6cabb263a21a7fa8d98dcd1ab0aaba0c09 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Sun, 14 Apr 2024 19:57:43 -0700 Subject: [PATCH 1/6] =?UTF-8?q?=F0=9F=94=A5=20Remove=20code=20to=20build?= =?UTF-8?q?=20JSON=20objects?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In an earlier version of this PR, before I added mocking to the plugin, we saved JSON objects directly. We created the objects to save by removing results from the in-memory objects using a destructuring assignment. However, after the mocking was added, we create objects in native code. So we don't need to create them here and can remove these unused variables. https://github.com/e-mission/e-mission-phone/pull/1144#discussion_r1564981905 --- www/js/bluetooth/BluetoothScanPage.tsx | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/www/js/bluetooth/BluetoothScanPage.tsx b/www/js/bluetooth/BluetoothScanPage.tsx index a4e5bda9e..b50bf5283 100644 --- a/www/js/bluetooth/BluetoothScanPage.tsx +++ b/www/js/bluetooth/BluetoothScanPage.tsx @@ -97,7 +97,6 @@ const BluetoothScanPage = ({ ...props }: any) => { in_range: status, }, })); - let { monitorResult: _, in_range: _, ...noResultDevice } = sampleBLEDevices[uuid]; window['cordova']?.plugins?.BEMDataCollection.mockBLEObjects( status ? 'REGION_ENTER' : 'REGION_EXIT', uuid, @@ -118,16 +117,6 @@ const BluetoothScanPage = ({ ...props }: any) => { rangeResult: result, }, })); - // we don't want to exclude monitorResult and rangeResult from the values - // that we save because they are the current or previous result, just - // in a different format - // https://stackoverflow.com/a/34710102 - let { - monitorResult: _, - rangeResult: _, - in_range: _, - ...noResultDevice - } = sampleBLEDevices[uuid]; let parsedResult = JSON.parse(result); parsedResult.beacons.forEach((beacon) => { window['cordova']?.plugins?.BEMDataCollection.mockBLEObjects( From 1fca7c58519c30823ab89f8654f3cfc47ed0392b Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Mon, 15 Apr 2024 00:00:39 -0700 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=91=B7=F0=9F=94=A7=20=F0=9F=AA=A0=20P?= =?UTF-8?q?lumb=20through=20support=20for=20requesting=20bluetooth=20scan?= =?UTF-8?q?=20permissions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Complementary to https://github.com/e-mission/e-mission-data-collection/pull/224 Very similar to the fitness checks, just calls through to the underlying native javascript Note that the bluetooth scan will currently only be used for fleet configs since we don't use bluetooth in the general case, and forcing people to enable it unnecessarily is bad. Testing done: https://github.com/e-mission/e-mission-data-collection/pull/224#issuecomment-2055712525 --- www/js/usePermissionStatus.ts | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/www/js/usePermissionStatus.ts b/www/js/usePermissionStatus.ts index 8c3128bea..43206973f 100644 --- a/www/js/usePermissionStatus.ts +++ b/www/js/usePermissionStatus.ts @@ -291,6 +291,41 @@ const usePermissionStatus = () => { setCheckList(tempChecks); } + function setupAndroidBluetoothChecks() { + if (window['device'].version.split('.')[0] >= 10) { + let fixPerms = () => { + logDebug('fix and refresh bluetooth permissions'); + return checkOrFix( + bluetoothPermissionsCheck, + window['cordova'].plugins.BEMDataCollection.fixBluetoothPermissions, + true, + ).then((error) => { + if (error) { + bluetoothPermissionsCheck.desc = error; + } + }); + }; + let checkPerms = () => { + logDebug('fix and refresh bluetooth permissions'); + return checkOrFix( + bluetoothPermissionsCheck, + window['cordova'].plugins.BEMDataCollection.isValidBluetoothPermissions, + false, + ); + }; + + let bluetoothPermissionsCheck = { + name: "Bluetooth scan permission", + desc: "Scan for BLE beacons to automatically match trips to vehicles", + fix: fixPerms, + refresh: checkPerms, + }; + let tempChecks = checkList; + tempChecks.push(bluetoothPermissionsCheck); + setCheckList(tempChecks); + } + } + function setupAndroidNotificationChecks() { let fixPerms = () => { logDebug('fix and refresh notification permissions'); @@ -409,6 +444,9 @@ const usePermissionStatus = () => { if (window['device'].platform.toLowerCase() == 'android') { setupAndroidLocChecks(); setupAndroidFitnessChecks(); + if (appConfig.tracking?.bluetooth_only) { + setupAndroidBluetoothChecks(); + } setupAndroidNotificationChecks(); setupAndroidBackgroundRestrictionChecks(); } else if (window['device'].platform.toLowerCase() == 'ios') { From 9d6e5292782ee9393e3e5f8e35255d785390ef48 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Mon, 15 Apr 2024 01:02:02 -0700 Subject: [PATCH 3/6] Prettier formatting fix --- www/js/usePermissionStatus.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/www/js/usePermissionStatus.ts b/www/js/usePermissionStatus.ts index 43206973f..f8fef085b 100644 --- a/www/js/usePermissionStatus.ts +++ b/www/js/usePermissionStatus.ts @@ -315,8 +315,8 @@ const usePermissionStatus = () => { }; let bluetoothPermissionsCheck = { - name: "Bluetooth scan permission", - desc: "Scan for BLE beacons to automatically match trips to vehicles", + name: 'Bluetooth scan permission', + desc: 'Scan for BLE beacons to automatically match trips to vehicles', fix: fixPerms, refresh: checkPerms, }; From 705413683b4591edef6493735725c68fc9f7a099 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Mon, 15 Apr 2024 01:03:47 -0700 Subject: [PATCH 4/6] Bump up the versions for the usercache and data collection plugins The data collection plugin may have other changes coming in, so we are installing it off a branch --- package.cordovabuild.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.cordovabuild.json b/package.cordovabuild.json index c3f7ec8d3..7ad923049 100644 --- a/package.cordovabuild.json +++ b/package.cordovabuild.json @@ -121,13 +121,13 @@ "cordova-plugin-app-version": "0.1.14", "cordova-plugin-customurlscheme": "5.0.2", "cordova-plugin-device": "2.1.0", - "cordova-plugin-em-datacollection": "git+https://github.com/e-mission/e-mission-data-collection.git#v1.8.3", + "cordova-plugin-em-datacollection": "git+https://github.com/e-mission/e-mission-data-collection.git#integrate_ble", "cordova-plugin-em-opcodeauth": "git+https://github.com/e-mission/cordova-jwt-auth.git#v1.7.2", "cordova-plugin-em-server-communication": "git+https://github.com/e-mission/cordova-server-communication.git#v1.2.6", "cordova-plugin-em-serversync": "git+https://github.com/e-mission/cordova-server-sync.git#v1.3.2", "cordova-plugin-em-settings": "git+https://github.com/e-mission/cordova-connection-settings.git#v1.2.3", "cordova-plugin-em-unifiedlogger": "git+https://github.com/e-mission/cordova-unified-logger.git#v1.3.6", - "cordova-plugin-em-usercache": "git+https://github.com/e-mission/cordova-usercache.git#v1.1.8", + "cordova-plugin-em-usercache": "git+https://github.com/e-mission/cordova-usercache.git#v1.1.9", "cordova-plugin-email-composer": "git+https://github.com/katzer/cordova-plugin-email-composer.git#0.10.1", "cordova-plugin-file": "8.0.0", "cordova-plugin-inappbrowser": "5.0.0", From 0eebe4b1a2bb3e58140e1806e90c2d3b34b47f5f Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Thu, 25 Apr 2024 21:30:41 -0700 Subject: [PATCH 5/6] Switch the data collection plugin version to the latest https://github.com/e-mission/e-mission-data-collection/pull/226 is now merged and a new release https://github.com/e-mission/e-mission-data-collection/releases/tag/v1.8.5 has been created So we can now use the version number instead of a branch while adding the plugin With this commit, the initial implementation in https://github.com/e-mission/e-mission-phone/pull/1144 is done, and we can merge it --- package.cordovabuild.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.cordovabuild.json b/package.cordovabuild.json index 7ad923049..180849033 100644 --- a/package.cordovabuild.json +++ b/package.cordovabuild.json @@ -121,7 +121,7 @@ "cordova-plugin-app-version": "0.1.14", "cordova-plugin-customurlscheme": "5.0.2", "cordova-plugin-device": "2.1.0", - "cordova-plugin-em-datacollection": "git+https://github.com/e-mission/e-mission-data-collection.git#integrate_ble", + "cordova-plugin-em-datacollection": "git+https://github.com/e-mission/e-mission-data-collection.git#1.8.5", "cordova-plugin-em-opcodeauth": "git+https://github.com/e-mission/cordova-jwt-auth.git#v1.7.2", "cordova-plugin-em-server-communication": "git+https://github.com/e-mission/cordova-server-communication.git#v1.2.6", "cordova-plugin-em-serversync": "git+https://github.com/e-mission/cordova-server-sync.git#v1.3.2", From ccab0ca17f22a11c7c4d9c2e27c79639502e8469 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Sun, 28 Apr 2024 10:49:01 -0700 Subject: [PATCH 6/6] =?UTF-8?q?=F0=9F=90=9B=20Use=20the=20correct=20versio?= =?UTF-8?q?n=20(v1.8.5)=20instead=20of=20just=201.8.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.cordovabuild.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.cordovabuild.json b/package.cordovabuild.json index 0a88e7133..282e3693d 100644 --- a/package.cordovabuild.json +++ b/package.cordovabuild.json @@ -121,7 +121,7 @@ "cordova-plugin-app-version": "0.1.14", "cordova-plugin-customurlscheme": "5.0.2", "cordova-plugin-device": "2.1.0", - "cordova-plugin-em-datacollection": "git+https://github.com/e-mission/e-mission-data-collection.git#1.8.5", + "cordova-plugin-em-datacollection": "git+https://github.com/e-mission/e-mission-data-collection.git#v1.8.5", "cordova-plugin-em-opcodeauth": "git+https://github.com/e-mission/cordova-jwt-auth.git#v1.7.2", "cordova-plugin-em-server-communication": "git+https://github.com/e-mission/cordova-server-communication.git#v1.2.6", "cordova-plugin-em-serversync": "git+https://github.com/e-mission/cordova-server-sync.git#v1.3.2",