Skip to content

Commit

Permalink
Merge pull request #171 from prey/fix-aware
Browse files Browse the repository at this point in the history
Fix aware
  • Loading branch information
oaliaga authored Mar 7, 2023
2 parents 518eacb + 7fc349e commit 74af0e9
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 55 deletions.
12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {

targetSdkVersion 33

versionCode 309
versionName '2.4.5'
versionCode 310
versionName '2.4.6'

multiDexEnabled true
}
Expand All @@ -39,20 +39,20 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

implementation 'com.google.android.material:material:1.7.0'
implementation 'com.google.android.material:material:1.8.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
implementation 'com.google.android.gms:play-services-location:21.0.1'
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.1.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:23.1.1'
implementation 'com.google.firebase:firebase-messaging:23.1.2'
implementation 'com.google.firebase:firebase-analytics:21.2.0'
implementation 'com.google.firebase:firebase-crashlytics:18.3.3'
implementation 'com.google.firebase:firebase-crashlytics:18.3.5'
implementation 'com.google.firebase:firebase-database:20.1.0'

implementation 'com.android.installreferrer:installreferrer:2.2'
Expand Down
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.5";
public static final String VERSION_PREY_DEFAULT = "2.4.6";
// Milliseconds per second
private static final int MILLISECONDS_PER_SECOND = 1000;
// Set to 1000 * 60 in production.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.prey.managers.PreyConnectivityManager;
import com.prey.managers.PreyTelephonyManager;
import com.prey.net.PreyWebServices;
import com.prey.net.UtilConnection;

public class PreyBetaActionsRunner implements Runnable {

Expand All @@ -43,12 +44,10 @@ public void run() {

public void execute() {
if (PreyConfig.getPreyConfig(ctx).isThisDeviceAlreadyRegisteredWithPrey(true)) {
PreyTelephonyManager preyTelephony = PreyTelephonyManager.getInstance(ctx);
PreyConnectivityManager preyConnectivity = PreyConnectivityManager.getInstance(ctx);
boolean connection = false;
try {
List<JSONObject> jsonObject = null;
connection = preyTelephony.isDataConnectivityEnabled() || preyConnectivity.isConnected();
connection = UtilConnection.isInternetAvailable();
if (connection) {
try {
if (cmd == null || "".equals(cmd)) {
Expand Down
14 changes: 9 additions & 5 deletions app/src/main/java/com/prey/json/actions/Lock.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,15 @@ public static boolean canDrawOverlays(Context ctx) {
* @return true if pattern set, false if not (or if an issue when checking)
*/
public static boolean isPatternSet(Context ctx) {
ContentResolver cr = ctx.getContentResolver();
try {
int lockPatternEnable = Settings.Secure.getInt(cr, Settings.Secure.LOCK_PATTERN_ENABLED);
return lockPatternEnable == 1;
} catch (Settings.SettingNotFoundException e) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
ContentResolver cr = ctx.getContentResolver();
try {
int lockPatternEnable = Settings.Secure.getInt(cr, Settings.Secure.LOCK_PATTERN_ENABLED);
return lockPatternEnable == 1;
} catch (Settings.SettingNotFoundException e) {
return false;
}
} else {
return false;
}
}
Expand Down
75 changes: 36 additions & 39 deletions app/src/main/java/com/prey/net/UtilConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -396,33 +396,35 @@ public static HttpURLConnection connectionJsonAuthorization(PreyConfig preyConfi
}

public static HttpURLConnection connectionJson(PreyConfig preyConfig, String uri, String method, JSONObject jsonParam, String authorization) {
HttpURLConnection connection=null;
HttpURLConnection connection = null;
int httpResult = -1;
try {
URL url = new URL(uri);
PreyLogger.d("postJson page:" + uri);
connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod(method);
connection.setUseCaches(USE_CACHES);
connection.setConnectTimeout(CONNECT_TIMEOUT);
connection.setReadTimeout(READ_TIMEOUT);
connection.setRequestProperty("Content-Type", "application/json");
if (authorization!=null)
connection.addRequestProperty("Authorization", authorization);
connection.addRequestProperty("User-Agent",getUserAgent(preyConfig));
connection.addRequestProperty("Origin", "android:com.prey");
connection.connect();
if(jsonParam!=null) {
PreyLogger.d("jsonParam.toString():" + jsonParam.toString());
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
out.write(jsonParam.toString());
out.close();
if (isInternetAvailable()) {
URL url = new URL(uri);
PreyLogger.d(String.format("postJson page: %s", uri));
connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod(method);
connection.setUseCaches(USE_CACHES);
connection.setConnectTimeout(CONNECT_TIMEOUT);
connection.setReadTimeout(READ_TIMEOUT);
connection.setRequestProperty("Content-Type", "application/json");
if (authorization != null)
connection.addRequestProperty("Authorization", authorization);
connection.addRequestProperty("User-Agent", getUserAgent(preyConfig));
connection.addRequestProperty("Origin", "android:com.prey");
connection.connect();
if (jsonParam != null) {
PreyLogger.d(String.format("jsonParam.toString():%s", jsonParam.toString()));
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
out.write(jsonParam.toString());
out.close();
}
httpResult = connection.getResponseCode();
PreyLogger.d(String.format("postJson responseCode:%s", httpResult));
}
httpResult = connection.getResponseCode();
PreyLogger.d("postJson responseCode:"+httpResult);
} catch (Exception e) {
PreyLogger.e("postJson error:" + e.getMessage(), e);
PreyLogger.e(String.format("postJson error:%s", e.getMessage()), e);
}
return connection;
}
Expand Down Expand Up @@ -550,22 +552,17 @@ public static int uploadFile(PreyConfig preyConfig,String page, File file,long t
}

public static boolean isInternetAvailable(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
if (activeNetwork == null) return false;
switch (activeNetwork.getType()) {
case ConnectivityManager.TYPE_WIFI:
if (activeNetwork.getState() == NetworkInfo.State.CONNECTED ||
activeNetwork.getState() == NetworkInfo.State.CONNECTING)
return true;
break;
case ConnectivityManager.TYPE_MOBILE:
if (activeNetwork.getState() == NetworkInfo.State.CONNECTED ||
activeNetwork.getState() == NetworkInfo.State.CONNECTING)
return true;
break;
default:
return false;
return isInternetAvailable();
}

public static boolean isInternetAvailable() {
try {
String command = "ping -c 1 google.com";
boolean isInternetAvailable= (Runtime.getRuntime().exec(command).waitFor() == 0);
PreyLogger.d(String.format("command:%s - %b",command,isInternetAvailable));
return isInternetAvailable;
} catch (Exception e) {
PreyLogger.e(String.format("isInternetAvailable error:%s", e.getMessage()), e);
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
classpath 'com.google.gms:google-services:4.3.15'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.4'
}
}

Expand Down

0 comments on commit 74af0e9

Please sign in to comment.