Skip to content

Commit 39ddfe7

Browse files
authored
Merge pull request #192 from prey/feat/restrictions2
Feat/restrictions2
2 parents e64d52d + 7cb0a20 commit 39ddfe7

File tree

8 files changed

+100
-7
lines changed

8 files changed

+100
-7
lines changed

app/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ android {
1212

1313
targetSdkVersion 34
1414

15-
versionCode 349
16-
versionName '2.6.3'
15+
versionCode 351
16+
versionName '2.6.4'
1717

1818
multiDexEnabled true
1919

@@ -42,7 +42,7 @@ android {
4242
dependencies {
4343
implementation fileTree(include: ['*.jar'], dir: 'libs')
4444
implementation 'androidx.appcompat:appcompat:1.7.0'
45-
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
45+
implementation 'androidx.constraintlayout:constraintlayout:2.2.0'
4646

4747
implementation 'com.google.android.material:material:1.12.0'
4848
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
@@ -52,9 +52,9 @@ dependencies {
5252
implementation 'com.google.android.gms:play-services-maps:19.0.0'
5353
implementation 'com.google.firebase:firebase-core:21.1.1'
5454
implementation 'com.google.firebase:firebase-iid:21.1.0'
55-
implementation 'com.google.firebase:firebase-messaging:24.0.2'
55+
implementation 'com.google.firebase:firebase-messaging:24.1.0'
5656
implementation 'com.google.firebase:firebase-analytics:22.1.2'
57-
implementation 'com.google.firebase:firebase-crashlytics:19.2.0'
57+
implementation 'com.google.firebase:firebase-crashlytics:19.2.1'
5858
implementation 'com.google.firebase:firebase-database:21.0.0'
5959

6060
implementation 'com.android.installreferrer:installreferrer:2.2'

app/src/main/java/com/prey/PreyConfig.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,4 +1758,29 @@ public void run() {
17581758
}
17591759
}
17601760

1761+
/**
1762+
* Key for storing the organization ID in the configuration.
1763+
*/
1764+
public static final String ORGANIZATION_ID = "ORGANIZATION_ID";
1765+
1766+
/**
1767+
* Retrieves the organization ID from the configuration.
1768+
*
1769+
* @return The organization ID, or an empty string if not set.
1770+
*/
1771+
public String getOrganizationId() {
1772+
// Retrieve the organization ID from the configuration, defaulting to an empty string if not set
1773+
return getString(ORGANIZATION_ID, "");
1774+
}
1775+
1776+
/**
1777+
* Sets the organization ID in the configuration.
1778+
*
1779+
* @param organizationId The organization ID to set.
1780+
*/
1781+
public void setOrganizationId(String organizationId) {
1782+
// Save the organization ID to the configuration
1783+
saveString(ORGANIZATION_ID, organizationId);
1784+
}
1785+
17611786
}

app/src/main/java/com/prey/PreyPhone.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Map;
2020
import java.util.List;
2121

22+
import com.prey.backwardcompatibility.FroyoSupport;
2223
import com.prey.managers.PreyConnectivityManager;
2324
import com.prey.net.PreyWebServices;
2425

@@ -79,7 +80,7 @@ private void updateHardware() {
7980
hardware.setCpuCores(String.valueOf(getCpuCores()));
8081
hardware.setRamSize(String.valueOf(getMemoryRamSize()));
8182
hardware.setSerialNumber(getSerialNumber());
82-
hardware.setUuid(getSerialNumber());
83+
hardware.setUuid(FroyoSupport.getInstance(ctx).getEnrollmentSpecificId());
8384
initMemory();
8485
}
8586

app/src/main/java/com/prey/activities/CheckPasswordHtmlActivity.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ private void resolveRestrictions(Context context) {
116116
RestrictionsManager restrictionsManager = (RestrictionsManager) context.getSystemService(Context.RESTRICTIONS_SERVICE);
117117
// Retrieve the application restrictions
118118
Bundle restrictions = restrictionsManager.getApplicationRestrictions();
119+
if (restrictions != null && restrictions.containsKey("enterprise_name")) {
120+
// Retrieve the enterprise name from the restrictions bundle
121+
String enterpriseName = restrictions.getString("enterprise_name");
122+
// Check if the enterprise name is not null and not empty
123+
if (enterpriseName != null && !"".equals(enterpriseName)) {
124+
// Set the organization ID in the Prey configuration
125+
PreyConfig.getPreyConfig(context).setOrganizationId(enterpriseName);
126+
}
127+
}
119128
// Check if the restrictions bundle is not null and contains the "setup_key"
120129
if (restrictions != null && restrictions.containsKey("setup_key")) {
121130
// Get the setup key from the restrictions bundle

app/src/main/java/com/prey/backwardcompatibility/FroyoSupport.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,36 @@ public static boolean supportSMS(Context ctx) {
119119
return isPhone;
120120
}
121121

122+
/**
123+
* Retrieves the enrollment-specific ID for the device, if available.
124+
*
125+
* This method checks if the device is running Android S (API level 31) or later,
126+
* and attempts to retrieve the enrollment-specific ID using the DevicePolicyManager.
127+
*
128+
* @return The enrollment-specific ID, or an empty string if not available.
129+
*/
130+
public String getEnrollmentSpecificId() {
131+
// Initialize the ID as an empty string
132+
String id = "";
133+
// Check if the device is running Android S (API level 31) or later
134+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
135+
try {
136+
// Retrieve the organization ID from the PreyConfig
137+
String organizationId = PreyConfig.getPreyConfig(ctx).getOrganizationId();
138+
// Check if the organization ID is not null and not empty
139+
if (organizationId != null && !"".equals(organizationId)) {
140+
// Set the organization ID before attempting to retrieve the enrollment-specific ID
141+
policyManager.setOrganizationId(PreyConfig.getPreyConfig(ctx).getOrganizationId());
142+
// Attempt to retrieve the enrollment-specific ID using the DevicePolicyManager
143+
id = policyManager.getEnrollmentSpecificId();
144+
}
145+
} catch (Exception e) {
146+
// Log any exceptions that occur during the retrieval process
147+
PreyLogger.e("Failed to get enrollment specific ID", e);
148+
}
149+
}
150+
// Return the retrieved ID, or an empty string if not available
151+
return id;
152+
}
153+
122154
}

app/src/main/java/com/prey/receivers/PreyBootController.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import android.content.BroadcastReceiver;
1010
import android.content.Context;
1111
import android.content.Intent;
12+
import android.content.RestrictionsManager;
1213
import android.os.Build;
14+
import android.os.Bundle;
1315

1416
import com.prey.PreyConfig;
1517
import com.prey.PreyLogger;
@@ -86,6 +88,21 @@ public void run() {
8688
}
8789
}
8890
}.start();
91+
new Thread() {
92+
public void run() {
93+
// Get the RestrictionsManager instance
94+
RestrictionsManager manager = (RestrictionsManager) context.getSystemService(Context.RESTRICTIONS_SERVICE);
95+
// Get the application restrictions
96+
Bundle applicationRestrictions = manager.getApplicationRestrictions();
97+
// Check if application restrictions are not null
98+
if (applicationRestrictions != null) {
99+
// Log the application restrictions
100+
PreyLogger.d(String.format("RestrictionsReceiver restrictions applied: %s", applicationRestrictions.toString()));
101+
// Handle the application restrictions
102+
RestrictionsReceiver.handleApplicationRestrictions(context, applicationRestrictions);
103+
}
104+
}
105+
}.start();
89106
} else {
90107
PreyLogger.e("Received unexpected intent " + intent.toString(), null);
91108
}

app/src/main/java/com/prey/receivers/RestrictionsReceiver.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ public void onReceive(Context context, Intent intent) {
5656
public static void handleApplicationRestrictions(Context context, Bundle restrictions) {
5757
// Check if the device is already registered with Prey
5858
if (!PreyConfig.getPreyConfig(context).isThisDeviceAlreadyRegisteredWithPrey()) {
59+
if (restrictions != null && restrictions.containsKey("enterprise_name")) {
60+
// Retrieve the enterprise name from the restrictions bundle
61+
String enterpriseName = restrictions.getString("enterprise_name");
62+
// Check if the enterprise name is not null and not empty
63+
if (enterpriseName != null && !"".equals(enterpriseName)) {
64+
// Set the organization ID in the Prey configuration
65+
PreyConfig.getPreyConfig(context).setOrganizationId(enterpriseName);
66+
}
67+
}
5968
// Check if the restrictions bundle is not null and contains the "setup_key"
6069
if (restrictions != null && restrictions.containsKey("setup_key")) {
6170
// Get the setup key from the restrictions bundle

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
mavenCentral()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:8.6.0'
9+
classpath 'com.android.tools.build:gradle:8.6.1'
1010
classpath 'com.google.gms:google-services:4.4.2'
1111
classpath 'com.google.firebase:firebase-crashlytics-gradle:3.0.2'
1212
}

0 commit comments

Comments
 (0)