diff options
author | Ben Murdoch <benm@google.com> | 2010-11-24 15:34:59 +0000 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2010-11-24 17:00:11 +0000 |
commit | f801fe2516298e08286cc161d7eb143635db205a (patch) | |
tree | 3ad1523cb2809de0b82250a17c4e90a94fbb509e /src | |
parent | bce31f3802958534e0aa31b8cee5a88dc8aa6df4 (diff) | |
download | packages_apps_Browser-f801fe2516298e08286cc161d7eb143635db205a.zip packages_apps_Browser-f801fe2516298e08286cc161d7eb143635db205a.tar.gz packages_apps_Browser-f801fe2516298e08286cc161d7eb143635db205a.tar.bz2 |
Fix StrictMode violation in PersonalPreferencesFragment
Reading account data with getAccountsByType() results in disk
IO and so is a strict mode violation. Move reading the
account data into an AsyncTask.
Change-Id: I258e35448190c8c66724438fcd24bc2a98794309
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/browser/preferences/PersonalPreferencesFragment.java | 60 |
1 files changed, 38 insertions, 22 deletions
diff --git a/src/com/android/browser/preferences/PersonalPreferencesFragment.java b/src/com/android/browser/preferences/PersonalPreferencesFragment.java index 656d47a..a0c8ea0 100644 --- a/src/com/android/browser/preferences/PersonalPreferencesFragment.java +++ b/src/com/android/browser/preferences/PersonalPreferencesFragment.java @@ -34,6 +34,7 @@ import android.content.DialogInterface; import android.content.OperationApplicationException; import android.content.SharedPreferences; import android.database.Cursor; +import android.os.AsyncTask; import android.os.Bundle; import android.os.RemoteException; import android.preference.Preference; @@ -80,31 +81,46 @@ public class PersonalPreferencesFragment extends PreferenceFragment refreshUi(context); } - void refreshUi(Context context) { - AccountManager am = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE); - Account[] accounts = am.getAccountsByType("com.google"); - if (accounts == null || accounts.length == 0) { - // No Google accounts setup, don't offer Chrome sync - if (mChromeSync != null) { - getPreferenceScreen().removePreference(mChromeSync); - } - } else { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - Bundle args = mChromeSync.getExtras(); - args.putParcelableArray("accounts", accounts); - mEnabled = BrowserContract.Settings.isSyncEnabled(context); - if (!mEnabled) { - // Google accounts are present, but Chrome sync isn't enabled yet. - // Setup a link to the enable wizard - mChromeSync.setSummary(R.string.pref_personal_sync_with_chrome_summary); + private class GetAccountsTask extends AsyncTask<Void, Void, Void> { + private Context mContext; + + GetAccountsTask(Context ctx) { + mContext = ctx; + } + + protected Void doInBackground(Void... unused) { + AccountManager am = (AccountManager) mContext.getSystemService(Context.ACCOUNT_SERVICE); + Account[] accounts = am.getAccountsByType("com.google"); + if (accounts == null || accounts.length == 0) { + // No Google accounts setup, don't offer Chrome sync + if (mChromeSync != null) { + getPreferenceScreen().removePreference(mChromeSync); + } } else { - // Chrome sync is enabled, setup a link to account switcher - String accountName = prefs.getString(BrowserBookmarksPage.PREF_ACCOUNT_NAME, null); - mChromeSync.setSummary(accountName); - args.putString("curAccount", accountName); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext); + Bundle args = mChromeSync.getExtras(); + args.putParcelableArray("accounts", accounts); + mEnabled = BrowserContract.Settings.isSyncEnabled(mContext); + if (!mEnabled) { + // Google accounts are present, but Chrome sync isn't enabled yet. + // Setup a link to the enable wizard + mChromeSync.setSummary(R.string.pref_personal_sync_with_chrome_summary); + } else { + // Chrome sync is enabled, setup a link to account switcher + String accountName = prefs.getString(BrowserBookmarksPage.PREF_ACCOUNT_NAME, + null); + mChromeSync.setSummary(accountName); + args.putString("curAccount", accountName); + } + mChromeSync.setOnPreferenceClickListener(PersonalPreferencesFragment.this); } - mChromeSync.setOnPreferenceClickListener(this); + + return null; } + } + + void refreshUi(Context context) { + new GetAccountsTask(context).execute(); PreferenceScreen autoFillSettings = (PreferenceScreen)findPreference(BrowserSettings.PREF_AUTOFILL_PROFILE); |