Skip to content

Commit

Permalink
Merge pull request #192 from prey/feat/restrictions2
Browse files Browse the repository at this point in the history
Feat/restrictions2
  • Loading branch information
oaliaga authored Nov 19, 2024
2 parents e64d52d + 7cb0a20 commit 39ddfe7
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 7 deletions.
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {

targetSdkVersion 34

versionCode 349
versionName '2.6.3'
versionCode 351
versionName '2.6.4'

multiDexEnabled true

Expand Down Expand Up @@ -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'
Expand All @@ -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'
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/java/com/prey/PreyConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
3 changes: 2 additions & 1 deletion app/src/main/java/com/prey/PreyPhone.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions app/src/main/java/com/prey/backwardcompatibility/FroyoSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
17 changes: 17 additions & 0 deletions app/src/main/java/com/prey/receivers/PreyBootController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down

0 comments on commit 39ddfe7

Please sign in to comment.