From 825051dbcb7cc9e867fa8f801b12bcf123b7f9b7 Mon Sep 17 00:00:00 2001 From: Orlando Aliaga Date: Mon, 6 Mar 2023 21:43:43 -0300 Subject: [PATCH 1/4] Fix API Fix API --- app/build.gradle | 8 ++++---- build.gradle | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e80dba74..2dda458c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -39,10 +39,10 @@ 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' @@ -50,9 +50,9 @@ dependencies { 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' diff --git a/build.gradle b/build.gradle index 7aaef1b9..9dd73d23 100644 --- a/build.gradle +++ b/build.gradle @@ -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' } } From c7d5b62cf45ba9189c106b1142de6f64510bc2be Mon Sep 17 00:00:00 2001 From: Orlando Aliaga Date: Mon, 6 Mar 2023 21:57:55 -0300 Subject: [PATCH 2/4] Verify connection Verify connection --- .../beta/actions/PreyBetaActionsRunner.java | 5 +- .../java/com/prey/net/UtilConnection.java | 75 +++++++++---------- 2 files changed, 38 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/com/prey/beta/actions/PreyBetaActionsRunner.java b/app/src/main/java/com/prey/beta/actions/PreyBetaActionsRunner.java index 5afec55e..97f5fb89 100644 --- a/app/src/main/java/com/prey/beta/actions/PreyBetaActionsRunner.java +++ b/app/src/main/java/com/prey/beta/actions/PreyBetaActionsRunner.java @@ -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 { @@ -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 = null; - connection = preyTelephony.isDataConnectivityEnabled() || preyConnectivity.isConnected(); + connection = UtilConnection.isInternetAvailable(); if (connection) { try { if (cmd == null || "".equals(cmd)) { diff --git a/app/src/main/java/com/prey/net/UtilConnection.java b/app/src/main/java/com/prey/net/UtilConnection.java index b08a0183..cf7aa221 100644 --- a/app/src/main/java/com/prey/net/UtilConnection.java +++ b/app/src/main/java/com/prey/net/UtilConnection.java @@ -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; } @@ -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; } From 9a612ab2ab5dc360af21a7e33ddecc1321e47c1c Mon Sep 17 00:00:00 2001 From: Orlando Aliaga Date: Mon, 6 Mar 2023 22:02:42 -0300 Subject: [PATCH 3/4] Fix deprecated Fix deprecated --- app/src/main/java/com/prey/json/actions/Lock.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/prey/json/actions/Lock.java b/app/src/main/java/com/prey/json/actions/Lock.java index 39834a72..a8d08c10 100644 --- a/app/src/main/java/com/prey/json/actions/Lock.java +++ b/app/src/main/java/com/prey/json/actions/Lock.java @@ -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; } } From 7fc349eef432f96c20c5d80136ceca7ce6536b63 Mon Sep 17 00:00:00 2001 From: Orlando Aliaga Date: Mon, 6 Mar 2023 22:03:27 -0300 Subject: [PATCH 4/4] New version 2.4.6 New version 2.4.6 --- app/build.gradle | 4 ++-- app/src/main/java/com/prey/PreyConfig.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 2dda458c..41463e45 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,8 +12,8 @@ android { targetSdkVersion 33 - versionCode 309 - versionName '2.4.5' + versionCode 310 + versionName '2.4.6' multiDexEnabled true } diff --git a/app/src/main/java/com/prey/PreyConfig.java b/app/src/main/java/com/prey/PreyConfig.java index af55d425..2e1abec8 100644 --- a/app/src/main/java/com/prey/PreyConfig.java +++ b/app/src/main/java/com/prey/PreyConfig.java @@ -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.