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

Feat/permission status #185

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 323
versionName '2.5.1'
versionCode 324
versionName '2.5.2'

multiDexEnabled true

Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/com/prey/FileConfigReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,13 @@ public String getPreyForgot() {
public boolean getOpenPin() {
return Boolean.parseBoolean(properties.getProperty("open-pin"));
}

/**
* Method returns logger maximum
* @return logger_max
*/
public int getLoggerMax() {
return Integer.parseInt(properties.getProperty("logger-max"));
}

}
1 change: 1 addition & 0 deletions app/src/main/java/com/prey/PreyApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.prey.actions.aware.AwareController;
import com.prey.actions.fileretrieval.FileretrievalController;
import com.prey.actions.geofences.GeofenceController;
import com.prey.actions.logger.LoggerController;
import com.prey.actions.report.ReportScheduled;
import com.prey.actions.triggers.TriggerController;
import com.prey.activities.LoginActivity;
Expand Down
15 changes: 13 additions & 2 deletions 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.9";
public static final String VERSION_PREY_DEFAULT = "2.5.2";
// Milliseconds per second
private static final int MILLISECONDS_PER_SECOND = 1000;
// Set to 1000 * 60 in production.
Expand Down Expand Up @@ -1610,4 +1610,15 @@ public void setDenyNotification(boolean denyNotification) {
public boolean getDenyNotification() {
return getBoolean(PreyConfig.DENY_NOTIFICATION, false);
}
}

public static final String LOGGER_ID = "LOGGER_ID";

public void setLoggerId(int loggerId){
saveInt(PreyConfig.LOGGER_ID, loggerId);
}

public int getLoggerId(){
return getInt(PreyConfig.LOGGER_ID, 1);
}

}
28 changes: 28 additions & 0 deletions app/src/main/java/com/prey/actions/HttpDataService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
import java.util.List;
import java.util.Map;

import com.prey.PreyLogger;
import com.prey.net.http.EntityFile;

import org.json.JSONException;
import org.json.JSONObject;

public class HttpDataService {

private String key;
Expand Down Expand Up @@ -72,6 +76,30 @@ public HashMap<String, String> getDataAsParameters() {
return parameters;
}

/**
* Method to transform parameter list into json
*
* @return json
*/
public JSONObject getDataJson() {
JSONObject json = new JSONObject();
try {
if (isList()) {
JSONObject jsonList = new JSONObject();
for (String valueKey : dataList.keySet()) {
String valueData = dataList.get(valueKey);
jsonList.put(valueKey, valueData);
}
json.put(key, jsonList);
} else {
json.put(key, singleData);
}
} catch (JSONException e) {
PreyLogger.e(String.format("error getDataJson:%s", e.getMessage()), e);
}
return json;
}

public String getDataAsString() {
StringBuffer sb = new StringBuffer();
if (isList()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ public List<FileretrievalDto> getAllFileretrieval() {
list.add(dto);
} while (cursor.moveToNext());
}
database.close();
}catch (Exception e){
PreyLogger.e("Error:"+e.getMessage(),e);
PreyLogger.e(String.format("Error:%s", e.getMessage()), e);
}finally {
if(cursor!=null){
try{cursor.close();}catch (Exception e1){}
Expand All @@ -142,8 +143,9 @@ public FileretrievalDto getFileretrieval(String id) {
dto.setStatus(cursor.getInt(3));
} while (cursor.moveToNext());
}
database.close();
}catch (Exception e){
PreyLogger.e("Error:"+e.getMessage(),e);
PreyLogger.e(String.format("Error:%s", e.getMessage()), e);
}finally {
if(cursor!=null){
try{cursor.close();}catch (Exception e1){}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ public List<GeofenceDto> getAllGeofences() {
list.add(geofence);
} while (cursor.moveToNext());
}
database.close();
}catch (Exception e){
PreyLogger.e("error:"+e.getMessage(),e);
PreyLogger.e(String.format("error:%s", e.getMessage()), e);
}finally {
if(cursor!=null){
try{cursor.close();}catch (Exception e1){}
Expand Down Expand Up @@ -169,8 +170,9 @@ public GeofenceDto getGeofence(String id) {
geofence.setExpires(cursor.getInt(6));
} while (cursor.moveToNext());
}
database.close();
}catch (Exception e){
PreyLogger.e("error:"+e.getMessage(),e);
PreyLogger.e(String.format("error:%s", e.getMessage()), e);
}finally {
if(cursor!=null){
try{cursor.close();}catch (Exception e1){}
Expand Down
19 changes: 15 additions & 4 deletions app/src/main/java/com/prey/actions/location/LocationUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@
import com.google.android.gms.tasks.OnSuccessListener;
import com.prey.PreyConfig;
import com.prey.PreyLogger;
import com.prey.PreyPermission;
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.JSONObject;

public class LocationUtil {

public static final String LAT = "lat";
Expand Down Expand Up @@ -71,10 +74,18 @@ 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+"}";
PreyConfig.getPreyConfig(ctx).setLocationInfo(locationInfo);
PreyLogger.d(locationInfo);
boolean isGooglePlayServicesAvailable = isGooglePlayServicesAvailable(ctx);
boolean canAccessBackgroundLocation = PreyPermission.canAccessBackgroundLocationView(ctx);
boolean canAccessFineLocation = PreyPermission.canAccessFineLocation(ctx);
boolean canAccessCoarseLocation = PreyPermission.canAccessCoarseLocation(ctx);
JSONObject json = new JSONObject();
json.put("location", (canAccessFineLocation || canAccessCoarseLocation));
json.put("location_background", canAccessBackgroundLocation);
json.put("gps", isGpsEnabled);
json.put("net", isNetworkEnabled);
json.put("wifi", isWifiEnabled);
json.put("play", isGooglePlayServicesAvailable);
PreyConfig.getPreyConfig(ctx).setLocationInfo(json.toString());
String method = getMethod(isGpsEnabled, isNetworkEnabled);
try {
preyLocation = getPreyLocationAppService(ctx, method, asynchronous, preyLocation, maximum);
Expand Down
163 changes: 163 additions & 0 deletions app/src/main/java/com/prey/actions/logger/LoggerController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*******************************************************************************
* Created by Orlando Aliaga
* Copyright 2023 Prey Inc. All rights reserved.
* License: GPLv3
* Full license at "/LICENSE"
******************************************************************************/
package com.prey.actions.logger;

import android.content.Context;

import com.prey.FileConfigReader;
import com.prey.PreyConfig;
import com.prey.PreyLogger;
import com.prey.events.Event;

import org.json.JSONObject;

import java.io.File;
import java.util.Date;
import java.util.Map;

public class LoggerController {

private Context ctx;
private static LoggerController INSTANCE;

public static LoggerController getInstance(Context ctx) {
if (INSTANCE == null) {
INSTANCE = new LoggerController(ctx);
}
return INSTANCE;
}

private final String CMD = "CMD";
private final String ACTION = "ACTION";
private final String DATA = "DATA";
private final String REPORT = "REPORT";
private final String UPLOAD = "UPLOAD";
private final String GEOFENCING = "GEOFENCING";
private final String EVENTS = "EVENTS";
private final String TREE = "TREE";

private int maxLogger;

private LoggerController(Context context) {
ctx = context;
try {
maxLogger = FileConfigReader.getInstance(context).getLoggerMax();
} catch (Exception e) {
maxLogger = 500;
}
sequence = PreyConfig.getPreyConfig(context).getLoggerId();
}

private int sequence = 1;

public synchronized int getSequence(Context context) {
sequence++;
PreyConfig.getPreyConfig(context).setLoggerId(sequence);
return sequence;
}

/**
* Method to register logger
*
* @param type
* @param txt
*/
public void addLogger(String type, String txt) {
int loggerID = getSequence(ctx);
LoggerDto dto = new LoggerDto();
dto.setType(type);
dto.setTxt(txt);
dto.setLoggerId(loggerID);
dto.setTime(new Date().toGMTString());
LoggerDatasource datasource = new LoggerDatasource(ctx);
try {
datasource.createLogger(dto);
} catch (Exception e) {
PreyLogger.e(String.format("logger error:%s", e.getMessage()), e);
}
if (loggerID > maxLogger) {
datasource.deleteMinorsLogger(loggerID - maxLogger);
}
PreyLogger.d(String.format("logger dto:%s", dto.toString()));
}

public void addComands(String commands) {
addLogger(CMD, commands);
}

public void addData(JSONObject json) {
addLogger(DATA, json.toString());
}

public void addTree(JSONObject json) {
addLogger(TREE, json.toString());
}

public void addEvents(Event event, JSONObject json) {
JSONObject newJson = new JSONObject();
try {
newJson.put("name", event.getName());
newJson.put("info", event.getInfo());
newJson.put("status", json);
} catch (Exception e) {
PreyLogger.e(String.format("error addEvents:%s", e.getMessage()), e);
}
addLogger(EVENTS, newJson.toString());
}

public void addReport(JSONObject json) {
addLogger(REPORT, json.toString());

}

public void addGeofencing(String json) {
try {
addLogger(GEOFENCING, json.toString());
} catch (Exception e) {
addLogger(GEOFENCING, json);
}
}

public void addUpload(File file, int responseCode) {
JSONObject newJson = new JSONObject();
try {
newJson.put("name", file.getName());
newJson.put("length", file.length());
newJson.put("responseCode", responseCode);
} catch (Exception e) {
PreyLogger.e(String.format("error addUpload:%s", e.getMessage()), e);
}
addLogger(UPLOAD, newJson.toString());
}

public void addActionResult(String status, Map<String, String> params) {
JSONObject json = new JSONObject();
try {
json.put("command", params.get("command"));
json.put("target", params.get("target"));
json.put("status", params.get("status"));
if (params.containsKey("reason")) {
String reason = params.get("reason");
try {
JSONObject jsonReason = new JSONObject(reason);
json.put("reason", jsonReason);
} catch (Exception e) {
json.put("reason", reason);
}
}
addLogger(ACTION, json.toString());
} catch (Exception e) {
PreyLogger.e(String.format("error addActionResult:%s", e.getMessage()), e);
}
}

public void deleteAllLogger() {
LoggerDatasource datasource = new LoggerDatasource(ctx);
datasource.deleteAllLogger();
}

}
Loading