Skip to content

Commit e0cdd3c

Browse files
jscott1989pfmaggi
authored andcommitted
No public description
PiperOrigin-RevId: 621853541
1 parent 68b5bf1 commit e0cdd3c

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

src/main/AndroidManifest.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,16 @@
230230
</intent-filter>
231231
</receiver>
232232

233+
<receiver android:name=".PolicyChangeMonitor"
234+
android:exported="true"
235+
android:enabled="@bool/is_u_or_later"
236+
android:permission="android.permission.BIND_DEVICE_ADMIN">
237+
<intent-filter>
238+
<action android:name="android.app.admin.action.DEVICE_POLICY_CHANGED"/>
239+
<action android:name="android.app.admin.action.DEVICE_POLICY_SET_RESULT"/>
240+
</intent-filter>
241+
</receiver>
242+
233243
<service android:name=".policy.resetpassword.ResetPasswordService"
234244
android:enabled="@bool/is_o_or_later"
235245
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/strings.xml

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

1180+
<string name="policy_altered_log_text">%1$s policy altered</string>
1181+
<string name="policy_restored_log_text">%1$s policy restored</string>
1182+
<string name="policy_set_log_text">%1$s policy set</string>
1183+
<string name="policy_cleared_log_text">%1$s policy cleared</string>
1184+
<string name="policy_not_set_log_text">%1$s policy could not be set as expected</string>
1185+
11801186
<string name="cross_profile_section">Cross profile</string>
11811187
<string name="cross_profile_apps_api">Demonstrate CrossProfileApps API</string>
11821188
<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)