Merge "Gray out the "Remove account" button when there's a restriction" into main

This commit is contained in:
Treehugger Robot
2023-08-17 09:22:10 +00:00
committed by Android (Google) Code Review
6 changed files with 226 additions and 51 deletions

View File

@@ -34,19 +34,17 @@ import android.os.UserManager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settings.widget.RestrictedButton;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.widget.LayoutPreference;
@@ -64,6 +62,7 @@ public class RemoveAccountPreferenceController extends AbstractPreferenceControl
private Fragment mParentFragment;
private UserHandle mUserHandle;
private LayoutPreference mRemoveAccountPreference;
private RestrictedButton mRemoveAccountButton;
public RemoveAccountPreferenceController(Context context, Fragment parent) {
super(context);
@@ -75,8 +74,14 @@ public class RemoveAccountPreferenceController extends AbstractPreferenceControl
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mRemoveAccountPreference = screen.findPreference(KEY_REMOVE_ACCOUNT);
final Button removeAccountButton = mRemoveAccountPreference.findViewById(R.id.button);
removeAccountButton.setOnClickListener(this);
mRemoveAccountButton = mRemoveAccountPreference.findViewById(R.id.button);
mRemoveAccountButton.setOnClickListener(this);
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
mRemoveAccountButton.updateState();
}
@Override
@@ -93,21 +98,13 @@ public class RemoveAccountPreferenceController extends AbstractPreferenceControl
public void onClick(View v) {
mMetricsFeatureProvider.logClickedPreference(mRemoveAccountPreference,
mMetricsFeatureProvider.getMetricsCategory(mParentFragment));
if (mUserHandle != null) {
final EnforcedAdmin admin = RestrictedLockUtilsInternal.checkIfRestrictionEnforced(
mContext, UserManager.DISALLOW_MODIFY_ACCOUNTS, mUserHandle.getIdentifier());
if (admin != null) {
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(mContext, admin);
return;
}
}
ConfirmRemoveAccountDialog.show(mParentFragment, mAccount, mUserHandle);
}
public void init(Account account, UserHandle userHandle) {
mAccount = account;
mUserHandle = userHandle;
mRemoveAccountButton.init(mUserHandle, UserManager.DISALLOW_MODIFY_ACCOUNTS);
}
/**