Skip to content

Commit 192ff0f

Browse files
committed
Enable the first account ready receiver in onProfileProvisioningComplete
Change-Id: I08da80359d4b37d4ea42170cec77b36c4cf010bf Fix: 29232240
1 parent c1a68a7 commit 192ff0f

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import android.accounts.OperationCanceledException;
2424
import android.app.Activity;
2525
import android.app.AlertDialog;
26-
import android.app.admin.DevicePolicyManager;
27-
import android.content.ComponentName;
2826
import android.content.DialogInterface;
2927
import android.content.Intent;
3028
import android.os.Bundle;
@@ -34,8 +32,6 @@
3432
import android.widget.EditText;
3533
import android.widget.RadioGroup;
3634

37-
import com.afwsamples.testdpc.common.LaunchIntentUtil;
38-
import com.afwsamples.testdpc.common.Util;
3935
import com.android.setupwizardlib.SetupWizardLayout;
4036
import com.android.setupwizardlib.view.NavigationBar;
4137

@@ -74,15 +70,6 @@ protected void onCreate(Bundle savedInstanceState) {
7470
}
7571

7672
private void addAccount(String accountName) {
77-
// Enable first account ready receiver for PO flow. On pre-N devices, the only supported
78-
// PO flow is managed profile. On N+ devices we need to check whether we're running in a
79-
// managed profile.
80-
DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);
81-
ComponentName adminComponent = DeviceAdminReceiver.getComponentName(this);
82-
if (dpm.isProfileOwnerApp(getPackageName())
83-
&& (Util.isBeforeN() || Util.isManagedProfile(this, adminComponent))) {
84-
FirstAccountReadyBroadcastReceiver.setEnabled(this, true);
85-
}
8673
AccountManager accountManager = AccountManager.get(this);
8774
Bundle bundle = new Bundle();
8875
if (!TextUtils.isEmpty(accountName)) {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ public void onProfileProvisioningComplete(Context context, Intent intent) {
133133
}
134134
}
135135

136+
// Enable first account ready receiver for PO flow. On pre-N devices, the only supported
137+
// PO flow is managed profile. On N+ devices we need to check whether we're running in a
138+
// managed profile.
139+
ComponentName adminComponent = DeviceAdminReceiver.getComponentName(context);
140+
if (devicePolicyManager.isProfileOwnerApp(context.getPackageName())
141+
&& (Util.isBeforeN() || Util.isManagedProfile(context, adminComponent))) {
142+
FirstAccountReadyBroadcastReceiver.setEnabled(context, true);
143+
}
144+
136145
// For synchronous auth cases, we can assume accounts are already setup (or will be shortly,
137146
// as account migration for Profile Owner is asynchronous). For COSU we don't want to show
138147
// the account option to the user, as no accounts should be added for now.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected void onCreate(Bundle savedInstanceState) {
6969
if (mEnableProfileNow) {
7070
ProvisioningUtil.enableProfile(this);
7171
} else {
72-
// Set up an alarm to enable profile in case we do not receive first account
72+
// Set up an alarm to enable profile in case we do not receive first account ready
7373
// broadcast for whatever reason.
7474
FirstAccountReadyBroadcastReceiver.scheduleFirstAccountReadyTimeoutAlarm(
7575
this, WAIT_FOR_FIRST_ACCOUNT_READY_TIMEOUT);

0 commit comments

Comments
 (0)