Bug 727958 - Sync set-up screen results in StrictMode policy violation. r=rnewman

This commit is contained in:
Chenxia Liu 2012-02-21 14:58:22 -08:00
parent 2b50ea839d
commit 0b9c148a1c

View File

@ -9,6 +9,7 @@ import java.util.HashMap;
import org.json.simple.JSONObject;
import org.mozilla.gecko.R;
import org.mozilla.gecko.sync.Logger;
import org.mozilla.gecko.sync.ThreadPool;
import org.mozilla.gecko.sync.jpake.JPakeClient;
import org.mozilla.gecko.sync.jpake.JPakeNoActivePairingException;
import org.mozilla.gecko.sync.setup.Constants;
@ -86,8 +87,18 @@ public class SetupSyncActivity extends AccountAuthenticatorActivity {
}
// Check whether Sync accounts exist; if not, display J-PAKE PIN.
// Run this on a separate thread to comply with Strict Mode thread policies.
ThreadPool.run(new Runnable() {
@Override
public void run() {
Account[] accts = mAccountManager.getAccountsByType(Constants.ACCOUNTTYPE_SYNC);
finishResume(accts);
}
});
}
public void finishResume(Account[] accts) {
Logger.debug(LOG_TAG, "Finishing Resume after fetching accounts.");
if (accts.length == 0) { // Start J-PAKE for pairing if no accounts present.
Logger.debug(LOG_TAG, "No accounts; starting J-PAKE receiver.");
displayReceiveNoPin();
@ -113,9 +124,14 @@ public class SetupSyncActivity extends AccountAuthenticatorActivity {
}
}
runOnUiThread(new Runnable() {
@Override
public void run() {
Logger.debug(LOG_TAG, "Only one account supported. Redirecting.");
// Display toast for "Only one account supported." and redirect to account management.
Toast toast = Toast.makeText(mContext, R.string.sync_notification_oneaccount, Toast.LENGTH_LONG);
// Display toast for "Only one account supported."
// Redirect to account management.
Toast toast = Toast.makeText(mContext,
R.string.sync_notification_oneaccount, Toast.LENGTH_LONG);
toast.show();
Intent intent = new Intent(Settings.ACTION_SYNC_SETTINGS);
@ -124,6 +140,9 @@ public class SetupSyncActivity extends AccountAuthenticatorActivity {
finish();
}
});
}
@Override
public void onPause() {
@ -418,8 +437,16 @@ public class SetupSyncActivity extends AccountAuthenticatorActivity {
return false;
}
/**
* Displays layout for entering a PIN from another device.
* A Sync Account has already been set up.
*/
private void displayPairWithPin() {
Logger.debug(LOG_TAG, "PairWithPin initiated.");
runOnUiThread(new Runnable() {
@Override
public void run() {
setContentView(R.layout.sync_setup_pair);
connectButton = (Button) findViewById(R.id.pair_button_connect);
pinError = (LinearLayout) findViewById(R.id.pair_error);
@ -445,8 +472,8 @@ public class SetupSyncActivity extends AccountAuthenticatorActivity {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
});
row2.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
@ -464,6 +491,7 @@ public class SetupSyncActivity extends AccountAuthenticatorActivity {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
row3.addTextChangedListener(new TextWatcher() {
@ -482,9 +510,19 @@ public class SetupSyncActivity extends AccountAuthenticatorActivity {
}
});
}
});
}
/**
* Displays layout with PIN for pairing with another device.
* No Sync Account has been set up yet.
*/
private void displayReceiveNoPin() {
Logger.debug(LOG_TAG, "ReceiveNoPin initiated");
runOnUiThread(new Runnable(){
@Override
public void run() {
setContentView(R.layout.sync_setup);
// Set up UI.
@ -506,4 +544,6 @@ public class SetupSyncActivity extends AccountAuthenticatorActivity {
Logger.error(LOG_TAG, "No 'no device' link view.");
}
}
});
}
}