37
37
import android .util .Log ;
38
38
import androidx .annotation .Nullable ;
39
39
import com .afwsamples .testdpc .DeviceAdminReceiver ;
40
+ import com .afwsamples .testdpc .common .Util ;
40
41
import com .afwsamples .testdpc .R ;
41
42
42
43
@ TargetApi (VERSION_CODES .O )
@@ -58,9 +59,11 @@ public static class LockedBootCompletedReceiver extends BroadcastReceiver {
58
59
@ Override
59
60
public void onReceive (Context context , Intent intent ) {
60
61
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
+ }
64
67
}
65
68
}
66
69
@@ -100,7 +103,11 @@ public int onStartCommand(Intent intent, int flags, int startId) {
100
103
IntentFilter filter = new IntentFilter ();
101
104
filter .addAction (ACTION_USER_UNLOCKED );
102
105
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
+ }
104
111
105
112
showNotification ();
106
113
return START_REDELIVER_INTENT ;
0 commit comments