@Override public void informUpgradeRequiredResponse(final GlobalSession session) { final AccountManager manager = AccountManager.get(mContext); final Account toDisable = localAccount; if (toDisable == null || manager == null) { Logger.warn(LOG_TAG, "Attempting to disable account, but null found."); return; } // Sync needs to be upgraded. Don't automatically sync anymore. ThreadPool.run( new Runnable() { @Override public void run() { manager.setUserData(toDisable, Constants.DATA_ENABLE_ON_UPGRADE, "1"); SyncAccounts.setSyncAutomatically(toDisable, false); } }); }
/** * Now that we have a sync key and password, go ahead and do the work. * * @throws NoSuchAlgorithmException * @throws IllegalArgumentException * @throws SyncConfigurationException * @throws AlreadySyncingException * @throws NonObjectJSONException * @throws ParseException * @throws IOException * @throws CryptoException */ protected void performSync( final Account account, final Bundle extras, final String authority, final ContentProviderClient provider, final SyncResult syncResult, final String username, final String password, final String prefsPath, final String serverURL, final String syncKey) throws NoSuchAlgorithmException, SyncConfigurationException, IllegalArgumentException, AlreadySyncingException, IOException, ParseException, NonObjectJSONException, CryptoException { Logger.trace(LOG_TAG, "Performing sync."); syncStartTimestamp = System.currentTimeMillis(); /** * Bug 769745: pickle Sync account parameters to JSON file. Un-pickle in <code> * SyncAccounts.syncAccountsExist</code>. */ try { // Constructor can throw on nulls, which should not happen -- but let's be safe. final SyncAccountParameters params = new SyncAccountParameters( mContext, null, account.name, // Un-encoded, like "*****@*****.**". syncKey, password, serverURL, null, // We'll re-fetch cluster URL; not great, but not harmful. getClientName(), getAccountGUID()); // Bug 772971: pickle Sync account parameters on background thread to // avoid strict mode warnings. ThreadPool.run( new Runnable() { @Override public void run() { final boolean syncAutomatically = ContentResolver.getSyncAutomatically(account, authority); try { AccountPickler.pickle( mContext, Constants.ACCOUNT_PICKLE_FILENAME, params, syncAutomatically); } catch (Exception e) { // Should never happen, but we really don't want to die in a background thread. Logger.warn( LOG_TAG, "Got exception pickling current account details; ignoring.", e); } } }); } catch (IllegalArgumentException e) { // Do nothing. } // TODO: default serverURL. final KeyBundle keyBundle = new KeyBundle(username, syncKey); GlobalSession globalSession = new GlobalSession( SyncConfiguration.DEFAULT_USER_API, serverURL, username, password, prefsPath, keyBundle, this, this.mContext, extras, this); globalSession.start(); }
public void execute(final GlobalSession session) throws NoSuchStageException { if (session.config.getClusterURL() != null) { Log.i(LOG_TAG, "Cluster URL already set. Continuing with sync."); session.advance(); return; } Log.i(LOG_TAG, "Fetching cluster URL."); final ClusterURLFetchDelegate delegate = new ClusterURLFetchDelegate() { @Override public void handleSuccess(final String url) { Log.i(LOG_TAG, "Node assignment pointed us to " + url); try { session.config.setClusterURL(url); ThreadPool.run( new Runnable() { @Override public void run() { session.advance(); } }); return; } catch (URISyntaxException e) { final URISyntaxException uriException = e; ThreadPool.run( new Runnable() { @Override public void run() { session.abort(uriException, "Invalid cluster URL."); } }); } } @Override public void handleFailure(HttpResponse response) { int statusCode = response.getStatusLine().getStatusCode(); Log.w(LOG_TAG, "Got HTTP failure fetching node assignment: " + statusCode); if (statusCode == 404) { URI serverURL = session.config.serverURL; if (serverURL != null) { Log.i( LOG_TAG, "Using serverURL <" + serverURL.toASCIIString() + "> as clusterURL."); session.config.setClusterURL(serverURL); session.advance(); return; } Log.w(LOG_TAG, "No serverURL set to use as fallback cluster URL. Aborting sync."); // Fallthrough to abort. } else { session.interpretHTTPFailure(response); } session.abort(new Exception("HTTP failure."), "Got failure fetching cluster URL."); } @Override public void handleError(Exception e) { session.abort(e, "Got exception fetching cluster URL."); } }; ThreadPool.run( new Runnable() { @Override public void run() { try { fetchClusterURL(session, delegate); } catch (URISyntaxException e) { session.abort(e, "Invalid URL for node/weave."); } } }); }