Skip to content

Commit

Permalink
Merge pull request #173 from prey/new-location
Browse files Browse the repository at this point in the history
New location
  • Loading branch information
oaliaga authored May 19, 2023
2 parents 1b9ea70 + 113b59d commit 3cc61b6
Show file tree
Hide file tree
Showing 24 changed files with 101 additions and 156 deletions.
1 change: 0 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {

targetSdkVersion 33

versionCode 312
versionName '2.4.7'
versionCode 314
versionName '2.4.8'

multiDexEnabled true
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/assets/html/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"main.css": "./static/css/main.cfa80321.chunk.css",
"main.js": "./static/js/main.e4910026.chunk.js",
"main.js.map": "./static/js/main.e4910026.chunk.js.map",
"main.js": "./static/js/main.2cd5e5a2.chunk.js",
"main.js.map": "./static/js/main.2cd5e5a2.chunk.js.map",
"runtime~main.js": "./static/js/runtime~main.8c97409f.js",
"runtime~main.js.map": "./static/js/runtime~main.8c97409f.js.map",
"static/js/2.d9125aad.chunk.js": "./static/js/2.d9125aad.chunk.js",
"static/js/2.d9125aad.chunk.js.map": "./static/js/2.d9125aad.chunk.js.map",
"index.html": "./index.html",
"precache-manifest.75a4185003e779fdf9586cee0711d4d2.js": "./precache-manifest.75a4185003e779fdf9586cee0711d4d2.js",
"precache-manifest.c571125ebf6ad31ab1b7032df34005d8.js": "./precache-manifest.c571125ebf6ad31ab1b7032df34005d8.js",
"service-worker.js": "./service-worker.js",
"static/css/main.cfa80321.chunk.css.map": "./static/css/main.cfa80321.chunk.css.map",
"static/media/02-Track-Find.png": "./static/media/02-Track-Find.ed00c298.png",
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/assets/html/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"/><meta name="apple-mobile-web-app-capable" content="yes"/><link rel="shortcut icon" href="./favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><title>Prey Client</title><link href="./static/css/main.cfa80321.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(l){function e(e){for(var r,t,n=e[0],o=e[1],u=e[2],f=0,i=[];f<n.length;f++)t=n[f],p[t]&&i.push(p[t][0]),p[t]=0;for(r in o)Object.prototype.hasOwnProperty.call(o,r)&&(l[r]=o[r]);for(s&&s(e);i.length;)i.shift()();return c.push.apply(c,u||[]),a()}function a(){for(var e,r=0;r<c.length;r++){for(var t=c[r],n=!0,o=1;o<t.length;o++){var u=t[o];0!==p[u]&&(n=!1)}n&&(c.splice(r--,1),e=f(f.s=t[0]))}return e}var t={},p={1:0},c=[];function f(e){if(t[e])return t[e].exports;var r=t[e]={i:e,l:!1,exports:{}};return l[e].call(r.exports,r,r.exports,f),r.l=!0,r.exports}f.m=l,f.c=t,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(r,e){if(1&e&&(r=f(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var n in r)f.d(t,n,function(e){return r[e]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="./";var r=window.webpackJsonp=window.webpackJsonp||[],n=r.push.bind(r);r.push=e,r=r.slice();for(var o=0;o<r.length;o++)e(r[o]);var s=n;a()}([])</script><script src="./static/js/2.d9125aad.chunk.js"></script><script src="./static/js/main.e4910026.chunk.js"></script></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"/><meta name="apple-mobile-web-app-capable" content="yes"/><link rel="shortcut icon" href="./favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><title>Prey Client</title><link href="./static/css/main.cfa80321.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(l){function e(e){for(var r,t,n=e[0],o=e[1],u=e[2],f=0,i=[];f<n.length;f++)t=n[f],p[t]&&i.push(p[t][0]),p[t]=0;for(r in o)Object.prototype.hasOwnProperty.call(o,r)&&(l[r]=o[r]);for(s&&s(e);i.length;)i.shift()();return c.push.apply(c,u||[]),a()}function a(){for(var e,r=0;r<c.length;r++){for(var t=c[r],n=!0,o=1;o<t.length;o++){var u=t[o];0!==p[u]&&(n=!1)}n&&(c.splice(r--,1),e=f(f.s=t[0]))}return e}var t={},p={1:0},c=[];function f(e){if(t[e])return t[e].exports;var r=t[e]={i:e,l:!1,exports:{}};return l[e].call(r.exports,r,r.exports,f),r.l=!0,r.exports}f.m=l,f.c=t,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(r,e){if(1&e&&(r=f(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var n in r)f.d(t,n,function(e){return r[e]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="./";var r=window.webpackJsonp=window.webpackJsonp||[],n=r.push.bind(r);r.push=e,r=r.slice();for(var o=0;o<r.length;o++)e(r[o]);var s=n;a()}([])</script><script src="./static/js/2.d9125aad.chunk.js"></script><script src="./static/js/main.2cd5e5a2.chunk.js"></script></body></html>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
self.__precacheManifest = [
{
"revision": "e4910026e3de78305e8f",
"revision": "2cd5e5a283ebf98ea08a",
"url": "./static/css/main.cfa80321.chunk.css"
},
{
"revision": "e4910026e3de78305e8f",
"url": "./static/js/main.e4910026.chunk.js"
"revision": "2cd5e5a283ebf98ea08a",
"url": "./static/js/main.2cd5e5a2.chunk.js"
},
{
"revision": "8c97409f0ee389fe75da",
Expand Down Expand Up @@ -120,23 +120,23 @@ self.__precacheManifest = [
"url": "./static/media/fondo2.ada00d71.png"
},
{
"revision": "6e8991140fc75b4927e2c440d9036429",
"url": "./static/media/regular-book-webfont.6e899114.woff"
"revision": "baaac74770efd8c34382afa00468f635",
"url": "./static/media/magdaclean-bold-webfont.baaac747.woff"
},
{
"revision": "c44603b2b93c1b7a984f21255d556ee9",
"url": "./static/media/magdaclean-regular-webfont.c44603b2.woff"
"revision": "6e8991140fc75b4927e2c440d9036429",
"url": "./static/media/regular-book-webfont.6e899114.woff"
},
{
"revision": "391159c582e0897e8d64ed22abe1ee2d",
"url": "./static/media/regular-bold-webfont.391159c5.woff"
},
{
"revision": "baaac74770efd8c34382afa00468f635",
"url": "./static/media/magdaclean-bold-webfont.baaac747.woff"
"revision": "c44603b2b93c1b7a984f21255d556ee9",
"url": "./static/media/magdaclean-regular-webfont.c44603b2.woff"
},
{
"revision": "8a5ed0cbd14ef0ec2b336f482a61984c",
"revision": "c5250d353970dfbeee3b848170aa1f31",
"url": "./index.html"
}
];
2 changes: 1 addition & 1 deletion app/src/main/assets/html/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
importScripts("https://storage.googleapis.com/workbox-cdn/releases/3.6.3/workbox-sw.js");

importScripts(
"./precache-manifest.75a4185003e779fdf9586cee0711d4d2.js"
"./precache-manifest.c571125ebf6ad31ab1b7032df34005d8.js"
);

workbox.clientsClaim();
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/assets/html/static/js/main.2cd5e5a2.chunk.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions app/src/main/assets/html/static/js/main.e4910026.chunk.js

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion app/src/main/java/com/prey/PreyConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class PreyConfig {
private static PreyConfig cachedInstance = null;
public static final String TAG = "PREY";
private static final String HTTP = "https://";
public static final String VERSION_PREY_DEFAULT = "2.4.7";
public static final String VERSION_PREY_DEFAULT = "2.4.8";
// Milliseconds per second
private static final int MILLISECONDS_PER_SECOND = 1000;
// Set to 1000 * 60 in production.
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/prey/PreyPermission.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.provider.Settings;

import androidx.core.app.ActivityCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.core.content.PermissionChecker;

public class PreyPermission {
Expand Down Expand Up @@ -192,4 +193,7 @@ public static boolean canAccessBackgroundLocationView(Context ctx) {
}
}

public static boolean areNotificationsEnabled(Context context){
return NotificationManagerCompat.from(context).areNotificationsEnabled();
}
}
8 changes: 8 additions & 0 deletions app/src/main/java/com/prey/actions/HttpDataService.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ public void setDataList(HashMap<String, String> dataList) {
this.dataList = dataList;
}

public String getDataListKey(String key) {
String value = "";
if (dataList != null && dataList.containsKey(key)) {
value = dataList.get(key);
}
return value;
}

public String getSingleData() {
return singleData;
}
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/java/com/prey/actions/alert/AlertThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,6 @@ public void notification(int notificationId) {
contentViewBig.setOnClickPendingIntent(R.id.noti_button, btPendingIntent);
String regularBold= "fonts/Regular/regular-bold.otf";
String regularBook= "fonts/Regular/regular-book.otf";
String title_alert=ctx.getString(R.string.title_alert);
PreyLogger.d("title_alert:"+title_alert);
SpannableStringBuilder notiTitle = new SpannableStringBuilder(title_alert);
notiTitle.setSpan (new CustomTypefaceSpan(ctx,regularBold), 0, notiTitle.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
contentViewBig.setTextViewText(R.id.noti_title, notiTitle);
contentViewSmall.setTextViewText(R.id.noti_title, notiTitle);
SpannableStringBuilder notiBody = new SpannableStringBuilder(description);
notiBody.setSpan (new CustomTypefaceSpan(ctx,regularBook), 0, notiBody.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
contentViewBig.setTextViewText(R.id.noti_body, notiBody);
Expand Down
42 changes: 10 additions & 32 deletions app/src/main/java/com/prey/actions/location/LocationUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private static void sendNotify(Context ctx, String message, String status) {

public final static int MAXIMUM_OF_ATTEMPTS=6;
public final static int MAXIMUM_OF_ATTEMPTS2=6;
public final static int []SLEEP_OF_ATTEMPTS=new int[]{2,2,2,3,3,3,4,4,4,5};
public final static int []SLEEP_OF_ATTEMPTS=new int[]{1,1,1,1,2,2,2,2,2,2};

public static PreyLocation getPreyLocationPlayService(final Context ctx, String method, boolean asynchronous, PreyLocation preyLocationOld) throws Exception {
PreyLocation preyLocation = null;
Expand All @@ -153,20 +153,10 @@ public void run() {
}).start();
Location currentLocation = null;
PreyLocationManager manager = PreyLocationManager.getInstance(ctx);
int i = 0;
while (i < MAXIMUM_OF_ATTEMPTS) {
try {
Thread.sleep(SLEEP_OF_ATTEMPTS[i] * 1000);
} catch (InterruptedException e) {
}
currentLocation = play.getLastLocation(ctx);
PreyLogger.d("currentLocation:%s" + currentLocation == null ? "" : currentLocation.toString());
if (currentLocation != null) {
preyLocation = new PreyLocation(currentLocation, method);
if (!asynchronous)
i = MAXIMUM_OF_ATTEMPTS;
}
i++;
currentLocation = play.getLastLocation(ctx);
if (currentLocation != null) {
PreyLogger.d(String.format("currentLocation:%s", currentLocation.toString()));
preyLocation = new PreyLocation(currentLocation, method);
}
} catch (Exception e) {
PreyLogger.d(String.format("Error getPreyLocationPlayService:%s", e.getMessage()));
Expand Down Expand Up @@ -250,23 +240,11 @@ public void onSuccess(Location location) {

public static PreyLocation waitLocation(final Context ctx, String method, boolean asynchronous, int maximum) {
PreyLocation preyLocation = null;
int i = 0;
while (i < maximum) {
try {
Thread.sleep(SLEEP_OF_ATTEMPTS[i] * 1000);
} catch (Exception e) {
i = MAXIMUM_OF_ATTEMPTS;
break;
}
PreyLocation location = PreyLocationManager.getInstance(ctx).getLastLocation();
if (location != null && location.isValid()) {
preyLocation = location;
preyLocation.setMethod(method);
PreyLogger.d(String.format("getPreyLocationAppService[%d]:%s", i, preyLocation.toString()));
if (!asynchronous)
i = MAXIMUM_OF_ATTEMPTS;
}
i++;
PreyLocation location = PreyLocationManager.getInstance(ctx).getLastLocation();
if (location != null && location.isValid()) {
preyLocation = location;
preyLocation.setMethod(method);
PreyLogger.d(String.format("getPreyLocationAppService:%s", preyLocation.toString()));
}
return preyLocation;
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/prey/activities/SignInActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.prey.PreyUtils;
import com.prey.R;
import com.prey.barcodereader.BarcodeActivity;
import com.prey.json.actions.Location;
import com.prey.net.PreyWebServices;
import com.prey.preferences.RunBackgroundCheckBoxPreference;
import com.prey.util.KeyboardStatusDetector;
Expand Down Expand Up @@ -168,6 +169,7 @@ protected Void doInBackground(String... data) {
PreyConfig.getPreyConfig(ctx).setRunBackground(true);
RunBackgroundCheckBoxPreference.notifyReady(ctx);
new PreyApp().run(ctx);
new Location().get(ctx, null, null);
} catch (Exception e) {
PreyLogger.e("error:"+e.getMessage(),e);
error = e.getMessage();
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/prey/activities/js/WebAppInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.prey.barcodereader.BarcodeActivity;
import com.prey.json.UtilJson;
import com.prey.json.actions.Detach;
import com.prey.json.actions.Location;
import com.prey.net.PreyHttpResponse;
import com.prey.net.PreyWebServices;
import com.prey.preferences.RunBackgroundCheckBoxPreference;
Expand Down Expand Up @@ -297,6 +298,7 @@ public void run() {
RunBackgroundCheckBoxPreference.notifyReady(mContext);
PreyConfig.getPreyConfig(mContext).setInstallationStatus("");
new PreyApp().run(mContext);
new Location().get(mContext, null, null);
}
} catch (Exception e) {
PreyLogger.d(String.format("mylogin error1:%s", e.getMessage()));
Expand Down Expand Up @@ -682,6 +684,7 @@ public String signup(String name, String email, String password1, String passwor
PreyConfig.getPreyConfig(ctx).setRunBackground(true);
PreyConfig.getPreyConfig(ctx).setInstallationStatus("Pending");
new PreyApp().run(ctx);
new Location().get(ctx, null, null);
} catch (Exception e) {
error = e.getMessage();
PreyLogger.e("error:" + error, e);
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/prey/barcodereader/BarcodeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.prey.activities.CheckPasswordHtmlActivity;
import com.prey.activities.LoginActivity;
import com.prey.activities.PermissionInformationActivity;
import com.prey.json.actions.Location;
import com.prey.net.PreyWebServices;
import com.prey.preferences.RunBackgroundCheckBoxPreference;

Expand Down Expand Up @@ -175,6 +176,7 @@ public void run() {
try {
PreyStatus.getInstance().initConfig(getApplicationContext());
AwareController.getInstance().init(ctx);
new Location().get(ctx, null, null);
}catch (Exception e){
PreyLogger.e("Error:"+e.getMessage(),e);
}
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/prey/json/actions/Alert.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.prey.PreyConfig;
import com.prey.PreyLogger;
import com.prey.PreyPermission;
import com.prey.actions.HttpDataService;
import com.prey.actions.alert.AlertThread;
import com.prey.actions.observer.ActionResult;
Expand Down Expand Up @@ -90,6 +91,9 @@ public void start(Context ctx, List<ActionResult> list, JSONObject parameters) {
} catch (Exception e) {
PreyLogger.e(String.format("Error:%s", e.getMessage()), e);
}
if (!PreyPermission.areNotificationsEnabled(ctx)) {
fullscreen_notification = true;
}
startAlert(ctx, alert, messageId, jobId, fullscreen_notification);
}

Expand Down
47 changes: 43 additions & 4 deletions app/src/main/java/com/prey/json/actions/Location.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,54 @@ public List<HttpDataService> get(Context ctx, List<ActionResult> list, JSONObje
PreyConfig.getPreyConfig(ctx).setLocationInfo("");
PreyWebServices.getInstance().sendNotifyActionResultPreyHttp(ctx,"processed", messageId, UtilJson.makeMapParam("get", "location", "started",reason));
PreyLogger.d(this.getClass().getName());
HttpDataService data = LocationUtil.dataLocation(ctx,messageId,true);
int i = 0;
int maximum = LocationUtil.MAXIMUM_OF_ATTEMPTS;
HttpDataService data = null;
ArrayList<HttpDataService> dataToBeSent = null;
float accuracy = -1;
boolean send;
while (i < maximum) {
send = false;
try {
data = LocationUtil.dataLocation(ctx, messageId, true);
dataToBeSent = new ArrayList<HttpDataService>();
dataToBeSent.add(data);
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;
}
}
}
if (send) {
PreyLogger.d(String.format("send [%s]:%s", i, accuracy));
PreyWebServices.getInstance().sendPreyHttpData(ctx, dataToBeSent);
}
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;
break;
}
i++;
}
if (data==null){
PreyWebServices.getInstance().sendNotifyActionResultPreyHttp(ctx,"failed", messageId, UtilJson.makeMapParam("get", "location", "failed",PreyConfig.getPreyConfig(ctx).getLocationInfo()));
}else{
PreyWebServices.getInstance().sendNotifyActionResultPreyHttp(ctx,"processed", messageId, UtilJson.makeMapParam("get", "location", "stopped",reason));
}
ArrayList<HttpDataService> dataToBeSent = new ArrayList<HttpDataService>();
dataToBeSent.add(data);
PreyWebServices.getInstance().sendPreyHttpData(ctx, dataToBeSent);
try {
String nameDevice = Settings.Secure.getString(ctx.getContentResolver(), "bluetooth_name");
if (nameDevice != null && !"".equals(nameDevice)) {
Expand Down
Loading

0 comments on commit 3cc61b6

Please sign in to comment.