Move reset options to one place
Change-Id: I419c16cbfc69861e01f28c14abdde137bd78f0bb Fix: 36458355 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -15,22 +15,30 @@
|
||||
*/
|
||||
package com.android.settings.system;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.content.Context;
|
||||
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FactoryResetPreferenceController extends PreferenceController {
|
||||
/** Key of the "Factory reset" preference in {@link R.xml.system_dashboard_fragment}.*/
|
||||
/** Key of the "Factory reset" preference in {@link R.xml.reset_dashboard_fragment}. */
|
||||
private static final String KEY_FACTORY_RESET = "factory_reset";
|
||||
|
||||
private final UserManager mUm;
|
||||
private final AccountManager mAm;
|
||||
|
||||
public FactoryResetPreferenceController(Context context, UserManager um) {
|
||||
public FactoryResetPreferenceController(Context context) {
|
||||
super(context);
|
||||
mUm = um;
|
||||
mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
mAm = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
|
||||
}
|
||||
|
||||
/** Hide "Factory reset" settings for secondary users. */
|
||||
@@ -43,4 +51,22 @@ public class FactoryResetPreferenceController extends PreferenceController {
|
||||
public String getPreferenceKey() {
|
||||
return KEY_FACTORY_RESET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
final List<UserInfo> profiles = mUm.getProfiles(UserHandle.myUserId());
|
||||
int accountsCount = 0;
|
||||
for (UserInfo userInfo : profiles) {
|
||||
final int profileId = userInfo.id;
|
||||
Account[] accounts = mAm.getAccountsAsUser(profileId);
|
||||
accountsCount += accounts.length;
|
||||
}
|
||||
if (accountsCount == 0) {
|
||||
preference.setSummary(R.string.master_clear_summary);
|
||||
} else {
|
||||
preference.setSummary(mContext.getResources().getQuantityString(
|
||||
R.plurals.master_clear_with_account_summary,
|
||||
accountsCount, accountsCount));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user