Skip to content

Commit 11296df

Browse files
jscott1989pfmaggi
authored andcommitted
No public description
PiperOrigin-RevId: 566956848
1 parent 8bc18ea commit 11296df

File tree

5 files changed

+65
-0
lines changed

5 files changed

+65
-0
lines changed

src/main/AndroidManifest.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,16 @@
201201
</intent-filter>
202202
</receiver>
203203

204+
<receiver android:name=".PolicyChangeMonitor"
205+
android:exported="true"
206+
android:enabled="@bool/is_u_or_later"
207+
android:permission="android.permission.BIND_DEVICE_ADMIN">
208+
<intent-filter>
209+
<action android:name="android.app.admin.action.DEVICE_POLICY_CHANGED"/>
210+
<action android:name="android.app.admin.action.DEVICE_POLICY_SET_RESULT"/>
211+
</intent-filter>
212+
</receiver>
213+
204214
<service android:name=".policy.resetpassword.ResetPasswordService"
205215
android:enabled="@bool/is_o_or_later"
206216
android:exported="false"
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.afwsamples.testdpc;
2+
3+
import android.app.admin.PolicyUpdateReceiver;
4+
import android.app.admin.PolicyUpdateResult;
5+
import android.app.admin.TargetUser;
6+
import android.content.Context;
7+
import android.os.Bundle;
8+
import android.util.Log;
9+
10+
/** Receiver for system notifications about device policy changes */
11+
public class PolicyChangeMonitor extends PolicyUpdateReceiver {
12+
private static final String TAG = "PolicyChangeMonitor";
13+
14+
public void onPolicyChanged(
15+
Context context,
16+
String policyIdentifier,
17+
Bundle additionalPolicyParams,
18+
TargetUser targetUser,
19+
PolicyUpdateResult policyUpdateResult) {
20+
if (policyUpdateResult.getResultCode() == PolicyUpdateResult.RESULT_POLICY_SET) {
21+
Log.i(TAG, context.getString(R.string.policy_restored_log_text, policyIdentifier));
22+
} else {
23+
Log.i(TAG, context.getString(R.string.policy_altered_log_text, policyIdentifier));
24+
}
25+
return;
26+
}
27+
28+
public void onPolicySetResult(
29+
Context context,
30+
String policyIdentifier,
31+
Bundle additionalPolicyParams,
32+
TargetUser targetUser,
33+
PolicyUpdateResult policyUpdateResult) {
34+
if (policyUpdateResult.getResultCode() == PolicyUpdateResult.RESULT_POLICY_SET) {
35+
Log.i(TAG, context.getString(R.string.policy_set_log_text, policyIdentifier));
36+
} else if (policyUpdateResult.getResultCode() == PolicyUpdateResult.RESULT_POLICY_CLEARED) {
37+
Log.i(TAG, context.getString(R.string.policy_cleared_log_text, policyIdentifier));
38+
} else {
39+
Log.i(TAG, context.getString(R.string.policy_not_set_log_text, policyIdentifier));
40+
}
41+
return;
42+
}
43+
}

src/main/res/values-v34/bools.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<bool name="is_o_or_later">true</bool>
4+
<bool name="is_u_or_later">true</bool>
5+
</resources>

src/main/res/values/bools.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33
<bool name="is_o_or_later">false</bool>
4+
<bool name="is_u_or_later">false</bool>
45
</resources>

src/main/res/values/strings.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,12 @@
11701170
<string name="package_added_notification_text">%1$s is added</string>
11711171
<string name="package_removed_notification_text">%1$s is removed</string>
11721172

1173+
<string name="policy_altered_log_text">%1$s policy altered</string>
1174+
<string name="policy_restored_log_text">%1$s policy restored</string>
1175+
<string name="policy_set_log_text">%1$s policy set</string>
1176+
<string name="policy_cleared_log_text">%1$s policy cleared</string>
1177+
<string name="policy_not_set_log_text">%1$s policy could not be set as expected</string>
1178+
11731179
<string name="cross_profile_section">Cross profile</string>
11741180
<string name="cross_profile_apps_api">Demonstrate CrossProfileApps API</string>
11751181
<string name="cross_profile_apps_api_explanation">By using the CrossProfileApps APIs, apps can start an instance in another profile, provided that the app is also installed in that profile.</string>

0 commit comments

Comments
 (0)