Skip to content

Commit d1fe4a1

Browse files
alexchau-googletony-mak
authored andcommitted
Show a different title when wait for account ready timed out
Bug: 30805764 Change-Id: I7d8a9b2c7892fe51d1c0de677a7d7cd4a08048d0 (cherry picked from commit 16edc882c52689b595f2b1a8be5d965cd4863aa1)
1 parent c553829 commit d1fe4a1

File tree

4 files changed

+50
-20
lines changed

4 files changed

+50
-20
lines changed

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

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import android.content.pm.ApplicationInfo;
2727
import android.content.pm.PackageManager;
2828
import android.os.Bundle;
29+
import android.support.annotation.StringRes;
2930
import android.support.v4.content.LocalBroadcastManager;
3031
import android.util.Log;
3132
import android.view.View;
@@ -54,7 +55,7 @@ public class EnableProfileActivity extends Activity implements NavigationBar.Nav
5455
private Button mFinishButton;
5556
private SetupWizardLayout mSetupWizardLayout;
5657

57-
private boolean mEnableProfileNow;
58+
private CheckInState mCheckinState;
5859

5960
public static final String EXTRA_ENABLE_PROFILE_NOW = "enable_profile_now";
6061
private static final IntentFilter sIntentFilter =
@@ -64,9 +65,11 @@ public class EnableProfileActivity extends Activity implements NavigationBar.Nav
6465
@Override
6566
protected void onCreate(Bundle savedInstanceState) {
6667
super.onCreate(savedInstanceState);
67-
mEnableProfileNow = getIntent().getBooleanExtra(EXTRA_ENABLE_PROFILE_NOW, false);
68+
69+
mCheckinState = new CheckInState(this);
6870
if (savedInstanceState == null) {
69-
if (mEnableProfileNow) {
71+
if (getIntent().getBooleanExtra(EXTRA_ENABLE_PROFILE_NOW, false)) {
72+
mCheckinState.setFirstAccountState(CheckInState.FIRST_ACCOUNT_STATE_READY);
7073
ProvisioningUtil.enableProfile(this);
7174
} else {
7275
// Set up an alarm to enable profile in case we do not receive first account ready
@@ -120,8 +123,7 @@ protected void onResume() {
120123
LocalBroadcastManager.getInstance(this).registerReceiver(mCheckInStateReceiver,
121124
sIntentFilter);
122125
// In case the broadcast is sent before we register the receiver.
123-
CheckInState checkInState = new CheckInState(this);
124-
refreshUi(mEnableProfileNow || checkInState.isFirstAccountReady() /* enableFinish */);
126+
refreshUi();
125127
}
126128

127129
@Override
@@ -140,16 +142,30 @@ private boolean isAccountMigrated(String addedAccount) {
140142
return false;
141143
}
142144

143-
private void refreshUi(boolean enableFinish) {
145+
private void refreshUi() {
146+
boolean enableFinish;
147+
@StringRes int headerTextResId;
148+
switch (mCheckinState.getFirstAccountState()) {
149+
case CheckInState.FIRST_ACCOUNT_STATE_READY:
150+
enableFinish = true;
151+
headerTextResId = R.string.finish_setup;
152+
break;
153+
case CheckInState.FIRST_ACCOUNT_STATE_TIMEOUT:
154+
enableFinish = true;
155+
headerTextResId = R.string.finish_setup_account_not_ready;
156+
break;
157+
case CheckInState.FIRST_ACCOUNT_STATE_PENDING:
158+
default:
159+
enableFinish = false;
160+
headerTextResId = R.string.waiting_for_first_account_check_in;
161+
break;
162+
}
144163
if (enableFinish) {
145164
mSetupWizardLayout.hideProgressBar();
146165
} else {
147166
mSetupWizardLayout.showProgressBar();
148167
}
149-
mSetupWizardLayout.setHeaderText(
150-
(enableFinish)
151-
? R.string.finish_setup
152-
: R.string.waiting_for_first_account_check_in);
168+
mSetupWizardLayout.setHeaderText(headerTextResId);
153169
mFinishButton.setEnabled(enableFinish);
154170
}
155171

@@ -167,7 +183,7 @@ class CheckInStateReceiver extends BroadcastReceiver {
167183
@Override
168184
public void onReceive(Context context, Intent intent) {
169185
// Processed the first check-in broadcast, allow user to tap the finish button.
170-
refreshUi(true);
186+
refreshUi();
171187
}
172188
}
173189
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,14 @@ public void onReceive(Context context, Intent intent) {
5151
if (FIRST_ACCOUNT_READY_ACTION.equals(action) ||
5252
FIRST_ACCOUNT_READY_TIMEOUT_ACTION.equals(action)) {
5353
CheckInState checkInState = new CheckInState(context);
54-
if (!checkInState.isFirstAccountReady()) {
55-
checkInState.setFirstAccountReady();
54+
if (checkInState.getFirstAccountState() == CheckInState.FIRST_ACCOUNT_STATE_PENDING) {
55+
int nextState;
56+
if (FIRST_ACCOUNT_READY_ACTION.equals(action)) {
57+
nextState = CheckInState.FIRST_ACCOUNT_STATE_READY;
58+
} else {
59+
nextState = CheckInState.FIRST_ACCOUNT_STATE_TIMEOUT;
60+
}
61+
checkInState.setFirstAccountState(nextState);
5662
ProvisioningUtil.enableProfile(context);
5763
}
5864
// This receiver is disabled in ProvisioningUtil.enableProfile, no more code should

app/src/main/java/com/afwsamples/testdpc/provision/CheckInState.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ public class CheckInState {
2626
private SharedPreferences mSharedPreferences;
2727
private Context mContext;
2828

29-
private static final String KEY_FIRST_ACCOUNT_READY = "first_account_ready";
29+
public static final int FIRST_ACCOUNT_STATE_PENDING = 0;
30+
public static final int FIRST_ACCOUNT_STATE_READY = 1;
31+
public static final int FIRST_ACCOUNT_STATE_TIMEOUT = 2;
32+
33+
private static final String KEY_FIRST_ACCOUNT_STATE = "first_account_state";
34+
3035
/**
3136
* Broadcast Action: FIRST_ACCOUNT_READY broadcast is processed.
3237
*/
@@ -38,13 +43,15 @@ public CheckInState(Context context) {
3843
mContext = context.getApplicationContext();
3944
}
4045

41-
public boolean isFirstAccountReady() {
42-
return mSharedPreferences.getBoolean(KEY_FIRST_ACCOUNT_READY, false);
46+
public int getFirstAccountState() {
47+
return mSharedPreferences.getInt(KEY_FIRST_ACCOUNT_STATE, FIRST_ACCOUNT_STATE_PENDING);
4348
}
4449

45-
public void setFirstAccountReady() {
46-
mSharedPreferences.edit().putBoolean(KEY_FIRST_ACCOUNT_READY, true).apply();
47-
LocalBroadcastManager.getInstance(mContext).sendBroadcast(
48-
new Intent(FIRST_ACCOUNT_READY_PROCESSED_ACTION));
50+
public void setFirstAccountState(int state) {
51+
mSharedPreferences.edit().putInt(KEY_FIRST_ACCOUNT_STATE, state).apply();
52+
if (state != FIRST_ACCOUNT_STATE_PENDING) {
53+
LocalBroadcastManager.getInstance(mContext).sendBroadcast(
54+
new Intent(FIRST_ACCOUNT_READY_PROCESSED_ACTION));
55+
}
4956
}
5057
}

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<string name="setup_label">Set up</string>
3434
<string name="profile_name">Sample Managed Profile</string>
3535
<string name="finish_setup">Finish setup</string>
36+
<string name="finish_setup_account_not_ready">Finish setup but account might not be ready</string>
3637
<string name="setup_finished">Setup finished</string>
3738
<string name="click_finish_to_complete">Click Finish to complete setup.</string>
3839
<string name="waiting_for_first_account_check_in">Putting finishing touches</string>

0 commit comments

Comments
 (0)