Fix the issue the if primary provider is disabled by work admin, it
should be removed from the settings' storage. Test: locally built and tested Bug: 337040395 Change-Id: Ic572cd87f571d93ee0e7fa29157172444c7c36ce
This commit is contained in:
@@ -20,16 +20,20 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.credentials.CredentialManager;
|
import android.credentials.CredentialManager;
|
||||||
import android.credentials.CredentialProviderInfo;
|
import android.credentials.CredentialProviderInfo;
|
||||||
|
import android.credentials.SetEnabledProvidersException;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.OutcomeReceiver;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.service.autofill.AutofillService;
|
import android.service.autofill.AutofillService;
|
||||||
import android.service.autofill.AutofillServiceInfo;
|
import android.service.autofill.AutofillServiceInfo;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.autofill.AutofillManager;
|
import android.view.autofill.AutofillManager;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
@@ -41,6 +45,7 @@ import com.android.settingslib.widget.TwoTargetPreference;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
public class DefaultCombinedPreferenceController extends DefaultAppPreferenceController {
|
public class DefaultCombinedPreferenceController extends DefaultAppPreferenceController {
|
||||||
|
|
||||||
@@ -49,10 +54,12 @@ public class DefaultCombinedPreferenceController extends DefaultAppPreferenceCon
|
|||||||
|
|
||||||
private final AutofillManager mAutofillManager;
|
private final AutofillManager mAutofillManager;
|
||||||
private final CredentialManager mCredentialManager;
|
private final CredentialManager mCredentialManager;
|
||||||
|
private final Executor mExecutor;
|
||||||
|
|
||||||
public DefaultCombinedPreferenceController(Context context) {
|
public DefaultCombinedPreferenceController(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
|
mExecutor = ContextCompat.getMainExecutor(context);
|
||||||
mAutofillManager = mContext.getSystemService(AutofillManager.class);
|
mAutofillManager = mContext.getSystemService(AutofillManager.class);
|
||||||
|
|
||||||
if (CredentialManager.isServiceEnabled(context)) {
|
if (CredentialManager.isServiceEnabled(context)) {
|
||||||
@@ -158,6 +165,9 @@ public class DefaultCombinedPreferenceController extends DefaultAppPreferenceCon
|
|||||||
// Apply device admin restrictions to top provider.
|
// Apply device admin restrictions to top provider.
|
||||||
if (topProvider != null
|
if (topProvider != null
|
||||||
&& topProvider.getDeviceAdminRestrictions(mContext, userId) != null) {
|
&& topProvider.getDeviceAdminRestrictions(mContext, userId) != null) {
|
||||||
|
// This case means, the provider is blocked by device admin, but settings' storage has
|
||||||
|
// not be cleared correctly. So clean the storage here.
|
||||||
|
removePrimaryProvider();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,4 +219,28 @@ public class DefaultCombinedPreferenceController extends DefaultAppPreferenceCon
|
|||||||
mContext.createContextAsUser(UserHandle.of(getUser()), /* flags= */ 0);
|
mContext.createContextAsUser(UserHandle.of(getUser()), /* flags= */ 0);
|
||||||
return new Intent(context, CredentialsPickerActivity.class);
|
return new Intent(context, CredentialsPickerActivity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removePrimaryProvider() {
|
||||||
|
// Commit using the CredMan API.
|
||||||
|
if (mCredentialManager == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mCredentialManager.setEnabledProviders(
|
||||||
|
List.of(), // empty primary provider.
|
||||||
|
List.of(), // empty enabled providers.
|
||||||
|
getUser(),
|
||||||
|
mExecutor,
|
||||||
|
new OutcomeReceiver<Void, SetEnabledProvidersException>() {
|
||||||
|
@Override
|
||||||
|
public void onResult(Void result) {
|
||||||
|
Log.i(TAG, "setEnabledProviders success");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(SetEnabledProvidersException e) {
|
||||||
|
Log.e(TAG, "setEnabledProviders error: " + e.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user