16
16
17
17
package com .afwsamples .testdpc ;
18
18
19
+ import android .app .admin .DevicePolicyManager ;
19
20
import android .content .BroadcastReceiver ;
21
+ import android .content .ComponentName ;
20
22
import android .content .Context ;
21
23
import android .content .Intent ;
22
24
import android .util .Log ;
23
25
26
+ import com .afwsamples .testdpc .common .Util ;
24
27
import com .afwsamples .testdpc .provision .CheckInState ;
25
28
import com .afwsamples .testdpc .provision .ProvisioningUtil ;
26
29
@@ -36,9 +39,15 @@ public class FirstAccountReadyBroadcastReceiver extends BroadcastReceiver {
36
39
public void onReceive (Context context , Intent intent ) {
37
40
Log .d (TAG , "Received: " + intent .getAction ());
38
41
if (FIRST_ACCOUNT_READY_ACTION .equals (intent .getAction ())) {
39
- CheckInState checkInState = new CheckInState (context );
40
- checkInState .setFirstAccountReady ();
41
- ProvisioningUtil .enableProfile (context );
42
+ ComponentName admin = DeviceAdminReceiver .getComponentName (context );
43
+ DevicePolicyManager dpm =
44
+ (DevicePolicyManager ) context .getSystemService (Context .DEVICE_POLICY_SERVICE );
45
+ if (dpm .isProfileOwnerApp (context .getPackageName ())
46
+ && Util .isManagedProfile (context , admin )) {
47
+ CheckInState checkInState = new CheckInState (context );
48
+ checkInState .setFirstAccountReady ();
49
+ ProvisioningUtil .enableProfile (context );
50
+ }
42
51
}
43
52
}
44
53
}
0 commit comments