Skip to content
This repository has been archived by the owner on Oct 18, 2018. It is now read-only.

Commit

Permalink
Merge branch 'rnewman/bug-716798-authenticator' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
rnewman committed Jan 10, 2012
2 parents f532f53 + f4b4f0b commit cce053f
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 66 deletions.
2 changes: 1 addition & 1 deletion res/xml/sync_authenticator.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="org.mozilla.firefox.sync"
android:accountType="org.mozilla.firefox_sync"
android:icon="@drawable/sync_icon"
android:smallIcon="@drawable/sync_icon"
android:label="@string/sync_account_label" />
2 changes: 1 addition & 1 deletion src/main/java/org/mozilla/gecko/sync/setup/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

public class Constants {
// Constants for Firefox Sync SyncAdapter Accounts
public static final String ACCOUNTTYPE_SYNC = "org.mozilla.firefox.sync";
public static final String ACCOUNTTYPE_SYNC = "org.mozilla.firefox_sync";
public static final String OPTION_SYNCKEY = "option.synckey";
public static final String OPTION_USERNAME = "option.username";
public static final String AUTHTOKEN_TYPE_PLAIN = "auth.plain";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Chenxia Liu <liuche@mozilla.com>
* Chenxia Liu <liuche@mozilla.com>
* Richard Newman <rnewman@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
Expand Down Expand Up @@ -134,6 +135,7 @@ public Bundle getAuthToken(AccountAuthenticatorResponse response,

// Extract the username and password from the Account Manager, and ask
// the server for an appropriate AuthToken.
Log.d(LOG_TAG, "AccountManager.get(" + mContext + ")");
final AccountManager am = AccountManager.get(mContext);
final String password = am.getPassword(account);
if (password != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Chenxia Liu <liuche@mozilla.com>
* Chenxia Liu <liuche@mozilla.com>
* Richard Newman <rnewman@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
Expand Down Expand Up @@ -83,7 +84,8 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sync_account);
mContext = getApplicationContext();
mAccountManager = AccountManager.get(getApplicationContext());
Log.d(LOG_TAG, "AccountManager.get(" + mContext + ")");
mAccountManager = AccountManager.get(mContext);

// Find UI elements.
usernameInput = (EditText) findViewById(R.id.usernameInput);
Expand Down Expand Up @@ -195,6 +197,7 @@ private boolean validateInputs() {
private void authCallback() {
// Create and add account to AccountManager
// TODO: only allow one account to be added?
Log.d(LOG_TAG, "Using account manager " + mAccountManager);
final Intent intent = createAccount(mAccountManager, username, key,
password, server);
setAccountAuthenticatorResult(intent.getExtras());
Expand All @@ -219,6 +222,7 @@ public void run() {
// TODO: lift this out.
public static Intent createAccount(AccountManager accountManager,
String username, String syncKey, String password, String serverURL) {

final Account account = new Account(username, Constants.ACCOUNTTYPE_SYNC);
final Bundle userbundle = new Bundle();

Expand All @@ -230,6 +234,7 @@ public static Intent createAccount(AccountManager accountManager,
} else {
userbundle.putString(Constants.OPTION_SERVER, DEFAULT_SERVER);
}
Log.d(LOG_TAG, "Adding account for " + Constants.ACCOUNTTYPE_SYNC);
accountManager.addAccountExplicitly(account, password, userbundle);

Log.d(LOG_TAG, "Account: " + account.toString());
Expand All @@ -244,8 +249,7 @@ public static Intent createAccount(AccountManager accountManager,

final Intent intent = new Intent();
intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, username);
intent
.putExtra(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNTTYPE_SYNC);
intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNTTYPE_SYNC);
intent.putExtra(AccountManager.KEY_AUTHTOKEN, Constants.ACCOUNTTYPE_SYNC);
return intent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Set Activity variables.
mAccountManager = AccountManager.get(getApplicationContext());
mContext = getApplicationContext();
Log.d(LOG_TAG, "AccountManager.get(" + mContext + ")");
mAccountManager = AccountManager.get(mContext);

}

Expand All @@ -105,26 +106,27 @@ public void onResume() {
super.onResume();

// Check whether Sync accounts exist; if not, display J-PAKE PIN.
AccountManager mAccountManager = AccountManager.get(this);
Account[] accts = mAccountManager
.getAccountsByType(Constants.ACCOUNTTYPE_SYNC);
Account[] accts = mAccountManager.getAccountsByType(Constants.ACCOUNTTYPE_SYNC);

if (accts.length == 0) { // Start J-PAKE for pairing if no accounts present.
displayReceiveNoPin();
jClient = new JPakeClient(this);
jClient.receiveNoPin();
} else { // Set layout based on starting Intent.
Bundle extras = this.getIntent().getExtras();
if (extras != null) {
boolean isSetup = extras.getBoolean(Constants.INTENT_EXTRA_IS_SETUP);
if (!isSetup) {
pairWithPin = true;
displayPairWithPin();
return;
}
return;
}

// Set layout based on starting Intent.
Bundle extras = this.getIntent().getExtras();
if (extras != null) {
boolean isSetup = extras.getBoolean(Constants.INTENT_EXTRA_IS_SETUP);
if (!isSetup) {
pairWithPin = true;
displayPairWithPin();
return;
}
// Go to Settings screen for Sync management.
displayAccount(false);
}
// Go to Settings screen for Sync management.
displayAccount(false);
}

@Override
Expand Down Expand Up @@ -211,18 +213,20 @@ public void run() {
pinError.setVisibility(View.VISIBLE);
}
});
} else { // Start new JPakeClient for restarting J-PAKE.
Log.d(LOG_TAG, "abort reason: " + error);
if (!Constants.JPAKE_ERROR_USERABORT.equals(error)) {
jClient = new JPakeClient(this);
runOnUiThread(new Runnable() {
@Override
public void run() {
// Restart pairing process.
jClient.receiveNoPin();
}
});
}
return;
}

// Start new JPakeClient for restarting J-PAKE.
Log.d(LOG_TAG, "abort reason: " + error);
if (!Constants.JPAKE_ERROR_USERABORT.equals(error)) {
jClient = new JPakeClient(this);
runOnUiThread(new Runnable() {
@Override
public void run() {
// Restart pairing process.
jClient.receiveNoPin();
}
});
}
}

Expand All @@ -239,34 +243,37 @@ public void run() {
setContentView(R.layout.sync_setup_jpake_waiting);
}
});
} else { // Extract Sync account data.
AccountManager mAccountManager = AccountManager.get(this);
Account[] accts = mAccountManager
.getAccountsByType(Constants.ACCOUNTTYPE_SYNC);
if (accts.length > 0) {
Account account = accts[0]; // TODO: Single account supported. Create
// account selection if spec changes.
String synckey = mAccountManager.getUserData(account,
Constants.OPTION_SYNCKEY);
String password = mAccountManager.getPassword(account);
String serverUrl = mAccountManager.getUserData(account,
Constants.OPTION_SERVER);
String username = account.name;

JSONObject jAccount = new JSONObject();
jAccount.put(Constants.JSON_KEY_SYNCKEY, synckey);
jAccount.put(Constants.JSON_KEY_ACCOUNT, username);
jAccount.put(Constants.JSON_KEY_PASSWORD, password);
jAccount.put(Constants.JSON_KEY_SERVER, serverUrl);
Log.d(LOG_TAG, "extracted account data: " + jAccount.toJSONString());
try {
jClient.sendAndComplete(jAccount);
} catch (JPakeNoActivePairingException e) {
e.printStackTrace();
}
} else { // Error, no account present.
displayAbort(Constants.JPAKE_ERROR_INVALID);
}
return;
}

// Extract Sync account data.
Account[] accts = mAccountManager.getAccountsByType(Constants.ACCOUNTTYPE_SYNC);
if (accts.length == 0) {
// Error, no account present.
Log.e(LOG_TAG, "No accounts present.");
displayAbort(Constants.JPAKE_ERROR_INVALID);
return;
}

// TODO: Single account supported. Create account selection if spec changes.
Account account = accts[0];
String username = account.name;
String password = mAccountManager.getPassword(account);
String syncKey = mAccountManager.getUserData(account, Constants.OPTION_SYNCKEY);
String serverURL = mAccountManager.getUserData(account, Constants.OPTION_SERVER);

JSONObject jAccount = new JSONObject();
jAccount.put(Constants.JSON_KEY_SYNCKEY, syncKey);
jAccount.put(Constants.JSON_KEY_ACCOUNT, username);
jAccount.put(Constants.JSON_KEY_PASSWORD, password);
jAccount.put(Constants.JSON_KEY_SERVER, serverURL);

Log.d(LOG_TAG, "Extracted account data: " + jAccount.toJSONString());
try {
jClient.sendAndComplete(jAccount);
} catch (JPakeNoActivePairingException e) {
Log.e(LOG_TAG, "No active J-PAKE pairing.", e);
// TODO: some user-visible action!
}
}

Expand All @@ -293,13 +300,15 @@ public void onComplete(JSONObject jCreds) {
String syncKey = (String) jCreds.get(Constants.JSON_KEY_SYNCKEY);
String serverURL = (String) jCreds.get(Constants.JSON_KEY_SERVER);

Log.d(LOG_TAG, "Using account manager " + mAccountManager);
final Intent intent = AccountActivity.createAccount(mAccountManager,
accountName, syncKey, password, serverURL);
setAccountAuthenticatorResult(intent.getExtras());

setResult(RESULT_OK, intent);
}
jClient = null; // Sync is set up, kill reference to JPakeClient object.

jClient = null; // Sync is set up. Kill reference to JPakeClient object.
runOnUiThread(new Runnable() {
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Chenxia Liu <liuche@mozilla.com>
* Chenxia Liu <liuche@mozilla.com>
* Richard Newman <rnewman@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
Expand Down Expand Up @@ -87,6 +88,7 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter implements GlobalSe
public SyncAdapter(Context context, boolean autoInitialize) {
super(context, autoInitialize);
mContext = context;
Log.d(LOG_TAG, "AccountManager.get(" + mContext + ")");
mAccountManager = AccountManager.get(context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public String ifUnmodifiedSince() {
@Override
public void handleRequestSuccess(SyncStorageResponse response) {
System.out.println("WBOs: " + this.wbos.size());
assertEquals(wbos.size(), 13);
assertEquals(13, wbos.size());
for (CryptoRecord record : this.wbos) {
try {
// TODO: make this an actual test. Return data locally.
Expand Down
2 changes: 1 addition & 1 deletion sync_syncadapter.xml.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?xml version="1.0" encoding="utf-8"?>
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:contentAuthority="@ANDROID_PACKAGE_NAME@.db.browser"
android:accountType="org.mozilla.firefox.sync"
android:accountType="org.mozilla.firefox_sync"
android:supportsUploading="true"
android:userVisible="true"
/>

0 comments on commit cce053f

Please sign in to comment.