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

Expand the profile screen to simulate bluetooth actions separately and handle them properly in the native code #1144

Merged
merged 7 commits into from
Apr 28, 2024
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(
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(
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 @@
setCheckList(tempChecks);
}

function setupAndroidBluetoothChecks() {

Check warning on line 294 in www/js/usePermissionStatus.ts

View check run for this annotation

Codecov / codecov/patch

www/js/usePermissionStatus.ts#L294

Added line #L294 was not covered by tests
if (window['device'].version.split('.')[0] >= 10) {
let fixPerms = () => {
logDebug('fix and refresh bluetooth permissions');
return checkOrFix(

Check warning on line 298 in www/js/usePermissionStatus.ts

View check run for this annotation

Codecov / codecov/patch

www/js/usePermissionStatus.ts#L296-L298

Added lines #L296 - L298 were not covered by tests
bluetoothPermissionsCheck,
window['cordova'].plugins.BEMDataCollection.fixBluetoothPermissions,
true,
).then((error) => {

Check warning on line 302 in www/js/usePermissionStatus.ts

View check run for this annotation

Codecov / codecov/patch

www/js/usePermissionStatus.ts#L302

Added line #L302 was not covered by tests
if (error) {
bluetoothPermissionsCheck.desc = error;

Check warning on line 304 in www/js/usePermissionStatus.ts

View check run for this annotation

Codecov / codecov/patch

www/js/usePermissionStatus.ts#L304

Added line #L304 was not covered by tests
}
});
};
let checkPerms = () => {
logDebug('fix and refresh bluetooth permissions');
return checkOrFix(

Check warning on line 310 in www/js/usePermissionStatus.ts

View check run for this annotation

Codecov / codecov/patch

www/js/usePermissionStatus.ts#L308-L310

Added lines #L308 - L310 were not covered by tests
bluetoothPermissionsCheck,
window['cordova'].plugins.BEMDataCollection.isValidBluetoothPermissions,
false,
);
};

let bluetoothPermissionsCheck = {

Check warning on line 317 in www/js/usePermissionStatus.ts

View check run for this annotation

Codecov / codecov/patch

www/js/usePermissionStatus.ts#L317

Added line #L317 was not covered by tests
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);

Check warning on line 325 in www/js/usePermissionStatus.ts

View check run for this annotation

Codecov / codecov/patch

www/js/usePermissionStatus.ts#L323-L325

Added lines #L323 - L325 were not covered by tests
}
}

function setupAndroidNotificationChecks() {
let fixPerms = () => {
logDebug('fix and refresh notification permissions');
Expand Down Expand Up @@ -409,6 +444,9 @@
if (window['device'].platform.toLowerCase() == 'android') {
setupAndroidLocChecks();
setupAndroidFitnessChecks();
if (appConfig.tracking?.bluetooth_only) {
setupAndroidBluetoothChecks();

Check warning on line 448 in www/js/usePermissionStatus.ts

View check run for this annotation

Codecov / codecov/patch

www/js/usePermissionStatus.ts#L448

Added line #L448 was not covered by tests
}
setupAndroidNotificationChecks();
setupAndroidBackgroundRestrictionChecks();
} else if (window['device'].platform.toLowerCase() == 'ios') {
Expand Down
Loading