Skip to content

Commit 574933b

Browse files
author
yuemingw
committed
Show AddAccountActivity for admin integrated PO flow.
Show AddAccountActivity, and send the added account back to ManagedProvisioning. Bug: 123355836 Test: manual Change-Id: I3e33cbab2b472f65fa79408133fd9428ce9d31d0
1 parent ad37a4f commit 574933b

File tree

4 files changed

+56
-11
lines changed

4 files changed

+56
-11
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
</intent-filter>
9797
</activity>
9898

99-
<activity android:name=".policy.DpcLoginActivity"
99+
<activity android:name=".provision.DpcLoginActivity"
100100
android:exported="true">
101101
<intent-filter>
102102
<action android:name="android.app.action.GET_PROVISIONING_MODE" />

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package com.afwsamples.testdpc;
1818

19+
import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE;
20+
21+
import android.accounts.Account;
1922
import android.accounts.AccountManager;
2023
import android.accounts.AuthenticatorException;
2124
import android.accounts.OperationCanceledException;
@@ -34,9 +37,7 @@
3437
import android.widget.EditText;
3538
import android.widget.RadioGroup;
3639
import android.widget.Toast;
37-
3840
import com.android.setupwizardlib.GlifLayout;
39-
4041
import java.io.IOException;
4142

4243
/**
@@ -106,6 +107,10 @@ private void addAccount(String accountName) {
106107
if (mNextActivityIntent != null) {
107108
startActivity(mNextActivityIntent);
108109
}
110+
final Intent resultIntent = new Intent();
111+
resultIntent.putExtra(EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE,
112+
new Account(accountNameAdded, GOOGLE_ACCOUNT_TYPE));
113+
setResult(RESULT_OK, resultIntent);
109114
finish();
110115
} catch (OperationCanceledException | AuthenticatorException
111116
| IOException e) {

app/src/main/java/com/afwsamples/testdpc/policy/DpcLoginActivity.java renamed to app/src/main/java/com/afwsamples/testdpc/provision/DpcLoginActivity.java

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.afwsamples.testdpc.policy;
17+
package com.afwsamples.testdpc.provision;
1818

19+
import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE;
20+
21+
import android.accounts.Account;
1922
import android.app.Activity;
2023
import android.content.Intent;
2124
import android.os.Bundle;
25+
import android.util.Log;
2226
import android.view.View;
2327
import android.widget.RadioGroup;
28+
import com.afwsamples.testdpc.AddAccountActivity;
2429
import com.afwsamples.testdpc.R;
2530
import com.android.setupwizardlib.GlifLayout;
2631

@@ -37,6 +42,9 @@ public class DpcLoginActivity extends Activity {
3742
public static final int PROVISIONING_MODE_PO = 2;
3843
public static final int PROVISIONING_MODE_MANAGED_PROFILE_ON_FULLY_MANAGED_DEVICE = 3;
3944

45+
private static final String LOG_TAG = "DpcLoginActivity";
46+
private static final int ADD_ACCOUNT_REQUEST_CODE = 1;
47+
4048
@Override
4149
public void onCreate(Bundle icicle) {
4250
super.onCreate(icicle);
@@ -51,22 +59,54 @@ public void onBackPressed() {
5159
super.onBackPressed();
5260
}
5361

62+
@Override
63+
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
64+
switch (requestCode) {
65+
case ADD_ACCOUNT_REQUEST_CODE:
66+
finishWithIntent(createResultIntentFromData(data));
67+
break;
68+
default:
69+
Log.d(LOG_TAG, "Unknown result code: " + resultCode);
70+
break;
71+
}
72+
}
73+
74+
private Intent createResultIntentFromData(Intent data) {
75+
final Intent resultIntent = new Intent();
76+
resultIntent.putExtra(EXTRA_PROVISIONING_MODE, PROVISIONING_MODE_PO);
77+
if (data != null && data.hasExtra(EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE)) {
78+
final Account accountToMigrate = data.getParcelableExtra(
79+
EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE);
80+
resultIntent.putExtra(EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE, accountToMigrate);
81+
}
82+
return resultIntent;
83+
}
84+
5485
private void onNavigateNext(View nextButton) {
55-
Intent intent = new Intent();
86+
final Intent intent = new Intent();
5687
RadioGroup dpcLoginOptions = findViewById(R.id.dpc_login_options);
5788
switch (dpcLoginOptions.getCheckedRadioButtonId()) {
5889
case R.id.dpc_login_do:
5990
intent.putExtra(EXTRA_PROVISIONING_MODE, PROVISIONING_MODE_DO);
60-
break;
91+
finishWithIntent(intent);
92+
return;
6193
case R.id.dpc_login_po:
62-
intent.putExtra(EXTRA_PROVISIONING_MODE, PROVISIONING_MODE_PO);
63-
break;
94+
startActivityForResult(
95+
new Intent(getApplicationContext(), AddAccountActivity.class),
96+
ADD_ACCOUNT_REQUEST_CODE);
97+
return;
6498
case R.id.dpc_login_comp:
6599
intent.putExtra(EXTRA_PROVISIONING_MODE,
66100
PROVISIONING_MODE_MANAGED_PROFILE_ON_FULLY_MANAGED_DEVICE);
67-
break;
101+
finishWithIntent(intent);
102+
return;
103+
default:
104+
finish();
68105
}
69-
setResult(RESULT_OK , intent);
106+
}
107+
108+
private void finishWithIntent(Intent intent) {
109+
setResult(RESULT_OK, intent);
70110
finish();
71111
}
72112
}

app/src/main/res/layout/activity_add_account.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
android:layout_height="match_parent"
2222
android:icon="@drawable/ic_enterprise_blue"
2323
app:suwFooter="@layout/next_footer"
24-
app:suwHeaderText="@string/setup_finished">
24+
app:suwHeaderText="@string/add_account">
2525

2626
<LinearLayout
2727
style="@style/SuwItemContainer"

0 commit comments

Comments
 (0)