Skip to content

Commit 445ac46

Browse files
Merge pull request #220 from prey/feat/mdm-setup-action-result
Feat/mdm setup action result
2 parents 0e636ae + d5f71d0 commit 445ac46

27 files changed

Lines changed: 1219 additions & 51 deletions

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
run: |
3838
echo '{"project_info":{"project_number":"0","project_id":"prey-ci","storage_bucket":"prey-ci.appspot.com"},"client":[{"client_info":{"mobilesdk_app_id":"1:0:android:0","android_client_info":{"package_name":"com.prey"}},"api_key":[{"current_key":"fake"}]}],"configuration_version":"1"}' > app/google-services.json
3939
printf 'properties\napi-key-batch=\nemail-batch=\nask-for-name-batch=false\ntoken=\n' > app/src/main/res/raw/batch.properties
40-
echo "google_maps_key=fake-key-for-ci" > secrets.properties
40+
printf '<resources>\n <string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">fake-key-for-ci</string>\n</resources>\n' > app/src/main/res/values/google_maps_api.xml
4141
printf 'properties\nprey-campaign=ci\nprey-panel=https://localhost\ngcm-id-prefix=0\nprey-domain=localhost\nprey-subdomain=panel\nemail-feedback=ci@test.com\nsubject-feedback=CI\napi-v2=/api/v2/\nscheduled=false\nminute-scheduled=15\ntimeout-report=60\ngeofence-maximum-accuracy=100\nprey-jwt=fake\nprey-google-play=https://play.google.com\ngeofence-loitering-delay=300000\ndistance-location=50\ngeofence-notification-responsiveness=30000\ndistance-aware=100\nradius-aware=200\nprey-terms=https://localhost/terms\nprey-terms-es=https://localhost/es/terms\nprey-forgot=https://localhost/forgot\nopen-pin=false\n' > app/src/main/res/raw/config.properties
4242
4343
- name: Run lint
@@ -71,7 +71,7 @@ jobs:
7171
run: |
7272
echo '{"project_info":{"project_number":"0","project_id":"prey-ci","storage_bucket":"prey-ci.appspot.com"},"client":[{"client_info":{"mobilesdk_app_id":"1:0:android:0","android_client_info":{"package_name":"com.prey"}},"api_key":[{"current_key":"fake"}]}],"configuration_version":"1"}' > app/google-services.json
7373
printf 'properties\napi-key-batch=\nemail-batch=\nask-for-name-batch=false\ntoken=\n' > app/src/main/res/raw/batch.properties
74-
echo "google_maps_key=fake-key-for-ci" > secrets.properties
74+
printf '<resources>\n <string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">fake-key-for-ci</string>\n</resources>\n' > app/src/main/res/values/google_maps_api.xml
7575
printf 'properties\nprey-campaign=ci\nprey-panel=https://localhost\ngcm-id-prefix=0\nprey-domain=localhost\nprey-subdomain=panel\nemail-feedback=ci@test.com\nsubject-feedback=CI\napi-v2=/api/v2/\nscheduled=false\nminute-scheduled=15\ntimeout-report=60\ngeofence-maximum-accuracy=100\nprey-jwt=fake\nprey-google-play=https://play.google.com\ngeofence-loitering-delay=300000\ndistance-location=50\ngeofence-notification-responsiveness=30000\ndistance-aware=100\nradius-aware=200\nprey-terms=https://localhost/terms\nprey-terms-es=https://localhost/es/terms\nprey-forgot=https://localhost/forgot\nopen-pin=false\n' > app/src/main/res/raw/config.properties
7676
7777
- name: Run unit tests
@@ -105,7 +105,7 @@ jobs:
105105
run: |
106106
echo '{"project_info":{"project_number":"0","project_id":"prey-ci","storage_bucket":"prey-ci.appspot.com"},"client":[{"client_info":{"mobilesdk_app_id":"1:0:android:0","android_client_info":{"package_name":"com.prey"}},"api_key":[{"current_key":"fake"}]}],"configuration_version":"1"}' > app/google-services.json
107107
printf 'properties\napi-key-batch=\nemail-batch=\nask-for-name-batch=false\ntoken=\n' > app/src/main/res/raw/batch.properties
108-
echo "google_maps_key=fake-key-for-ci" > secrets.properties
108+
printf '<resources>\n <string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">fake-key-for-ci</string>\n</resources>\n' > app/src/main/res/values/google_maps_api.xml
109109
printf 'properties\nprey-campaign=ci\nprey-panel=https://localhost\ngcm-id-prefix=0\nprey-domain=localhost\nprey-subdomain=panel\nemail-feedback=ci@test.com\nsubject-feedback=CI\napi-v2=/api/v2/\nscheduled=false\nminute-scheduled=15\ntimeout-report=60\ngeofence-maximum-accuracy=100\nprey-jwt=fake\nprey-google-play=https://play.google.com\ngeofence-loitering-delay=300000\ndistance-location=50\ngeofence-notification-responsiveness=30000\ndistance-aware=100\nradius-aware=200\nprey-terms=https://localhost/terms\nprey-terms-es=https://localhost/es/terms\nprey-forgot=https://localhost/forgot\nopen-pin=false\n' > app/src/main/res/raw/config.properties
110110
111111
- name: Enable KVM

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ local.properties
1414
/docs
1515
*.keystore
1616
app/src/main/res/values/google_maps_api.xml
17+
keystore.properties

.idea/gradle.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ android {
2020

2121
targetSdk 35
2222

23-
versionCode 404
24-
versionName '2.6.16'
23+
versionCode 413
24+
versionName '2.6.17'
2525

2626
multiDexEnabled true
2727

@@ -49,6 +49,12 @@ android {
4949
buildConfig = true
5050
}
5151
namespace 'com.prey'
52+
53+
testOptions {
54+
unitTests {
55+
includeAndroidResources = true
56+
}
57+
}
5258
}
5359

5460

@@ -74,12 +80,14 @@ dependencies {
7480
implementation 'com.android.support:multidex:1.0.3'
7581
implementation 'com.google.code.gson:gson:2.13.1'
7682
implementation 'androidx.biometric:biometric:1.2.0-alpha05'
83+
implementation 'androidx.enterprise:enterprise-feedback:1.1.0'
7784
implementation "androidx.work:work-runtime:2.8.1"
7885

7986
testImplementation 'junit:junit:4.13.2'
8087
testImplementation 'org.robolectric:robolectric:4.14.1'
8188
testImplementation 'androidx.test:core:1.6.1'
8289
testImplementation 'androidx.test.ext:junit:1.2.1'
90+
testImplementation 'androidx.enterprise:enterprise-feedback-testing:1.1.0'
8391
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
8492
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
8593

app/build.gradle.internal

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,35 +44,31 @@ android {
4444

4545
dependencies {
4646
implementation fileTree(include: ['*.jar'], dir: 'libs')
47-
implementation 'androidx.appcompat:appcompat:1.7.1'
48-
implementation 'androidx.constraintlayout:constraintlayout:2.2.1'
47+
implementation 'androidx.appcompat:appcompat:1.6.1'
48+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
4949

50-
implementation 'com.google.android.material:material:1.12.0'
50+
implementation 'com.google.android.material:material:1.9.0'
5151
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
52-
implementation 'com.google.android.gms:play-services-location:21.3.0'
52+
implementation 'com.google.android.gms:play-services-location:21.0.1'
5353
implementation 'com.google.android.gms:play-services-gcm:17.0.0'
5454
implementation 'com.google.android.gms:play-services-vision:20.1.3'
55-
implementation 'com.google.android.gms:play-services-maps:19.2.0'
55+
implementation 'com.google.android.gms:play-services-maps:18.1.0'
5656
implementation 'com.google.firebase:firebase-core:21.1.1'
5757
implementation 'com.google.firebase:firebase-iid:21.1.0'
58-
implementation 'com.google.firebase:firebase-messaging:24.1.2'
59-
implementation 'com.google.firebase:firebase-analytics:22.5.0'
60-
implementation 'com.google.firebase:firebase-crashlytics:19.4.4'
61-
implementation 'com.google.firebase:firebase-database:21.0.0'
58+
implementation 'com.google.firebase:firebase-messaging:23.2.1'
59+
implementation 'com.google.firebase:firebase-analytics:21.3.0'
60+
implementation 'com.google.firebase:firebase-crashlytics:18.4.1'
61+
implementation 'com.google.firebase:firebase-database:20.2.2'
6262

6363
implementation 'com.android.installreferrer:installreferrer:2.2'
6464
implementation 'com.android.support:multidex:1.0.3'
65-
implementation 'com.google.code.gson:gson:2.13.1'
65+
implementation 'com.google.code.gson:gson:2.11.0'
6666
implementation 'androidx.biometric:biometric:1.2.0-alpha05'
67+
implementation 'androidx.enterprise:enterprise-feedback:1.1.0'
6768
implementation "androidx.work:work-runtime:2.8.1"
6869

6970
testImplementation 'junit:junit:4.13.2'
70-
testImplementation 'org.robolectric:robolectric:4.14.1'
71-
testImplementation 'androidx.test:core:1.6.1'
72-
testImplementation 'androidx.test.ext:junit:1.2.1'
7371
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
7472
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
7573

7674
}
77-
78-

app/src/main/AndroidManifest.xml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.prey"
43
xmlns:tools="http://schemas.android.com/tools"
54
android:installLocation="internalOnly"
65
>
@@ -53,9 +52,9 @@
5352
<!-- This app has permission to register and receive message -->
5453
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
5554

56-
<permission android:name="com.prey.permission.C2D_MESSAGE" android:protectionLevel="signature" />
55+
<permission android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature" />
5756

58-
<uses-permission android:name="com.prey.permission.C2D_MESSAGE" />
57+
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
5958

6059
<!-- This app has permission to camera -->
6160
<uses-permission android:name="android.permission.CAMERA" />
@@ -100,7 +99,6 @@
10099
android:clearTaskOnLaunch="true"
101100
android:configChanges="keyboardHidden|orientation"
102101
android:screenOrientation="portrait"
103-
android:launchMode="singleInstance"
104102
android:noHistory="true"
105103
android:exported="true"
106104
android:name=".activities.LoginActivity">
@@ -506,6 +504,11 @@
506504
<meta-data android:name="android.accessibilityservice" android:resource="@xml/accessibilityservice"/>
507505
</service>
508506

507+
<activity
508+
android:name=".activities.SplashMdmActivity"
509+
android:screenOrientation="portrait"
510+
android:theme="@style/AppTheme" />
511+
509512
</application>
510513

511514
</manifest>

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -567,13 +567,13 @@ public void removeApiKey(){
567567

568568
public boolean isThisDeviceAlreadyRegisteredWithPrey(boolean notifyUser) {
569569
String deviceId = getString(PreyConfig.DEVICE_ID, null);
570-
boolean isVerified = (deviceId != null && !"".equals(deviceId));
570+
boolean isVerified = (deviceId != null && !deviceId.isEmpty());
571571
return isVerified;
572572
}
573573

574574
public boolean isThisDeviceAlreadyRegisteredWithPrey() {
575575
String deviceID = getDeviceId();
576-
return deviceID != null && !"".equals(deviceID);
576+
return deviceID != null && !deviceID.isEmpty();
577577
}
578578

579579
public String getSimSerialNumber(){
@@ -611,7 +611,7 @@ public void registerC2dm() {
611611
String deviceId = PreyConfig.getPreyConfig(ctx).getDeviceId();
612612
boolean isTimeC2dm=PreyConfig.getPreyConfig(ctx).isTimeC2dm();
613613
PreyLogger.d("registerC2dm deviceId:"+deviceId+" isTimeC2dm:"+isTimeC2dm);
614-
if (deviceId != null && !"".equals(deviceId)) {
614+
if (deviceId != null && !deviceId.isEmpty()) {
615615
if (!isTimeC2dm) {
616616
String token = null;
617617
try {
@@ -653,7 +653,7 @@ public void onComplete(@NonNull Task<String> task) {
653653

654654
public static void sendToken(Context ctx,String token) {
655655
PreyLogger.d("registerC2dm send token:"+token);
656-
if(token!=null && !"null".equals(token) && !"".equals(token) && UtilConnection.isInternetAvailable(ctx)) {
656+
if(token!=null && !"null".equals(token) && !token.isEmpty() && UtilConnection.isInternetAvailable(ctx)) {
657657
try {
658658
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
659659
StrictMode.setThreadPolicy(policy);
@@ -1192,7 +1192,7 @@ public PreyLocation getLocationAware() {
11921192
// Retrieve the accuracy value from storage
11931193
float acc = getFloat(PreyConfig.AWARE_ACC, 0f);
11941194
// Check if the latitude or longitude values are empty or null
1195-
if (lat == null || "".equals(lat) || lng == null || "".equals(lng)) {
1195+
if (lat == null || lat.isEmpty() || lng == null || lng.isEmpty()) {
11961196
// If either value is empty or null, return null
11971197
return null;
11981198
}
@@ -1752,13 +1752,17 @@ public boolean isTimeNextAware() {
17521752
*/
17531753
public String buildDeviceName(String defaultName) {
17541754
String mdmDeviceName = getMdmDeviceName();
1755-
if (mdmDeviceName != null && !"".equals(mdmDeviceName)) {
1755+
if (mdmDeviceName != null && !mdmDeviceName.isEmpty()) {
17561756
return mdmDeviceName;
17571757
}
17581758
String serialNumber = getMdmSerialNumber();
1759-
if (serialNumber != null && !"".equals(serialNumber)) {
1759+
if (serialNumber != null && !serialNumber.isEmpty()) {
17601760
return defaultName + " - " + serialNumber;
17611761
}
1762+
String workEmail = resolveWorkEmail();
1763+
if (workEmail != null && !workEmail.isEmpty()) {
1764+
return workEmail;
1765+
}
17621766
return defaultName;
17631767
}
17641768

@@ -1770,7 +1774,7 @@ public String buildDeviceName(String defaultName) {
17701774
*/
17711775
public String resolveImei() {
17721776
String mdmImei = getMdmImei();
1773-
if (mdmImei != null && !"".equals(mdmImei)) {
1777+
if (mdmImei != null && !mdmImei.isEmpty()) {
17741778
return mdmImei;
17751779
}
17761780
return new PreyPhone(ctx).getHardware().getAndroidDeviceId();
@@ -1787,6 +1791,8 @@ public void registerNewDeviceWithApiKey(String apiKey) throws Exception {
17871791
PreyAccountData accountData = PreyWebServices.getInstance().registerNewDeviceWithApiKeyEmail(ctx, apiKey, deviceType, nameDevice);
17881792
if (accountData != null) {
17891793
PreyConfig.getPreyConfig(ctx).saveAccount(accountData);
1794+
PreyConfig.getPreyConfig(ctx).setNotificationId("");
1795+
PreyConfig.getPreyConfig(ctx).setRegisterC2dm(false);
17901796
// Register C2DM
17911797
PreyConfig.getPreyConfig(ctx).registerC2dm();
17921798
// Get the email associated with the account
@@ -1885,6 +1891,17 @@ public void setMdmDeviceName(String deviceName) {
18851891
saveString(MDM_DEVICE_NAME, deviceName);
18861892
}
18871893

1894+
/**
1895+
* Resolves the user's work email from the first Google account registered
1896+
* on the device — typically the work profile account under Android Enterprise
1897+
* (work profile apps see the work Google account, not the personal one).
1898+
*
1899+
* @return The work email, or null if no account is available.
1900+
*/
1901+
public String resolveWorkEmail() {
1902+
return PreyEmail.getEmail(ctx);
1903+
}
1904+
18881905
/**
18891906
* Key for storing the IMEI received from MDM restrictions in the configuration.
18901907
*/

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ public static void sendDataMail(Context ctx, HttpDataService data) {
4343
}
4444
}
4545

46+
// Account types searched, in preference order, to resolve the user's work email:
47+
// - "com.google": Google work account (work profile under Android Enterprise,
48+
// Google Endpoint Manager, managed Google Play).
49+
// - "com.microsoft.workaccount": Microsoft work account used by Intune
50+
// (Company Portal / Authenticator) on AAD-joined / Entra ID enrollments.
51+
private static final String[] WORK_ACCOUNT_TYPES = {
52+
"com.google",
53+
"com.microsoft.workaccount"
54+
};
55+
4656
@SuppressLint("NewApi")
4757
public static String getEmail(Context context) {
4858
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
@@ -62,12 +72,13 @@ public static String getEmail(Context context) {
6272
@SuppressLint("NewApi")
6373
private static Account getAccount(Context context,AccountManager accountManager) {
6474
if (PreyConfig.getPreyConfig(context).isEclairOrAbove()) {
65-
Account[] accounts = accountManager.getAccountsByType("com.google");
66-
if (accounts.length > 0) {
67-
return accounts[0];
68-
}else{
69-
PreyLogger.d("account length 0");
75+
for (String type : WORK_ACCOUNT_TYPES) {
76+
Account[] accounts = accountManager.getAccountsByType(type);
77+
if (accounts.length > 0) {
78+
return accounts[0];
79+
}
7080
}
81+
PreyLogger.d("account length 0");
7182
}else {
7283
PreyLogger.d("account bajo eckair");
7384
}

0 commit comments

Comments
 (0)