Merge "Count isActivityEmbedded() state to show split screen warning dialog" into udc-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 3f58e1e..d9e1735 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -657,6 +657,7 @@
         <activity android:name="Settings$FaceSettingsActivity"
             android:label="@string/security_settings_face_preference_title"
             android:exported="true"
+            android:configChanges="orientation|screenSize"
             android:icon="@drawable/ic_face_header">
             <intent-filter>
                 <action android:name="android.settings.FACE_SETTINGS" />
@@ -672,6 +673,7 @@
                   android:label="@string/security_settings_face_preference_title"
                   android:exported="false"
                   android:icon="@drawable/ic_face_header"
+                  android:configChanges="orientation|screenSize"
                   android:taskAffinity="com.android.settings.root">
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                        android:value="com.android.settings.biometrics.face.FaceSettings" />
diff --git a/res/values/strings.xml b/res/values/strings.xml
index d957e17..6d0577b 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -5433,6 +5433,10 @@
     <string name="battery_system_usage_for">System usage for <xliff:g id="slot">%s</xliff:g></string>
     <!-- [CHAR_LIMIT=NONE] Battery app usage section header -->
     <string name="battery_app_usage_for">App usage for <xliff:g id="slot">%s</xliff:g></string>
+    <!-- [CHAR_LIMIT=NONE] Battery system usage section header since last full charge to slot_timestamp. Please use similar text with tc/3248552137819897140 -->
+    <string name="battery_system_usage_since_last_full_charge_to">System usage since last full charge to <xliff:g id="slot_timestamp" example="Friday 10 am">%s</xliff:g></string>
+    <!-- [CHAR_LIMIT=NONE] Battery app usage section header since last full charge to slot_timestamp. Please use similar text with tc/7309909074935858949 -->
+    <string name="battery_app_usage_since_last_full_charge_to">App usage since last full charge to <xliff:g id="slot_timestamp" example="Friday 10 am">%s</xliff:g></string>
     <!-- [CHAR_LIMIT=NONE] Battery usage item for total usage time less than a minute -->
     <string name="battery_usage_total_less_than_one_minute">Total: less than a min</string>
     <!-- [CHAR_LIMIT=NONE] Battery usage item for total background time less than a minute -->
diff --git a/res/xml/development_settings.xml b/res/xml/development_settings.xml
index e7aac3e..b5ce57e 100644
--- a/res/xml/development_settings.xml
+++ b/res/xml/development_settings.xml
@@ -669,9 +669,6 @@
         <Preference
             android:key="tare"
             android:title="@string/tare_title" >
-            <intent
-                android:targetPackage="com.android.settings"
-                android:targetClass="com.android.settings.development.tare.TareHomePage" />
         </Preference>
 
         <SwitchPreference
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index 990f18a..5b2b983 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -52,9 +52,26 @@
     public static class AssistGestureSettingsActivity extends SettingsActivity { /* empty */}
     public static class BluetoothSettingsActivity extends SettingsActivity { /* empty */ }
     public static class CreateShortcutActivity extends SettingsActivity { /* empty */ }
-    public static class FaceSettingsActivity extends SettingsActivity { /* empty */ }
+    public static class FaceSettingsActivity extends SettingsActivity {
+        @Override
+        protected void onCreate(Bundle savedState) {
+            setTheme(SetupWizardUtils.getTheme(this, getIntent()));
+            setTheme(R.style.SettingsPreferenceTheme_SetupWizard);
+            ThemeHelper.trySetDynamicColor(this);
+            super.onCreate(savedState);
+        }
+    }
     /** Container for {@link FaceSettings} to use with a pre-defined task affinity. */
-    public static class FaceSettingsInternalActivity extends SettingsActivity { /* empty */ }
+    public static class FaceSettingsInternalActivity extends SettingsActivity {
+        @Override
+        protected void onCreate(Bundle savedState) {
+            setTheme(SetupWizardUtils.getTheme(this, getIntent()));
+            setTheme(R.style.SettingsPreferenceTheme_SetupWizard);
+            ThemeHelper.trySetDynamicColor(this);
+            super.onCreate(savedState);
+        }
+    }
+
     public static class FingerprintSettingsActivity extends SettingsActivity { /* empty */ }
     public static class CombinedBiometricSettingsActivity extends SettingsActivity { /* empty */ }
     public static class CombinedBiometricProfileSettingsActivity extends SettingsActivity { /* empty */ }
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
index 65d3be0..194a13a 100644
--- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
+++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
@@ -710,6 +710,7 @@
         controllers.add(new DefaultLaunchPreferenceController(context, "density"));
         controllers.add(new DefaultLaunchPreferenceController(context, "background_check"));
         controllers.add(new DefaultLaunchPreferenceController(context, "inactive_apps"));
+        controllers.add(new TarePreferenceController(context));
         controllers.add(new AutofillCategoryController(context, lifecycle));
         controllers.add(new AutofillLoggingLevelPreferenceController(context, lifecycle));
         controllers.add(new AutofillResetOptionsPreferenceController(context));
diff --git a/src/com/android/settings/development/TarePreferenceController.java b/src/com/android/settings/development/TarePreferenceController.java
new file mode 100644
index 0000000..8c70246
--- /dev/null
+++ b/src/com/android/settings/development/TarePreferenceController.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2023 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.settings.development;
+
+import android.app.tare.EconomyManager;
+import android.content.Context;
+import android.content.Intent;
+import android.os.UserManager;
+import android.provider.Settings;
+
+import androidx.preference.Preference;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.development.tare.TareHomePage;
+import com.android.settingslib.development.DeveloperOptionsPreferenceController;
+
+/** PreferenceController that serves as an entry point to the TARE configuration screen. */
+public class TarePreferenceController extends
+        DeveloperOptionsPreferenceController implements PreferenceControllerMixin {
+
+    private static final String KEY_TARE = "tare";
+
+    private final EconomyManager mEconomyManager;
+    private final UserManager mUserManager;
+
+    public TarePreferenceController(Context context) {
+        super(context);
+        mEconomyManager = context.getSystemService(EconomyManager.class);
+        mUserManager = context.getSystemService(UserManager.class);
+    }
+
+    @Override
+    public boolean isAvailable() {
+        // Enable the UI if the dedicated flag enables it or if TARE itself is on.
+        final boolean settingEnabled = Settings.Global.getInt(
+                mContext.getContentResolver(), Settings.Global.SHOW_TARE_DEVELOPER_OPTIONS, 0) == 1;
+        final boolean isTareUiEnabled = settingEnabled
+                || mEconomyManager.getEnabledMode() != EconomyManager.ENABLED_MODE_OFF;
+        return isTareUiEnabled
+                && !mUserManager.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return KEY_TARE;
+    }
+
+    @Override
+    public boolean handlePreferenceTreeClick(Preference preference) {
+        if (!KEY_TARE.equals(preference.getKey())) {
+            return false;
+        }
+        mContext.startActivity(new Intent(mContext, TareHomePage.class));
+        return false;
+    }
+}
diff --git a/src/com/android/settings/network/PrivateDnsPreferenceController.java b/src/com/android/settings/network/PrivateDnsPreferenceController.java
index ed6f9ed..4f727b1 100644
--- a/src/com/android/settings/network/PrivateDnsPreferenceController.java
+++ b/src/com/android/settings/network/PrivateDnsPreferenceController.java
@@ -89,8 +89,8 @@
             return UNSUPPORTED_ON_DEVICE;
         }
         final UserManager userManager = mContext.getSystemService(UserManager.class);
-        if (userManager.isGuestUser()) return DISABLED_FOR_USER;
-        return AVAILABLE;
+        if (userManager.isAdminUser()) return AVAILABLE;
+        return DISABLED_FOR_USER;
     }
 
     @Override
diff --git a/tests/robotests/src/com/android/settings/biometrics/face/FaceSettingsActivityTest.java b/tests/robotests/src/com/android/settings/biometrics/face/FaceSettingsActivityTest.java
new file mode 100644
index 0000000..2a95f4c
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/biometrics/face/FaceSettingsActivityTest.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2023 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.settings.biometrics.face;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
+
+import android.content.res.Resources;
+import android.os.Bundle;
+
+import com.android.settings.Settings;
+import com.android.settings.testutils.FakeFeatureFactory;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.android.controller.ActivityController;
+
+@RunWith(RobolectricTestRunner.class)
+public class FaceSettingsActivityTest {
+
+    private static final String APPLIED_SETUP_WIZARD_THEME = "SettingsPreferenceTheme.SetupWizard";
+
+    private Settings.FaceSettingsActivity mActivity;
+    private Resources.Theme mTheme;
+
+    @Before
+    public void setUp() {
+        FakeFeatureFactory.setupForTest();
+        mActivity = spy(Settings.FaceSettingsActivity.class);
+    }
+
+    @Test
+    public void verifyFaceSettingsActivity_shouldAppliedSetupWizardTheme() {
+        createActivity();
+
+        assertThat(isThemeApplied(APPLIED_SETUP_WIZARD_THEME)).isTrue();
+    }
+
+    private boolean isThemeApplied(String themeName) {
+        final String [] appliedThemes =  mTheme.getTheme();
+        for (String theme : appliedThemes) {
+            if (theme.contains(themeName)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private void createActivity() {
+        ActivityController.of(mActivity).create(new Bundle());
+        mTheme = mActivity.getTheme();
+    }
+}