Add partner-customizable immersive mode
am: 5ac1671ba6

Change-Id: If319d5a4794c9c416eee4db917a9bc7e3a02885b
diff --git a/library/main/src/com/android/car/setupwizardlib/BaseSetupWizardActivity.java b/library/main/src/com/android/car/setupwizardlib/BaseSetupWizardActivity.java
index 03dba6b..cf9829b 100644
--- a/library/main/src/com/android/car/setupwizardlib/BaseSetupWizardActivity.java
+++ b/library/main/src/com/android/car/setupwizardlib/BaseSetupWizardActivity.java
@@ -29,6 +29,7 @@
 import androidx.fragment.app.FragmentActivity;
 
 import com.android.car.setupwizardlib.util.CarDrivingStateMonitor;
+import com.android.car.setupwizardlib.util.CarSetupWizardUiUtils;
 import com.android.car.setupwizardlib.util.CarWizardManagerHelper;
 
 /**
@@ -109,6 +110,8 @@
     @CallSuper
     protected void onStart() {
         super.onStart();
+        // Must be done here so that the SystemUI is hidden when back button is clicked
+        CarSetupWizardUiUtils.maybeHideSystemUI(this);
         // Fragment commits are not allowed once the Activity's state has been saved. Once
         // onStart() has been called, the FragmentManager should now allow commits.
         mAllowFragmentCommits = true;
diff --git a/library/main/src/com/android/car/setupwizardlib/partner/PartnerConfig.java b/library/main/src/com/android/car/setupwizardlib/partner/PartnerConfig.java
index 443e132..d3f6ea2 100644
--- a/library/main/src/com/android/car/setupwizardlib/partner/PartnerConfig.java
+++ b/library/main/src/com/android/car/setupwizardlib/partner/PartnerConfig.java
@@ -19,6 +19,9 @@
 /** Resources that can be customized by partner overlay APK. */
 public enum PartnerConfig {
 
+    CONFIG_IS_IMMERSIVE(
+            PartnerConfigKey.KEY_IS_IMMERSIVE, ResourceType.BOOLEAN),
+
     CONFIG_TOOLBAR_BG_COLOR(
             PartnerConfigKey.KEY_TOOLBAR_BG_COLOR, ResourceType.COLOR),
 
@@ -72,6 +75,7 @@
         DRAWABLE,
         STRING,
         DIMENSION,
+        BOOLEAN,
     }
 
     private final String mResourceName;
diff --git a/library/main/src/com/android/car/setupwizardlib/partner/PartnerConfigHelper.java b/library/main/src/com/android/car/setupwizardlib/partner/PartnerConfigHelper.java
index b337012..2f367a8 100644
--- a/library/main/src/com/android/car/setupwizardlib/partner/PartnerConfigHelper.java
+++ b/library/main/src/com/android/car/setupwizardlib/partner/PartnerConfigHelper.java
@@ -223,6 +223,42 @@
         return result;
     }
 
+    /**
+     * Returns the boolean value of given {@code partnerConfig}. If the given {@code partnerConfig}
+     * not found, will return {@code defaultValue}. If the {@code ResourceType} of given {@code
+     * resourceConfig} is not boolean, will throw IllegalArgumentException.
+     *
+     * @param context The context of client activity
+     * @param partnerConfig The {@code PartnerConfig} of target resource
+     * @param defaultValue The default value
+     */
+    public boolean getBoolean(
+            @NonNull Context context, PartnerConfig partnerConfig, boolean defaultValue) {
+        if (partnerConfig.getResourceType() != PartnerConfig.ResourceType.BOOLEAN) {
+            throw new IllegalArgumentException("Not a boolean resource");
+        }
+
+        if (mPartnerResourceCache.containsKey(partnerConfig)) {
+            return (boolean) mPartnerResourceCache.get(partnerConfig);
+        }
+
+        boolean result = defaultValue;
+        try {
+            String resourceName = partnerConfig.getResourceName();
+            ResourceEntry resourceEntry = getResourceEntryFromKey(resourceName);
+            if (resourceEntry == null) {
+                Log.w(TAG, "Resource not found: " + resourceName);
+                return defaultValue;
+            }
+            Resources resource = getResourcesByPackageName(context, resourceEntry.getPackageName());
+            result = resource.getBoolean(resourceEntry.getResourceId());
+            mPartnerResourceCache.put(partnerConfig, result);
+        } catch (PackageManager.NameNotFoundException exception) {
+            Log.e(TAG, exception.getMessage());
+        }
+        return result;
+    }
+
     private void getPartnerConfigBundle(Context context) {
         if (mResultBundle == null) {
             try {
diff --git a/library/main/src/com/android/car/setupwizardlib/partner/PartnerConfigKey.java b/library/main/src/com/android/car/setupwizardlib/partner/PartnerConfigKey.java
index e07b883..e98a533 100644
--- a/library/main/src/com/android/car/setupwizardlib/partner/PartnerConfigKey.java
+++ b/library/main/src/com/android/car/setupwizardlib/partner/PartnerConfigKey.java
@@ -23,6 +23,7 @@
 
 @Retention(RetentionPolicy.SOURCE)
 @StringDef({
+        PartnerConfigKey.KEY_IS_IMMERSIVE,
         PartnerConfigKey.KEY_TOOLBAR_BG_COLOR,
         PartnerConfigKey.KEY_TOOLBAR_BUTTON_ICON_BACK,
         PartnerConfigKey.KEY_TOOLBAR_BUTTON_FONT_FAMILY,
@@ -44,6 +45,8 @@
 /** Resource names that can be customized by partner overlay APK. */
 public @interface PartnerConfigKey {
 
+    String KEY_IS_IMMERSIVE = "suw_compat_is_immersive";
+
     String KEY_TOOLBAR_BG_COLOR = "suw_compat_toolbar_bg_color";
 
     String KEY_TOOLBAR_BUTTON_ICON_BACK = "suw_compat_toolbar_button_icon_back";
diff --git a/library/main/src/com/android/car/setupwizardlib/util/CarSetupWizardUiUtils.java b/library/main/src/com/android/car/setupwizardlib/util/CarSetupWizardUiUtils.java
new file mode 100644
index 0000000..5a87323
--- /dev/null
+++ b/library/main/src/com/android/car/setupwizardlib/util/CarSetupWizardUiUtils.java
@@ -0,0 +1,66 @@
+/*
+ * 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.util;
+
+import android.app.Activity;
+import android.util.Log;
+import android.view.View;
+
+import androidx.core.util.Preconditions;
+
+import com.android.car.setupwizardlib.partner.PartnerConfig;
+import com.android.car.setupwizardlib.partner.PartnerConfigHelper;
+
+/** Utilities to aid in UI for car setup wizard flow. */
+public final class CarSetupWizardUiUtils {
+    private static final String TAG = CarSetupWizardUiUtils.class.getSimpleName();
+    private static final boolean VERBOSE = Log.isLoggable(TAG, Log.VERBOSE);
+
+    /** Hide system UI if configured as such by partner */
+    public static void maybeHideSystemUI(Activity activity) {
+        Preconditions.checkNotNull(activity);
+
+        if (!PartnerConfigHelper.get(activity)
+                .getBoolean(activity, PartnerConfig.CONFIG_IS_IMMERSIVE, true)) {
+            if (VERBOSE) {
+                Log.v(TAG, "Immersive mode disabled");
+            }
+            return;
+        }
+        if (VERBOSE) {
+            Log.v(TAG, "Setting immersive mode for SystemUi");
+        }
+        // See https://developer.android.com/training/system-ui/immersive#EnableFullscreen
+        // Enables regular immersive mode.
+        // For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
+        // Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
+        View decorView = activity.getWindow().getDecorView();
+        decorView.setSystemUiVisibility(
+                View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
+                        // Set the content to appear under the system bars so that the
+                        // content doesn't resize when the system bars hide and show.
+                        | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
+                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+                        // Hide the nav bar and status bar
+                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
+                        | View.SYSTEM_UI_FLAG_FULLSCREEN);
+    }
+
+    private CarSetupWizardUiUtils() {
+    }
+}