Add the following method to your class in MainActivity.java
.
private void startResetFlow() {
LOGGER.debug("starting Reset flow");
StoreHelper.reset();
// Creating flow and configuring steps
Flow flow = new Flow("reset");
flow.setSteps(new Step[]{
new StoreManagerStep(), // clears the application store (APP_SECURE_STORE)
new BasicAuthStep(), // removes any saved cookies
new PasscodePolicyStoreStep() // clears the passcode policy store (RLM_SECURE_STORE) and creates a new one
});
// Preparing flow context
flowContext.setContext(this.getApplication());
flowContext.setFlowPresentationActionHandler(new FlowPresentationActionHandlerImpl(this));
flowManagerService.execute(flow, flowContext, new FlowActionHandler() {
@Override
public void onFailure(Throwable t) {
LOGGER.debug("Reset failed. ");
showAlertDialog("Reset", t);
}
@Override
public void onSuccess(FlowContext result) {
LOGGER.debug("Successfully reset");
// show splash screen again then start onboarding flow
getSupportActionBar().hide();
setContentView(R.layout.splash_screen);
// After the reset, the stores should be empty
LOGGER.debug("About to log values from the Passcode Policy Store");
StoreHelper.logStoreValues(((OnboardingContext) result).getPasscodePolicyStore());
LOGGER.debug("About to log values from the Application Store");
StoreHelper.logStoreValues(((OnboardingContext) result).getApplicationStore());
startOnboardingFlow();
}
});
}
The added method calls the StoreHelper's
reset method which clears data in the stores and then starts the onboarding flow.
Add the following line to the onReset
method.
startResetFlow();
Within the showAlertDialog
method, uncomment the following code.
if (t.getMessage().equals("Eula Rejected") || flow.equals("Onboard")) {
startResetFlow();
}
This will ensure that if the EULA is rejected, or if onboarding fails, then the onboarding flow will begin again.