/**
* @throws FailedToLoadSessionException if we're unable to load the account.
* @return a FirefoxAccount.
*/
@NonNull
@AnyThread
FirefoxAccountSession loadSession() throws FailedToLoadSessionException {
if (sharedPrefs.getInt(KEY_VERSION, -1) < 0) { throw new FailedToLoadSessionException("account does not exist"); }
final State state;
try {
final StateLabel stateLabel = State.StateLabel.valueOf(sharedPrefs.getString(KEY_STATE_LABEL, null));
final ExtendedJSONObject stateJSON = new ExtendedJSONObject(sharedPrefs.getString(KEY_STATE_JSON, null));
state = StateFactory.fromJSONObject(stateLabel, stateJSON);
} catch (final NoSuchAlgorithmException | IOException | NonObjectJSONException | InvalidKeySpecException | IllegalArgumentException e) {
throw new FailedToLoadSessionException("unable to restore account state", e);
}
final String endpointConfigLabel = sharedPrefs.getString(KEY_ENDPOINT_CONFIG_LABEL, "");
final FirefoxAccountEndpointConfig endpointConfig;
switch (endpointConfigLabel) { // We should probably use enums over Strings, but it wasn't worth my time.
case LABEL_STABLE_DEV: endpointConfig = FirefoxAccountEndpointConfig.getStableDev(); break;
case LABEL_LATEST_DEV: endpointConfig = FirefoxAccountEndpointConfig.getLatestDev(); break;
case LABEL_STAGE: endpointConfig = FirefoxAccountEndpointConfig.getStage(); break;
case LABEL_PRODUCTION: endpointConfig = FirefoxAccountEndpointConfig.getProduction(); break;
default: throw new FailedToLoadSessionException("unable to restore account - unknown endpoint label: " + endpointConfigLabel);
}
final String email = sharedPrefs.getString(KEY_EMAIL, null);
final String uid = sharedPrefs.getString(KEY_UID, null);
final FirefoxAccount firefoxAccount = new FirefoxAccount(email, uid, state, endpointConfig);
final String applicationName = sharedPrefs.getString(KEY_APPLICATION_NAME, null);
return new FirefoxAccountSession(firefoxAccount, applicationName);
}
FirefoxAccountSessionSharedPrefsStore.java 文件源码
java
阅读 45
收藏 0
点赞 0
评论 0
项目:FirefoxData-android
作者:
评论列表
文章目录