From 5236f640e01a42d97b6cf5e8ba2758457c8eba1b Mon Sep 17 00:00:00 2001 From: Orlando Aliaga Date: Fri, 15 Nov 2024 12:00:08 -0300 Subject: [PATCH 1/3] Add enrollment-specific ID Add enrollment-specific ID --- app/src/main/java/com/prey/PreyConfig.java | 25 +++++++++++++++ app/src/main/java/com/prey/PreyPhone.java | 3 +- .../activities/CheckPasswordHtmlActivity.java | 9 ++++++ .../backwardcompatibility/FroyoSupport.java | 32 +++++++++++++++++++ .../prey/receivers/PreyBootController.java | 17 ++++++++++ .../prey/receivers/RestrictionsReceiver.java | 9 ++++++ 6 files changed, 94 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/prey/PreyConfig.java b/app/src/main/java/com/prey/PreyConfig.java index f9aa3280..42290313 100644 --- a/app/src/main/java/com/prey/PreyConfig.java +++ b/app/src/main/java/com/prey/PreyConfig.java @@ -1758,4 +1758,29 @@ public void run() { } } + /** + * Key for storing the organization ID in the configuration. + */ + public static final String ORGANIZATION_ID = "ORGANIZATION_ID"; + + /** + * Retrieves the organization ID from the configuration. + * + * @return The organization ID, or an empty string if not set. + */ + public String getOrganizationId() { + // Retrieve the organization ID from the configuration, defaulting to an empty string if not set + return getString(ORGANIZATION_ID, ""); + } + + /** + * Sets the organization ID in the configuration. + * + * @param organizationId The organization ID to set. + */ + public void setOrganizationId(String organizationId) { + // Save the organization ID to the configuration + saveString(ORGANIZATION_ID, organizationId); + } + } diff --git a/app/src/main/java/com/prey/PreyPhone.java b/app/src/main/java/com/prey/PreyPhone.java index 7d15e7c5..aa8fb779 100644 --- a/app/src/main/java/com/prey/PreyPhone.java +++ b/app/src/main/java/com/prey/PreyPhone.java @@ -19,6 +19,7 @@ import java.util.Map; import java.util.List; +import com.prey.backwardcompatibility.FroyoSupport; import com.prey.managers.PreyConnectivityManager; import com.prey.net.PreyWebServices; @@ -79,7 +80,7 @@ private void updateHardware() { hardware.setCpuCores(String.valueOf(getCpuCores())); hardware.setRamSize(String.valueOf(getMemoryRamSize())); hardware.setSerialNumber(getSerialNumber()); - hardware.setUuid(getSerialNumber()); + hardware.setUuid(FroyoSupport.getInstance(ctx).getEnrollmentSpecificId()); initMemory(); } diff --git a/app/src/main/java/com/prey/activities/CheckPasswordHtmlActivity.java b/app/src/main/java/com/prey/activities/CheckPasswordHtmlActivity.java index c7a75b7e..bda3ef2f 100644 --- a/app/src/main/java/com/prey/activities/CheckPasswordHtmlActivity.java +++ b/app/src/main/java/com/prey/activities/CheckPasswordHtmlActivity.java @@ -116,6 +116,15 @@ private void resolveRestrictions(Context context) { RestrictionsManager restrictionsManager = (RestrictionsManager) context.getSystemService(Context.RESTRICTIONS_SERVICE); // Retrieve the application restrictions Bundle restrictions = restrictionsManager.getApplicationRestrictions(); + if (restrictions != null && restrictions.containsKey("enterprise_name")) { + // Retrieve the enterprise name from the restrictions bundle + String enterpriseName = restrictions.getString("enterprise_name"); + // Check if the enterprise name is not null and not empty + if (enterpriseName != null && !"".equals(enterpriseName)) { + // Set the organization ID in the Prey configuration + PreyConfig.getPreyConfig(context).setOrganizationId(enterpriseName); + } + } // Check if the restrictions bundle is not null and contains the "setup_key" if (restrictions != null && restrictions.containsKey("setup_key")) { // Get the setup key from the restrictions bundle diff --git a/app/src/main/java/com/prey/backwardcompatibility/FroyoSupport.java b/app/src/main/java/com/prey/backwardcompatibility/FroyoSupport.java index 78f89de6..c1cf4a24 100644 --- a/app/src/main/java/com/prey/backwardcompatibility/FroyoSupport.java +++ b/app/src/main/java/com/prey/backwardcompatibility/FroyoSupport.java @@ -119,4 +119,36 @@ public static boolean supportSMS(Context ctx) { return isPhone; } + /** + * Retrieves the enrollment-specific ID for the device, if available. + * + * This method checks if the device is running Android S (API level 31) or later, + * and attempts to retrieve the enrollment-specific ID using the DevicePolicyManager. + * + * @return The enrollment-specific ID, or an empty string if not available. + */ + public String getEnrollmentSpecificId() { + // Initialize the ID as an empty string + String id = ""; + // Check if the device is running Android S (API level 31) or later + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + try { + // Retrieve the organization ID from the PreyConfig + String organizationId = PreyConfig.getPreyConfig(ctx).getOrganizationId(); + // Check if the organization ID is not null and not empty + if (organizationId != null && !"".equals(organizationId)) { + // Set the organization ID before attempting to retrieve the enrollment-specific ID + policyManager.setOrganizationId(PreyConfig.getPreyConfig(ctx).getOrganizationId()); + // Attempt to retrieve the enrollment-specific ID using the DevicePolicyManager + id = policyManager.getEnrollmentSpecificId(); + } + } catch (Exception e) { + // Log any exceptions that occur during the retrieval process + PreyLogger.e("Failed to get enrollment specific ID", e); + } + } + // Return the retrieved ID, or an empty string if not available + return id; + } + } \ No newline at end of file diff --git a/app/src/main/java/com/prey/receivers/PreyBootController.java b/app/src/main/java/com/prey/receivers/PreyBootController.java index 829bf72d..a22f52f7 100644 --- a/app/src/main/java/com/prey/receivers/PreyBootController.java +++ b/app/src/main/java/com/prey/receivers/PreyBootController.java @@ -9,7 +9,9 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.RestrictionsManager; import android.os.Build; +import android.os.Bundle; import com.prey.PreyConfig; import com.prey.PreyLogger; @@ -86,6 +88,21 @@ public void run() { } } }.start(); + new Thread() { + public void run() { + // Get the RestrictionsManager instance + RestrictionsManager manager = (RestrictionsManager) context.getSystemService(Context.RESTRICTIONS_SERVICE); + // Get the application restrictions + Bundle applicationRestrictions = manager.getApplicationRestrictions(); + // Check if application restrictions are not null + if (applicationRestrictions != null) { + // Log the application restrictions + PreyLogger.d(String.format("RestrictionsReceiver restrictions applied: %s", applicationRestrictions.toString())); + // Handle the application restrictions + RestrictionsReceiver.handleApplicationRestrictions(context, applicationRestrictions); + } + } + }.start(); } else { PreyLogger.e("Received unexpected intent " + intent.toString(), null); } diff --git a/app/src/main/java/com/prey/receivers/RestrictionsReceiver.java b/app/src/main/java/com/prey/receivers/RestrictionsReceiver.java index 988c1f36..e09302f2 100644 --- a/app/src/main/java/com/prey/receivers/RestrictionsReceiver.java +++ b/app/src/main/java/com/prey/receivers/RestrictionsReceiver.java @@ -56,6 +56,15 @@ public void onReceive(Context context, Intent intent) { public static void handleApplicationRestrictions(Context context, Bundle restrictions) { // Check if the device is already registered with Prey if (!PreyConfig.getPreyConfig(context).isThisDeviceAlreadyRegisteredWithPrey()) { + if (restrictions != null && restrictions.containsKey("enterprise_name")) { + // Retrieve the enterprise name from the restrictions bundle + String enterpriseName = restrictions.getString("enterprise_name"); + // Check if the enterprise name is not null and not empty + if (enterpriseName != null && !"".equals(enterpriseName)) { + // Set the organization ID in the Prey configuration + PreyConfig.getPreyConfig(context).setOrganizationId(enterpriseName); + } + } // Check if the restrictions bundle is not null and contains the "setup_key" if (restrictions != null && restrictions.containsKey("setup_key")) { // Get the setup key from the restrictions bundle From 580f61f2840b2b6abe1ae4b2bd579a2441054696 Mon Sep 17 00:00:00 2001 From: Orlando Aliaga Date: Fri, 15 Nov 2024 12:00:39 -0300 Subject: [PATCH 2/3] Update API Update API --- app/build.gradle | 6 +++--- build.gradle | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index fd08d3af..d2d8dd3b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -42,7 +42,7 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'androidx.appcompat:appcompat:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + implementation 'androidx.constraintlayout:constraintlayout:2.2.0' implementation 'com.google.android.material:material:1.12.0' implementation 'com.android.support.constraint:constraint-layout:2.0.4' @@ -52,9 +52,9 @@ dependencies { 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.2' + implementation 'com.google.firebase:firebase-messaging:24.1.0' implementation 'com.google.firebase:firebase-analytics:22.1.2' - implementation 'com.google.firebase:firebase-crashlytics:19.2.0' + implementation 'com.google.firebase:firebase-crashlytics:19.2.1' implementation 'com.google.firebase:firebase-database:21.0.0' implementation 'com.android.installreferrer:installreferrer:2.2' diff --git a/build.gradle b/build.gradle index 7725b7c6..18552dc2 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:8.6.0' + classpath 'com.android.tools.build:gradle:8.6.1' classpath 'com.google.gms:google-services:4.4.2' classpath 'com.google.firebase:firebase-crashlytics-gradle:3.0.2' } From 7cb0a20e1e206c51b53aa7a2669fcb3c848ac4b4 Mon Sep 17 00:00:00 2001 From: Orlando Aliaga Date: Fri, 15 Nov 2024 12:02:49 -0300 Subject: [PATCH 3/3] New version 2.6.4 New version 2.6.4 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d2d8dd3b..c65832bc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,8 +12,8 @@ android { targetSdkVersion 34 - versionCode 349 - versionName '2.6.3' + versionCode 351 + versionName '2.6.4' multiDexEnabled true