Only show AccountSyncSettings when we have an account
Also removes useless list of accounts Bug: 16295803 Change-Id: Ida3c1846327874af9f97695a485b12ec689fd343
This commit is contained in:
@@ -17,7 +17,6 @@
|
|||||||
package com.android.settings.accounts;
|
package com.android.settings.accounts;
|
||||||
|
|
||||||
import com.google.android.collect.Lists;
|
import com.google.android.collect.Lists;
|
||||||
import com.google.android.collect.Maps;
|
|
||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
import android.accounts.AccountManager;
|
import android.accounts.AccountManager;
|
||||||
@@ -59,7 +58,6 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AccountSyncSettings extends AccountPreferenceBase {
|
public class AccountSyncSettings extends AccountPreferenceBase {
|
||||||
@@ -76,9 +74,6 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
private ImageView mProviderIcon;
|
private ImageView mProviderIcon;
|
||||||
private TextView mErrorInfoView;
|
private TextView mErrorInfoView;
|
||||||
private Account mAccount;
|
private Account mAccount;
|
||||||
// List of all accounts, updated when accounts are added/removed
|
|
||||||
// We need to re-scan the accounts on sync events, in case sync state changes.
|
|
||||||
private Account[] mAccounts;
|
|
||||||
private ArrayList<SyncStateCheckBoxPreference> mCheckBoxes =
|
private ArrayList<SyncStateCheckBoxPreference> mCheckBoxes =
|
||||||
new ArrayList<SyncStateCheckBoxPreference>();
|
new ArrayList<SyncStateCheckBoxPreference>();
|
||||||
private ArrayList<SyncAdapterType> mInvisibleAdapters = Lists.newArrayList();
|
private ArrayList<SyncAdapterType> mInvisibleAdapters = Lists.newArrayList();
|
||||||
@@ -185,12 +180,17 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mAccount = (Account) arguments.getParcelable(ACCOUNT_KEY);
|
mAccount = (Account) arguments.getParcelable(ACCOUNT_KEY);
|
||||||
if (mAccount != null) {
|
if (!accountExists(mAccount)) {
|
||||||
if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "Got account: " + mAccount);
|
Log.e(TAG, "Account provided does not exist: " + mAccount);
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
||||||
|
Log.v(TAG, "Got account: " + mAccount);
|
||||||
|
}
|
||||||
mUserId.setText(mAccount.name);
|
mUserId.setText(mAccount.name);
|
||||||
mProviderId.setText(mAccount.type);
|
mProviderId.setText(mAccount.type);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
@@ -336,13 +336,10 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
// plus whatever the system needs to sync, e.g., invisible sync adapters
|
// plus whatever the system needs to sync, e.g., invisible sync adapters
|
||||||
if (mAccount != null) {
|
if (mAccount != null) {
|
||||||
for (SyncAdapterType syncAdapter : mInvisibleAdapters) {
|
for (SyncAdapterType syncAdapter : mInvisibleAdapters) {
|
||||||
// invisible sync adapters' account type should be same as current account type
|
|
||||||
if (syncAdapter.accountType.equals(mAccount.type)) {
|
|
||||||
requestOrCancelSync(mAccount, syncAdapter.authority, startSync);
|
requestOrCancelSync(mAccount, syncAdapter.authority, startSync);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void requestOrCancelSync(Account account, String authority, boolean flag) {
|
private void requestOrCancelSync(Account account, String authority, boolean flag) {
|
||||||
if (flag) {
|
if (flag) {
|
||||||
@@ -378,7 +375,7 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
boolean syncIsFailing = false;
|
boolean syncIsFailing = false;
|
||||||
|
|
||||||
// Refresh the sync status checkboxes - some syncs may have become active.
|
// Refresh the sync status checkboxes - some syncs may have become active.
|
||||||
updateAccountCheckboxes(mAccounts);
|
updateAccountCheckboxes();
|
||||||
|
|
||||||
for (int i = 0, count = getPreferenceScreen().getPreferenceCount(); i < count; i++) {
|
for (int i = 0, count = getPreferenceScreen().getPreferenceCount(); i < count; i++) {
|
||||||
Preference pref = getPreferenceScreen().getPreference(i);
|
Preference pref = getPreferenceScreen().getPreference(i);
|
||||||
@@ -446,29 +443,42 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
@Override
|
@Override
|
||||||
public void onAccountsUpdate(final UserHandle userHandle) {
|
public void onAccountsUpdate(final UserHandle userHandle) {
|
||||||
super.onAccountsUpdate(userHandle);
|
super.onAccountsUpdate(userHandle);
|
||||||
mAccounts = AccountManager.get(getActivity()).getAccountsAsUser(
|
if (!accountExists(mAccount)) {
|
||||||
mUserHandle.getIdentifier());
|
// The account was deleted
|
||||||
updateAccountCheckboxes(mAccounts);
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
updateAccountCheckboxes();
|
||||||
onSyncStateUpdated();
|
onSyncStateUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateAccountCheckboxes(Account[] accounts) {
|
private boolean accountExists(Account account) {
|
||||||
|
if (account == null) return false;
|
||||||
|
|
||||||
|
Account[] accounts = AccountManager.get(getActivity()).getAccountsByTypeAsUser(
|
||||||
|
account.type, mUserHandle);
|
||||||
|
final int count = accounts.length;
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
if (accounts[i].equals(account)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateAccountCheckboxes() {
|
||||||
mInvisibleAdapters.clear();
|
mInvisibleAdapters.clear();
|
||||||
|
|
||||||
SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypesAsUser(
|
SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypesAsUser(
|
||||||
mUserHandle.getIdentifier());
|
mUserHandle.getIdentifier());
|
||||||
HashMap<String, ArrayList<String>> accountTypeToAuthorities =
|
ArrayList<String> authorities = new ArrayList<String>();
|
||||||
Maps.newHashMap();
|
|
||||||
for (int i = 0, n = syncAdapters.length; i < n; i++) {
|
for (int i = 0, n = syncAdapters.length; i < n; i++) {
|
||||||
final SyncAdapterType sa = syncAdapters[i];
|
final SyncAdapterType sa = syncAdapters[i];
|
||||||
|
// Only keep track of sync adapters for this account
|
||||||
|
if (!sa.accountType.equals(mAccount.type)) continue;
|
||||||
if (sa.isUserVisible()) {
|
if (sa.isUserVisible()) {
|
||||||
ArrayList<String> authorities = accountTypeToAuthorities.get(sa.accountType);
|
|
||||||
if (authorities == null) {
|
|
||||||
authorities = new ArrayList<String>();
|
|
||||||
accountTypeToAuthorities.put(sa.accountType, authorities);
|
|
||||||
}
|
|
||||||
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
||||||
Log.d(TAG, "onAccountUpdated: added authority " + sa.authority
|
Log.d(TAG, "updateAccountCheckboxes: added authority " + sa.authority
|
||||||
+ " to accountType " + sa.accountType);
|
+ " to accountType " + sa.accountType);
|
||||||
}
|
}
|
||||||
authorities.add(sa.authority);
|
authorities.add(sa.authority);
|
||||||
@@ -484,25 +494,19 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
}
|
}
|
||||||
mCheckBoxes.clear();
|
mCheckBoxes.clear();
|
||||||
|
|
||||||
for (int i = 0, n = accounts.length; i < n; i++) {
|
|
||||||
final Account account = accounts[i];
|
|
||||||
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
||||||
Log.d(TAG, "looking for sync adapters that match account " + account);
|
Log.d(TAG, "looking for sync adapters that match account " + mAccount);
|
||||||
}
|
}
|
||||||
final ArrayList<String> authorities = accountTypeToAuthorities.get(account.type);
|
|
||||||
if (authorities != null && (mAccount == null || mAccount.equals(account))) {
|
|
||||||
for (int j = 0, m = authorities.size(); j < m; j++) {
|
for (int j = 0, m = authorities.size(); j < m; j++) {
|
||||||
final String authority = authorities.get(j);
|
final String authority = authorities.get(j);
|
||||||
// We could check services here....
|
// We could check services here....
|
||||||
int syncState = ContentResolver.getIsSyncableAsUser(account, authority,
|
int syncState = ContentResolver.getIsSyncableAsUser(mAccount, authority,
|
||||||
mUserHandle.getIdentifier());
|
mUserHandle.getIdentifier());
|
||||||
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
||||||
Log.d(TAG, " found authority " + authority + " " + syncState);
|
Log.d(TAG, " found authority " + authority + " " + syncState);
|
||||||
}
|
}
|
||||||
if (syncState > 0) {
|
if (syncState > 0) {
|
||||||
addSyncStateCheckBox(account, authority);
|
addSyncStateCheckBox(mAccount, authority);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user