Removed AccountSettings used in old IA only.
- remove AccountSettings and all related code that is used in old IA, so that it will not show up in search. Change-Id: I9f83112f760fd991caf89de109fde9e675b8c981 Fix: 34165913 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -2254,26 +2254,6 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name="Settings$AccountSettingsActivity"
|
|
||||||
android:label="@string/account_settings_title"
|
|
||||||
android:icon="@drawable/ic_settings_accounts"
|
|
||||||
android:taskAffinity=""
|
|
||||||
android:parentActivityName="Settings">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.MAIN" />
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
</intent-filter>
|
|
||||||
<intent-filter android:priority="1">
|
|
||||||
<action android:name="com.android.settings.action.SETTINGS" />
|
|
||||||
</intent-filter>
|
|
||||||
<meta-data android:name="com.android.settings.category"
|
|
||||||
android:value="com.android.settings.category.personal" />
|
|
||||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
|
||||||
android:value="com.android.settings.accounts.AccountSettings" />
|
|
||||||
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
|
|
||||||
android:value="true" />
|
|
||||||
</activity>
|
|
||||||
|
|
||||||
<activity android:name="Settings$AccountSyncSettingsActivity"
|
<activity android:name="Settings$AccountSyncSettingsActivity"
|
||||||
android:label="@string/account_sync_settings_title"
|
android:label="@string/account_sync_settings_title"
|
||||||
android:taskAffinity=""
|
android:taskAffinity=""
|
||||||
@@ -2309,7 +2289,7 @@
|
|||||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||||
android:label="@string/header_add_an_account"
|
android:label="@string/header_add_an_account"
|
||||||
android:taskAffinity="com.android.settings"
|
android:taskAffinity="com.android.settings"
|
||||||
android:parentActivityName="Settings$ManageAccountsSettingsActivity">
|
android:parentActivityName="Settings$UserAndAccountDashboardActivity">
|
||||||
<intent-filter android:priority="1">
|
<intent-filter android:priority="1">
|
||||||
<action android:name="android.settings.ADD_ACCOUNT_SETTINGS" />
|
<action android:name="android.settings.ADD_ACCOUNT_SETTINGS" />
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
@@ -3146,6 +3126,8 @@
|
|||||||
android:value="com.android.settings.accounts.UserAndAccountDashboardFragment"/>
|
android:value="com.android.settings.accounts.UserAndAccountDashboardFragment"/>
|
||||||
<meta-data android:name="com.android.settings.category"
|
<meta-data android:name="com.android.settings.category"
|
||||||
android:value="com.android.settings.category.ia.homepage"/>
|
android:value="com.android.settings.category.ia.homepage"/>
|
||||||
|
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
|
||||||
|
android:value="true" />
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity-alias android:name="AccessibilityDashboardAlias"
|
<activity-alias android:name="AccessibilityDashboardAlias"
|
||||||
|
@@ -1,22 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- Copyright (C) 2014 The Android Open Source Project
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
|
|
||||||
android:key="account"
|
|
||||||
android:title="@string/account_settings_title"
|
|
||||||
settings:keywords="@string/keywords_accounts">
|
|
||||||
</PreferenceScreen>
|
|
@@ -1,19 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- Copyright (C) 2008 The Android Open Source Project
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<PreferenceCategory android:title="@string/account_settings" />
|
|
||||||
</PreferenceScreen>
|
|
@@ -83,11 +83,9 @@ public class Settings extends SettingsActivity {
|
|||||||
public static class PrivacySettingsActivity extends SettingsActivity { /* empty */ }
|
public static class PrivacySettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class FactoryResetActivity extends SettingsActivity { /* empty */ }
|
public static class FactoryResetActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class RunningServicesActivity extends SettingsActivity { /* empty */ }
|
public static class RunningServicesActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class ManageAccountsSettingsActivity extends SettingsActivity { /* empty */ }
|
|
||||||
public static class PowerUsageSummaryActivity extends SettingsActivity { /* empty */ }
|
public static class PowerUsageSummaryActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class BatterySaverSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class BatterySaverSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class AccountSyncSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class AccountSyncSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class AccountSettingsActivity extends SettingsActivity { /* empty */ }
|
|
||||||
public static class AccountSyncSettingsInAddAccountActivity extends SettingsActivity { /* empty */ }
|
public static class AccountSyncSettingsInAddAccountActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class GestureSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class GestureSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class CryptKeeperSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class CryptKeeperSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
|
@@ -46,7 +46,7 @@ import java.util.Date;
|
|||||||
abstract class AccountPreferenceBase extends SettingsPreferenceFragment
|
abstract class AccountPreferenceBase extends SettingsPreferenceFragment
|
||||||
implements AuthenticatorHelper.OnAccountsUpdateListener {
|
implements AuthenticatorHelper.OnAccountsUpdateListener {
|
||||||
|
|
||||||
protected static final String TAG = "AccountSettings";
|
protected static final String TAG = "AccountPreferenceBase";
|
||||||
protected static final boolean VERBOSE = Log.isLoggable(TAG, Log.VERBOSE);
|
protected static final boolean VERBOSE = Log.isLoggable(TAG, Log.VERBOSE);
|
||||||
|
|
||||||
public static final String AUTHORITIES_FILTER_KEY = "authorities";
|
public static final String AUTHORITIES_FILTER_KEY = "authorities";
|
||||||
|
@@ -30,7 +30,6 @@ import android.graphics.drawable.Drawable;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.support.v14.preference.PreferenceFragment;
|
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.Preference.OnPreferenceClickListener;
|
import android.support.v7.preference.Preference.OnPreferenceClickListener;
|
||||||
import android.support.v7.preference.PreferenceGroup;
|
import android.support.v7.preference.PreferenceGroup;
|
||||||
@@ -43,6 +42,7 @@ import com.android.settings.AccessiblePreferenceCategory;
|
|||||||
import com.android.settings.DimmableIconPreference;
|
import com.android.settings.DimmableIconPreference;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.core.PreferenceController;
|
import com.android.settings.core.PreferenceController;
|
||||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||||
@@ -53,6 +53,7 @@ import com.android.settings.dashboard.DashboardFeatureProvider;
|
|||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.search.Index;
|
import com.android.settings.search.Index;
|
||||||
import com.android.settings.search.SearchIndexableRaw;
|
import com.android.settings.search.SearchIndexableRaw;
|
||||||
|
import com.android.settings.search2.SearchFeatureProviderImpl;
|
||||||
import com.android.settingslib.RestrictedPreference;
|
import com.android.settingslib.RestrictedPreference;
|
||||||
import com.android.settingslib.accounts.AuthenticatorHelper;
|
import com.android.settingslib.accounts.AuthenticatorHelper;
|
||||||
|
|
||||||
@@ -85,8 +86,7 @@ public class AccountPreferenceController extends PreferenceController
|
|||||||
private Preference mProfileNotAvailablePreference;
|
private Preference mProfileNotAvailablePreference;
|
||||||
private String[] mAuthorities;
|
private String[] mAuthorities;
|
||||||
private int mAuthoritiesCount = 0;
|
private int mAuthoritiesCount = 0;
|
||||||
private PreferenceFragment mParent;
|
private SettingsPreferenceFragment mParent;
|
||||||
private boolean mIAEnabled;
|
|
||||||
private int mAccountProfileOrder = ORDER_ACCOUNT_PROFILES;
|
private int mAccountProfileOrder = ORDER_ACCOUNT_PROFILES;
|
||||||
private AccountRestrictionHelper mHelper;
|
private AccountRestrictionHelper mHelper;
|
||||||
private DashboardFeatureProvider mDashboardFeatureProvider;
|
private DashboardFeatureProvider mDashboardFeatureProvider;
|
||||||
@@ -122,13 +122,13 @@ public class AccountPreferenceController extends PreferenceController
|
|||||||
public UserInfo userInfo;
|
public UserInfo userInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccountPreferenceController(Context context, PreferenceFragment parent,
|
public AccountPreferenceController(Context context, SettingsPreferenceFragment parent,
|
||||||
String[] authorities) {
|
String[] authorities) {
|
||||||
this(context, parent, authorities, new AccountRestrictionHelper(context));
|
this(context, parent, authorities, new AccountRestrictionHelper(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
AccountPreferenceController(Context context, PreferenceFragment parent,
|
AccountPreferenceController(Context context, SettingsPreferenceFragment parent,
|
||||||
String[] authorities, AccountRestrictionHelper helper) {
|
String[] authorities, AccountRestrictionHelper helper) {
|
||||||
super(context);
|
super(context);
|
||||||
mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||||
@@ -140,7 +140,6 @@ public class AccountPreferenceController extends PreferenceController
|
|||||||
final FeatureFactory featureFactory = FeatureFactory.getFactory(mContext);
|
final FeatureFactory featureFactory = FeatureFactory.getFactory(mContext);
|
||||||
mDashboardFeatureProvider = featureFactory.getDashboardFeatureProvider(mContext);
|
mDashboardFeatureProvider = featureFactory.getDashboardFeatureProvider(mContext);
|
||||||
mMetricsFeatureProvider = featureFactory.getMetricsFeatureProvider();
|
mMetricsFeatureProvider = featureFactory.getMetricsFeatureProvider();
|
||||||
mIAEnabled = mDashboardFeatureProvider.isEnabled();
|
|
||||||
mHelper = helper;
|
mHelper = helper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,17 +254,9 @@ public class AccountPreferenceController extends PreferenceController
|
|||||||
if (!isAvailable()) {
|
if (!isAvailable()) {
|
||||||
// This should not happen
|
// This should not happen
|
||||||
Log.e(TAG, "We should not be showing settings for a managed profile");
|
Log.e(TAG, "We should not be showing settings for a managed profile");
|
||||||
if (!mIAEnabled) {
|
|
||||||
((AccountSettings) mParent).finish();
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mIAEnabled) {
|
|
||||||
// Load the preferences from an XML resource
|
|
||||||
mParent.addPreferencesFromResource(R.xml.account_settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mUm.isLinkedUser()) {
|
if (mUm.isLinkedUser()) {
|
||||||
// Restricted user or similar
|
// Restricted user or similar
|
||||||
UserInfo userInfo = mUm.getUserInfo(UserHandle.myUserId());
|
UserInfo userInfo = mUm.getUserInfo(UserHandle.myUserId());
|
||||||
@@ -330,8 +321,8 @@ public class AccountPreferenceController extends PreferenceController
|
|||||||
DISALLOW_MODIFY_ACCOUNTS, userInfo.id);
|
DISALLOW_MODIFY_ACCOUNTS, userInfo.id);
|
||||||
}
|
}
|
||||||
mProfiles.put(userInfo.id, profileData);
|
mProfiles.put(userInfo.id, profileData);
|
||||||
Index.getInstance(mContext).updateFromClassNameResource(
|
new SearchFeatureProviderImpl().getIndexingManager(mContext).updateFromClassNameResource(
|
||||||
AccountSettings.class.getName(), true, true);
|
UserAndAccountDashboardFragment.class.getName(), true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DimmableIconPreference newAddAccountPreference(Context context) {
|
private DimmableIconPreference newAddAccountPreference(Context context) {
|
||||||
@@ -471,7 +462,6 @@ public class AccountPreferenceController extends PreferenceController
|
|||||||
final Drawable icon = helper.getDrawableForType(mContext, accountType);
|
final Drawable icon = helper.getDrawableForType(mContext, accountType);
|
||||||
final Context prefContext = mParent.getPreferenceManager().getContext();
|
final Context prefContext = mParent.getPreferenceManager().getContext();
|
||||||
|
|
||||||
if (mIAEnabled) {
|
|
||||||
// Add a preference row for each individual account
|
// Add a preference row for each individual account
|
||||||
for (Account account : accounts) {
|
for (Account account : accounts) {
|
||||||
final ArrayList<String> auths =
|
final ArrayList<String> auths =
|
||||||
@@ -496,38 +486,13 @@ public class AccountPreferenceController extends PreferenceController
|
|||||||
account.name, titleResPackageName, titleResId, label,
|
account.name, titleResPackageName, titleResId, label,
|
||||||
AccountDetailDashboardFragment.class.getName(), fragmentArguments, icon));
|
AccountDetailDashboardFragment.class.getName(), fragmentArguments, icon));
|
||||||
}
|
}
|
||||||
} else if (skipToAccount) {
|
|
||||||
final Bundle fragmentArguments = new Bundle();
|
|
||||||
fragmentArguments.putParcelable(AccountSyncSettings.ACCOUNT_KEY,
|
|
||||||
accounts[0]);
|
|
||||||
fragmentArguments.putParcelable(EXTRA_USER, userHandle);
|
|
||||||
|
|
||||||
accountTypePreferences.add(new AccountTypePreference(
|
|
||||||
prefContext, mMetricsFeatureProvider.getMetricsCategory(mParent),
|
|
||||||
label, titleResPackageName, titleResId, AccountSyncSettings.class.getName(),
|
|
||||||
fragmentArguments, icon));
|
|
||||||
} else {
|
|
||||||
final Bundle fragmentArguments = new Bundle();
|
|
||||||
fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType);
|
|
||||||
fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_LABEL,
|
|
||||||
label.toString());
|
|
||||||
fragmentArguments.putParcelable(EXTRA_USER, userHandle);
|
|
||||||
|
|
||||||
accountTypePreferences.add(new AccountTypePreference(
|
|
||||||
prefContext, mMetricsFeatureProvider.getMetricsCategory(mParent), label,
|
|
||||||
titleResPackageName, titleResId, ManageAccountsSettings.class.getName(),
|
|
||||||
fragmentArguments, icon));
|
|
||||||
}
|
|
||||||
helper.preloadDrawableForType(mContext, accountType);
|
helper.preloadDrawableForType(mContext, accountType);
|
||||||
}
|
}
|
||||||
// Sort by label
|
// Sort by label
|
||||||
Collections.sort(accountTypePreferences, new Comparator<AccountTypePreference>() {
|
Collections.sort(accountTypePreferences, new Comparator<AccountTypePreference>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(AccountTypePreference t1, AccountTypePreference t2) {
|
public int compare(AccountTypePreference t1, AccountTypePreference t2) {
|
||||||
int result = 0;
|
int result = t1.getSummary().toString().compareTo(t2.getSummary().toString());
|
||||||
if (mIAEnabled) {
|
|
||||||
result = t1.getSummary().toString().compareTo(t2.getSummary().toString());
|
|
||||||
}
|
|
||||||
return result != 0
|
return result != 0
|
||||||
? result : t1.getTitle().toString().compareTo(t2.getTitle().toString());
|
? result : t1.getTitle().toString().compareTo(t2.getTitle().toString());
|
||||||
}
|
}
|
||||||
|
@@ -1,151 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2014 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.accounts;
|
|
||||||
|
|
||||||
import android.app.ActivityManager;
|
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Process;
|
|
||||||
import android.os.UserHandle;
|
|
||||||
import android.provider.SearchIndexableResource;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.util.SparseArray;
|
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuInflater;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
|
||||||
import com.android.settings.search.Indexable;
|
|
||||||
import com.android.settings.search.SearchIndexableRaw;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static android.provider.Settings.EXTRA_AUTHORITIES;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Settings screen for the account types on the device.
|
|
||||||
* This shows all account types available for personal and work profiles.
|
|
||||||
*
|
|
||||||
* An extra {@link UserHandle} can be specified in the intent as {@link EXTRA_USER}, if the user for
|
|
||||||
* which the action needs to be performed is different to the one the Settings App will run in.
|
|
||||||
*/
|
|
||||||
public class AccountSettings extends SettingsPreferenceFragment implements Indexable {
|
|
||||||
public static final String TAG = "AccountSettings";
|
|
||||||
|
|
||||||
|
|
||||||
private String[] mAuthorities;
|
|
||||||
|
|
||||||
private AccountPreferenceController mAccountPreferenceController;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMetricsCategory() {
|
|
||||||
return MetricsEvent.ACCOUNT;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
mAuthorities = getActivity().getIntent().getStringArrayExtra(EXTRA_AUTHORITIES);
|
|
||||||
setHasOptionsMenu(true);
|
|
||||||
mAccountPreferenceController =
|
|
||||||
new AccountPreferenceController(getActivity(), this, mAuthorities);
|
|
||||||
getLifecycle().addObserver(mAccountPreferenceController);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
||||||
inflater.inflate(R.menu.account_settings, menu);
|
|
||||||
super.onCreateOptionsMenu(menu, inflater);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPrepareOptionsMenu(Menu menu) {
|
|
||||||
final UserHandle currentProfile = Process.myUserHandle();
|
|
||||||
SparseArray<AccountPreferenceController.ProfileData> profiles =
|
|
||||||
mAccountPreferenceController.getProfileData();
|
|
||||||
|
|
||||||
if (profiles.size() == 1) {
|
|
||||||
menu.findItem(R.id.account_settings_menu_auto_sync)
|
|
||||||
.setVisible(true)
|
|
||||||
.setOnMenuItemClickListener(new MasterSyncStateClickListener(currentProfile))
|
|
||||||
.setChecked(ContentResolver.getMasterSyncAutomaticallyAsUser(
|
|
||||||
currentProfile.getIdentifier()));
|
|
||||||
menu.findItem(R.id.account_settings_menu_auto_sync_personal).setVisible(false);
|
|
||||||
menu.findItem(R.id.account_settings_menu_auto_sync_work).setVisible(false);
|
|
||||||
} else if (profiles.size() > 1) {
|
|
||||||
// We assume there's only one managed profile, otherwise UI needs to change
|
|
||||||
final UserHandle managedProfile = profiles.valueAt(1).userInfo.getUserHandle();
|
|
||||||
|
|
||||||
menu.findItem(R.id.account_settings_menu_auto_sync_personal)
|
|
||||||
.setVisible(true)
|
|
||||||
.setOnMenuItemClickListener(new MasterSyncStateClickListener(currentProfile))
|
|
||||||
.setChecked(ContentResolver.getMasterSyncAutomaticallyAsUser(
|
|
||||||
currentProfile.getIdentifier()));
|
|
||||||
menu.findItem(R.id.account_settings_menu_auto_sync_work)
|
|
||||||
.setVisible(true)
|
|
||||||
.setOnMenuItemClickListener(new MasterSyncStateClickListener(managedProfile))
|
|
||||||
.setChecked(ContentResolver.getMasterSyncAutomaticallyAsUser(
|
|
||||||
managedProfile.getIdentifier()));
|
|
||||||
menu.findItem(R.id.account_settings_menu_auto_sync).setVisible(false);
|
|
||||||
} else {
|
|
||||||
Log.w(TAG, "Method onPrepareOptionsMenu called before profiles was initialized");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class MasterSyncStateClickListener implements MenuItem.OnMenuItemClickListener {
|
|
||||||
private final UserHandle mUserHandle;
|
|
||||||
|
|
||||||
public MasterSyncStateClickListener(UserHandle userHandle) {
|
|
||||||
mUserHandle = userHandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
|
||||||
if (ActivityManager.isUserAMonkey()) {
|
|
||||||
Log.d(TAG, "ignoring monkey's attempt to flip sync state");
|
|
||||||
} else {
|
|
||||||
AutoSyncDataPreferenceController.ConfirmAutoSyncChangeFragment.show(
|
|
||||||
AccountSettings.this, !item.isChecked(), mUserHandle, null/*preference*/);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
|
||||||
new BaseSearchIndexProvider() {
|
|
||||||
@Override
|
|
||||||
public List<SearchIndexableResource> getXmlResourcesToIndex(
|
|
||||||
Context context, boolean enabled) {
|
|
||||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
|
||||||
sir.xmlResId = R.xml.account_settings;
|
|
||||||
return Arrays.asList(sir);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) {
|
|
||||||
final List<SearchIndexableRaw> result = new ArrayList<SearchIndexableRaw>();
|
|
||||||
new AccountPreferenceController(context, null, null).updateRawDataToIndex(result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
@@ -72,7 +72,7 @@ public class AddAccountSettings extends Activity {
|
|||||||
private static final String KEY_CALLER_IDENTITY = "pendingIntent";
|
private static final String KEY_CALLER_IDENTITY = "pendingIntent";
|
||||||
private static final String SHOULD_NOT_RESOLVE = "SHOULDN'T RESOLVE!";
|
private static final String SHOULD_NOT_RESOLVE = "SHOULDN'T RESOLVE!";
|
||||||
|
|
||||||
private static final String TAG = "AccountSettings";
|
private static final String TAG = "AddAccountSettings";
|
||||||
|
|
||||||
/* package */ static final String EXTRA_SELECTED_ACCOUNT = "selected_account";
|
/* package */ static final String EXTRA_SELECTED_ACCOUNT = "selected_account";
|
||||||
|
|
||||||
|
@@ -1,426 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2008 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.accounts;
|
|
||||||
|
|
||||||
import android.accounts.Account;
|
|
||||||
import android.accounts.AccountManager;
|
|
||||||
import android.app.ActionBar;
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.SyncAdapterType;
|
|
||||||
import android.content.SyncInfo;
|
|
||||||
import android.content.SyncStatusInfo;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.UserHandle;
|
|
||||||
import android.support.annotation.VisibleForTesting;
|
|
||||||
import android.support.v7.preference.Preference;
|
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
|
||||||
import android.util.ArraySet;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuInflater;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.SettingsActivity;
|
|
||||||
import com.android.settings.Utils;
|
|
||||||
import com.android.settingslib.accounts.AuthenticatorHelper;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static android.content.Intent.EXTRA_USER;
|
|
||||||
|
|
||||||
/** Manages settings for Google Account. */
|
|
||||||
public class ManageAccountsSettings extends AccountPreferenceBase
|
|
||||||
implements AuthenticatorHelper.OnAccountsUpdateListener {
|
|
||||||
public static final String KEY_ACCOUNT_TYPE = "account_type";
|
|
||||||
public static final String KEY_ACCOUNT_LABEL = "account_label";
|
|
||||||
|
|
||||||
private static final int MENU_SYNC_NOW_ID = Menu.FIRST;
|
|
||||||
private static final int MENU_SYNC_CANCEL_ID = Menu.FIRST + 1;
|
|
||||||
|
|
||||||
private static final int REQUEST_SHOW_SYNC_SETTINGS = 1;
|
|
||||||
|
|
||||||
private String[] mAuthorities;
|
|
||||||
private TextView mErrorInfoView;
|
|
||||||
|
|
||||||
// If an account type is set, then show only accounts of that type
|
|
||||||
private String mAccountType;
|
|
||||||
// Temporary hack, to deal with backward compatibility
|
|
||||||
// mFirstAccount is used for the injected preferences
|
|
||||||
private Account mFirstAccount;
|
|
||||||
|
|
||||||
protected Set<String> mUserFacingSyncAuthorities;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMetricsCategory() {
|
|
||||||
return MetricsEvent.ACCOUNTS_MANAGE_ACCOUNTS;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle icicle) {
|
|
||||||
super.onCreate(icicle);
|
|
||||||
|
|
||||||
Bundle args = getArguments();
|
|
||||||
if (args != null && args.containsKey(KEY_ACCOUNT_TYPE)) {
|
|
||||||
mAccountType = args.getString(KEY_ACCOUNT_TYPE);
|
|
||||||
}
|
|
||||||
addPreferencesFromResource(R.xml.manage_accounts_settings);
|
|
||||||
setHasOptionsMenu(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
mAuthenticatorHelper.listenToAccountUpdates();
|
|
||||||
updateAuthDescriptions();
|
|
||||||
showAccountsIfNeeded();
|
|
||||||
showSyncState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
||||||
Bundle savedInstanceState) {
|
|
||||||
final View view = inflater.inflate(R.layout.manage_accounts_screen, container, false);
|
|
||||||
final ViewGroup prefs_container = (ViewGroup) view.findViewById(R.id.prefs_container);
|
|
||||||
Utils.prepareCustomPreferencesList(container, view, prefs_container, false);
|
|
||||||
View prefs = super.onCreateView(inflater, prefs_container, savedInstanceState);
|
|
||||||
prefs_container.addView(prefs);
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
|
||||||
super.onActivityCreated(savedInstanceState);
|
|
||||||
|
|
||||||
final Activity activity = getActivity();
|
|
||||||
final View view = getView();
|
|
||||||
|
|
||||||
mErrorInfoView = (TextView) view.findViewById(R.id.sync_settings_error_info);
|
|
||||||
mErrorInfoView.setVisibility(View.GONE);
|
|
||||||
|
|
||||||
mAuthorities = activity.getIntent().getStringArrayExtra(AUTHORITIES_FILTER_KEY);
|
|
||||||
|
|
||||||
Bundle args = getArguments();
|
|
||||||
if (args != null && args.containsKey(KEY_ACCOUNT_LABEL)) {
|
|
||||||
getActivity().setTitle(args.getString(KEY_ACCOUNT_LABEL));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
mAuthenticatorHelper.stopListeningToAccountUpdates();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStop() {
|
|
||||||
super.onStop();
|
|
||||||
final Activity activity = getActivity();
|
|
||||||
activity.getActionBar().setDisplayOptions(0, ActionBar.DISPLAY_SHOW_CUSTOM);
|
|
||||||
activity.getActionBar().setCustomView(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onPreferenceTreeClick(Preference preference) {
|
|
||||||
if (preference instanceof AccountPreference) {
|
|
||||||
startAccountSettings((AccountPreference) preference);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startAccountSettings(AccountPreference acctPref) {
|
|
||||||
Bundle args = new Bundle();
|
|
||||||
args.putParcelable(AccountSyncSettings.ACCOUNT_KEY, acctPref.getAccount());
|
|
||||||
args.putParcelable(EXTRA_USER, mUserHandle);
|
|
||||||
((SettingsActivity) getActivity()).startPreferencePanel(this,
|
|
||||||
AccountSyncSettings.class.getCanonicalName(), args,
|
|
||||||
R.string.account_sync_settings_title, acctPref.getAccount().name,
|
|
||||||
this, REQUEST_SHOW_SYNC_SETTINGS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
||||||
menu.add(0, MENU_SYNC_NOW_ID, 0, getString(R.string.sync_menu_sync_now))
|
|
||||||
.setIcon(R.drawable.ic_menu_refresh_holo_dark);
|
|
||||||
menu.add(0, MENU_SYNC_CANCEL_ID, 0, getString(R.string.sync_menu_sync_cancel))
|
|
||||||
.setIcon(com.android.internal.R.drawable.ic_menu_close_clear_cancel);
|
|
||||||
super.onCreateOptionsMenu(menu, inflater);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPrepareOptionsMenu(Menu menu) {
|
|
||||||
super.onPrepareOptionsMenu(menu);
|
|
||||||
boolean syncActive = !getCurrentSyncs(mUserHandle.getIdentifier()).isEmpty();
|
|
||||||
menu.findItem(MENU_SYNC_NOW_ID).setVisible(!syncActive);
|
|
||||||
menu.findItem(MENU_SYNC_CANCEL_ID).setVisible(syncActive);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
switch (item.getItemId()) {
|
|
||||||
case MENU_SYNC_NOW_ID:
|
|
||||||
requestOrCancelSyncForAccounts(true);
|
|
||||||
return true;
|
|
||||||
case MENU_SYNC_CANCEL_ID:
|
|
||||||
requestOrCancelSyncForAccounts(false);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void requestOrCancelSyncForAccounts(boolean sync) {
|
|
||||||
final int userId = mUserHandle.getIdentifier();
|
|
||||||
SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypesAsUser(userId);
|
|
||||||
Bundle extras = new Bundle();
|
|
||||||
extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
|
|
||||||
int count = getPreferenceScreen().getPreferenceCount();
|
|
||||||
// For each account
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
Preference pref = getPreferenceScreen().getPreference(i);
|
|
||||||
if (pref instanceof AccountPreference) {
|
|
||||||
Account account = ((AccountPreference) pref).getAccount();
|
|
||||||
// For all available sync authorities, sync those that are enabled for the account
|
|
||||||
for (int j = 0; j < syncAdapters.length; j++) {
|
|
||||||
SyncAdapterType sa = syncAdapters[j];
|
|
||||||
if (syncAdapters[j].accountType.equals(mAccountType)
|
|
||||||
&& ContentResolver.getSyncAutomaticallyAsUser(account, sa.authority,
|
|
||||||
userId)) {
|
|
||||||
if (sync) {
|
|
||||||
ContentResolver.requestSyncAsUser(account, sa.authority, userId,
|
|
||||||
extras);
|
|
||||||
} else {
|
|
||||||
ContentResolver.cancelSyncAsUser(account, sa.authority, userId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onSyncStateUpdated() {
|
|
||||||
final Activity activity = getActivity();
|
|
||||||
// Catch any delayed delivery of update messages
|
|
||||||
if (activity == null || activity.isFinishing()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
showSyncState();
|
|
||||||
activity.invalidateOptionsMenu();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void tryInitUserFacingSyncAuthorities(int userId) {
|
|
||||||
if (mUserFacingSyncAuthorities != null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mUserFacingSyncAuthorities = new ArraySet<>();
|
|
||||||
|
|
||||||
// only track userfacing sync adapters when deciding if account is synced or not
|
|
||||||
final SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypesAsUser(userId);
|
|
||||||
for (int k = 0, n = syncAdapters.length; k < n; k++) {
|
|
||||||
final SyncAdapterType sa = syncAdapters[k];
|
|
||||||
if (sa.isUserVisible()) {
|
|
||||||
mUserFacingSyncAuthorities.add(sa.authority);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shows the sync state of the accounts. Note: it must be called after the accounts have been
|
|
||||||
* loaded.
|
|
||||||
*
|
|
||||||
* @see {@link #showAccountsIfNeeded()}.
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
|
||||||
void showSyncState() {
|
|
||||||
final int userId = mUserHandle.getIdentifier();
|
|
||||||
tryInitUserFacingSyncAuthorities(userId);
|
|
||||||
|
|
||||||
// iterate over all the preferences, setting the state properly for each
|
|
||||||
final List<SyncInfo> currentSyncs = getCurrentSyncs(userId);
|
|
||||||
|
|
||||||
boolean anySyncFailed = false; // true if sync on any account failed
|
|
||||||
Date date = new Date();
|
|
||||||
|
|
||||||
final PreferenceScreen screen = getPreferenceScreen();
|
|
||||||
final int prefCount = screen.getPreferenceCount();
|
|
||||||
for (int i = 0; i < prefCount; i++) {
|
|
||||||
Preference pref = screen.getPreference(i);
|
|
||||||
if (!(pref instanceof AccountPreference)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
final AccountPreference accountPref = (AccountPreference) pref;
|
|
||||||
final Account account = accountPref.getAccount();
|
|
||||||
int syncCount = 0;
|
|
||||||
long lastSuccessTime = 0;
|
|
||||||
boolean syncIsFailing = false;
|
|
||||||
final ArrayList<String> authorities = accountPref.getAuthorities();
|
|
||||||
boolean syncingNow = false;
|
|
||||||
if (authorities != null) {
|
|
||||||
for (String authority : authorities) {
|
|
||||||
SyncStatusInfo status = getSyncStatusInfo(account, authority, userId);
|
|
||||||
boolean syncEnabled = isSyncEnabled(userId, account, authority);
|
|
||||||
boolean activelySyncing = isSyncing(currentSyncs, account, authority);
|
|
||||||
boolean lastSyncFailed = status != null
|
|
||||||
&& syncEnabled
|
|
||||||
&& status.lastFailureTime != 0
|
|
||||||
&& status.getLastFailureMesgAsInt(0)
|
|
||||||
!= ContentResolver.SYNC_ERROR_SYNC_ALREADY_IN_PROGRESS;
|
|
||||||
if (lastSyncFailed && !activelySyncing
|
|
||||||
&& !ContentResolver.isSyncPending(account, authority)) {
|
|
||||||
syncIsFailing = true;
|
|
||||||
anySyncFailed = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (status != null && lastSuccessTime < status.lastSuccessTime) {
|
|
||||||
lastSuccessTime = status.lastSuccessTime;
|
|
||||||
}
|
|
||||||
syncCount += syncEnabled && mUserFacingSyncAuthorities.contains(authority)
|
|
||||||
? 1 : 0;
|
|
||||||
syncingNow |= activelySyncing;
|
|
||||||
if (syncingNow) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (VERBOSE) {
|
|
||||||
Log.v(TAG, "no syncadapters found for " + account);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (syncIsFailing) {
|
|
||||||
accountPref.setSyncStatus(AccountPreference.SYNC_ERROR, true);
|
|
||||||
} else if (syncCount == 0) {
|
|
||||||
accountPref.setSyncStatus(AccountPreference.SYNC_DISABLED, true);
|
|
||||||
} else if (syncCount > 0) {
|
|
||||||
if (syncingNow) {
|
|
||||||
accountPref.setSyncStatus(AccountPreference.SYNC_IN_PROGRESS, true);
|
|
||||||
} else {
|
|
||||||
accountPref.setSyncStatus(AccountPreference.SYNC_ENABLED, true);
|
|
||||||
if (lastSuccessTime > 0) {
|
|
||||||
accountPref.setSyncStatus(AccountPreference.SYNC_ENABLED, false);
|
|
||||||
date.setTime(lastSuccessTime);
|
|
||||||
final String timeString = formatSyncDate(date);
|
|
||||||
accountPref.setSummary(getResources().getString(
|
|
||||||
R.string.last_synced, timeString));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
accountPref.setSyncStatus(AccountPreference.SYNC_DISABLED, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mErrorInfoView != null) {
|
|
||||||
mErrorInfoView.setVisibility(anySyncFailed ? View.VISIBLE : View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isSyncing(List<SyncInfo> currentSyncs, Account account, String authority) {
|
|
||||||
final int count = currentSyncs.size();
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
SyncInfo syncInfo = currentSyncs.get(i);
|
|
||||||
if (syncInfo.account.equals(account) && syncInfo.authority.equals(authority)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
protected boolean isSyncEnabled(int userId, Account account, String authority) {
|
|
||||||
return ContentResolver.getSyncAutomaticallyAsUser(account, authority, userId)
|
|
||||||
&& ContentResolver.getMasterSyncAutomaticallyAsUser(userId)
|
|
||||||
&& (ContentResolver.getIsSyncableAsUser(account, authority, userId) > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAccountsUpdate(UserHandle userHandle) {
|
|
||||||
showAccountsIfNeeded();
|
|
||||||
onSyncStateUpdated();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showAccountsIfNeeded() {
|
|
||||||
if (getActivity() == null) return;
|
|
||||||
Account[] accounts = AccountManager.get(getActivity()).getAccountsAsUser(
|
|
||||||
mUserHandle.getIdentifier());
|
|
||||||
getPreferenceScreen().removeAll();
|
|
||||||
mFirstAccount = null;
|
|
||||||
addPreferencesFromResource(R.xml.manage_accounts_settings);
|
|
||||||
for (int i = 0, n = accounts.length; i < n; i++) {
|
|
||||||
final Account account = accounts[i];
|
|
||||||
// If an account type is specified for this screen, skip other types
|
|
||||||
if (mAccountType != null && !account.type.equals(mAccountType)) continue;
|
|
||||||
final ArrayList<String> auths = getAuthoritiesForAccountType(account.type);
|
|
||||||
|
|
||||||
if (AccountRestrictionHelper.showAccount(mAuthorities, auths)) {
|
|
||||||
final Drawable icon = getDrawableForType(account.type);
|
|
||||||
final AccountPreference preference =
|
|
||||||
new AccountPreference(getPrefContext(), account, icon, auths, false);
|
|
||||||
getPreferenceScreen().addPreference(preference);
|
|
||||||
if (mFirstAccount == null) {
|
|
||||||
mFirstAccount = account;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mAccountType != null && mFirstAccount != null) {
|
|
||||||
addAuthenticatorSettings();
|
|
||||||
} else {
|
|
||||||
// There's no account, close activity
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addAuthenticatorSettings() {
|
|
||||||
PreferenceScreen prefs = addPreferencesForType(mAccountType, getPreferenceScreen());
|
|
||||||
if (prefs != null) {
|
|
||||||
mAccountTypePreferenceLoader.updatePreferenceIntents(prefs, mAccountType, mFirstAccount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onAuthDescriptionsUpdated() {
|
|
||||||
// Update account icons for all account preference items
|
|
||||||
for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) {
|
|
||||||
Preference pref = getPreferenceScreen().getPreference(i);
|
|
||||||
if (pref instanceof AccountPreference) {
|
|
||||||
AccountPreference accPref = (AccountPreference) pref;
|
|
||||||
accPref.setSummary(getLabelForType(accPref.getAccount().type));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
protected List<SyncInfo> getCurrentSyncs(int userId) {
|
|
||||||
return ContentResolver.getCurrentSyncsAsUser(userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
protected SyncStatusInfo getSyncStatusInfo(Account account, String authority, int userId) {
|
|
||||||
return ContentResolver.getSyncStatusAsUser(account, authority, userId);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -44,7 +44,6 @@ import com.android.settings.accessibility.AccessibilitySettings;
|
|||||||
import com.android.settings.accessibility.AccessibilitySettingsForSetupWizard;
|
import com.android.settings.accessibility.AccessibilitySettingsForSetupWizard;
|
||||||
import com.android.settings.accessibility.CaptionPropertiesFragment;
|
import com.android.settings.accessibility.CaptionPropertiesFragment;
|
||||||
import com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment;
|
import com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment;
|
||||||
import com.android.settings.accounts.AccountSettings;
|
|
||||||
import com.android.settings.accounts.AccountSyncSettings;
|
import com.android.settings.accounts.AccountSyncSettings;
|
||||||
import com.android.settings.accounts.ChooseAccountActivity;
|
import com.android.settings.accounts.ChooseAccountActivity;
|
||||||
import com.android.settings.accounts.ManagedProfileSettings;
|
import com.android.settings.accounts.ManagedProfileSettings;
|
||||||
@@ -181,7 +180,6 @@ public class SettingsGateway {
|
|||||||
WifiDisplaySettings.class.getName(),
|
WifiDisplaySettings.class.getName(),
|
||||||
PowerUsageSummary.class.getName(),
|
PowerUsageSummary.class.getName(),
|
||||||
AccountSyncSettings.class.getName(),
|
AccountSyncSettings.class.getName(),
|
||||||
AccountSettings.class.getName(),
|
|
||||||
GestureSettings.class.getName(),
|
GestureSettings.class.getName(),
|
||||||
AssistGestureSettings.class.getName(),
|
AssistGestureSettings.class.getName(),
|
||||||
SwipeToNotificationSettings.class.getName(),
|
SwipeToNotificationSettings.class.getName(),
|
||||||
@@ -271,7 +269,6 @@ public class SettingsGateway {
|
|||||||
Settings.SecuritySettingsActivity.class.getName(),
|
Settings.SecuritySettingsActivity.class.getName(),
|
||||||
Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
|
Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
|
||||||
Settings.UserSettingsActivity.class.getName(),
|
Settings.UserSettingsActivity.class.getName(),
|
||||||
Settings.AccountSettingsActivity.class.getName(),
|
|
||||||
//system_section
|
//system_section
|
||||||
Settings.DateTimeSettingsActivity.class.getName(),
|
Settings.DateTimeSettingsActivity.class.getName(),
|
||||||
Settings.DeviceInfoSettingsActivity.class.getName(),
|
Settings.DeviceInfoSettingsActivity.class.getName(),
|
||||||
|
@@ -84,7 +84,7 @@ public class WorkModeCondition extends Condition {
|
|||||||
@Override
|
@Override
|
||||||
public void onPrimaryClick() {
|
public void onPrimaryClick() {
|
||||||
mManager.getContext().startActivity(new Intent(mManager.getContext(),
|
mManager.getContext().startActivity(new Intent(mManager.getContext(),
|
||||||
Settings.AccountSettingsActivity.class));
|
Settings.UserAndAccountDashboardActivity.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -28,7 +28,7 @@ import com.android.settings.SecuritySettings;
|
|||||||
import com.android.settings.WallpaperTypeSettings;
|
import com.android.settings.WallpaperTypeSettings;
|
||||||
import com.android.settings.WirelessSettings;
|
import com.android.settings.WirelessSettings;
|
||||||
import com.android.settings.accessibility.AccessibilitySettings;
|
import com.android.settings.accessibility.AccessibilitySettings;
|
||||||
import com.android.settings.accounts.AccountSettings;
|
import com.android.settings.accounts.UserAndAccountDashboardFragment;
|
||||||
import com.android.settings.applications.AdvancedAppSettings;
|
import com.android.settings.applications.AdvancedAppSettings;
|
||||||
import com.android.settings.applications.SpecialAccessSettings;
|
import com.android.settings.applications.SpecialAccessSettings;
|
||||||
import com.android.settings.bluetooth.BluetoothSettings;
|
import com.android.settings.bluetooth.BluetoothSettings;
|
||||||
@@ -166,7 +166,7 @@ public final class Ranking {
|
|||||||
sRankMap.put(ScreenPinningSettings.class.getName(), RANK_SECURITY);
|
sRankMap.put(ScreenPinningSettings.class.getName(), RANK_SECURITY);
|
||||||
|
|
||||||
// Accounts
|
// Accounts
|
||||||
sRankMap.put(AccountSettings.class.getName(), RANK_ACCOUNT);
|
sRankMap.put(UserAndAccountDashboardFragment.class.getName(), RANK_ACCOUNT);
|
||||||
|
|
||||||
// IMEs
|
// IMEs
|
||||||
sRankMap.put(InputMethodAndLanguageSettings.class.getName(), RANK_IME);
|
sRankMap.put(InputMethodAndLanguageSettings.class.getName(), RANK_IME);
|
||||||
|
@@ -33,7 +33,6 @@ import com.android.settings.SecuritySettings;
|
|||||||
import com.android.settings.WallpaperTypeSettings;
|
import com.android.settings.WallpaperTypeSettings;
|
||||||
import com.android.settings.WirelessSettings;
|
import com.android.settings.WirelessSettings;
|
||||||
import com.android.settings.accessibility.AccessibilitySettings;
|
import com.android.settings.accessibility.AccessibilitySettings;
|
||||||
import com.android.settings.accounts.AccountSettings;
|
|
||||||
import com.android.settings.accounts.UserAndAccountDashboardFragment;
|
import com.android.settings.accounts.UserAndAccountDashboardFragment;
|
||||||
import com.android.settings.applications.AdvancedAppSettings;
|
import com.android.settings.applications.AdvancedAppSettings;
|
||||||
import com.android.settings.applications.AppAndNotificationDashboardFragment;
|
import com.android.settings.applications.AppAndNotificationDashboardFragment;
|
||||||
@@ -155,7 +154,6 @@ public final class SearchIndexableResources {
|
|||||||
addIndex(EncryptionAndCredential.class, R.xml.encryption_and_credential,
|
addIndex(EncryptionAndCredential.class, R.xml.encryption_and_credential,
|
||||||
R.drawable.ic_settings_security);
|
R.drawable.ic_settings_security);
|
||||||
addIndex(ScreenPinningSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_security);
|
addIndex(ScreenPinningSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_security);
|
||||||
addIndex(AccountSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_accounts);
|
|
||||||
addIndex(UserAndAccountDashboardFragment.class, NO_DATA_RES_ID,
|
addIndex(UserAndAccountDashboardFragment.class, NO_DATA_RES_ID,
|
||||||
R.drawable.ic_settings_accounts);
|
R.drawable.ic_settings_accounts);
|
||||||
addIndex(InputMethodAndLanguageSettings.class,
|
addIndex(InputMethodAndLanguageSettings.class,
|
||||||
|
@@ -8,7 +8,6 @@ com.android.settings.inputmethod.KeyboardLayoutPickerFragment
|
|||||||
com.android.settings.notification.ZenModeEventRuleSettings
|
com.android.settings.notification.ZenModeEventRuleSettings
|
||||||
com.android.settings.fuelgauge.InactiveApps
|
com.android.settings.fuelgauge.InactiveApps
|
||||||
com.android.settings.accessibility.CaptionPropertiesFragment
|
com.android.settings.accessibility.CaptionPropertiesFragment
|
||||||
com.android.settings.accounts.ManageAccountsSettings
|
|
||||||
com.android.settings.accessibility.AccessibilitySettingsForSetupWizard
|
com.android.settings.accessibility.AccessibilitySettingsForSetupWizard
|
||||||
com.android.settings.deviceinfo.ImeiInformation
|
com.android.settings.deviceinfo.ImeiInformation
|
||||||
com.android.settings.datausage.DataUsageList
|
com.android.settings.datausage.DataUsageList
|
||||||
|
@@ -22,7 +22,6 @@ import android.content.Context;
|
|||||||
import android.content.pm.UserInfo;
|
import android.content.pm.UserInfo;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.support.v14.preference.PreferenceFragment;
|
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.PreferenceGroup;
|
import android.support.v7.preference.PreferenceGroup;
|
||||||
import android.support.v7.preference.PreferenceManager;
|
import android.support.v7.preference.PreferenceManager;
|
||||||
@@ -30,6 +29,7 @@ import android.support.v7.preference.PreferenceScreen;
|
|||||||
|
|
||||||
import com.android.settings.AccessiblePreferenceCategory;
|
import com.android.settings.AccessiblePreferenceCategory;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
import com.android.settings.SettingsRobolectricTestRunner;
|
import com.android.settings.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.search.SearchIndexableRaw;
|
import com.android.settings.search.SearchIndexableRaw;
|
||||||
@@ -70,7 +70,7 @@ public class AccountPreferenceControllerTest {
|
|||||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||||
private UserManager mUserManager;
|
private UserManager mUserManager;
|
||||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||||
private PreferenceFragment mFragment;
|
private SettingsPreferenceFragment mFragment;
|
||||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||||
private AccountManager mAccountManager;
|
private AccountManager mAccountManager;
|
||||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||||
|
@@ -1,135 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.accounts;
|
|
||||||
|
|
||||||
import android.accounts.Account;
|
|
||||||
import android.content.SyncInfo;
|
|
||||||
import android.content.SyncStatusInfo;
|
|
||||||
import android.os.UserHandle;
|
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
|
||||||
import android.util.ArraySet;
|
|
||||||
|
|
||||||
import com.android.settings.SettingsRobolectricTestRunner;
|
|
||||||
import com.android.settings.TestConfig;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Answers;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.annotation.Config;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.mockito.Matchers.anyInt;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.never;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
|
||||||
public class ManageAccountsSettingsTest {
|
|
||||||
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
|
||||||
private AccountPreference mAccountPref;
|
|
||||||
private Account mAccount;
|
|
||||||
private ArrayList<String> mAuthorities;
|
|
||||||
private TestFragment mSettings;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
mAuthorities = new ArrayList<>();
|
|
||||||
mAuthorities.add("authority");
|
|
||||||
mAccount = new Account("name", "type");
|
|
||||||
when(mAccountPref.getAccount()).thenReturn(mAccount);
|
|
||||||
when(mAccountPref.getAuthorities()).thenReturn(mAuthorities);
|
|
||||||
mSettings = new TestFragment();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void showSyncState_noAccountPrefs_shouldUpdateNothing() {
|
|
||||||
when(mAccountPref.getAuthorities()).thenReturn(null);
|
|
||||||
mSettings.showSyncState();
|
|
||||||
verify(mSettings.getPreferenceScreen(), never()).getPreference(anyInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void showSyncState_syncInProgress_shouldUpdateInProgress() {
|
|
||||||
mSettings.mUserFacingSyncAuthorities.add(mAuthorities.get(0));
|
|
||||||
mSettings.mSyncInfos.add(new SyncInfo(0, mAccount, mAuthorities.get(0), 0));
|
|
||||||
mSettings.mSyncStatusInfo = new SyncStatusInfo(0);
|
|
||||||
when(mSettings.getPreferenceScreen().getPreferenceCount()).thenReturn(1);
|
|
||||||
when(mSettings.getPreferenceScreen().getPreference(0)).thenReturn(mAccountPref);
|
|
||||||
|
|
||||||
mSettings.showSyncState();
|
|
||||||
|
|
||||||
verify(mSettings.getPreferenceScreen()).getPreference(anyInt());
|
|
||||||
verify(mAccountPref).setSyncStatus(AccountPreference.SYNC_IN_PROGRESS, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void showSyncState_noUserFacingSynclets_shouldUpdateToDisabled() {
|
|
||||||
mSettings.mSyncInfos.add(new SyncInfo(0, mAccount, mAuthorities.get(0), 0));
|
|
||||||
mSettings.mSyncStatusInfo = new SyncStatusInfo(0);
|
|
||||||
when(mSettings.getPreferenceScreen().getPreferenceCount()).thenReturn(1);
|
|
||||||
when(mSettings.getPreferenceScreen().getPreference(0)).thenReturn(mAccountPref);
|
|
||||||
|
|
||||||
mSettings.showSyncState();
|
|
||||||
|
|
||||||
verify(mSettings.getPreferenceScreen()).getPreference(anyInt());
|
|
||||||
verify(mAccountPref).setSyncStatus(AccountPreference.SYNC_DISABLED, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class TestFragment extends ManageAccountsSettings {
|
|
||||||
|
|
||||||
private PreferenceScreen mScreen;
|
|
||||||
private List<SyncInfo> mSyncInfos;
|
|
||||||
private SyncStatusInfo mSyncStatusInfo;
|
|
||||||
|
|
||||||
public TestFragment() {
|
|
||||||
mUserHandle = mock(UserHandle.class);
|
|
||||||
mScreen = mock(PreferenceScreen.class);
|
|
||||||
mUserFacingSyncAuthorities = new ArraySet<>();
|
|
||||||
mSyncInfos = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PreferenceScreen getPreferenceScreen() {
|
|
||||||
return mScreen;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean isSyncEnabled(int userId, Account account, String authority) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<SyncInfo> getCurrentSyncs(int userId) {
|
|
||||||
return mSyncInfos;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected SyncStatusInfo getSyncStatusInfo(Account account, String authority, int userId) {
|
|
||||||
return mSyncStatusInfo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Reference in New Issue
Block a user