diff --git a/app/build.gradle b/app/build.gradle index cb2ddeb7..8d229080 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,7 +12,7 @@ android { targetSdkVersion 34 - versionCode 341 + versionCode 342 versionName '2.6.1' multiDexEnabled true @@ -49,12 +49,12 @@ dependencies { implementation 'com.google.android.gms:play-services-location:21.3.0' implementation 'com.google.android.gms:play-services-gcm:17.0.0' implementation 'com.google.android.gms:play-services-vision:20.1.3' - implementation 'com.google.android.gms:play-services-maps:18.2.0' + implementation 'com.google.android.gms:play-services-maps:19.0.0' implementation 'com.google.firebase:firebase-core:21.1.1' implementation 'com.google.firebase:firebase-iid:21.1.0' implementation 'com.google.firebase:firebase-messaging:24.0.0' - implementation 'com.google.firebase:firebase-analytics:22.0.1' - implementation 'com.google.firebase:firebase-crashlytics:19.0.1' + implementation 'com.google.firebase:firebase-analytics:22.0.2' + implementation 'com.google.firebase:firebase-crashlytics:19.0.3' implementation 'com.google.firebase:firebase-database:21.0.0' implementation 'com.android.installreferrer:installreferrer:2.2' @@ -63,8 +63,8 @@ dependencies { implementation 'androidx.biometric:biometric:1.2.0-alpha05' testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.5' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' + androidTestImplementation 'androidx.test.ext:junit:1.2.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' } diff --git a/app/src/main/java/com/prey/PreyApp.java b/app/src/main/java/com/prey/PreyApp.java index 30cc52f5..537d4b01 100644 --- a/app/src/main/java/com/prey/PreyApp.java +++ b/app/src/main/java/com/prey/PreyApp.java @@ -111,7 +111,8 @@ public void run() { if (!verifyNotification) { EventFactory.notification(ctx); } - if ((accessCoarseLocation || accessFineLocation) && canAccessBackgroundLocation) { + boolean isGooglePlayServicesAvailable = PreyUtils.isGooglePlayServicesAvailable(ctx); + if (isGooglePlayServicesAvailable && (accessCoarseLocation || accessFineLocation) && canAccessBackgroundLocation) { GeofenceController.getInstance().run(ctx); AwareController.getInstance().init(ctx); AwareScheduled.getInstance(ctx).run(); @@ -129,7 +130,9 @@ public void run() { try { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { PreyJobService.schedule(ctx); - AwareJobService.schedule(ctx); + if (isGooglePlayServicesAvailable) { + AwareJobService.schedule(ctx); + } } } catch (Exception e) { PreyLogger.e(String.format("error jobService.schedule : %s", e.getMessage()), e); diff --git a/app/src/main/java/com/prey/PreyConfig.java b/app/src/main/java/com/prey/PreyConfig.java index 098f1af3..535dae50 100644 --- a/app/src/main/java/com/prey/PreyConfig.java +++ b/app/src/main/java/com/prey/PreyConfig.java @@ -1621,4 +1621,15 @@ public void setDailyLocation(String dailyLocation){ PreyLogger.d(String.format("DAILY setDailyLocation [%s]", dailyLocation)); saveString(PreyConfig.DAILY_LOCATION, dailyLocation); } + + public static final String MINUTES_TO_QUERY_SERVER = "MINUTES_TO_QUERY_SERVER"; + + public int getMinutesToQueryServer() { + return getInt(PreyConfig.MINUTES_TO_QUERY_SERVER, 15); + } + + public void setMinutesToQueryServer(int minutesToQueryServer) { + PreyLogger.d(String.format("setMinutesToQueryServer [%s]", minutesToQueryServer)); + saveInt(PreyConfig.MINUTES_TO_QUERY_SERVER, minutesToQueryServer); + } } diff --git a/app/src/main/java/com/prey/PreyStatus.java b/app/src/main/java/com/prey/PreyStatus.java index 05e401f2..e1a9e3ed 100644 --- a/app/src/main/java/com/prey/PreyStatus.java +++ b/app/src/main/java/com/prey/PreyStatus.java @@ -78,6 +78,7 @@ public void setPreyPopUpOnclick(boolean preyPopUpOnclick) { public void initConfig(Context ctx){ boolean aware = false; boolean autoconnect = false; + int minutesToQueryServer; try { JSONObject jsnobject = PreyWebServices.getInstance().getStatus(ctx); if (jsnobject != null) { @@ -97,11 +98,18 @@ public void initConfig(Context ctx){ } PreyConfig.getPreyConfig(ctx).setAware(aware); PreyConfig.getPreyConfig(ctx).setAutoConnect(autoconnect); - PreyLogger.d("STATUS aware :" + aware); - PreyLogger.d("STATUS autoconnect :" + autoconnect); + PreyLogger.d(String.format("STATUS aware :%b", aware)); + PreyLogger.d(String.format("STATUS autoconnect :%b", autoconnect)); + try { + minutesToQueryServer = jsnobject.getInt("minutes_to_query_server"); + } catch (Exception e) { + minutesToQueryServer = PreyConfig.getPreyConfig(ctx).getMinutesToQueryServer(); + } + PreyConfig.getPreyConfig(ctx).setMinutesToQueryServer(minutesToQueryServer); + PreyLogger.d(String.format("STATUS minutesToQueryServer :%s", minutesToQueryServer)); } } catch (Exception e) { - PreyLogger.e("STATUS Error:" + e.getMessage(), e); + PreyLogger.e(String.format("STATUS Error:%s", e.getMessage()), e); } } diff --git a/app/src/main/java/com/prey/PreyUtils.java b/app/src/main/java/com/prey/PreyUtils.java index 837aecfe..ae2b1515 100644 --- a/app/src/main/java/com/prey/PreyUtils.java +++ b/app/src/main/java/com/prey/PreyUtils.java @@ -21,6 +21,8 @@ import android.util.DisplayMetrics; import android.widget.Toast; +import com.google.android.gms.common.ConnectionResult; +import com.google.android.gms.common.GoogleApiAvailability; import com.prey.backwardcompatibility.AboveCupcakeSupport; public class PreyUtils { @@ -146,4 +148,17 @@ public static long copyFile(InputStream input, OutputStream output) throws IOExc return count; } + public static boolean isGooglePlayServicesAvailable(Context context) { + boolean isGooglePlayServicesAvailable; + try { + GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance(); + int resultCode = googleApiAvailability.isGooglePlayServicesAvailable(context); + isGooglePlayServicesAvailable = (resultCode == ConnectionResult.SUCCESS); + } catch (Exception e) { + isGooglePlayServicesAvailable = false; + } + PreyLogger.d(String.format("isGooglePlayServicesAvailable:%s", isGooglePlayServicesAvailable)); + return isGooglePlayServicesAvailable; + } + } \ No newline at end of file diff --git a/app/src/main/java/com/prey/actions/location/LocationUtil.java b/app/src/main/java/com/prey/actions/location/LocationUtil.java index 10ee2eb0..2968fcf7 100644 --- a/app/src/main/java/com/prey/actions/location/LocationUtil.java +++ b/app/src/main/java/com/prey/actions/location/LocationUtil.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import android.Manifest; @@ -21,18 +22,19 @@ import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; -import com.google.android.gms.location.FusedLocationProviderClient; -import com.google.android.gms.location.LocationServices; -import com.google.android.gms.tasks.OnSuccessListener; import com.prey.PreyConfig; import com.prey.PreyLogger; +import com.prey.PreyPhone; +import com.prey.PreyUtils; import com.prey.actions.HttpDataService; -import com.prey.actions.geofences.GeofenceController; import com.prey.json.UtilJson; import com.prey.managers.PreyWifiManager; import com.prey.net.PreyWebServices; import com.prey.services.LocationService; +import org.json.JSONException; +import org.json.JSONObject; + public class LocationUtil { public static final String LAT = "lat"; @@ -51,6 +53,7 @@ public static HttpDataService dataLocation(final Context ctx, String messageId, if (preyLocation != null && (preyLocation.getLat() != 0 && preyLocation.getLng() != 0)) { PreyLogger.d(String.format("locationData:%s %s %s", preyLocation.getLat(), preyLocation.getLng(), preyLocation.getAccuracy())); PreyConfig.getPreyConfig(ctx).setLocation(preyLocation); + PreyLocationManager.getInstance(ctx).setLastLocation(preyLocation); data = convertData(preyLocation); } else { PreyLogger.d("locationData else:"); @@ -71,32 +74,39 @@ public static PreyLocation getLocation(Context ctx, String messageId, boolean as boolean isGpsEnabled = PreyLocationManager.getInstance(ctx).isGpsLocationServiceActive(); boolean isNetworkEnabled = PreyLocationManager.getInstance(ctx).isNetworkLocationServiceActive(); boolean isWifiEnabled = PreyWifiManager.getInstance(ctx).isWifiEnabled(); - boolean isGooglePlayServicesAvailable=isGooglePlayServicesAvailable(ctx); - String locationInfo="{\"gps\":" + isGpsEnabled + ",\"net\":" + isNetworkEnabled + ",\"wifi\":" + isWifiEnabled+",\"play\":"+isGooglePlayServicesAvailable+"}"; + boolean isGooglePlayServicesAvailable = PreyUtils.isGooglePlayServicesAvailable(ctx); + JSONObject json = new JSONObject(); + try { + json.put("gps", isGpsEnabled); + json.put("net", isNetworkEnabled); + json.put("wifi", isWifiEnabled); + json.put("play", isGooglePlayServicesAvailable); + } catch (JSONException e) { + PreyLogger.e(String.format("Error:%s", e.getMessage()), e); + } + String locationInfo = json.toString(); PreyConfig.getPreyConfig(ctx).setLocationInfo(locationInfo); PreyLogger.d(locationInfo); String method = getMethod(isGpsEnabled, isNetworkEnabled); try { preyLocation = getPreyLocationAppService(ctx, method, asynchronous, preyLocation, maximum); } catch (Exception e) { - PreyLogger.e("Error PreyLocationApp:"+e.getMessage(),e); + PreyLogger.e(String.format("Error PreyLocationApp:%s", e.getMessage()), e); } try { - if(preyLocation==null||preyLocation.getLocation()==null||(preyLocation.getLocation().getLatitude()==0&&preyLocation.getLocation().getLongitude()==0)) { + if (preyLocation == null || preyLocation.getLocation() == null || (preyLocation.getLocation().getLatitude() == 0 && preyLocation.getLocation().getLongitude() == 0)) { preyLocation = getPreyLocationAppServiceOreo(ctx, method, asynchronous, preyLocation); } } catch (Exception e) { - PreyLogger.e("Error AppServiceOreo:"+e.getMessage(),e); + PreyLogger.e(String.format("Error AppServiceOreo:%s", e.getMessage()), e); + } + if (!isGooglePlayServicesAvailable && (preyLocation == null || preyLocation.getLocation() == null || (preyLocation.getLocation().getLatitude() == 0 && preyLocation.getLocation().getLongitude() == 0))) { + List listWifi = new PreyPhone(ctx).getListWifi(); + preyLocation = PreyWebServices.getInstance().getLocationWithWifi(ctx, listWifi); } if (preyLocation != null) { PreyLogger.d(String.format("preyLocation lat:%s lng:%s acc:%s", preyLocation.getLat(), preyLocation.getLng(), preyLocation.getAccuracy())); } - final PreyLocation location = preyLocation; - new Thread() { - public void run() { - GeofenceController.verifyGeozone(ctx, location); - } - }.start(); return preyLocation; } @@ -207,22 +217,6 @@ private static PreyLocation getPreyLocationAppService(final Context ctx, String if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M && (ActivityCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED)) { - try { - FusedLocationProviderClient fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(ctx); - fusedLocationProviderClient.getLastLocation() - .addOnSuccessListener(new OnSuccessListener() { - @Override - public void onSuccess(Location location) { - if (location != null) { - PreyLocationManager.getInstance(ctx).setLastLocation(new PreyLocation(location)); - } - } - }); - preyLocation = waitLocation(ctx, method, asynchronous, maximum); - } catch (Exception e) { - PreyLogger.e(String.format("getPreyLocationAppService e:%s", e.getMessage()), e); - } - } else { Intent intentLocation = new Intent(ctx, LocationService.class); try { ctx.startService(intentLocation); diff --git a/app/src/main/java/com/prey/json/actions/Location.java b/app/src/main/java/com/prey/json/actions/Location.java index ec01cd28..fcbe7846 100644 --- a/app/src/main/java/com/prey/json/actions/Location.java +++ b/app/src/main/java/com/prey/json/actions/Location.java @@ -16,12 +16,10 @@ import com.prey.PreyConfig; import com.prey.PreyLogger; -import com.prey.PreyUtils; import com.prey.actions.HttpDataService; -import com.prey.actions.aware.AwareConfig; import com.prey.actions.aware.AwareController; -import com.prey.actions.location.LocationThread; import com.prey.actions.location.LocationUtil; +import com.prey.actions.location.PreyLocation; import com.prey.actions.location.PreyLocationManager; import com.prey.actions.observer.ActionResult; import com.prey.json.JsonAction; @@ -60,6 +58,7 @@ public List get(Context ctx, List list, JSONObje reason = "{\"device_job_id\":\"" + jobId + "\"}"; } PreyLocationManager.getInstance(ctx).setLastLocation(null); + PreyConfig.getPreyConfig(ctx).setLocation(null); PreyConfig.getPreyConfig(ctx).setLocationInfo(""); PreyWebServices.getInstance().sendNotifyActionResultPreyHttp(ctx,"processed", messageId, UtilJson.makeMapParam("get", "location", "started",reason)); PreyLogger.d(this.getClass().getName()); @@ -73,40 +72,48 @@ public List get(Context ctx, List list, JSONObje while (i < maximum) { send = false; try { - data = LocationUtil.dataLocation(ctx, messageId, true); - String acc = data.getDataListKey(LocationUtil.ACC); - if (acc != null && !acc.equals("")) { - float newAccuracy = 0; - try { - newAccuracy = Float.parseFloat(acc); - PreyLogger.d(String.format("accuracy_:%s newAccuracy:%s", accuracy, newAccuracy)); - } catch (Exception e) { - } - if (newAccuracy > 0) { - if (accuracy == -1 || accuracy > newAccuracy) { - send = true; - accuracy = newAccuracy; + LocationUtil.dataLocation(ctx, messageId, true); + PreyLocation location = PreyConfig.getPreyConfig(ctx).getLocation(); + if (location != null) { + data = LocationUtil.convertData(location); + String acc = data.getDataListKey(LocationUtil.ACC); + if (acc != null && !acc.equals("")) { + float newAccuracy = 0; + try { + newAccuracy = Float.parseFloat(acc); + PreyLogger.d(String.format("accuracy_:%s newAccuracy:%s", accuracy, newAccuracy)); + } catch (Exception e) { + PreyLogger.e(String.format("Error:%s", e.getMessage()), e); + } + if (newAccuracy > 0) { + if (accuracy == -1 || accuracy > newAccuracy) { + send = true; + accuracy = newAccuracy; + } } } + if (send) { + //It is added if it is the first time the location is sent + HttpDataService dataToast = new HttpDataService("skip_toast"); + dataToast.setList(false); + dataToast.setKey("skip_toast"); + dataToast.setSingleData(Boolean.toString(!first)); + dataToBeSent = new ArrayList(); + dataToBeSent.add(data); + dataToBeSent.add(dataToast); + PreyLogger.d(String.format("send [%s]:%s", i, accuracy)); + PreyWebServices.getInstance().sendPreyHttpData(ctx, dataToBeSent); + first = false; + i = LocationUtil.MAXIMUM_OF_ATTEMPTS; + } } - if (send) { - //It is added if it is the first time the location is sent - HttpDataService dataToast = new HttpDataService("skip_toast"); - dataToast.setList(false); - dataToast.setKey("skip_toast"); - dataToast.setSingleData(Boolean.toString(! first)); - dataToBeSent = new ArrayList(); - dataToBeSent.add(data); - dataToBeSent.add(dataToast); - PreyLogger.d(String.format("send [%s]:%s", i, accuracy)); - PreyWebServices.getInstance().sendPreyHttpData(ctx, dataToBeSent); - first = false; - } - try { - Thread.sleep(LocationUtil.SLEEP_OF_ATTEMPTS[i] * 1000); - } catch (Exception e) { - i = LocationUtil.MAXIMUM_OF_ATTEMPTS; - break; + if (i < maximum) { + try { + Thread.sleep(LocationUtil.SLEEP_OF_ATTEMPTS[i] * 1000); + } catch (Exception e) { + i = LocationUtil.MAXIMUM_OF_ATTEMPTS; + break; + } } } catch (Exception e) { i = LocationUtil.MAXIMUM_OF_ATTEMPTS; diff --git a/app/src/main/java/com/prey/net/PreyWebServices.java b/app/src/main/java/com/prey/net/PreyWebServices.java index b8df7b4f..ca50546a 100644 --- a/app/src/main/java/com/prey/net/PreyWebServices.java +++ b/app/src/main/java/com/prey/net/PreyWebServices.java @@ -39,6 +39,8 @@ import com.prey.PreyVerify; import com.prey.actions.HttpDataService; import com.prey.actions.fileretrieval.FileretrievalDto; +import com.prey.actions.location.PreyLocation; +import com.prey.actions.location.PreyLocationManager; import com.prey.actions.observer.ActionsController; import com.prey.backwardcompatibility.AboveCupcakeSupport; import com.prey.events.Event; @@ -572,6 +574,7 @@ public HashMap increaseData(Context ctx, HashMap parameters.put(prefix + "[cpu_cores]", hardware.getCpuCores()); parameters.put(prefix + "[ram_size]", "" + hardware.getTotalMemory()); parameters.put(prefix + "[serial_number]", hardware.getSerialNumber()); + parameters.put(prefix + "[google_services]", String.valueOf(PreyUtils.isGooglePlayServicesAvailable(ctx))); int nic = 0; Wifi wifi = phone.getWifi(); if (wifi != null) { @@ -1271,4 +1274,78 @@ public boolean validToken(Context ctx, String token) throws Exception { return statusCode == 200; } + /** + * Method returns the location using WiFi networks + * + * @param ctx + * @param listWifi + * @return PreyLocation + */ + public PreyLocation getLocationWithWifi(final Context ctx, List listWifi) { + PreyLocation location = null; + try { + JSONObject jsonParam = new JSONObject(); + JSONArray array = new JSONArray(); + for (int i = 0; listWifi != null && i < listWifi.size() && i < 15; i++) { + Wifi wifi = listWifi.get(i); + JSONObject jsonRed = new JSONObject(); + jsonRed.put("macAddress", wifi.getMacAddress()); + jsonRed.put("ssid", wifi.getSsid()); + jsonRed.put("signalStrength", Integer.parseInt(wifi.getSignalStrength())); + jsonRed.put("channel", Integer.parseInt(wifi.getChannel())); + array.put(jsonRed); + } + jsonParam.put("wifiAccessPoints", array); + if (array != null && array.length() > 0) { + String url = PreyConfig.getPreyConfig(ctx).getPreyUrl() + "geo"; + PreyLogger.d(String.format("url:%s", url)); + PreyHttpResponse response = PreyRestHttpClient.getInstance(ctx).jsonMethodAutentication(url, UtilConnection.REQUEST_METHOD_POST, jsonParam); + if (response != null) { + if (response.getStatusCode() == HttpURLConnection.HTTP_OK) { + String out = response.getResponseAsString(); + JSONObject outJson = new JSONObject(out); + if (!outJson.isNull("geolocation")) { + JSONObject geolocationJson = outJson.getJSONObject("geolocation"); + JSONObject locationJSon = geolocationJson.getJSONObject("location"); + double lat = locationJSon.getDouble("lat"); + double lng = locationJSon.getDouble("lng"); + int accuracy = geolocationJson.getInt("accuracy"); + location = new PreyLocation(); + location.setLat(lat); + location.setLng(lng); + location.setAccuracy(accuracy); + location.setMethod("wifi"); + } + if (!outJson.isNull("endpoint")) { + JSONObject endpointJson = outJson.getJSONObject("endpoint"); + String urlJson = endpointJson.getString("url"); + String userAgentJson = endpointJson.getString("user-agent"); + PreyHttpResponse response2 = UtilConnection.postJson(urlJson, userAgentJson, jsonParam); + if (response2.getStatusCode() == HttpURLConnection.HTTP_OK) { + String outEndpoint = response2.getResponseAsString(); + JSONObject outJsonEndpoint = new JSONObject(outEndpoint); + JSONObject locationJsonEndpoint = outJsonEndpoint.getJSONObject("location"); + double lat = locationJsonEndpoint.getDouble("lat"); + double lng = locationJsonEndpoint.getDouble("lng"); + int accuracy = outJsonEndpoint.getInt("accuracy"); + location = new PreyLocation(); + location.setLat(lat); + location.setLng(lng); + location.setAccuracy(accuracy); + location.setMethod("wifi"); + } + } + } + } + } + } catch (Exception e) { + PreyLogger.e(String.format("Error:%s", e.getMessage()), e); + } + if (location != null) { + PreyLocationManager.getInstance(ctx).setLastLocation(location); + PreyConfig.getPreyConfig(ctx).setLocation(location); + } + return location; + } + } \ No newline at end of file diff --git a/app/src/main/java/com/prey/services/LocationService.java b/app/src/main/java/com/prey/services/LocationService.java index bb28f263..40e54bea 100644 --- a/app/src/main/java/com/prey/services/LocationService.java +++ b/app/src/main/java/com/prey/services/LocationService.java @@ -63,6 +63,8 @@ public void onCreate() { LocationProvider gpsLocationProvider = androidLocationManager.getProvider(LocationManager.GPS_PROVIDER); LocationProvider networkProvider = androidLocationManager.getProvider(LocationManager.NETWORK_PROVIDER); + LocationProvider passiveProvider = androidLocationManager.getProvider(LocationManager.PASSIVE_PROVIDER); + LocationProvider fusedProvider = androidLocationManager.getProvider(LocationManager.FUSED_PROVIDER); if (gpsLocationProvider != null && androidLocationManager.isProviderEnabled(gpsLocationProvider.getName())) { androidLocationManager.requestLocationUpdates(gpsLocationProvider.getName(), PreyConfig.UPDATE_INTERVAL, PreyConfig.LOCATION_PROVIDERS_MIN_REFRESH_DISTANCE, gpsLocationListener); @@ -73,6 +75,16 @@ public void onCreate() { networkLocationListener); PreyLogger.d("NETWORK Location provider has been started."); } + if (passiveProvider != null && androidLocationManager.isProviderEnabled(passiveProvider.getName())) { + androidLocationManager.requestLocationUpdates(passiveProvider.getName(), PreyConfig.UPDATE_INTERVAL, PreyConfig.LOCATION_PROVIDERS_MIN_REFRESH_DISTANCE, + passiveLocationListener); + PreyLogger.d("Passive Location provider has been started."); + } + if (fusedProvider != null && androidLocationManager.isProviderEnabled(fusedProvider.getName())) { + androidLocationManager.requestLocationUpdates(fusedProvider.getName(), PreyConfig.UPDATE_INTERVAL, PreyConfig.LOCATION_PROVIDERS_MIN_REFRESH_DISTANCE, + fusedLocationListener); + PreyLogger.d("Fused Location provider has been started."); + } } else { PreyLogger.d("___________ask for permission LocationService ACCESS_FINE_LOCATION"); } @@ -90,6 +102,8 @@ public void onDestroy() { && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED)) { androidLocationManager.removeUpdates(gpsLocationListener); androidLocationManager.removeUpdates(networkLocationListener); + androidLocationManager.removeUpdates(passiveLocationListener); + androidLocationManager.removeUpdates(fusedLocationListener); } } } @@ -172,5 +186,54 @@ public void onLocationChanged(Location location) { setNewLocation(location); } }; + + private LocationListener passiveLocationListener = new LocationListener() { + + public void onStatusChanged(String provider, int status, Bundle extras) { + String statusAsString = "Available"; + if (status == LocationProvider.OUT_OF_SERVICE) + statusAsString = "Out of service"; + else if (status == LocationProvider.TEMPORARILY_UNAVAILABLE) + statusAsString = "Temporarily Unavailable"; + PreyLogger.d(String.format("[LocationService] Network Location provider status has changed: [%s].", statusAsString)); + } + + public void onProviderEnabled(String provider) { + PreyLogger.d(String.format("[LocationService] Passive Location Provider has been enabled: %s", provider)); + } + + public void onProviderDisabled(String provider) { + PreyLogger.d(String.format("[LocationService] Passive Location Provider has been disabled: %s", provider)); + } + + public void onLocationChanged(Location location) { + setNewLocation(location); + } + }; + + + private LocationListener fusedLocationListener = new LocationListener() { + + public void onStatusChanged(String provider, int status, Bundle extras) { + String statusAsString = "Available"; + if (status == LocationProvider.OUT_OF_SERVICE) + statusAsString = "Out of service"; + else if (status == LocationProvider.TEMPORARILY_UNAVAILABLE) + statusAsString = "Temporarily Unavailable"; + PreyLogger.d(String.format("[LocationService] Network Location provider status has changed: [%s].", statusAsString)); + } + + public void onProviderEnabled(String provider) { + PreyLogger.d(String.format("[LocationService] Fused Location Provider has been enabled: %s", provider)); + } + + public void onProviderDisabled(String provider) { + PreyLogger.d(String.format("[LocationService] Fused Location Provider has been disabled: %s", provider)); + } + + public void onLocationChanged(Location location) { + setNewLocation(location); + } + }; } diff --git a/app/src/main/java/com/prey/services/PreyJobService.java b/app/src/main/java/com/prey/services/PreyJobService.java index 9b7136fb..9b821d81 100644 --- a/app/src/main/java/com/prey/services/PreyJobService.java +++ b/app/src/main/java/com/prey/services/PreyJobService.java @@ -18,6 +18,7 @@ import com.prey.PreyConfig; import com.prey.PreyLogger; import com.prey.PreyScheduled; +import com.prey.PreyUtils; import com.prey.beta.actions.PreyBetaActionsRunner; @TargetApi(21) @@ -26,6 +27,10 @@ public class PreyJobService extends JobService { public static int getMinuteScheduled(Context ctx){ int minutes = 15; + boolean isGooglePlayServicesAvailable = PreyUtils.isGooglePlayServicesAvailable(ctx); + if (!isGooglePlayServicesAvailable) { + minutes = PreyConfig.getPreyConfig(ctx).getMinutesToQueryServer(); + } return minutes; } public static void schedule(Context ctx ) { @@ -36,8 +41,6 @@ public static void schedule(Context ctx ) { cancel(ctx); } else { PreyScheduled.getInstance(ctx).run(minutes); - if(minutes<20) - minutes=15; JobScheduler jobScheduler = null; jobScheduler = (JobScheduler) ctx.getSystemService(Context.JOB_SCHEDULER_SERVICE); JobInfo.Builder builder = new JobInfo.Builder(JOB_ID, new ComponentName(ctx, PreyJobService.class.getName())); diff --git a/build.gradle b/build.gradle index f12b1b37..319d1518 100644 --- a/build.gradle +++ b/build.gradle @@ -6,9 +6,9 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:8.4.1' + classpath 'com.android.tools.build:gradle:8.5.1' classpath 'com.google.gms:google-services:4.4.2' - classpath 'com.google.firebase:firebase-crashlytics-gradle:3.0.1' + classpath 'com.google.firebase:firebase-crashlytics-gradle:3.0.2' } } allprojects {