Merge changes from topic "update-androidx-ae"

* changes:
  Fix build for jetpack update
  Update ActivityEmbedding usage.
diff --git a/res/drawable/ic_edit.xml b/res/drawable/ic_edit.xml
new file mode 100644
index 0000000..0d7cd1c
--- /dev/null
+++ b/res/drawable/ic_edit.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ 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.
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24"
+        android:viewportHeight="24"
+        android:tint="?android:attr/colorControlNormal">
+    <path android:fillColor="#FFFFFFFF"
+          android:pathData="M5,19H6.4L16.45,8.975L15.75,8.25L15.025,7.55L5,17.6ZM3,21V16.75L16.45,3.325Q17.025,2.75 17.863,2.75Q18.7,2.75 19.275,3.325L20.675,4.75Q21.25,5.325 21.25,6.15Q21.25,6.975 20.675,7.55L7.25,21ZM19.25,6.15 L17.85,4.75ZM16.45,8.975 L15.75,8.25 15.025,7.55 16.45,8.975Z"/>
+</vector>
\ No newline at end of file
diff --git a/res/drawable/work_challenge_emergency_button_background.xml b/res/drawable/work_challenge_emergency_button_background.xml
new file mode 100644
index 0000000..1a92fed
--- /dev/null
+++ b/res/drawable/work_challenge_emergency_button_background.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2022 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.
+  -->
+<inset xmlns:android="http://schemas.android.com/apk/res/android">
+    <shape android:shape="rectangle">
+        <corners android:radius="25dp"/>
+        <solid android:color="@android:color/system_accent3_100" />
+    </shape>
+</inset>
\ No newline at end of file
diff --git a/res/layout-land/confirm_lock_pattern_base.xml b/res/layout-land/confirm_lock_pattern_base.xml
index f79fc72..9961769 100644
--- a/res/layout-land/confirm_lock_pattern_base.xml
+++ b/res/layout-land/confirm_lock_pattern_base.xml
@@ -89,6 +89,19 @@
                 android:layout_marginTop="12dp"
                 android:gravity="center_vertical"/>
 
+            <Button
+                android:id="@+id/emergencyCallButton"
+                style="@style/WorkChallengeEmergencyButtonStyle"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginStart="?attr/sudMarginStart"
+                android:layout_marginEnd="?attr/sudMarginEnd"
+                android:layout_marginTop="60dp"
+                android:layout_marginBottom="14dp"
+                android:visibility="gone"
+                android:layout_gravity="center_horizontal"
+                android:text="@string/work_challenge_emergency_button_text"/>
+
         </LinearLayout>
 
     </com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient>
diff --git a/res/layout-land/confirm_lock_pattern_normal_base.xml b/res/layout-land/confirm_lock_pattern_normal_base.xml
index ced0e2c..9a5097e 100644
--- a/res/layout-land/confirm_lock_pattern_normal_base.xml
+++ b/res/layout-land/confirm_lock_pattern_normal_base.xml
@@ -70,6 +70,19 @@
                 android:layout_marginBottom="80dp"
                 android:text="@string/cancel" />
 
+            <Button
+                android:id="@+id/emergencyCallButton"
+                style="@style/WorkChallengeEmergencyButtonStyle"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginStart="?attr/sudMarginStart"
+                android:layout_marginEnd="?attr/sudMarginEnd"
+                android:layout_marginTop="60dp"
+                android:layout_marginBottom="14dp"
+                android:visibility="gone"
+                android:layout_gravity="center_horizontal"
+                android:text="@string/work_challenge_emergency_button_text"/>
+
         </LinearLayout>
 
     </com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient>
diff --git a/res/layout/confirm_lock_password_base.xml b/res/layout/confirm_lock_password_base.xml
index a3e5659..84b6668 100644
--- a/res/layout/confirm_lock_password_base.xml
+++ b/res/layout/confirm_lock_password_base.xml
@@ -91,5 +91,17 @@
             android:layout_gravity="center_horizontal"
             android:text="@string/cancel" />
 
+        <Button
+            android:id="@+id/emergencyCallButton"
+            style="@style/WorkChallengeEmergencyButtonStyle"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="?attr/sudMarginStart"
+            android:layout_marginEnd="?attr/sudMarginEnd"
+            android:layout_marginBottom="12dp"
+            android:visibility="gone"
+            android:layout_gravity="center_horizontal"
+            android:text="@string/work_challenge_emergency_button_text"/>
+
     </com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient>
 </com.google.android.setupdesign.GlifLayout>
diff --git a/res/layout/confirm_lock_password_normal.xml b/res/layout/confirm_lock_password_normal.xml
index 645c444..c2a7b5d 100644
--- a/res/layout/confirm_lock_password_normal.xml
+++ b/res/layout/confirm_lock_password_normal.xml
@@ -84,5 +84,17 @@
             android:layout_gravity="center_horizontal"
             android:text="@string/cancel" />
 
+        <Button
+            android:id="@+id/emergencyCallButton"
+            style="@style/WorkChallengeEmergencyButtonStyle"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="?attr/sudMarginStart"
+            android:layout_marginEnd="?attr/sudMarginEnd"
+            android:layout_marginBottom="12dp"
+            android:visibility="gone"
+            android:layout_gravity="center_horizontal"
+            android:text="@string/work_challenge_emergency_button_text"/>
+
     </com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient>
 </com.google.android.setupdesign.GlifLayout>
diff --git a/res/layout/confirm_lock_pattern_base.xml b/res/layout/confirm_lock_pattern_base.xml
index 5b19105..01f028e 100644
--- a/res/layout/confirm_lock_pattern_base.xml
+++ b/res/layout/confirm_lock_pattern_base.xml
@@ -89,6 +89,19 @@
                 android:layout_marginTop="12dp"
                 android:gravity="center_vertical"/>
 
+            <Button
+                android:id="@+id/emergencyCallButton"
+                style="@style/WorkChallengeEmergencyButtonStyle"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginStart="?attr/sudMarginStart"
+                android:layout_marginEnd="?attr/sudMarginEnd"
+                android:layout_marginTop="60dp"
+                android:layout_marginBottom="14dp"
+                android:visibility="gone"
+                android:layout_gravity="center_horizontal"
+                android:text="@string/work_challenge_emergency_button_text"/>
+
         </LinearLayout>
 
     </com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient>
diff --git a/res/layout/confirm_lock_pattern_normal_base.xml b/res/layout/confirm_lock_pattern_normal_base.xml
index 5d1ca7c..44d9ab7 100644
--- a/res/layout/confirm_lock_pattern_normal_base.xml
+++ b/res/layout/confirm_lock_pattern_normal_base.xml
@@ -71,6 +71,18 @@
                 android:layout_marginBottom="80dp"
                 android:text="@string/cancel" />
 
+            <Button
+                android:id="@+id/emergencyCallButton"
+                style="@style/WorkChallengeEmergencyButtonStyle"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginStart="?attr/sudMarginStart"
+                android:layout_marginEnd="?attr/sudMarginEnd"
+                android:layout_marginBottom="12dp"
+                android:visibility="gone"
+                android:layout_gravity="center_horizontal"
+                android:text="@string/work_challenge_emergency_button_text"/>
+
         </LinearLayout>
 
     </com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 273e3ae..8625fe3 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3350,6 +3350,8 @@
     <!-- Security & location settings screen, change unlock pattern screen instruction if user
          draws incorrect pattern [CHAR LIMIT=30] -->
     <string name="lockpattern_need_to_unlock_wrong">Wrong pattern</string>
+    <!-- Work challenge screen, this string is the label for an emergency call button, which opens the personal safety app to allow the user to make an emergency call. [CHAR LIMIT=20] -->
+    <string name="work_challenge_emergency_button_text">Emergency</string>
 
     <!-- Lock Pattern settings -->
     <!-- Security & location settings screen, header -->
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 0dc19be..42ccf0d 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -406,6 +406,17 @@
         <item name="android:layout_gravity">start|top</item>
     </style>
 
+    <style name="WorkChallengeEmergencyButtonStyle">
+        <item name="android:background">@drawable/work_challenge_emergency_button_background</item>
+        <item name="android:textColor">?android:attr/textColorPrimary</item>
+        <item name="android:outlineProvider">none</item>
+        <item name="android:paddingTop">15dp</item>
+        <item name="android:paddingBottom">15dp</item>
+        <item name="android:paddingLeft">30dp</item>
+        <item name="android:paddingRight">30dp</item>
+        <item name="android:textSize">16dp</item>
+    </style>
+
     <style name="device_info_dialog_label">
         <item name="android:textAlignment">viewStart</item>
         <item name="android:fontFamily">@*android:string/config_headlineFontFamily</item>
diff --git a/src/com/android/settings/connecteddevice/stylus/StylusDeviceUpdater.java b/src/com/android/settings/connecteddevice/stylus/StylusDeviceUpdater.java
index 575c526..46ef3fb 100644
--- a/src/com/android/settings/connecteddevice/stylus/StylusDeviceUpdater.java
+++ b/src/com/android/settings/connecteddevice/stylus/StylusDeviceUpdater.java
@@ -168,7 +168,7 @@
         mUsiPreference.setKey(PREF_KEY);
         mUsiPreference.setTitle(R.string.stylus_connected_devices_title);
         // TODO(b/250909304): pending actual icon visD
-        mUsiPreference.setIcon(R.drawable.circle);
+        mUsiPreference.setIcon(R.drawable.ic_edit);
         mUsiPreference.setOnPreferenceClickListener((Preference p) -> {
             mMetricsFeatureProvider.logClickedPreference(p, mFragment.getMetricsCategory());
             launchDeviceDetails();
diff --git a/src/com/android/settings/connecteddevice/stylus/StylusUsiHeaderController.java b/src/com/android/settings/connecteddevice/stylus/StylusUsiHeaderController.java
index 13d7b57..379815b 100644
--- a/src/com/android/settings/connecteddevice/stylus/StylusUsiHeaderController.java
+++ b/src/com/android/settings/connecteddevice/stylus/StylusUsiHeaderController.java
@@ -71,7 +71,7 @@
         ImageView iconView = mHeaderPreference.findViewById(R.id.entity_header_icon);
         if (iconView != null) {
             // TODO(b/250909304): get proper icon once VisD ready
-            iconView.setImageResource(R.drawable.circle);
+            iconView.setImageResource(R.drawable.ic_edit);
             iconView.setContentDescription("Icon for stylus");
         }
         refresh();
diff --git a/src/com/android/settings/datetime/AutoTimePreferenceController.java b/src/com/android/settings/datetime/AutoTimePreferenceController.java
index 8e54a9e..2b158e0 100644
--- a/src/com/android/settings/datetime/AutoTimePreferenceController.java
+++ b/src/com/android/settings/datetime/AutoTimePreferenceController.java
@@ -53,16 +53,25 @@
                 getTimeCapabilitiesAndConfig().getCapabilities();
         int capability = timeCapabilities.getConfigureAutoDetectionEnabledCapability();
 
-        // The preference only has two states: present and not present. The preference is never
-        // present but disabled.
-        if (capability == CAPABILITY_NOT_SUPPORTED
-                || capability == CAPABILITY_NOT_ALLOWED
-                || capability == CAPABILITY_NOT_APPLICABLE) {
-            return false;
-        } else if (capability == CAPABILITY_POSSESSED) {
-            return true;
-        } else {
-            throw new IllegalStateException("Unknown capability=" + capability);
+        // The preference has three states: visible, not visible, and visible but disabled.
+        // This method handles the "is visible?" check.
+        switch (capability) {
+            case CAPABILITY_NOT_SUPPORTED:
+                return false;
+            case CAPABILITY_POSSESSED:
+                return true;
+            case CAPABILITY_NOT_ALLOWED:
+                // This case is expected for enterprise restrictions, where the toggle should be
+                // present but disabled. Disabling is handled declaratively via the
+                // settings:userRestriction attribute in .xml. The client-side logic is expected to
+                // concur with the capabilities logic in the system server.
+                return true;
+            case CAPABILITY_NOT_APPLICABLE:
+                // CAPABILITY_NOT_APPLICABLE is not currently expected, so this is return value is
+                // arbitrary.
+                return true;
+            default:
+                throw new IllegalStateException("Unknown capability=" + capability);
         }
     }
 
@@ -71,6 +80,7 @@
         if (!(preference instanceof SwitchPreference)) {
             return;
         }
+
         ((SwitchPreference) preference).setChecked(isEnabled());
     }
 
diff --git a/src/com/android/settings/datetime/AutoTimeZonePreferenceController.java b/src/com/android/settings/datetime/AutoTimeZonePreferenceController.java
index a4d745b..7d1c1b6 100644
--- a/src/com/android/settings/datetime/AutoTimeZonePreferenceController.java
+++ b/src/com/android/settings/datetime/AutoTimeZonePreferenceController.java
@@ -27,11 +27,11 @@
 import android.app.time.TimeZoneConfiguration;
 import android.content.Context;
 
-import androidx.annotation.VisibleForTesting;
 import androidx.preference.Preference;
 import androidx.preference.PreferenceScreen;
 import androidx.preference.SwitchPreference;
 
+import com.android.internal.annotations.VisibleForTesting;
 import com.android.settings.R;
 import com.android.settings.core.PreferenceControllerMixin;
 import com.android.settingslib.core.AbstractPreferenceController;
@@ -63,16 +63,25 @@
                 getTimeZoneCapabilitiesAndConfig().getCapabilities();
         int capability = timeZoneCapabilities.getConfigureAutoDetectionEnabledCapability();
 
-        // The preference only has two states: present and not present. The preference is never
-        // present but disabled.
-        if (capability == CAPABILITY_NOT_SUPPORTED
-                || capability == CAPABILITY_NOT_ALLOWED
-                || capability == CAPABILITY_NOT_APPLICABLE) {
-            return false;
-        } else if (capability == CAPABILITY_POSSESSED) {
-            return true;
-        } else {
-            throw new IllegalStateException("Unknown capability=" + capability);
+        // The preference has three states: visible, not visible, and visible but disabled.
+        // This method handles the "is visible?" check.
+        switch (capability) {
+            case CAPABILITY_NOT_SUPPORTED:
+                return false;
+            case CAPABILITY_POSSESSED:
+                return true;
+            case CAPABILITY_NOT_ALLOWED:
+                // This case is expected for enterprise restrictions, where the toggle should be
+                // present but disabled. Disabling is handled declaratively via the
+                // settings:userRestriction attribute in .xml. The client-side logic is expected to
+                // concur with the capabilities logic in the system server.
+                return true;
+            case CAPABILITY_NOT_APPLICABLE:
+                // CAPABILITY_NOT_APPLICABLE is not currently expected, so this is return value is
+                // arbitrary.
+                return true;
+            default:
+                throw new IllegalStateException("Unknown capability=" + capability);
         }
     }
 
@@ -86,6 +95,7 @@
         if (!(preference instanceof SwitchPreference)) {
             return;
         }
+
         ((SwitchPreference) preference).setChecked(isEnabled());
     }
 
diff --git a/src/com/android/settings/fuelgauge/BatteryUtils.java b/src/com/android/settings/fuelgauge/BatteryUtils.java
index fe396bd..b08f4e3 100644
--- a/src/com/android/settings/fuelgauge/BatteryUtils.java
+++ b/src/com/android/settings/fuelgauge/BatteryUtils.java
@@ -639,6 +639,13 @@
         return DockDefenderMode.DISABLED;
     }
 
+    /** Formats elapsed time without commas in between.  */
+    public static CharSequence formatElapsedTimeWithoutComma(
+            Context context, double millis, boolean withSeconds, boolean collapseTimeUnit) {
+        return StringUtil.formatElapsedTime(context, millis, withSeconds, collapseTimeUnit)
+                .toString().replaceAll(",", "");
+    }
+
     /** Builds the battery usage time summary. */
     public static String buildBatteryUsageTimeSummary(final Context context, final boolean isSystem,
             final long foregroundUsageTimeInMs, final long backgroundUsageTimeInMs,
@@ -675,7 +682,7 @@
         if (timeInMs < DateUtils.MINUTE_IN_MILLIS) {
             return context.getString(lessThanOneMinuteResId);
         }
-        final CharSequence timeSequence = StringUtil.formatElapsedTime(
+        final CharSequence timeSequence = formatElapsedTimeWithoutComma(
                 context, (double) timeInMs, /*withSeconds=*/ false, /*collapseTimeUnit=*/ false);
         return context.getString(normalResId, timeSequence);
     }
diff --git a/src/com/android/settings/fuelgauge/batteryusage/ScreenOnTimeController.java b/src/com/android/settings/fuelgauge/batteryusage/ScreenOnTimeController.java
index 64642d7..286a95f 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/ScreenOnTimeController.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/ScreenOnTimeController.java
@@ -28,7 +28,7 @@
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.settings.R;
 import com.android.settings.core.BasePreferenceController;
-import com.android.settingslib.utils.StringUtil;
+import com.android.settings.fuelgauge.BatteryUtils;
 
 import java.util.Locale;
 import java.util.regex.Matcher;
@@ -89,10 +89,10 @@
     @VisibleForTesting
     void showScreenOnTimeText(Long screenOnTime) {
         final CharSequence timeSequence =
-                StringUtil.formatElapsedTime(mPrefContext, (double) screenOnTime,
+                BatteryUtils.formatElapsedTimeWithoutComma(mPrefContext, (double) screenOnTime,
                         /*withSeconds=*/ false, /*collapseTimeUnit=*/ false);
         mScreenOnTimeTextPreference.setText(
-                enlargeFontOfNumberIfNeeded(mPrefContext, removeCommas(timeSequence)));
+                enlargeFontOfNumberIfNeeded(mPrefContext, timeSequence));
         mScreenOnTimeTextPreference.setVisible(true);
     }
 
@@ -115,8 +115,4 @@
         }
         return spannableText;
     }
-
-    private static CharSequence removeCommas(CharSequence text) {
-        return text.toString().replaceAll(",", "");
-    }
 }
diff --git a/src/com/android/settings/password/ConfirmDeviceCredentialBaseFragment.java b/src/com/android/settings/password/ConfirmDeviceCredentialBaseFragment.java
index 7feb2b1..7787ae1 100644
--- a/src/com/android/settings/password/ConfirmDeviceCredentialBaseFragment.java
+++ b/src/com/android/settings/password/ConfirmDeviceCredentialBaseFragment.java
@@ -25,6 +25,7 @@
 import android.app.Dialog;
 import android.app.KeyguardManager;
 import android.app.admin.DevicePolicyManager;
+import android.app.admin.ManagedSubscriptionsPolicy;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
@@ -34,6 +35,7 @@
 import android.os.Handler;
 import android.os.UserHandle;
 import android.os.UserManager;
+import android.telecom.TelecomManager;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.View;
@@ -139,6 +141,31 @@
             getActivity().finish();
         });
         setupForgotButtonIfManagedProfile(view);
+        setupEmergencyCallButtonIfManagedSubscription(view);
+    }
+
+    private void setupEmergencyCallButtonIfManagedSubscription(View view) {
+        int policyType = getContext().getSystemService(
+                DevicePolicyManager.class).getManagedSubscriptionsPolicy().getPolicyType();
+
+        if (policyType == ManagedSubscriptionsPolicy.TYPE_ALL_MANAGED_SUBSCRIPTIONS) {
+            Button emergencyCallButton = view.findViewById(R.id.emergencyCallButton);
+            if (emergencyCallButton == null) {
+                Log.wtf(TAG,
+                        "Emergency call button not found in managed profile credential dialog");
+                return;
+            }
+            emergencyCallButton.setVisibility(View.VISIBLE);
+            emergencyCallButton.setOnClickListener(v -> {
+                final Intent intent = getActivity()
+                        .getSystemService(TelecomManager.class)
+                        .createLaunchEmergencyDialerIntent(null)
+                        .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+                                | Intent.FLAG_ACTIVITY_CLEAR_TOP);
+                getActivity().startActivity(intent);
+                getActivity().finish();
+            });
+        }
     }
 
     private void setupForgotButtonIfManagedProfile(View view) {