Merge tag 'android-14.0.0_r54' into leaf-3.2

Android 14.0.0 release 54

* tag 'android-14.0.0_r54':
  Bump minSdk to 21

Change-Id: I970c23217246cb063cb492f0eff756fc4c3027a4
diff --git a/main/java/com/google/android/setupcompat/util/WizardManagerHelper.java b/main/java/com/google/android/setupcompat/util/WizardManagerHelper.java
index 1378c06..bb78eba 100644
--- a/main/java/com/google/android/setupcompat/util/WizardManagerHelper.java
+++ b/main/java/com/google/android/setupcompat/util/WizardManagerHelper.java
@@ -49,6 +49,11 @@
     }
   }
 
+  // EXTRA_SCRIPT_URI and EXTRA_ACTION_ID are used in setup wizard in versions before M and are
+  // kept for backwards compatibility.
+  @VisibleForTesting static final String EXTRA_SCRIPT_URI = "scriptUri";
+  @VisibleForTesting static final String EXTRA_ACTION_ID = "actionId";
+
   /** Extra for notifying an Activity that what SetupWizard flow is. */
   public static final String EXTRA_SUW_LIFECYCLE = "suw_lifecycle";
 
@@ -143,6 +148,10 @@
       dstIntent.putExtra(key, srcIntent.getBooleanExtra(key, false));
     }
 
+    for (String key : Arrays.asList(EXTRA_THEME, EXTRA_SCRIPT_URI, EXTRA_ACTION_ID)) {
+      dstIntent.putExtra(key, srcIntent.getStringExtra(key));
+    }
+
     // The TikTok code in Restore doesn't let us put serializable extras into intents.
     dstIntent.putExtra(
         EXTRA_SUW_LIFECYCLE,
diff --git a/main/res/values-land/dimens.xml b/main/res/values-land/dimens.xml
new file mode 100644
index 0000000..57c9372
--- /dev/null
+++ b/main/res/values-land/dimens.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <dimen name="setup_compat_footer_button_min_height">36.0dip</dimen>
+    <dimen name="setup_compat_footer_button_padding_bottom">0.0dip</dimen>
+    <dimen name="setup_compat_footer_button_padding_top">0.0dip</dimen>
+    <dimen name="setup_design_content_padding_top">32.0dip</dimen>
+    <dimen name="setup_design_layout_margin_end">32.0dip</dimen>
+    <dimen name="setup_design_layout_margin_start">32.0dip</dimen>
+</resources>
diff --git a/main/res/values-night/config.xml b/main/res/values-night/config.xml
new file mode 100644
index 0000000..13894ab
--- /dev/null
+++ b/main/res/values-night/config.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2018 The Android Open Source Project
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+
+<resources>
+    <bool name="setup_compat_light_navigation_bar">false</bool>
+    <bool name="setup_compat_light_status_bar">false</bool>
+</resources>
diff --git a/main/res/values/config.xml b/main/res/values/config.xml
index 99bad1c..0b43583 100644
--- a/main/res/values/config.xml
+++ b/main/res/values/config.xml
@@ -20,4 +20,46 @@
     <!-- ID used with View#setTag to store the original weight on a ButtonBar -->
     <item name="suc_customization_original_weight" type="id" />
 
+    <!-- Pixel theme -->
+    <string name="setup_design_layout_gravity">start</string>
+    <integer name="setup_design_header_auto_size_max_line_of_max_size">2</integer>
+    <dimen name="setup_compat_footer_button_min_height">56.0dip</dimen>
+    <dimen name="setup_compat_footer_button_padding_bottom">6.0dip</dimen>
+    <dimen name="setup_compat_footer_button_padding_top">6.0dip</dimen>
+    <dimen name="setup_compat_footer_button_radius">26.0dip</dimen>
+    <dimen name="setup_compat_footer_button_text_size">14.0sp</dimen>
+    <dimen name="setup_design_content_info_icon_margin_end">16.0dip</dimen>
+    <dimen name="setup_design_content_info_icon_size">18.0dip</dimen>
+    <dimen name="setup_design_content_info_line_spacing_extra">8.0sp</dimen>
+    <dimen name="setup_design_content_info_padding_bottom">16.0dip</dimen>
+    <dimen name="setup_design_content_info_padding_top">16.0dip</dimen>
+    <dimen name="setup_design_content_info_text_size">16.0sp</dimen>
+    <dimen name="setup_design_content_padding_top">8.0dip</dimen>
+    <dimen name="setup_design_content_text_size">18.0sp</dimen>
+    <dimen name="setup_design_description_text_margin_bottom">0.0dip</dimen>
+    <dimen name="setup_design_description_text_margin_top">24.0dip</dimen>
+    <dimen name="setup_design_description_text_size">18.0sp</dimen>
+    <dimen name="setup_design_header_auto_size_line_spacing_extra">8.0sp</dimen>
+    <dimen name="setup_design_header_auto_size_max_text_size">36.0sp</dimen>
+    <dimen name="setup_design_header_auto_size_min_text_size">28.0sp</dimen>
+    <dimen name="setup_design_header_container_margin_bottom">24.0dip</dimen>
+    <dimen name="setup_design_header_text_margin_bottom">0.0dip</dimen>
+    <dimen name="setup_design_header_text_margin_top">24.0dip</dimen>
+    <dimen name="setup_design_header_text_size">36.0sp</dimen>
+    <dimen name="setup_design_icon_margin_top">32.0dip</dimen>
+    <dimen name="setup_design_icon_size">48.0dip</dimen>
+    <dimen name="setup_design_items_min_height">72.0dip</dimen>
+    <dimen name="setup_design_items_padding_bottom">16.0dip</dimen>
+    <dimen name="setup_design_items_padding_top">16.0dip</dimen>
+    <dimen name="setup_design_items_summary_margin_top">4.0dip</dimen>
+    <dimen name="setup_design_items_summary_text_size">14.0sp</dimen>
+    <dimen name="setup_design_items_title_text_size">20.0sp</dimen>
+    <dimen name="setup_design_layout_margin_end">24.0dip</dimen>
+    <dimen name="setup_design_layout_margin_start">40.0dip</dimen>
+    <bool name="dynamic_color_enabled">true</bool>
+    <bool name="extended_partner_config_enabled">true</bool>
+    <bool name="setup_design_header_auto_size_enabled">true</bool>
+    <bool name="setup_design_items_divider_shown">false</bool>
+    <bool name="setup_compat_light_navigation_bar">true</bool>
+    <bool name="setup_compat_light_status_bar">true</bool>
 </resources>
diff --git a/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigHelper.java b/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigHelper.java
index f027011..9bd844e 100644
--- a/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigHelper.java
+++ b/partnerconfig/java/com/google/android/setupcompat/partnerconfig/PartnerConfigHelper.java
@@ -115,6 +115,8 @@
 
   private static PartnerConfigHelper instance = null;
 
+  private final Context mContext;
+
   @VisibleForTesting Bundle resultBundle = null;
 
   @VisibleForTesting
@@ -192,6 +194,7 @@
     getPartnerConfigBundle(context);
 
     registerContentObserver(context);
+    mContext = context;
   }
 
   /**
@@ -200,7 +203,7 @@
    * are customized by the overlay APK.
    */
   public boolean isAvailable() {
-    return resultBundle != null && !resultBundle.isEmpty();
+    return (resultBundle != null && !resultBundle.isEmpty()) || mContext != null;
   }
 
   /**
@@ -210,7 +213,17 @@
    * overlay APK.
    */
   public boolean isPartnerConfigAvailable(PartnerConfig resourceConfig) {
-    return isAvailable() && resultBundle.containsKey(resourceConfig.getResourceName());
+    if (resultBundle != null && !resultBundle.isEmpty())
+      return resultBundle.containsKey(resourceConfig.getResourceName());
+    else {
+      String resType = resourceConfig.getResourceType().name().toLowerCase();
+      if (resType.equals("dimension"))
+        resType = "dimen";
+
+      int resId = mContext.getResources().getIdentifier(resourceConfig.getResourceName(), resType,
+          mContext.getPackageName());
+      return (resId != 0);
+    }
   }
 
   /**
@@ -328,9 +341,20 @@
 
       result = resource.getString(resId);
       partnerResourceCache.put(resourceConfig, result);
+      return result;
     } catch (NullPointerException exception) {
       // fall through
     }
+
+    Resources appResource = context.getResources();
+    int resIdApp = appResource.getIdentifier(resourceConfig.getResourceName(), "string",
+        context.getPackageName());
+
+    if (resIdApp != 0) {
+      result = appResource.getString(resIdApp);
+      partnerResourceCache.put(resourceConfig, result);
+    }
+
     return result;
   }
 
@@ -359,10 +383,21 @@
 
       result = resource.getStringArray(resId);
       Collections.addAll(listResult, result);
+      return listResult;
     } catch (NullPointerException exception) {
       // fall through
     }
 
+    Resources appResource = context.getResources();
+    int resIdApp = appResource.getIdentifier(resourceConfig.getResourceName(), "array",
+        context.getPackageName());
+
+    if (resIdApp != 0) {
+      result = appResource.getStringArray(resIdApp);
+      Collections.addAll(listResult, result);
+      return listResult;
+    }
+
     return listResult;
   }
 
@@ -394,9 +429,20 @@
 
       result = resource.getBoolean(resId);
       partnerResourceCache.put(resourceConfig, result);
+      return result;
     } catch (NullPointerException | NotFoundException exception) {
       // fall through
     }
+
+    Resources appResource = context.getResources();
+    int resIdApp = appResource.getIdentifier(resourceConfig.getResourceName(), "bool",
+        context.getPackageName());
+
+    if (resIdApp != 0) {
+      result = appResource.getBoolean(resIdApp);
+      partnerResourceCache.put(resourceConfig, result);
+    }
+
     return result;
   }
 
@@ -443,9 +489,23 @@
       result =
           getDimensionFromTypedValue(
               context, (TypedValue) partnerResourceCache.get(resourceConfig));
+      return result;
     } catch (NullPointerException | NotFoundException exception) {
       // fall through
     }
+
+    Resources appResource = context.getResources();
+    int resIdApp = appResource.getIdentifier(resourceConfig.getResourceName(), "dimen",
+        context.getPackageName());
+
+    if (resIdApp != 0) {
+      TypedValue value = getTypedValueFromResource(appResource, resIdApp,
+          TypedValue.TYPE_DIMENSION);
+      partnerResourceCache.put(resourceConfig, value);
+      result =
+          getDimensionFromTypedValue(
+              context, (TypedValue) partnerResourceCache.get(resourceConfig));
+    }
     return result;
   }
 
@@ -487,9 +547,19 @@
 
       result = resource.getFraction(resId, 1, 1);
       partnerResourceCache.put(resourceConfig, result);
+      return result;
     } catch (NullPointerException | NotFoundException exception) {
       // fall through
     }
+
+    Resources appResource = context.getResources();
+    int resIdApp = appResource.getIdentifier(resourceConfig.getResourceName(), "fraction",
+        context.getPackageName());
+
+    if (resIdApp != 0) {
+      result = appResource.getFraction(resIdApp, 1, 1);
+      partnerResourceCache.put(resourceConfig, result);
+    }
     return result;
   }
 
@@ -520,9 +590,19 @@
 
       result = resource.getInteger(resId);
       partnerResourceCache.put(resourceConfig, result);
+      return result;
     } catch (NullPointerException | NotFoundException exception) {
       // fall through
     }
+
+    Resources appResource = context.getResources();
+    int resIdApp = appResource.getIdentifier(resourceConfig.getResourceName(), "integer",
+        context.getPackageName());
+
+    if (resIdApp != 0) {
+      result = appResource.getInteger(resIdApp);
+      partnerResourceCache.put(resourceConfig, result);
+    }
     return result;
   }
 
@@ -818,9 +898,9 @@
                     /* arg= */ null,
                     /* extras= */ null);
       } catch (IllegalArgumentException | SecurityException exception) {
-        Log.w(TAG, "SetupWizard DayNight supporting status unknown; return as false.");
+        Log.w(TAG, "SetupWizard DayNight supporting status unknown; return as true.");
         suwDayNightEnabledBundle = null;
-        return false;
+        return true;
       }
     }
 
@@ -843,9 +923,9 @@
       } catch (IllegalArgumentException | SecurityException exception) {
         Log.w(
             TAG,
-            "SetupWizard extended partner configs supporting status unknown; return as false.");
+            "SetupWizard extended partner configs supporting status unknown; return as true.");
         applyExtendedPartnerConfigBundle = null;
-        return false;
+        return true;
       }
     }
 
@@ -928,9 +1008,9 @@
                     /* arg= */ null,
                     /* extras= */ null);
       } catch (IllegalArgumentException | SecurityException exception) {
-        Log.w(TAG, "SetupWizard dynamic color supporting status unknown; return as false.");
+        Log.w(TAG, "SetupWizard dynamic color supporting status unknown; return as true.");
         applyDynamicColorBundle = null;
-        return false;
+        return true;
       }
     }