From 0bf3d147f00218cffd9ecbb90bccac6d3e284e97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mieszko=20Wrzeszczy=C5=84ski?= Date: Wed, 2 Jan 2019 09:03:44 +0100 Subject: [PATCH] Don't use GPS when manual sharing has been choosen --- .../BackgroundLocalizationService.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/uam/wmi/findmytutor/service/BackgroundLocalizationService.java b/app/src/main/java/com/uam/wmi/findmytutor/service/BackgroundLocalizationService.java index d59d533..8933d69 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/service/BackgroundLocalizationService.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/service/BackgroundLocalizationService.java @@ -65,11 +65,17 @@ public class BackgroundLocalizationService extends Service { private Handler mHandler = new Handler(); private Runnable mStatusChecker; private FusedLocationProviderClient mFusedLocationClient; + private Location fakeLoc = null; public BackgroundLocalizationService() { providers.add(LocationManager.GPS_PROVIDER); providers.add(LocationManager.NETWORK_PROVIDER); providers.add(LocationManager.PASSIVE_PROVIDER); + fakeLoc = new Location(""); + + fakeLoc.setLatitude(0); + fakeLoc.setLongitude(0); + fakeLoc.setAltitude(0); } @Override @@ -112,9 +118,13 @@ public class BackgroundLocalizationService extends Service { if (!stopService) { mStatusChecker = () -> { try { - mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this); - getLocalizationFromListeners(); - changeBackgroundMode(); + if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.MANUAL.toString())) { + sendCoordinateToBackend(fakeLoc); + } else { + mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this); + getLocalizationFromListeners(); + changeBackgroundMode(); + } } finally { mFusedLocationClient = null; destroyLocationListeners(); @@ -200,7 +210,7 @@ public class BackgroundLocalizationService extends Service { destroyLocationListeners(); } - private void destroyLocationListeners(){ + private void destroyLocationListeners() { } @@ -230,10 +240,9 @@ public class BackgroundLocalizationService extends Service { String locationLevel = PrefUtils.getLocationLevel(getApplicationContext()); String status = (PrefUtils.isStatusEnabled(getApplicationContext())) ? PrefUtils.getUserStatus(getApplicationContext()) : ""; - - + if (locationLevel.equals(SharingLevel.PRESENCE.toString())) { - if(!MapUtils.checkIfCoordinateIsValid(latitude,longitude)){ + if (!MapUtils.checkIfCoordinateIsValid(latitude, longitude)) { return null; } @@ -277,7 +286,7 @@ public class BackgroundLocalizationService extends Service { @Override public void onError(Throwable e) { - Log.e(TAG,"onErr" + valueOf(e)); + Log.e(TAG, "onErr" + valueOf(e)); } }));