Merge stage-aosp-master to aosp-master - DO NOT MERGE

Change-Id: I2694d97892260c549e016c2c2255bbc6d35d74c6
diff --git a/library/main/src/com/android/car/setupwizardlib/BaseSetupWizardActivity.java b/library/main/src/com/android/car/setupwizardlib/BaseSetupWizardActivity.java
index cf9829b..910f37e 100644
--- a/library/main/src/com/android/car/setupwizardlib/BaseSetupWizardActivity.java
+++ b/library/main/src/com/android/car/setupwizardlib/BaseSetupWizardActivity.java
@@ -152,6 +152,14 @@
         super.onSaveInstanceState(outState);
     }
 
+    @Override
+    public void onWindowFocusChanged(boolean hasFocus) {
+        super.onWindowFocusChanged(hasFocus);
+        if (hasFocus) {
+            CarSetupWizardUiUtils.maybeHideSystemUI(this);
+        }
+    }
+
     // Content Fragment accessors
 
     /**
diff --git a/library/main/src/com/android/car/setupwizardlib/CarSetupWizardBaseLayout.java b/library/main/src/com/android/car/setupwizardlib/CarSetupWizardBaseLayout.java
index 6a95a15..1ef99bb 100644
--- a/library/main/src/com/android/car/setupwizardlib/CarSetupWizardBaseLayout.java
+++ b/library/main/src/com/android/car/setupwizardlib/CarSetupWizardBaseLayout.java
@@ -202,20 +202,14 @@
         }
         primaryToolbarButtonStub.inflate();
         setPrimaryToolbarButton(findViewById(R.id.primary_toolbar_button));
-        if (showPrimaryToolbarButton) {
-            setPrimaryToolbarButtonText(primaryToolbarButtonText);
-            setPrimaryToolbarButtonEnabled(primaryToolbarButtonEnabled);
-            stylePrimaryToolbarButton(mPrimaryToolbarButton);
-        } else {
-            setPrimaryToolbarButtonVisible(false);
-        }
+        stylePrimaryToolbarButton(mPrimaryToolbarButton);
+        setPrimaryToolbarButtonText(primaryToolbarButtonText);
+        setPrimaryToolbarButtonEnabled(primaryToolbarButtonEnabled);
+        setPrimaryToolbarButtonVisible(showPrimaryToolbarButton);
 
         // Set the secondary continue button visibility and text based on the custom attributes.
-        ViewStub secondaryToolbarButtonStub =
-                (ViewStub) findViewById(R.id.secondary_toolbar_button_stub);
         if (showSecondaryToolbarButton || !TextUtils.isEmpty(secondaryToolbarButtonText)) {
-            secondaryToolbarButtonStub.inflate();
-            mSecondaryToolbarButton = findViewById(R.id.secondary_toolbar_button);
+            inflateSecondaryToolbarButtonIfNecessary();
             setSecondaryToolbarButtonText(secondaryToolbarButtonText);
             setSecondaryToolbarButtonEnabled(secondaryToolbarButtonEnabled);
             setSecondaryToolbarButtonVisible(showSecondaryToolbarButton);
@@ -445,7 +439,7 @@
         if (!visible && mSecondaryToolbarButton == null) {
             return;
         }
-        maybeInflateSecondaryToolbarButton();
+        inflateSecondaryToolbarButtonIfNecessary();
         setViewVisible(mSecondaryToolbarButton, visible);
     }
 
@@ -453,7 +447,7 @@
      * Sets whether the secondary continue button is enabled.
      */
     public void setSecondaryToolbarButtonEnabled(boolean enabled) {
-        maybeInflateSecondaryToolbarButton();
+        inflateSecondaryToolbarButtonIfNecessary();
         mSecondaryToolbarButton.setEnabled(enabled);
     }
 
@@ -461,7 +455,7 @@
      * Sets the secondary continue button text to the given text.
      */
     public void setSecondaryToolbarButtonText(String text) {
-        maybeInflateSecondaryToolbarButton();
+        inflateSecondaryToolbarButtonIfNecessary();
         mSecondaryToolbarButton.setText(text);
     }
 
@@ -470,7 +464,7 @@
      * listener should be overridden so no callback is made.
      */
     public void setSecondaryToolbarButtonListener(@Nullable View.OnClickListener listener) {
-        maybeInflateSecondaryToolbarButton();
+        inflateSecondaryToolbarButtonIfNecessary();
         mSecondaryToolbarButton.setOnClickListener(listener);
     }
 
@@ -576,7 +570,7 @@
      * A method that inflates the SecondaryToolbarButton if it is has not already been
      * inflated. If it has been inflated already this method will do nothing.
      */
-    private void maybeInflateSecondaryToolbarButton() {
+    private void inflateSecondaryToolbarButtonIfNecessary() {
         ViewStub secondaryToolbarButtonStub = findViewById(R.id.secondary_toolbar_button_stub);
         // If the secondaryToolbarButtonStub is null then the stub has been inflated so there is
         // nothing to do.
diff --git a/library/main/tests/robotests/res/layout/car_setup_wizard_layout_alternative_activity.xml b/library/main/tests/robotests/res/layout/car_setup_wizard_layout_alternative_activity.xml
new file mode 100644
index 0000000..5de2a09
--- /dev/null
+++ b/library/main/tests/robotests/res/layout/car_setup_wizard_layout_alternative_activity.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2019 Google Inc.
+
+    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.
+-->
+<com.android.car.setupwizardlib.CarSetupWizardCompatLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:id="@+id/car_setup_wizard_layout"
+    android:orientation="vertical"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    app:showPrimaryToolbarButton="false"
+    app:showSecondaryToolbarButton="true"/>
diff --git a/library/main/tests/robotests/res/layout/car_setup_wizard_layout_test_activity.xml b/library/main/tests/robotests/res/layout/car_setup_wizard_layout_test_activity.xml
index dd74b11..a9bcfbe 100644
--- a/library/main/tests/robotests/res/layout/car_setup_wizard_layout_test_activity.xml
+++ b/library/main/tests/robotests/res/layout/car_setup_wizard_layout_test_activity.xml
@@ -16,7 +16,6 @@
 -->
 <com.android.car.setupwizardlib.CarSetupWizardCompatLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:custom="http://schemas.android.com/apk/res-auto"
     android:id="@+id/car_setup_wizard_layout"
     android:orientation="vertical"
     android:layout_width="match_parent"
diff --git a/library/main/tests/robotests/res/values/attrs.xml b/library/main/tests/robotests/res/values/attrs.xml
new file mode 100644
index 0000000..4454939
--- /dev/null
+++ b/library/main/tests/robotests/res/values/attrs.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2019 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>
+    <!-- Custom attribute definitions for the CarSetupWizardBaseLayout -->
+    <declare-styleable name="CarSetupWizardBaseLayout">
+        <!-- Attributes related to the visibility of the back button -->
+        <attr name="showBackButton" format="boolean"/>
+
+        <!-- Attributes related to the visibility and text of the toolbar title -->
+        <attr name="showToolbarTitle" format="boolean"/>
+        <attr name="toolbarTitleText" format="string"/>
+
+        <!--  Attributes related to the visibility and text of primary continue button -->
+        <attr name="showPrimaryToolbarButton" format="boolean"/>
+        <attr name="primaryToolbarButtonText" format="string"/>
+        <attr name="primaryToolbarButtonEnabled" format="boolean"/>
+        <attr name="primaryToolbarButtonFlat" format="boolean"/>
+
+        <!--  Attributes related to the visibility and text of secondary continue button -->
+        <attr name="showSecondaryToolbarButton" format="boolean"/>
+        <attr name="secondaryToolbarButtonText" format="string"/>
+        <attr name="secondaryToolbarButtonEnabled" format="boolean"/>
+
+        <!--  Attributes related to the visibility and indeterminate/determinate state
+              of the progress bar -->
+        <attr name="showProgressBar" format="boolean"/>
+        <attr name="indeterminateProgressBar" format="boolean"/>
+    </declare-styleable>
+
+</resources>
\ No newline at end of file
diff --git a/library/main/tests/robotests/src/com/android/car/setupwizardlib/CarSetupWizardCompatLayoutTest.java b/library/main/tests/robotests/src/com/android/car/setupwizardlib/CarSetupWizardCompatLayoutTest.java
index dddb660..2ec9db8 100644
--- a/library/main/tests/robotests/src/com/android/car/setupwizardlib/CarSetupWizardCompatLayoutTest.java
+++ b/library/main/tests/robotests/src/com/android/car/setupwizardlib/CarSetupWizardCompatLayoutTest.java
@@ -31,8 +31,10 @@
 import androidx.annotation.ColorRes;
 import androidx.annotation.StyleRes;
 
+import com.android.car.setupwizardlib.partner.ExternalResources;
 import com.android.car.setupwizardlib.partner.FakeOverrideContentProvider;
 import com.android.car.setupwizardlib.partner.PartnerConfig;
+import com.android.car.setupwizardlib.partner.ResourceEntry;
 import com.android.car.setupwizardlib.robolectric.BaseRobolectricTest;
 import com.android.car.setupwizardlib.robolectric.TestHelper;
 
@@ -46,6 +48,8 @@
 import org.robolectric.shadows.ShadowTextView;
 import org.robolectric.util.ReflectionHelpers;
 
+import java.util.Arrays;
+import java.util.List;
 import java.util.Locale;
 
 /**
@@ -59,10 +63,25 @@
 
     private CarSetupWizardCompatLayout mCarSetupWizardCompatLayout;
 
+    private static final String TEST_PACKAGE_NAME = "test.packageName";
+
+    private static final PartnerConfig TEST_TOOLBAR_BUTTON_TEXT_SIZE_RESOURCE_NAME =
+            PartnerConfig.CONFIG_TOOLBAR_BUTTON_TEXT_SIZE;
+
+    private static final float TOLERANCE = 0.001f;
+    // A small value is picked so that it's not likely to coincide with the default font size
+    private static final float EXCEPTED_TEXT_SIZE = 4;
+
     @Before
     public void setUp() {
-        mCarSetupWizardCompatLayout = createCarSetupWizardCompatLayout();
+        FakeOverrideContentProvider fakeOverrideDataProvider =
+                FakeOverrideContentProvider.installEmptyProvider();
+        List<ResourceEntry> resourceEntries = prepareFakeData();
+        for (ResourceEntry entry : resourceEntries) {
+            fakeOverrideDataProvider.injectResourceEntry(entry);
+        }
 
+        mCarSetupWizardCompatLayout = createCarSetupWizardCompatLayout();
         // Have to make this call first to ensure secondaryToolbar button is created from stub.
         mCarSetupWizardCompatLayout.setSecondaryToolbarButtonVisible(true);
         mCarSetupWizardCompatLayout.setSecondaryToolbarButtonVisible(false);
@@ -501,6 +520,30 @@
                 .isEqualTo(getDrawbleDefaultColor(expected));
     }
 
+    @Test
+    public void test_bothButtons_areStyled_inDefaultLayout() {
+        Button primaryButton = mCarSetupWizardCompatLayout.getPrimaryToolbarButton();
+        Button secondaryButton = mCarSetupWizardCompatLayout.getSecondaryToolbarButton();
+
+        assertThat(primaryButton.getTextSize()).isWithin(TOLERANCE).of(EXCEPTED_TEXT_SIZE);
+        assertThat(secondaryButton.getTextSize()).isWithin(TOLERANCE).of(EXCEPTED_TEXT_SIZE);
+    }
+
+    @Test
+    public void test_bothButtons_areStyled_inAlternativeLayout() {
+        Activity activity = Robolectric
+                .buildActivity(CarSetupWizardLayoutAlternativeActivity.class)
+                .create()
+                .get();
+        CarSetupWizardCompatLayout layout = activity.findViewById(R.id.car_setup_wizard_layout);
+
+        Button primaryButton = layout.getPrimaryToolbarButton();
+        Button secondaryButton = layout.getSecondaryToolbarButton();
+
+        assertThat(primaryButton.getTextSize()).isWithin(TOLERANCE).of(EXCEPTED_TEXT_SIZE);
+        assertThat(secondaryButton.getTextSize()).isWithin(TOLERANCE).of(EXCEPTED_TEXT_SIZE);
+    }
+
     private void setupFakeContentProvider() {
         FakeOverrideContentProvider.installDefaultProvider();
     }
@@ -519,4 +562,22 @@
         ColorStateList colorStateList = ReflectionHelpers.getField(state, "mColor");
         return colorStateList.getDefaultColor();
     }
+
+    private List<ResourceEntry> prepareFakeData() {
+        ExternalResources.Resources testResources =
+                ExternalResources.injectExternalResources(TEST_PACKAGE_NAME);
+
+        testResources.putDimension(
+                TEST_TOOLBAR_BUTTON_TEXT_SIZE_RESOURCE_NAME.getResourceName(), EXCEPTED_TEXT_SIZE);
+
+        return Arrays.asList(
+                new ResourceEntry(
+                        TEST_PACKAGE_NAME,
+                        TEST_TOOLBAR_BUTTON_TEXT_SIZE_RESOURCE_NAME.getResourceName(),
+                        testResources.getIdentifier(
+                                TEST_TOOLBAR_BUTTON_TEXT_SIZE_RESOURCE_NAME.getResourceName(),
+                                /* defType= */ "dimen",
+                                TEST_PACKAGE_NAME))
+        );
+    }
 }
diff --git a/library/main/tests/robotests/src/com/android/car/setupwizardlib/CarSetupWizardLayoutAlternativeActivity.java b/library/main/tests/robotests/src/com/android/car/setupwizardlib/CarSetupWizardLayoutAlternativeActivity.java
new file mode 100644
index 0000000..b20da7c
--- /dev/null
+++ b/library/main/tests/robotests/src/com/android/car/setupwizardlib/CarSetupWizardLayoutAlternativeActivity.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+package com.android.car.setupwizardlib;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+/**
+ * Activity for CarSetupWizardLayoutTest where primary button isn't shown but secondary button is.
+ */
+public class CarSetupWizardLayoutAlternativeActivity extends Activity {
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.car_setup_wizard_layout_alternative_activity);
+    }
+}
diff --git a/library/main/tests/robotests/src/com/android/car/setupwizardlib/partner/ExternalResources.java b/library/main/tests/robotests/src/com/android/car/setupwizardlib/partner/ExternalResources.java
index 16a6d2a..fec2290 100644
--- a/library/main/tests/robotests/src/com/android/car/setupwizardlib/partner/ExternalResources.java
+++ b/library/main/tests/robotests/src/com/android/car/setupwizardlib/partner/ExternalResources.java
@@ -44,7 +44,7 @@
  * used with {@link org.robolectric.shadows.ShadowPackageManager#resources} to simulate loading
  * resources from another package.
  */
-class ExternalResources {
+public class ExternalResources {
 
     public static Resources injectExternalResources(String packageName) {
         return injectExternalResources(createPackageInfo(packageName));
diff --git a/library/utils/Android.bp b/library/utils/Android.bp
index ac1f514..f8cb4c7 100644
--- a/library/utils/Android.bp
+++ b/library/utils/Android.bp
@@ -15,8 +15,14 @@
 
 android_library {
     name: "car-setup-wizard-lib-utils",
-    srcs: ["src/**/*.java",
-            "src/**/*.aidl"],
+    srcs: [
+        "src/**/*.java",
+        "src/com/android/car/setupwizardlib/IInitialLockSetupService.aidl",
+        "src/com/android/car/setupwizardlib/InitialLockListener.java",
+        "src/com/android/car/setupwizardlib/InitialLockSetupClient.java",
+        "src/com/android/car/setupwizardlib/InitialLockSetupConstants.java",
+        "src/com/android/car/setupwizardlib/InitialLockSetupHelper.java",
+    ],
     libs: ["android.car"],
     optimize: {
         enabled: false,