Obeying Settings.EXTRA_AUTHORITIES extra for SYNC_SETTINGS
Bug: 17188306 Change-Id: I00481c6c4f346b6f4037554296735f4323cbbcfb
This commit is contained in:
@@ -17,15 +17,10 @@
|
|||||||
|
|
||||||
package com.android.settings.accounts;
|
package com.android.settings.accounts;
|
||||||
|
|
||||||
import com.google.android.collect.Maps;
|
|
||||||
|
|
||||||
import android.accounts.AuthenticatorDescription;
|
import android.accounts.AuthenticatorDescription;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.ActivityManagerNative;
|
|
||||||
import android.app.IActivityManager;
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SyncAdapterType;
|
|
||||||
import android.content.SyncStatusObserver;
|
import android.content.SyncStatusObserver;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
@@ -45,7 +40,6 @@ import com.android.settings.Utils;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
class AccountPreferenceBase extends SettingsPreferenceFragment
|
class AccountPreferenceBase extends SettingsPreferenceFragment
|
||||||
implements AuthenticatorHelper.OnAccountsUpdateListener {
|
implements AuthenticatorHelper.OnAccountsUpdateListener {
|
||||||
@@ -59,7 +53,6 @@ class AccountPreferenceBase extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
private UserManager mUm;
|
private UserManager mUm;
|
||||||
private Object mStatusChangeListenerHandle;
|
private Object mStatusChangeListenerHandle;
|
||||||
private HashMap<String, ArrayList<String>> mAccountTypeToAuthorities = null;
|
|
||||||
protected AuthenticatorHelper mAuthenticatorHelper;
|
protected AuthenticatorHelper mAuthenticatorHelper;
|
||||||
protected UserHandle mUserHandle;
|
protected UserHandle mUserHandle;
|
||||||
|
|
||||||
@@ -136,25 +129,7 @@ class AccountPreferenceBase extends SettingsPreferenceFragment
|
|||||||
};
|
};
|
||||||
|
|
||||||
public ArrayList<String> getAuthoritiesForAccountType(String type) {
|
public ArrayList<String> getAuthoritiesForAccountType(String type) {
|
||||||
if (mAccountTypeToAuthorities == null) {
|
return mAuthenticatorHelper.getAuthoritiesForAccountType(type);
|
||||||
mAccountTypeToAuthorities = Maps.newHashMap();
|
|
||||||
SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypesAsUser(
|
|
||||||
mUserHandle.getIdentifier());
|
|
||||||
for (int i = 0, n = syncAdapters.length; i < n; i++) {
|
|
||||||
final SyncAdapterType sa = syncAdapters[i];
|
|
||||||
ArrayList<String> authorities = mAccountTypeToAuthorities.get(sa.accountType);
|
|
||||||
if (authorities == null) {
|
|
||||||
authorities = new ArrayList<String>();
|
|
||||||
mAccountTypeToAuthorities.put(sa.accountType, authorities);
|
|
||||||
}
|
|
||||||
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
|
||||||
Log.d(TAG, "added authority " + sa.authority + " to accountType "
|
|
||||||
+ sa.accountType);
|
|
||||||
}
|
|
||||||
authorities.add(sa.authority);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return mAccountTypeToAuthorities.get(type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -57,6 +57,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import static android.content.Intent.EXTRA_USER;
|
import static android.content.Intent.EXTRA_USER;
|
||||||
import static android.os.UserManager.DISALLOW_MODIFY_ACCOUNTS;
|
import static android.os.UserManager.DISALLOW_MODIFY_ACCOUNTS;
|
||||||
|
import static android.provider.Settings.EXTRA_AUTHORITIES;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Settings screen for the account types on the device.
|
* Settings screen for the account types on the device.
|
||||||
@@ -83,6 +84,8 @@ public class AccountSettings extends SettingsPreferenceFragment
|
|||||||
private ManagedProfileBroadcastReceiver mManagedProfileBroadcastReceiver
|
private ManagedProfileBroadcastReceiver mManagedProfileBroadcastReceiver
|
||||||
= new ManagedProfileBroadcastReceiver();
|
= new ManagedProfileBroadcastReceiver();
|
||||||
private Preference mProfileNotAvailablePreference;
|
private Preference mProfileNotAvailablePreference;
|
||||||
|
private String[] mAuthorities;
|
||||||
|
private int mAuthoritiesCount = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds data related to the accounts belonging to one profile.
|
* Holds data related to the accounts belonging to one profile.
|
||||||
@@ -114,7 +117,10 @@ public class AccountSettings extends SettingsPreferenceFragment
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
mUm = (UserManager) getSystemService(Context.USER_SERVICE);
|
mUm = (UserManager) getSystemService(Context.USER_SERVICE);
|
||||||
mProfileNotAvailablePreference = new Preference(getActivity());
|
mAuthorities = getActivity().getIntent().getStringArrayExtra(EXTRA_AUTHORITIES);
|
||||||
|
if (mAuthorities != null) {
|
||||||
|
mAuthoritiesCount = mAuthorities.length;
|
||||||
|
}
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,6 +196,7 @@ public class AccountSettings extends SettingsPreferenceFragment
|
|||||||
if (preference == profileData.addAccountPreference) {
|
if (preference == profileData.addAccountPreference) {
|
||||||
Intent intent = new Intent(ADD_ACCOUNT_ACTION);
|
Intent intent = new Intent(ADD_ACCOUNT_ACTION);
|
||||||
intent.putExtra(EXTRA_USER, profileData.userInfo.getUserHandle());
|
intent.putExtra(EXTRA_USER, profileData.userInfo.getUserHandle());
|
||||||
|
intent.putExtra(EXTRA_AUTHORITIES, mAuthorities);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -353,6 +360,21 @@ public class AccountSettings extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
for (int i = 0; i < accountTypes.length; i++) {
|
for (int i = 0; i < accountTypes.length; i++) {
|
||||||
final String accountType = accountTypes[i];
|
final String accountType = accountTypes[i];
|
||||||
|
if (mAuthoritiesCount > 0) {
|
||||||
|
// Skip showing any account that does not have any of the requested authorities
|
||||||
|
final ArrayList<String> authoritiesForType = helper.getAuthoritiesForAccountType(
|
||||||
|
accountType);
|
||||||
|
boolean show = false;
|
||||||
|
for (int j = 0; j < mAuthoritiesCount; j++) {
|
||||||
|
if (authoritiesForType.contains(mAuthorities[j])) {
|
||||||
|
show = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!show) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
final CharSequence label = helper.getLabelForType(getActivity(), accountType);
|
final CharSequence label = helper.getLabelForType(getActivity(), accountType);
|
||||||
if (label == null) {
|
if (label == null) {
|
||||||
continue;
|
continue;
|
||||||
|
@@ -16,13 +16,17 @@
|
|||||||
|
|
||||||
package com.android.settings.accounts;
|
package com.android.settings.accounts;
|
||||||
|
|
||||||
|
import com.google.android.collect.Maps;
|
||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
import android.accounts.AccountManager;
|
import android.accounts.AccountManager;
|
||||||
import android.accounts.AuthenticatorDescription;
|
import android.accounts.AuthenticatorDescription;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.content.SyncAdapterType;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
@@ -52,6 +56,7 @@ final public class AuthenticatorHelper extends BroadcastReceiver {
|
|||||||
private AuthenticatorDescription[] mAuthDescs;
|
private AuthenticatorDescription[] mAuthDescs;
|
||||||
private ArrayList<String> mEnabledAccountTypes = new ArrayList<String>();
|
private ArrayList<String> mEnabledAccountTypes = new ArrayList<String>();
|
||||||
private Map<String, Drawable> mAccTypeIconCache = new HashMap<String, Drawable>();
|
private Map<String, Drawable> mAccTypeIconCache = new HashMap<String, Drawable>();
|
||||||
|
private HashMap<String, ArrayList<String>> mAccountTypeToAuthorities = Maps.newHashMap();
|
||||||
|
|
||||||
private final UserHandle mUserHandle;
|
private final UserHandle mUserHandle;
|
||||||
private final UserManager mUm;
|
private final UserManager mUm;
|
||||||
@@ -69,7 +74,8 @@ final public class AuthenticatorHelper extends BroadcastReceiver {
|
|||||||
mUm = userManager;
|
mUm = userManager;
|
||||||
mUserHandle = userHandle;
|
mUserHandle = userHandle;
|
||||||
mListener = listener;
|
mListener = listener;
|
||||||
// This guarantees that the helper is ready to use once constructed
|
// This guarantees that the helper is ready to use once constructed: the account types and
|
||||||
|
// authorities are initialized
|
||||||
onAccountsUpdated(null);
|
onAccountsUpdated(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,6 +193,7 @@ final public class AuthenticatorHelper extends BroadcastReceiver {
|
|||||||
if (mListeningToAccountUpdates) {
|
if (mListeningToAccountUpdates) {
|
||||||
mListener.onAccountsUpdate(mUserHandle);
|
mListener.onAccountsUpdate(mUserHandle);
|
||||||
}
|
}
|
||||||
|
buildAccountTypeToAuthoritiesMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -215,4 +222,27 @@ final public class AuthenticatorHelper extends BroadcastReceiver {
|
|||||||
mListeningToAccountUpdates = false;
|
mListeningToAccountUpdates = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getAuthoritiesForAccountType(String type) {
|
||||||
|
return mAccountTypeToAuthorities.get(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildAccountTypeToAuthoritiesMap() {
|
||||||
|
mAccountTypeToAuthorities.clear();
|
||||||
|
SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypesAsUser(
|
||||||
|
mUserHandle.getIdentifier());
|
||||||
|
for (int i = 0, n = syncAdapters.length; i < n; i++) {
|
||||||
|
final SyncAdapterType sa = syncAdapters[i];
|
||||||
|
ArrayList<String> authorities = mAccountTypeToAuthorities.get(sa.accountType);
|
||||||
|
if (authorities == null) {
|
||||||
|
authorities = new ArrayList<String>();
|
||||||
|
mAccountTypeToAuthorities.put(sa.accountType, authorities);
|
||||||
|
}
|
||||||
|
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
||||||
|
Log.d(TAG, "Added authority " + sa.authority + " to accountType "
|
||||||
|
+ sa.accountType);
|
||||||
|
}
|
||||||
|
authorities.add(sa.authority);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user