mirror of https://github.com/espruino/BangleApps
android - Remove GBGPS tracking
parent
2675783aae
commit
436a3dfd97
|
@ -141,7 +141,7 @@
|
|||
Bangle.emit('GPS', event);
|
||||
},
|
||||
"is_gps_active": function() {
|
||||
gbSend({ t: "gps_power", status: Bangle.isGBGPSOn() });
|
||||
gbSend({ t: "gps_power", status: Bangle.isGPSOn() });
|
||||
}
|
||||
};
|
||||
var h = HANDLERS[event.t];
|
||||
|
@ -207,24 +207,19 @@
|
|||
};
|
||||
// GPS overwrite logic
|
||||
if (settings.overwriteGps) { // if the overwrite option is set../
|
||||
const origIsGPSOn = Bangle.isGPSOn;
|
||||
const origSetGPSPower = Bangle.setGPSPower;
|
||||
// migrate all GPS clients to the other variant on connection events
|
||||
let handleConnect = () => {
|
||||
if (origIsGPSOn()){
|
||||
for (let c of Bangle._PWR.GPS){
|
||||
Bangle.setGBGPSPower(1, c);
|
||||
origSetGPSPower(0, c);
|
||||
}
|
||||
}
|
||||
let orig = Bangle._PWR.GPS;
|
||||
delete Bangle._PWR.GPS;
|
||||
origSetGPSPower(0);
|
||||
Bangle._PWR.GPS = orig;
|
||||
};
|
||||
let handleDisconnect = () => {
|
||||
if (Bangle.isGBGPSOn()){
|
||||
for (let c of Bangle._PWR.GBGPS){
|
||||
origSetGPSPower(1, c);
|
||||
Bangle.setGBGPSPower(0, c);
|
||||
}
|
||||
}
|
||||
let orig = Bangle._PWR.GPS;
|
||||
delete Bangle._PWR.GPS;
|
||||
origSetGPSPower(1);
|
||||
Bangle._PWR.GPS = orig;
|
||||
};
|
||||
NRF.on('connect', handleConnect);
|
||||
NRF.on('disconnect', handleDisconnect);
|
||||
|
@ -240,35 +235,28 @@
|
|||
o(s);
|
||||
})(Serial1.write);
|
||||
|
||||
Bangle.setGBGPSPower = (isOn, appID) => {
|
||||
if (!Bangle._PWR) Bangle._PWR={};
|
||||
if (!Bangle._PWR.GBGPS) Bangle._PWR.GBGPS=[];
|
||||
if (!appID) appID="?";
|
||||
if (isOn && !Bangle._PWR.GBGPS.includes(appID)) Bangle._PWR.GBGPS.push(appID);
|
||||
if (!isOn && Bangle._PWR.GBGPS.includes(appID)) Bangle._PWR.GBGPS.splice(Bangle._PWR.GBGPS.indexOf(appID),1);
|
||||
let pwr = Bangle._PWR.GBGPS.length>0;
|
||||
gbSend({ t: "gps_power", status: pwr });
|
||||
return pwr;
|
||||
};
|
||||
// Replace set GPS power logic to suppress activation of gps (and instead request it from the phone)
|
||||
Bangle.setGPSPower = (isOn, appID) => {
|
||||
// disable our own request for GPS power first
|
||||
// disable our own request for GPS power first and always
|
||||
if (!isOn) origSetGPSPower(0,"android_gpsserial");
|
||||
// if not connected use internal GPS power function
|
||||
if (!NRF.getSecurityStatus().connected) return origSetGPSPower(isOn, appID);
|
||||
return Bangle.setGBGPSPower(isOn, appID);
|
||||
if (!Bangle._PWR) Bangle._PWR={};
|
||||
if (!Bangle._PWR.GPS) Bangle._PWR.GPS=[];
|
||||
if (!appID) appID="?";
|
||||
if (isOn && !Bangle._PWR.GPS.includes(appID)) Bangle._PWR.GPS.push(appID);
|
||||
if (!isOn && Bangle._PWR.GPS.includes(appID)) Bangle._PWR.GPS.splice(Bangle._PWR.GPS.indexOf(appID),1);
|
||||
let pwr = Bangle._PWR.GPS.length>0;
|
||||
gbSend({ t: "gps_power", status: pwr });
|
||||
return pwr;
|
||||
};
|
||||
// Allow checking for GPS via GadgetBridge
|
||||
Bangle.isGBGPSOn = () => {
|
||||
return !!(Bangle._PWR && Bangle._PWR.GBGPS && Bangle._PWR.GBGPS.length>0);
|
||||
};
|
||||
// Replace check if the GPS is on to check both internal and external GPS
|
||||
Bangle.isGPSOn = () => {
|
||||
return Bangle.isGBGPSOn() || origIsGPSOn();
|
||||
return !!(Bangle._PWR && Bangle._PWR.GPS && Bangle._PWR.GPS.length>0);
|
||||
};
|
||||
// stop GPS on boot if not activated
|
||||
setTimeout(()=>{
|
||||
if (!Bangle.isGBGPSOn()) gbSend({ t: "gps_power", status: false });
|
||||
if (!Bangle.isGPSOn()) gbSend({ t: "gps_power", status: false });
|
||||
},3000);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,84 +26,55 @@ let sec = {
|
|||
NRF.getSecurityStatus = () => sec;
|
||||
|
||||
setTimeout(() => {
|
||||
print(Bangle._PWR);
|
||||
// add an empty starting point to make the asserts work
|
||||
Bangle._PWR={};
|
||||
|
||||
print("Not connected, should use internal GPS");
|
||||
assertTrue(!NRF.getSecurityStatus().connected, "Not connected");
|
||||
|
||||
assertUndefinedOrEmpty(Bangle._PWR.GBGPS, "No GBGPS");
|
||||
assertUndefinedOrEmpty(Bangle._PWR.GPS, "No GPS");
|
||||
assertFalse(Bangle.isGPSOn(), "isGPSOn");
|
||||
assertFalse(Bangle.isGBGPSOn(), "isGBGPSOn");
|
||||
|
||||
assertTrue(Bangle.setGPSPower(1), "Switch GPS on");
|
||||
|
||||
assertUndefinedOrEmpty(Bangle._PWR.GBGPS, "No GBGPS");
|
||||
assertNotEmpty(Bangle._PWR.GPS, "GPS");
|
||||
assertTrue(Bangle.isGPSOn(), "isGPSOn");
|
||||
assertFalse(Bangle.isGBGPSOn(), "isGBGPSOn");
|
||||
|
||||
assertFalse(Bangle.setGPSPower(0), "Switch GPS off");
|
||||
|
||||
assertUndefinedOrEmpty(Bangle._PWR.GBGPS, "No GBGPS");
|
||||
assertUndefinedOrEmpty(Bangle._PWR.GPS, "No GPS");
|
||||
assertFalse(Bangle.isGPSOn(), "isGPSOn");
|
||||
assertFalse(Bangle.isGBGPSOn(), "isGBGPSOn");
|
||||
|
||||
assertTrue(Bangle.setGBGPSPower(1), "Switch GBGPS on");
|
||||
|
||||
assertUndefinedOrEmpty(Bangle._PWR.GPS, "No GPS");
|
||||
assertNotEmpty(Bangle._PWR.GBGPS, "GBGPS");
|
||||
assertTrue(Bangle.isGPSOn(), "isGPSOn");
|
||||
assertTrue(Bangle.isGBGPSOn(), "isGBGPSOn");
|
||||
|
||||
assertFalse(Bangle.setGBGPSPower(0), "Switch GBGPS off");
|
||||
|
||||
assertUndefinedOrEmpty(Bangle._PWR.GBGPS, "No GBGPS");
|
||||
assertUndefinedOrEmpty(Bangle._PWR.GPS, "No GPS");
|
||||
assertFalse(Bangle.isGPSOn(), "isGPSOn");
|
||||
assertFalse(Bangle.isGBGPSOn(), "isGBGPSOn");
|
||||
|
||||
print("Connected, should use GB GPS");
|
||||
sec.connected = true;
|
||||
|
||||
assertTrue(NRF.getSecurityStatus().connected, "Connected");
|
||||
|
||||
assertUndefinedOrEmpty(Bangle._PWR.GBGPS, "No GBGPS");
|
||||
assertUndefinedOrEmpty(Bangle._PWR.GPS, "No GPS");
|
||||
assertFalse(Bangle.isGPSOn(), "isGPSOn");
|
||||
assertFalse(Bangle.isGBGPSOn(), "isGBGPSOn");
|
||||
|
||||
assertTrue(Bangle.setGPSPower(1), "Switch GPS on");
|
||||
|
||||
assertUndefinedOrEmpty(Bangle._PWR.GPS, "No GPS");
|
||||
assertNotEmpty(Bangle._PWR.GBGPS, "GBGPS");
|
||||
assertNotEmpty(Bangle._PWR.GPS, "GPS");
|
||||
assertTrue(Bangle.isGPSOn(), "isGPSOn");
|
||||
assertTrue(Bangle.isGBGPSOn(), "isGBGPSOn");
|
||||
|
||||
assertFalse(Bangle.setGPSPower(0), "Switch GPS off");
|
||||
|
||||
assertUndefinedOrEmpty(Bangle._PWR.GBGPS, "No GBGPS");
|
||||
assertUndefinedOrEmpty(Bangle._PWR.GPS, "No GPS");
|
||||
assertFalse(Bangle.isGPSOn(), "isGPSOn");
|
||||
assertFalse(Bangle.isGBGPSOn(), "isGBGPSOn");
|
||||
|
||||
print("Connected, then reconnect cycle");
|
||||
sec.connected = true;
|
||||
|
||||
assertTrue(NRF.getSecurityStatus().connected, "Connected");
|
||||
|
||||
assertUndefinedOrEmpty(Bangle._PWR.GBGPS, "No GBGPS");
|
||||
assertUndefinedOrEmpty(Bangle._PWR.GPS, "No GPS");
|
||||
assertFalse(Bangle.isGPSOn(), "isGPSOn");
|
||||
assertFalse(Bangle.isGBGPSOn(), "isGBGPSOn");
|
||||
|
||||
assertTrue(Bangle.setGPSPower(1), "Switch GPS on");
|
||||
|
||||
assertUndefinedOrEmpty(Bangle._PWR.GPS, "No GPS");
|
||||
assertNotEmpty(Bangle._PWR.GBGPS, "GBGPS");
|
||||
assertNotEmpty(Bangle._PWR.GPS, "GPS");
|
||||
assertTrue(Bangle.isGPSOn(), "isGPSOn");
|
||||
assertTrue(Bangle.isGBGPSOn(), "isGBGPSOn");
|
||||
|
||||
print("disconnect");
|
||||
NRF.emit("disconnect", {});
|
||||
|
@ -112,34 +83,26 @@ setTimeout(() => {
|
|||
setTimeout(() => {
|
||||
|
||||
assertNotEmpty(Bangle._PWR.GPS, "GPS");
|
||||
assertUndefinedOrEmpty(Bangle._PWR.GBGPS, "No GBGPS");
|
||||
assertTrue(Bangle.isGPSOn(), "isGPSOn");
|
||||
assertFalse(Bangle.isGBGPSOn(), "isGBGPSOn");
|
||||
|
||||
print("connect");
|
||||
NRF.emit("connect", {});
|
||||
sec.connected = true;
|
||||
|
||||
setTimeout(() => {
|
||||
assertUndefinedOrEmpty(Bangle._PWR.GPS, "No GPS");
|
||||
assertNotEmpty(Bangle._PWR.GBGPS, "GBGPS");
|
||||
assertNotEmpty(Bangle._PWR.GPS, "GPS");
|
||||
assertTrue(Bangle.isGPSOn(), "isGPSOn");
|
||||
assertTrue(Bangle.isGBGPSOn(), "isGBGPSOn");
|
||||
|
||||
assertFalse(Bangle.setGPSPower(0), "Switch GPS off");
|
||||
|
||||
assertUndefinedOrEmpty(Bangle._PWR.GBGPS, "No GBGPS");
|
||||
assertUndefinedOrEmpty(Bangle._PWR.GPS, "No GPS");
|
||||
assertFalse(Bangle.isGPSOn(), "isGPSOn");
|
||||
assertFalse(Bangle.isGBGPSOn(), "isGBGPSOn");
|
||||
|
||||
setTimeout(() => {
|
||||
print("Test disconnect without gps on");
|
||||
|
||||
assertUndefinedOrEmpty(Bangle._PWR.GBGPS, "No GBGPS");
|
||||
assertUndefinedOrEmpty(Bangle._PWR.GPS, "No GPS");
|
||||
assertFalse(Bangle.isGPSOn(), "isGPSOn");
|
||||
assertFalse(Bangle.isGBGPSOn(), "isGBGPSOn");
|
||||
|
||||
print("Result Overall is " + (result ? "OK" : "FAIL"));
|
||||
}, 0);
|
||||
|
|
Loading…
Reference in New Issue