Skip to content

Commit

Permalink
Merge pull request #1144 from shankari/simulate_ble_scans
Browse files Browse the repository at this point in the history
Expand the profile screen to simulate bluetooth actions separately and handle them properly in the native code
  • Loading branch information
shankari authored Apr 28, 2024
2 parents 5093541 + ccab0ca commit 8a9d9b3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
4 changes: 2 additions & 2 deletions package.cordovabuild.json
Original file line number Diff line number Diff line change
Expand Up @@ -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#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",
"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",
Expand Down
11 changes: 0 additions & 11 deletions www/js/bluetooth/BluetoothScanPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ const BluetoothScanPage = ({ ...props }: any) => {
in_range: status,
},
}));
let { monitorResult: _, in_range: _, ...noResultDevice } = sampleBLEDevices[uuid];
window['cordova']?.plugins?.BEMDataCollection.mockBLEObjects(

Check warning on line 100 in www/js/bluetooth/BluetoothScanPage.tsx

View check run for this annotation

Codecov / codecov/patch

www/js/bluetooth/BluetoothScanPage.tsx#L100

Added line #L100 was not covered by tests
status ? 'REGION_ENTER' : 'REGION_EXIT',
uuid,
Expand All @@ -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(

Check warning on line 122 in www/js/bluetooth/BluetoothScanPage.tsx

View check run for this annotation

Codecov / codecov/patch

www/js/bluetooth/BluetoothScanPage.tsx#L120-L122

Added lines #L120 - L122 were not covered by tests
Expand Down
38 changes: 38 additions & 0 deletions www/js/usePermissionStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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') {
Expand Down

0 comments on commit 8a9d9b3

Please sign in to comment.