Update all preferences when the account preference updates UI
When an account is added or removed, the account preference controller just updates the account list, whereas there's no trigger point for the account data sync preferences to refresh. Add an API to update all preferences in DashboardFragment, so we can refresh the account sync preferences whenever the account list is updated. Bug: 185479221 Test: robotest, manual Change-Id: Ide3d972abae09ce0175e3bafbb1f4a5e307d20c8
This commit is contained in:
@@ -26,7 +26,6 @@ import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.applications.autofill.PasswordsPreferenceController;
|
||||
import com.android.settings.applications.defaultapps.DefaultAutofillPreferenceController;
|
||||
import com.android.settings.applications.defaultapps.DefaultWorkAutofillPreferenceController;
|
||||
@@ -96,7 +95,7 @@ public class AccountDashboardFragment extends DashboardFragment {
|
||||
}
|
||||
|
||||
private static void buildAccountPreferenceControllers(
|
||||
Context context, SettingsPreferenceFragment parent, String[] authorities,
|
||||
Context context, DashboardFragment parent, String[] authorities,
|
||||
List<AbstractPreferenceController> controllers) {
|
||||
final AccountPreferenceController accountPrefController =
|
||||
new AccountPreferenceController(context, parent, authorities,
|
||||
|
@@ -24,7 +24,6 @@ import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.applications.autofill.PasswordsPreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
|
||||
@@ -78,7 +77,7 @@ public class AccountPersonalDashboardFragment extends DashboardFragment {
|
||||
}
|
||||
|
||||
private static void buildAccountPreferenceControllers(
|
||||
Context context, SettingsPreferenceFragment parent, String[] authorities,
|
||||
Context context, DashboardFragment parent, String[] authorities,
|
||||
List<AbstractPreferenceController> controllers) {
|
||||
final AccountPreferenceController accountPrefController =
|
||||
new AccountPreferenceController(context, parent, authorities,
|
||||
|
@@ -58,10 +58,10 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.AccessiblePreferenceCategory;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
@@ -101,7 +101,7 @@ public class AccountPreferenceController extends AbstractPreferenceController
|
||||
private Preference mProfileNotAvailablePreference;
|
||||
private String[] mAuthorities;
|
||||
private int mAuthoritiesCount = 0;
|
||||
private SettingsPreferenceFragment mFragment;
|
||||
private DashboardFragment mFragment;
|
||||
private int mAccountProfileOrder = ORDER_ACCOUNT_PROFILES;
|
||||
private AccountRestrictionHelper mHelper;
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
@@ -145,13 +145,13 @@ public class AccountPreferenceController extends AbstractPreferenceController
|
||||
public ArrayMap<String, AccountTypePreference> accountPreferences = new ArrayMap<>();
|
||||
}
|
||||
|
||||
public AccountPreferenceController(Context context, SettingsPreferenceFragment parent,
|
||||
public AccountPreferenceController(Context context, DashboardFragment parent,
|
||||
String[] authorities, @ProfileSelectFragment.ProfileType int type) {
|
||||
this(context, parent, authorities, new AccountRestrictionHelper(context), type);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
AccountPreferenceController(Context context, SettingsPreferenceFragment parent,
|
||||
AccountPreferenceController(Context context, DashboardFragment parent,
|
||||
String[] authorities, AccountRestrictionHelper helper,
|
||||
@ProfileSelectFragment.ProfileType int type) {
|
||||
super(context);
|
||||
@@ -314,6 +314,9 @@ public class AccountPreferenceController extends AbstractPreferenceController
|
||||
for (int i = 0; i < profilesCount; i++) {
|
||||
updateAccountTypes(mProfiles.valueAt(i));
|
||||
}
|
||||
|
||||
// Refresh for the auto-sync preferences
|
||||
mFragment.forceUpdatePreferences();
|
||||
}
|
||||
|
||||
private void updateProfileUi(final UserInfo userInfo) {
|
||||
@@ -409,7 +412,6 @@ public class AccountPreferenceController extends AbstractPreferenceController
|
||||
return preference;
|
||||
}
|
||||
|
||||
|
||||
private Preference newManagedProfileSettings() {
|
||||
Preference preference = new Preference(mFragment.getPreferenceManager().getContext());
|
||||
preference.setKey(PREF_KEY_WORK_PROFILE_SETTING);
|
||||
|
@@ -24,7 +24,6 @@ import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.applications.autofill.PasswordsPreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
|
||||
@@ -78,7 +77,7 @@ public class AccountWorkProfileDashboardFragment extends DashboardFragment {
|
||||
}
|
||||
|
||||
private static void buildAccountPreferenceControllers(
|
||||
Context context, SettingsPreferenceFragment parent, String[] authorities,
|
||||
Context context, DashboardFragment parent, String[] authorities,
|
||||
List<AbstractPreferenceController> controllers) {
|
||||
final AccountPreferenceController accountPrefController =
|
||||
new AccountPreferenceController(context, parent, authorities,
|
||||
|
@@ -415,6 +415,30 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
updatePreferenceVisibility(mPreferenceControllers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force update all the preferences in this fragment.
|
||||
*/
|
||||
public void forceUpdatePreferences() {
|
||||
final PreferenceScreen screen = getPreferenceScreen();
|
||||
if (screen == null || mPreferenceControllers == null) {
|
||||
return;
|
||||
}
|
||||
for (List<AbstractPreferenceController> controllerList : mPreferenceControllers.values()) {
|
||||
for (AbstractPreferenceController controller : controllerList) {
|
||||
final String key = controller.getPreferenceKey();
|
||||
final Preference preference = findPreference(key);
|
||||
if (preference == null) {
|
||||
continue;
|
||||
}
|
||||
final boolean available = controller.isAvailable();
|
||||
if (available) {
|
||||
controller.updateState(preference);
|
||||
}
|
||||
preference.setVisible(available);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void updatePreferenceVisibility(
|
||||
Map<Class, List<AbstractPreferenceController>> preferenceControllers) {
|
||||
|
@@ -22,7 +22,8 @@ import androidx.preference.PreferenceFragmentCompat;
|
||||
|
||||
import com.android.settings.Utils;
|
||||
|
||||
public class AutoSyncWorkDataPreferenceController extends AutoSyncPersonalDataPreferenceController {
|
||||
/** An account sync data preference controller for work */
|
||||
public class AutoSyncWorkDataPreferenceController extends AutoSyncDataPreferenceController {
|
||||
|
||||
private static final String KEY_AUTO_SYNC_WORK_ACCOUNT = "auto_sync_work_account_data";
|
||||
|
||||
@@ -38,6 +39,7 @@ public class AutoSyncWorkDataPreferenceController extends AutoSyncPersonalDataPr
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
mUserHandle = Utils.getManagedProfileWithDisabled(mUserManager);
|
||||
return mUserHandle != null && !mUserManager.isManagedProfile() && !mUserManager.isLinkedUser()
|
||||
&& mUserManager.getProfiles(UserHandle.myUserId()).size() > 1;
|
||||
}
|
||||
|
@@ -45,7 +45,7 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.AccessiblePreferenceCategory;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
|
||||
import com.android.settings.testutils.shadow.ShadowAccountManager;
|
||||
import com.android.settings.testutils.shadow.ShadowContentResolver;
|
||||
@@ -77,7 +77,7 @@ public class AccountPreferenceControllerTest {
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private UserManager mUserManager;
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private SettingsPreferenceFragment mFragment;
|
||||
private DashboardFragment mFragment;
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private AccountManager mAccountManager;
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
|
@@ -297,6 +297,14 @@ public class DashboardFragmentTest {
|
||||
mTestFragment.updatePreferenceVisibility(prefControllers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forceUpdatePreferences_prefKeyNull_shouldNotCrash() {
|
||||
mTestFragment.addPreferenceController(new TestPreferenceController(mContext));
|
||||
|
||||
// Should not crash
|
||||
mTestFragment.forceUpdatePreferences();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkUiBlocker_noUiBlocker_controllerIsNull() {
|
||||
mTestFragment.mBlockerController = null;
|
||||
|
Reference in New Issue
Block a user