Skip to content

Commit 7bdee2f

Browse files
committed
Only enable profile if it is managed profile
Bug: 29065614 Change-Id: I1beb7c5b6ccbd51acfcb063da8524ee07e1c25c9
1 parent e0a2049 commit 7bdee2f

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

app/src/main/java/com/afwsamples/testdpc/FirstAccountReadyBroadcastReceiver.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616

1717
package com.afwsamples.testdpc;
1818

19+
import android.app.admin.DevicePolicyManager;
1920
import android.content.BroadcastReceiver;
21+
import android.content.ComponentName;
2022
import android.content.Context;
2123
import android.content.Intent;
2224
import android.util.Log;
2325

26+
import com.afwsamples.testdpc.common.Util;
2427
import com.afwsamples.testdpc.provision.CheckInState;
2528
import com.afwsamples.testdpc.provision.ProvisioningUtil;
2629

@@ -36,9 +39,15 @@ public class FirstAccountReadyBroadcastReceiver extends BroadcastReceiver {
3639
public void onReceive(Context context, Intent intent) {
3740
Log.d(TAG, "Received: " + intent.getAction());
3841
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+
}
4251
}
4352
}
4453
}

0 commit comments

Comments
 (0)