Import updated Android SetupCompat Library 437961224 am: 76ab3e344b am: c9e1534352

Original change: https://googleplex-android-review.googlesource.com/c/platform/external/setupcompat/+/17506552

Change-Id: I7fd9a66ba4c52143bc0ca1ce588537577c1601e6
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/main/java/com/google/android/setupcompat/util/WizardManagerHelper.java b/main/java/com/google/android/setupcompat/util/WizardManagerHelper.java
index 84bd68b..90de25e 100644
--- a/main/java/com/google/android/setupcompat/util/WizardManagerHelper.java
+++ b/main/java/com/google/android/setupcompat/util/WizardManagerHelper.java
@@ -186,6 +186,17 @@
   }
 
   /**
+   * Checks whether an intent is running in the portal setup wizard flow.
+   *
+   * @param originalIntent The original intent that was used to start the step, usually via {@link
+   *     Activity#getIntent()}.
+   * @return true if the intent passed in was running in portal setup wizard.
+   */
+  public static boolean isPortalSetupWizard(Intent originalIntent) {
+    return originalIntent != null && originalIntent.getBooleanExtra(EXTRA_IS_PORTAL_SETUP, false);
+  }
+
+  /**
    * Checks whether an intent is running in the deferred setup wizard flow.
    *
    * @param originalIntent The original intent that was used to start the step, usually via {@link
diff --git a/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigHelper.java b/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigHelper.java
index 98f6b6b..aca9a07 100644
--- a/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigHelper.java
+++ b/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigHelper.java
@@ -35,6 +35,7 @@
 import androidx.annotation.Nullable;
 import androidx.annotation.VisibleForTesting;
 import com.google.android.setupcompat.partnerconfig.PartnerConfig.ResourceType;
+import com.google.android.setupcompat.util.BuildCompatUtils;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.EnumMap;
@@ -547,10 +548,10 @@
     if (fallbackBundle != null) {
       resourceEntryBundle.putBundle(KEY_FALLBACK_CONFIG, fallbackBundle.getBundle(resourceName));
     }
-    ResourceEntry tempResult =
+    ResourceEntry adjustResourceEntry =
         adjustResourceEntryDefaultValue(
             context, ResourceEntry.fromBundle(context, resourceEntryBundle));
-    return adjustResourceEntryDayNightMode(context, tempResult);
+    return adjustResourceEntryDayNightMode(context, adjustResourceEntry);
   }
 
   /**
@@ -576,11 +577,10 @@
   }
 
   // Check the MNStyle flag and replace the inputResourceEntry.resourceName &
-  // inputResourceEntry.resourceId
-  private ResourceEntry adjustResourceEntryDefaultValue(
-      Context context, ResourceEntry inputResourceEntry) {
-    boolean useMaterialYouDefaultValue = shouldApplyMaterialYouStyle(context);
-    if (useMaterialYouDefaultValue) {
+  // inputResourceEntry.resourceId after T, that means if using Gliv4 before S, will always use
+  // glifv3 resources.
+  ResourceEntry adjustResourceEntryDefaultValue(Context context, ResourceEntry inputResourceEntry) {
+    if (BuildCompatUtils.isAtLeastT() && shouldApplyMaterialYouStyle(context)) {
       // If not overlay resource
       try {
         if (SUW_PACKAGE_NAME.equals(inputResourceEntry.getPackageName())) {
@@ -678,9 +678,12 @@
             IS_EXTENDED_PARTNER_CONFIG_ENABLED_METHOD, false));
   }
 
-  /** Returns true if the SetupWizard is flow enabled "Material You(Glifv4)" style. */
+  /**
+   * Returns true if the SetupWizard is flow enabled "Material You(Glifv4)" style, or the result of
+   * shouldApplyExtendedPartnerConfig() in SDK S as fallback.
+   */
   public static boolean shouldApplyMaterialYouStyle(@NonNull Context context) {
-    if (applyMaterialYouConfigBundle == null) {
+    if (applyMaterialYouConfigBundle == null || applyMaterialYouConfigBundle.isEmpty()) {
       try {
         applyMaterialYouConfigBundle =
             context
@@ -690,6 +693,13 @@
                     IS_MATERIAL_YOU_STYLE_ENABLED_METHOD,
                     /* arg= */ null,
                     /* extras= */ null);
+        // The suw version did not support the flag yet, fallback to
+        // shouldApplyExtendedPartnerConfig() for SDK S.
+        if (applyMaterialYouConfigBundle != null
+            && applyMaterialYouConfigBundle.isEmpty()
+            && !BuildCompatUtils.isAtLeastT()) {
+          return shouldApplyExtendedPartnerConfig(context);
+        }
       } catch (IllegalArgumentException | SecurityException exception) {
         Log.w(TAG, "SetupWizard Material You configs supporting status unknown; return as false.");
         applyMaterialYouConfigBundle = null;