Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1bf1e411 authored by Becca Hughes's avatar Becca Hughes
Browse files

Add support for default providers

Adds support for default providers
at the moment they also need to be
a system provider. CTS tests are
blocked on ag/21546183

Test: make
Bug: 267669743
Change-Id: I65ac62cd44550a0ab57a732d3effdc5a301d8dbb
parent 8c79f224
Loading
Loading
Loading
Loading
+44 −1
Original line number Diff line number Diff line
@@ -3695,7 +3695,7 @@ public class SettingsProvider extends ContentProvider {
        }

        private final class UpgradeController {
            private static final int SETTINGS_VERSION = 214;
            private static final int SETTINGS_VERSION = 215;

            private final int mUserId;

@@ -5650,6 +5650,49 @@ public class SettingsProvider extends ContentProvider {
                    currentVersion = 214;
                }

                if (currentVersion == 214) {
                    // Version 214: Set a default value for Credential Manager service.

                    final SettingsState secureSettings = getSecureSettingsLocked(userId);
                    final Setting currentSetting = secureSettings
                            .getSettingLocked(Settings.Secure.CREDENTIAL_SERVICE);
                    if (currentSetting.isNull()) {
                        final int resourceId =
                            com.android.internal.R.string.config_defaultCredentialProviderService;
                        final Resources resources = getContext().getResources();
                        // If the config has not be defined we might get an exception. We also get
                        // values from both the string array type and the single string in case the
                        // OEM uses the wrong one.
                        final List<String> providers = new ArrayList<>();
                        try {
                            providers.addAll(Arrays.asList(resources.getStringArray(resourceId)));
                        } catch (Resources.NotFoundException e) {
                            Slog.w(LOG_TAG,
                                "Get default array Cred Provider not found: " + e.toString());
                        }
                        try {
                            final String storedValue = resources.getString(resourceId);
                            if (!TextUtils.isEmpty(storedValue)) {
                                providers.add(storedValue);
                            }
                        } catch (Resources.NotFoundException e) {
                            Slog.w(LOG_TAG,
                                "Get default Cred Provider not found: " + e.toString());
                        }

                        if (!providers.isEmpty()) {
                            final String defaultValue = String.join(":", providers);
                            Slog.d(LOG_TAG, "Setting [" + defaultValue + "] as CredMan Service "
                                    + "for user " + userId);
                            secureSettings.insertSettingOverrideableByRestoreLocked(
                                    Settings.Secure.CREDENTIAL_SERVICE, defaultValue, null, true,
                                    SettingsState.SYSTEM_PACKAGE_NAME);
                        }
                    }

                    currentVersion = 215;
                }

                // vXXX: Add new settings above this point.

                if (currentVersion != newVersion) {