Skip to content

Commit 14b6de2

Browse files
jscott1989pfmaggi
authored andcommitted
No public description
PiperOrigin-RevId: 627391609
1 parent 3d2ad46 commit 14b6de2

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/main/java/com/afwsamples/testdpc/policy/resetpassword/ResetPasswordService.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import android.util.Log;
3838
import androidx.annotation.Nullable;
3939
import com.afwsamples.testdpc.DeviceAdminReceiver;
40+
import com.afwsamples.testdpc.common.Util;
4041
import com.afwsamples.testdpc.R;
4142

4243
@TargetApi(VERSION_CODES.O)
@@ -58,9 +59,11 @@ public static class LockedBootCompletedReceiver extends BroadcastReceiver {
5859
@Override
5960
public void onReceive(Context context, Intent intent) {
6061
Log.d(TAG, "onReceive: " + intent.toString());
61-
Intent serviceIntent = new Intent(context, ResetPasswordService.class);
62-
serviceIntent.setAction(intent.getAction());
63-
context.startForegroundService(serviceIntent);
62+
if (Util.isDeviceOwner(context) || Util.isProfileOwner(context)) {
63+
Intent serviceIntent = new Intent(context, ResetPasswordService.class);
64+
serviceIntent.setAction(intent.getAction());
65+
context.startForegroundService(serviceIntent);
66+
}
6467
}
6568
}
6669

@@ -100,7 +103,11 @@ public int onStartCommand(Intent intent, int flags, int startId) {
100103
IntentFilter filter = new IntentFilter();
101104
filter.addAction(ACTION_USER_UNLOCKED);
102105
filter.addAction(ACTION_RESET_PASSWORD);
103-
registerReceiver(receiver, filter);
106+
if (Util.SDK_INT >= VERSION_CODES.TIRAMISU) {
107+
registerReceiver(receiver, filter, Context.RECEIVER_EXPORTED);
108+
} else {
109+
registerReceiver(receiver, filter);
110+
}
104111

105112
showNotification();
106113
return START_REDELIVER_INTENT;

0 commit comments

Comments
 (0)