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

Commit 5062b6ea authored by Jerry Shi's avatar Jerry Shi
Browse files

Add a new config to support primary credential providers. Also renamed

the existing defaultCredentialProvider to enabledCredentialProvider to
reduce the confusiton.

Test: built locally
Bug: 280492574

Change-Id: Ife5c36f2c26f854465f2353e641ac06233854a85
parent cf3cbe8a
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -4464,17 +4464,27 @@
    -->
    <string name="config_defaultCredentialManagerHybridService" translatable="false"></string>

    <!-- The component name, flattened to a string, for the system's credential manager
      provider service. This service allows credential retrieval and storage od credentials.
    <!-- The component name(s), flattened to a string, for the system's credential manager
      provider services. These services allow retrieving and storing credentials.

     This service must be trusted, as it can be activated without explicit consent of the user.
     These services must be trusted, as they can be activated without explicit consent of the user.
     If no service with the specified name exists on the device, there will be no user configurable
     provider to service credential manager requests. However, credential manager system
     services that do not require user consent, will still work.

     See android.credentials.CredentialManager
    -->
    <string-array name="config_defaultCredentialProviderService" translatable="false">
    <string-array name="config_enabledCredentialProviderService" translatable="false">
    </string-array>

    <!-- The component name(s), flattened to a string, for the system's primary credential manager
      provider services. These service will be used by default for storing credentials.

     These services must be trusted, as they can be activated without explicit consent of the user.

     See android.credentials.CredentialManager
    -->
    <string-array name="config_primaryCredentialProviderService" translatable="false">
    </string-array>

    <!-- The package name for the system's smartspace service.
+2 −1
Original line number Diff line number Diff line
@@ -3756,7 +3756,8 @@
  <java-symbol type="string" name="config_defaultAppPredictionService" />
  <java-symbol type="string" name="config_defaultContentSuggestionsService" />
  <java-symbol type="string" name="config_defaultCredentialManagerHybridService" />
  <java-symbol type="array" name="config_defaultCredentialProviderService" />
  <java-symbol type="array" name="config_enabledCredentialProviderService" />
  <java-symbol type="array" name="config_primaryCredentialProviderService" />
  <java-symbol type="string" name="config_defaultSearchUiService" />
  <java-symbol type="string" name="config_defaultSmartspaceService" />
  <java-symbol type="string" name="config_defaultWallpaperEffectsGenerationService" />
+33 −41
Original line number Diff line number Diff line
@@ -3748,7 +3748,7 @@ public class SettingsProvider extends ContentProvider {
        }

        private final class UpgradeController {
            private static final int SETTINGS_VERSION = 219;
            private static final int SETTINGS_VERSION = 220;

            private final int mUserId;

@@ -5656,45 +5656,7 @@ public class SettingsProvider extends ContentProvider {
                }

                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.array.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);
                        }
                    }

                    // Version 214: Removed, moved to version 216
                    currentVersion = 215;
                }

@@ -5732,7 +5694,7 @@ public class SettingsProvider extends ContentProvider {
                            .getSettingLocked(Settings.Secure.CREDENTIAL_SERVICE);
                    if (currentSetting.isNull()) {
                        final int resourceId =
                            com.android.internal.R.array.config_defaultCredentialProviderService;
                            com.android.internal.R.array.config_enabledCredentialProviderService;
                        final Resources resources = getContext().getResources();
                        // If the config has not be defined we might get an exception.
                        final List<String> providers = new ArrayList<>();
@@ -5848,6 +5810,36 @@ public class SettingsProvider extends ContentProvider {
                    currentVersion = 219;
                }

                if (currentVersion == 219) {

                    final SettingsState secureSettings = getSecureSettingsLocked(userId);
                    final Setting currentSetting = secureSettings
                            .getSettingLocked(Settings.Secure.CREDENTIAL_SERVICE_PRIMARY);
                    if (currentSetting.isNull()) {
                        final int resourceId =
                              com.android.internal.R.array.config_primaryCredentialProviderService;
                        final Resources resources = getContext().getResources();
                        // If the config has not be defined we might get an exception.
                        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());
                        }

                        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_PRIMARY, defaultValue, null,
                                    true, SettingsState.SYSTEM_PACKAGE_NAME);
                        }
                    }
                    currentVersion = 220;
                }

                // vXXX: Add new settings above this point.

                if (currentVersion != newVersion) {