Merge "[PK Setting] Refine layout for Keyboard review" into main
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 4bf615f..a3acd49 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2517,7 +2517,7 @@
 
         <activity android:name=".biometrics.face.FaceEnrollIntroduction"
                   android:exported="true"
-                  android:screenOrientation="portrait">
+                  android:screenOrientation="nosensor">
             <intent-filter>
                 <action android:name="android.settings.FACE_ENROLL"/>
                 <category android:name="android.intent.category.DEFAULT"/>
@@ -2526,12 +2526,12 @@
 
         <activity android:name=".biometrics.face.FaceEnrollIntroductionInternal"
                   android:exported="false"
-                  android:screenOrientation="portrait"
+                  android:screenOrientation="nosensor"
                   android:taskAffinity="com.android.settings.root" />
 
         <activity android:name=".biometrics.face.FaceEnrollEducation"
             android:exported="false"
-            android:screenOrientation="portrait"/>
+            android:screenOrientation="nosensor"/>
 
         <activity android:name=".biometrics.face.FaceEnrollEnrolling"
             android:exported="false"
@@ -3885,6 +3885,7 @@
             android:launchMode="singleTop"
             android:taskAffinity=".wifi.NetworkRequestDialogActivity"
             android:exported="true"
+            android:configChanges="orientation|keyboard|keyboardHidden|screenSize|smallestScreenSize|screenLayout"
             android:permission="android.permission.NETWORK_SETTINGS">
             <intent-filter>
                 <action android:name="com.android.settings.wifi.action.NETWORK_REQUEST" />
diff --git a/res/values/config.xml b/res/values/config.xml
index d084ff9..d0cd96b 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -38,6 +38,11 @@
     <!-- Whether to show Camera laser sensor switch in Developer Options -->
     <bool name="config_show_camera_laser_sensor">false</bool>
 
+    <!-- Intent action to open Avatar Picker app -->
+    <string name="config_avatar_picker_action" translatable="false">
+        com.android.avatarpicker.FULL_SCREEN_ACTIVITY
+    </string>
+
     <!-- Package name and fully-qualified class name for the wallpaper picker activity. -->
     <string name="config_wallpaper_picker_package" translatable="false">com.android.settings</string>
     <string name="config_wallpaper_picker_class" translatable="false">com.android.settings.Settings$WallpaperSettingsActivity</string>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 0b12142..1fd5252 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1207,7 +1207,7 @@
     <!-- Title for the Private Space page. [CHAR LIMIT=60] -->
     <string name="private_space_title">Private Space</string>
     <!-- Summary for the Private Space page. [CHAR LIMIT=NONE] -->
-    <string name="private_space_summary">Hide apps in a private folder</string>
+    <string name="private_space_summary">Keep private apps locked and hidden</string>
     <!-- Description for the Private Space page. [CHAR LIMIT=NONE] -->
     <string name="private_space_description">Hide apps in a private folder that only you can access</string>
     <!-- Title for the Private Space one lock preference. [CHAR LIMIT=60] -->
@@ -1281,7 +1281,7 @@
     <!-- Title for private space setup in auto advancing screen informing private space notifications are hidden when locked. [CHAR LIMIT=NONE] -->
     <string name="private_space_notifications_hidden_title">Notifications from apps in private space are hidden when it\u2019s locked</string>
     <!-- Title for private space setup in auto advancing screen informing photos/files from private space can be shared when unlocked. [CHAR LIMIT=NONE] -->
-    <string name="private_space_share_photos_title">Unlock your space to share photos or files from private space apps</string>
+    <string name="private_space_share_photos_title">Unlock private space to share photos or files from private space apps</string>
     <!-- Title for private space setup in auto advancing screen informing some system apps are already installed in private space. [CHAR LIMIT=NONE] -->
     <string name="private_space_apps_installed_title">Some apps are already installed in your private space</string>
     <!-- Title for private space creation error screen. [CHAR LIMIT=60] -->
@@ -1312,6 +1312,12 @@
     <string name="private_space_lock_setup_title">Choose a lock for your private space</string>
     <!-- private space lock setup screen description [CHAR LIMIT=NONE] -->
     <string name="private_space_lock_setup_description">You can unlock your private space using your fingerprint. For security, this option requires a backup lock.</string>
+    <!-- Header for private space choose your PIN screen [CHAR LIMIT=40] -->
+    <string name="private_space_choose_your_pin_header">Set a PIN for your private space</string>
+    <!-- Header for private space choose your password screen [CHAR LIMIT=40] -->
+    <string name="private_space_choose_your_password_header">Set a password for your private space</string>
+    <!-- Header for private space choose your pattern screen [CHAR LIMIT=40] -->
+    <string name="private_space_choose_your_pattern_header">Set a pattern for your private space</string>
 
     <!-- TODO(b/309950257): Remove below strings once QSTIle fulfillment is complete. -->
     <!-- Header in hide Private Space settings page to unhide Private Space. [CHAR LIMIT=90] -->
@@ -12633,4 +12639,7 @@
     <string name="content_protection_preference_subpage_summary"></string>
     <!-- Default information at the bottom of the subpage of content protection settings. Will be overlaid by OEM. -->
     <string name="content_protection_preference_subpage_info"></string>
+
+    <!-- Content description for setting password complete-->
+    <string name="accessibility_setup_password_complete">Password is now set up</string>
 </resources>
diff --git a/src/com/android/settings/IccLockSettings.java b/src/com/android/settings/IccLockSettings.java
index 4628221..422610a 100644
--- a/src/com/android/settings/IccLockSettings.java
+++ b/src/com/android/settings/IccLockSettings.java
@@ -52,6 +52,7 @@
 import android.widget.TextView;
 import android.widget.Toast;
 
+import androidx.annotation.Nullable;
 import androidx.preference.Preference;
 import androidx.preference.TwoStatePreference;
 
@@ -716,13 +717,18 @@
         return slotId;
     }
 
+    @Nullable
     private SubscriptionInfo getVisibleSubscriptionInfoForSimSlotIndex(int slotId) {
         final List<SubscriptionInfo> subInfoList =
                 mProxySubscriptionMgr.getActiveSubscriptionsInfo();
         if (subInfoList == null) {
             return null;
         }
-        final CarrierConfigManager carrierConfigManager = getContext().getSystemService(
+        Context context = getContext();
+        if (context == null) {
+            return null;
+        }
+        final CarrierConfigManager carrierConfigManager = context.getSystemService(
                 CarrierConfigManager.class);
         for (SubscriptionInfo subInfo : subInfoList) {
             if ((isSubscriptionVisible(carrierConfigManager, subInfo)
diff --git a/src/com/android/settings/activityembedding/ActivityEmbeddingRulesController.java b/src/com/android/settings/activityembedding/ActivityEmbeddingRulesController.java
index 3b79b47..50134ba 100644
--- a/src/com/android/settings/activityembedding/ActivityEmbeddingRulesController.java
+++ b/src/com/android/settings/activityembedding/ActivityEmbeddingRulesController.java
@@ -34,6 +34,7 @@
 import androidx.window.embedding.SplitPlaceholderRule;
 import androidx.window.embedding.SplitRule;
 
+import com.android.settings.R;
 import com.android.settings.Settings;
 import com.android.settings.SettingsActivity;
 import com.android.settings.SubSettings;
@@ -261,8 +262,13 @@
         addActivityFilter(activityFilters, FaceEnrollIntroduction.class);
         addActivityFilter(activityFilters, RemoteAuthActivity.class);
         addActivityFilter(activityFilters, RemoteAuthActivityInternal.class);
-        addActivityFilter(activityFilters, AvatarPickerActivity.class);
         addActivityFilter(activityFilters, ChooseLockPattern.class);
+        if (android.multiuser.Flags.avatarSync()) {
+            String action = mContext.getString(R.string.config_avatar_picker_action);
+            addActivityFilter(activityFilters, new Intent(action));
+        } else {
+            addActivityFilter(activityFilters, AvatarPickerActivity.class);
+        }
         ActivityRule activityRule = new ActivityRule.Builder(activityFilters).setAlwaysExpand(true)
                 .build();
         mRuleController.addRule(activityRule);
diff --git a/src/com/android/settings/applications/ApplicationFeatureProviderImpl.java b/src/com/android/settings/applications/ApplicationFeatureProviderImpl.java
index 80d3947..081d99a 100644
--- a/src/com/android/settings/applications/ApplicationFeatureProviderImpl.java
+++ b/src/com/android/settings/applications/ApplicationFeatureProviderImpl.java
@@ -16,6 +16,8 @@
 
 package com.android.settings.applications;
 
+import static android.webkit.Flags.updateServiceV2;
+
 import android.Manifest;
 import android.app.admin.DevicePolicyManager;
 import android.content.ComponentName;
@@ -41,6 +43,7 @@
 
 import com.android.internal.telephony.SmsApplication;
 import com.android.settings.R;
+import com.android.settings.webview.WebViewUpdateServiceWrapper;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -54,6 +57,7 @@
     private final IPackageManager mPms;
     private final DevicePolicyManager mDpm;
     private final UserManager mUm;
+    private final WebViewUpdateServiceWrapper mWebViewUpdateServiceWrapper;
     /** Flags to use when querying PackageManager for Euicc component implementations. */
     private static final int EUICC_QUERY_FLAGS =
             PackageManager.MATCH_SYSTEM_ONLY | PackageManager.MATCH_DEBUG_TRIAGED_MISSING
@@ -61,11 +65,16 @@
 
     public ApplicationFeatureProviderImpl(Context context, PackageManager pm,
             IPackageManager pms, DevicePolicyManager dpm) {
+        this(context, pm, pms, dpm, new WebViewUpdateServiceWrapper());
+    }
+    public ApplicationFeatureProviderImpl(Context context, PackageManager pm,
+            IPackageManager pms, DevicePolicyManager dpm, WebViewUpdateServiceWrapper wvusWrapper) {
         mContext = context.getApplicationContext();
         mPm = pm;
         mPms = pms;
         mDpm = dpm;
         mUm = UserManager.get(mContext);
+        mWebViewUpdateServiceWrapper = wvusWrapper;
     }
 
     @Override
@@ -159,6 +168,14 @@
             keepEnabledPackages.add(euicc.packageName);
         }
 
+        // Keep WebView default package enabled.
+        if (updateServiceV2()) {
+            String packageName = mWebViewUpdateServiceWrapper.getDefaultWebViewPackageName();
+            if (packageName != null) {
+                keepEnabledPackages.add(packageName);
+            }
+        }
+
         keepEnabledPackages.addAll(getEnabledPackageAllowlist());
 
         final LocationManager locationManager =
diff --git a/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceController.java b/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceController.java
index fb78e3e..00f0625 100644
--- a/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceController.java
+++ b/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceController.java
@@ -139,7 +139,11 @@
         AsyncTask.execute(() -> {
             if (!mNm.isNotificationPolicyAccessGrantedForPackage(
                     cn.getPackageName())) {
-                mNm.removeAutomaticZenRules(cn.getPackageName());
+                if (android.app.Flags.modesApi()) {
+                    mNm.removeAutomaticZenRules(cn.getPackageName(), /* fromUser= */ true);
+                } else {
+                    mNm.removeAutomaticZenRules(cn.getPackageName());
+                }
             }
         });
     }
diff --git a/src/com/android/settings/applications/specialaccess/zenaccess/ZenAccessController.java b/src/com/android/settings/applications/specialaccess/zenaccess/ZenAccessController.java
index b4a0c88..6f4137c 100644
--- a/src/com/android/settings/applications/specialaccess/zenaccess/ZenAccessController.java
+++ b/src/com/android/settings/applications/specialaccess/zenaccess/ZenAccessController.java
@@ -101,8 +101,12 @@
     }
 
     public static void deleteRules(final Context context, final String pkg) {
-       final NotificationManager mgr = context.getSystemService(NotificationManager.class);
-       mgr.removeAutomaticZenRules(pkg);
+        final NotificationManager mgr = context.getSystemService(NotificationManager.class);
+        if (android.app.Flags.modesApi()) {
+            mgr.removeAutomaticZenRules(pkg, /* fromUser= */ true);
+        } else {
+            mgr.removeAutomaticZenRules(pkg);
+        }
     }
 
     @VisibleForTesting
diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java
index 6e90885..1b80838 100644
--- a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java
+++ b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java
@@ -53,7 +53,6 @@
 import android.view.View;
 import android.view.accessibility.AccessibilityEvent;
 import android.view.accessibility.AccessibilityManager;
-import android.view.animation.AccelerateDecelerateInterpolator;
 import android.view.animation.AnimationUtils;
 import android.view.animation.Interpolator;
 import android.widget.ProgressBar;
@@ -191,7 +190,7 @@
     private boolean mHaveShownSfpsRightEdgeLottie;
     private boolean mShouldShowLottie;
 
-    private ObjectAnimator mHelpAnimation;
+    private Animator mHelpAnimation;
 
     private OrientationEventListener mOrientationEventListener;
     private int mPreviousRotation = 0;
@@ -341,16 +340,10 @@
     }
 
     private void setHelpAnimation() {
-        final float translationX = 40;
-        final int duration = 550;
         final RelativeLayout progressLottieLayout = findViewById(R.id.progress_lottie);
-        mHelpAnimation = ObjectAnimator.ofFloat(progressLottieLayout,
-                "translationX" /* propertyName */,
-                0, translationX, -1 * translationX, translationX, 0f);
-        mHelpAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
-        mHelpAnimation.setDuration(duration);
-        mHelpAnimation.setAutoCancel(false);
+        mHelpAnimation = mSfpsEnrollmentFeature.getHelpAnimator(progressLottieLayout);
     }
+
     @Override
     protected BiometricEnrollSidecar getSidecar() {
         final FingerprintEnrollSidecar sidecar = new FingerprintEnrollSidecar(this,
@@ -703,6 +696,9 @@
         view.setComposition(composition);
         view.setVisibility(View.VISIBLE);
         view.playAnimation();
+        if (mCanAssumeSfps) {
+            mSfpsEnrollmentFeature.handleOnEnrollmentLottieComposition(view);
+        }
     }
 
     @EnrollStage
@@ -1226,5 +1222,10 @@
         public float getEnrollStageThreshold(@NonNull Context context, int index) {
             throw new IllegalStateException(exceptionStr);
         }
+
+        @Override
+        public Animator getHelpAnimator(@NonNull View target) {
+            throw new IllegalStateException(exceptionStr);
+        }
     }
 }
diff --git a/src/com/android/settings/biometrics/fingerprint/feature/SfpsEnrollmentFeature.java b/src/com/android/settings/biometrics/fingerprint/feature/SfpsEnrollmentFeature.java
index a1a18e5..f99d394 100644
--- a/src/com/android/settings/biometrics/fingerprint/feature/SfpsEnrollmentFeature.java
+++ b/src/com/android/settings/biometrics/fingerprint/feature/SfpsEnrollmentFeature.java
@@ -16,12 +16,16 @@
 
 package com.android.settings.biometrics.fingerprint.feature;
 
+import android.animation.Animator;
 import android.content.Context;
+import android.view.View;
 
 import androidx.annotation.NonNull;
 
 import com.android.settings.biometrics.fingerprint.FingerprintEnrollEnrolling;
 
+import com.airbnb.lottie.LottieAnimationView;
+
 import java.util.function.Function;
 import java.util.function.Supplier;
 
@@ -76,4 +80,17 @@
      * @return threshold
      */
     float getEnrollStageThreshold(@NonNull Context context, int index);
+
+    /**
+     * Gets the help animator used when get help message.
+     * @param target the target view to animate
+     * @return animator
+     */
+    Animator getHelpAnimator(@NonNull View target);
+
+    /**
+     * Handles extra stuffs on lottie composition.
+     * @param lottieView the view related to the lottie
+     */
+    default void handleOnEnrollmentLottieComposition(LottieAnimationView lottieView) {}
 }
diff --git a/src/com/android/settings/biometrics/fingerprint/feature/SfpsEnrollmentFeatureImpl.java b/src/com/android/settings/biometrics/fingerprint/feature/SfpsEnrollmentFeatureImpl.java
index 5a97537..abc31c9 100644
--- a/src/com/android/settings/biometrics/fingerprint/feature/SfpsEnrollmentFeatureImpl.java
+++ b/src/com/android/settings/biometrics/fingerprint/feature/SfpsEnrollmentFeatureImpl.java
@@ -23,8 +23,12 @@
 import static com.android.settings.biometrics.fingerprint.FingerprintEnrollEnrolling.SFPS_STAGE_RIGHT_EDGE;
 import static com.android.settings.biometrics.fingerprint.FingerprintEnrollEnrolling.STAGE_UNKNOWN;
 
+import android.animation.Animator;
+import android.animation.ObjectAnimator;
 import android.content.Context;
 import android.hardware.fingerprint.FingerprintManager;
+import android.view.View;
+import android.view.animation.AccelerateInterpolator;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
@@ -88,4 +92,17 @@
         }
         return mFingerprintManager.getEnrollStageThreshold(index);
     }
+
+    @Override
+    public Animator getHelpAnimator(@NonNull View target) {
+        final float translationX = 40;
+        final int duration = 550;
+        final ObjectAnimator help = ObjectAnimator.ofFloat(target,
+                "translationX" /* propertyName */,
+                0, translationX, -1 * translationX, translationX, 0f);
+        help.setInterpolator(new AccelerateInterpolator());
+        help.setDuration(duration);
+        help.setAutoCancel(false);
+        return help;
+    }
 }
diff --git a/src/com/android/settings/datausage/DataUsageList.kt b/src/com/android/settings/datausage/DataUsageList.kt
index 6a187d8..3083fb7 100644
--- a/src/com/android/settings/datausage/DataUsageList.kt
+++ b/src/com/android/settings/datausage/DataUsageList.kt
@@ -30,6 +30,7 @@
 import androidx.fragment.app.viewModels
 import androidx.preference.Preference
 import com.android.settings.R
+import com.android.settings.dashboard.DashboardFragment
 import com.android.settings.datausage.lib.BillingCycleRepository
 import com.android.settings.datausage.lib.NetworkUsageData
 import com.android.settings.network.MobileNetworkRepository
@@ -45,43 +46,42 @@
  * to inspect based on usage cycle and control through [NetworkPolicy].
  */
 @OpenForTesting
-open class DataUsageList : DataUsageBaseFragment() {
-    @JvmField
+open class DataUsageList : DashboardFragment() {
     @VisibleForTesting
     var template: NetworkTemplate? = null
+        private set
 
-    @JvmField
     @VisibleForTesting
     var subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID
+        private set
 
-    private lateinit var usageAmount: Preference
-    private var subscriptionInfoEntity: SubscriptionInfoEntity? = null
-    private lateinit var dataUsageListAppsController: DataUsageListAppsController
-    private lateinit var chartDataUsagePreferenceController: ChartDataUsagePreferenceController
     private lateinit var billingCycleRepository: BillingCycleRepository
 
-    private val viewModel: DataUsageListViewModel by viewModels()
+    private var usageAmount: Preference? = null
+    private var subscriptionInfoEntity: SubscriptionInfoEntity? = null
+    private var dataUsageListAppsController: DataUsageListAppsController? = null
+    private var chartDataUsagePreferenceController: ChartDataUsagePreferenceController? = null
+    private var dataUsageListHeaderController: DataUsageListHeaderController? = null
 
-    @VisibleForTesting
-    var dataUsageListHeaderController: DataUsageListHeaderController? = null
+    private val viewModel: DataUsageListViewModel by viewModels()
 
     override fun getMetricsCategory() = SettingsEnums.DATA_USAGE_LIST
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
+        billingCycleRepository = BillingCycleRepository(requireContext())
         if (requireContext().userManager.isGuestUser) {
             Log.e(TAG, "This setting isn't available for guest user")
             EventLog.writeEvent(0x534e4554, "262741858", -1 /* UID */, "Guest user")
             finish()
             return
         }
-        billingCycleRepository = createBillingCycleRepository()
         if (!billingCycleRepository.isBandwidthControlEnabled()) {
             Log.w(TAG, "No bandwidth control; leaving")
             finish()
             return
         }
-        usageAmount = findPreference(KEY_USAGE_AMOUNT)!!
+        usageAmount = findPreference(KEY_USAGE_AMOUNT)
         processArgument()
         val template = template
         if (template == null) {
@@ -94,12 +94,9 @@
             init(template)
         }
         chartDataUsagePreferenceController = use(ChartDataUsagePreferenceController::class.java)
-        chartDataUsagePreferenceController.init(template)
+            .apply { init(template) }
     }
 
-    @VisibleForTesting
-    open fun createBillingCycleRepository() = BillingCycleRepository(requireContext())
-
     override fun onViewCreated(v: View, savedInstanceState: Bundle?) {
         super.onViewCreated(v, savedInstanceState)
 
@@ -117,10 +114,10 @@
             ::updateSelectedCycle,
         )
         viewModel.cyclesFlow.collectLatestWithLifecycle(viewLifecycleOwner) { cycles ->
-            dataUsageListAppsController.updateCycles(cycles)
+            dataUsageListAppsController?.updateCycles(cycles)
         }
         viewModel.chartDataFlow.collectLatestWithLifecycle(viewLifecycleOwner) { chartData ->
-            chartDataUsagePreferenceController.update(chartData)
+            chartDataUsagePreferenceController?.update(chartData)
         }
     }
 
@@ -128,7 +125,7 @@
 
     override fun getLogTag() = TAG
 
-    fun processArgument() {
+    private fun processArgument() {
         arguments?.let {
             subId = it.getInt(EXTRA_SUB_ID, SubscriptionManager.INVALID_SUBSCRIPTION_ID)
             template = it.getParcelable(EXTRA_NETWORK_TEMPLATE, NetworkTemplate::class.java)
@@ -145,8 +142,7 @@
         }
     }
 
-    @VisibleForTesting
-    open fun updateSubscriptionInfoEntity() {
+    private fun updateSubscriptionInfoEntity() {
         ThreadUtils.postOnBackgroundThread {
             subscriptionInfoEntity =
                 MobileNetworkRepository.getInstance(context).getSubInfoById(subId.toString())
@@ -154,19 +150,16 @@
     }
 
     /** Update chart sweeps and cycle list to reflect [NetworkPolicy] for current [template]. */
-    @VisibleForTesting
-    fun updatePolicy() {
+    private fun updatePolicy() {
         val isBillingCycleModifiable = isBillingCycleModifiable()
         dataUsageListHeaderController?.setConfigButtonVisible(isBillingCycleModifiable)
-        chartDataUsagePreferenceController.setBillingCycleModifiable(isBillingCycleModifiable)
+        chartDataUsagePreferenceController?.setBillingCycleModifiable(isBillingCycleModifiable)
     }
 
-    @VisibleForTesting
-    open fun isBillingCycleModifiable(): Boolean {
-        return (billingCycleRepository.isModifiable(subId) &&
+    private fun isBillingCycleModifiable(): Boolean =
+        billingCycleRepository.isModifiable(subId) &&
             requireContext().getSystemService(SubscriptionManager::class.java)!!
-                .getActiveSubscriptionInfo(subId) != null)
-    }
+                .getActiveSubscriptionInfo(subId) != null
 
     /**
      * Updates the chart and detail data when initial loaded or selected cycle changed.
@@ -174,7 +167,7 @@
     private fun updateSelectedCycle(usageData: NetworkUsageData) {
         Log.d(TAG, "showing cycle $usageData")
 
-        usageAmount.title = usageData.getDataUsedString(requireContext())
+        usageAmount?.title = usageData.getDataUsedString(requireContext())
         viewModel.selectedCycleFlow.value = usageData
 
         updateApps(usageData)
@@ -182,7 +175,7 @@
 
     /** Updates applications data usage. */
     private fun updateApps(usageData: NetworkUsageData) {
-        dataUsageListAppsController.update(
+        dataUsageListAppsController?.update(
             carrierId = subscriptionInfoEntity?.carrierId,
             startTime = usageData.startTime,
             endTime = usageData.endTime,
diff --git a/src/com/android/settings/fuelgauge/BatteryUtils.java b/src/com/android/settings/fuelgauge/BatteryUtils.java
index 5a808f2..f4217b6 100644
--- a/src/com/android/settings/fuelgauge/BatteryUtils.java
+++ b/src/com/android/settings/fuelgauge/BatteryUtils.java
@@ -144,7 +144,6 @@
         sInstance = null;
     }
 
-
     /** Gets the process time */
     public long getProcessTimeMs(@StatusType int type, @Nullable BatteryStats.Uid uid, int which) {
         if (uid == null) {
@@ -345,6 +344,25 @@
     }
 
     /**
+     * Find package uid from package name
+     *
+     * @param packageName used to find the uid
+     * @param userId The user handle identifier to look up the package under
+     * @return uid for packageName, or {@link #UID_NULL} if exception happens or {@code packageName}
+     *     is null
+     */
+    public int getPackageUidAsUser(String packageName, int userId) {
+        try {
+            return packageName == null
+                    ? UID_NULL
+                    : mPackageManager.getPackageUidAsUser(
+                            packageName, PackageManager.GET_META_DATA, userId);
+        } catch (PackageManager.NameNotFoundException e) {
+            return UID_NULL;
+        }
+    }
+
+    /**
      * Parses proto object from string.
      *
      * @param serializedProto the serialized proto string
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffEntry.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffEntry.java
index 2c376e5..5b05e34 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffEntry.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryDiffEntry.java
@@ -324,7 +324,8 @@
             }
         }
 
-        int uid = BatteryUtils.getInstance(mContext).getPackageUid(packageName);
+        int uid =
+                BatteryUtils.getInstance(mContext).getPackageUidAsUser(packageName, (int) mUserId);
         synchronized (sPackageNameAndUidCacheLock) {
             sPackageNameAndUidCache.put(packageName, uid);
         }
@@ -379,8 +380,7 @@
                     mAppIcon = nameAndIconForUser.mIcon;
                     mAppLabel = nameAndIconForUser.mName;
                     putResourceCache(
-                            getKey(),
-                            new NameAndIcon(mAppLabel, mAppIcon, /* iconId= */ 0));
+                            getKey(), new NameAndIcon(mAppLabel, mAppIcon, /* iconId= */ 0));
                 }
                 break;
             case ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY:
@@ -392,8 +392,7 @@
                         mAppIconId = nameAndIconForSystem.mIconId;
                         mAppIcon = mContext.getDrawable(nameAndIconForSystem.mIconId);
                     }
-                    putResourceCache(
-                            getKey(), new NameAndIcon(mAppLabel, mAppIcon, mAppIconId));
+                    putResourceCache(getKey(), new NameAndIcon(mAppLabel, mAppIcon, mAppIconId));
                 }
                 break;
             case ConvertUtils.CONSUMER_TYPE_UID_BATTERY:
@@ -406,8 +405,7 @@
                 mAppIcon = getBadgeIconForUser(mAppIcon);
                 if (mAppLabel != null || mAppIcon != null) {
                     putResourceCache(
-                            getKey(),
-                            new NameAndIcon(mAppLabel, mAppIcon, /* iconId= */ 0));
+                            getKey(), new NameAndIcon(mAppLabel, mAppIcon, /* iconId= */ 0));
                 }
                 break;
         }
diff --git a/src/com/android/settings/homepage/contextualcards/conditional/DndConditionCardController.java b/src/com/android/settings/homepage/contextualcards/conditional/DndConditionCardController.java
index 4d79a01..e69a336 100644
--- a/src/com/android/settings/homepage/contextualcards/conditional/DndConditionCardController.java
+++ b/src/com/android/settings/homepage/contextualcards/conditional/DndConditionCardController.java
@@ -16,6 +16,7 @@
 
 package com.android.settings.homepage.contextualcards.conditional;
 
+import android.app.Flags;
 import android.app.NotificationManager;
 import android.app.settings.SettingsEnums;
 import android.content.BroadcastReceiver;
@@ -86,7 +87,12 @@
 
     @Override
     public void onActionClick() {
-        mNotificationManager.setZenMode(Settings.Global.ZEN_MODE_OFF, null, TAG);
+        if (Flags.modesApi()) {
+            mNotificationManager.setZenMode(Settings.Global.ZEN_MODE_OFF, null, TAG,
+                    /* fromUser= */ true);
+        } else {
+            mNotificationManager.setZenMode(Settings.Global.ZEN_MODE_OFF, null, TAG);
+        }
     }
 
     @Override
diff --git a/src/com/android/settings/notification/zen/ZenModeBackend.java b/src/com/android/settings/notification/zen/ZenModeBackend.java
index 1079865..c290c83 100644
--- a/src/com/android/settings/notification/zen/ZenModeBackend.java
+++ b/src/com/android/settings/notification/zen/ZenModeBackend.java
@@ -56,7 +56,6 @@
     @VisibleForTesting
     protected static final String ZEN_MODE_FROM_NONE = "zen_mode_from_none";
     protected static final int SOURCE_NONE = -1;
-    private static List<String> mDefaultRuleIds;
 
     private static ZenModeBackend sInstance;
 
@@ -65,7 +64,7 @@
     protected NotificationManager.Policy mPolicy;
     private final NotificationManager mNotificationManager;
 
-    private String TAG = "ZenModeSettingsBackend";
+    private static final String TAG = "ZenModeSettingsBackend";
     private final Context mContext;
 
     public static ZenModeBackend getInstance(Context context) {
@@ -95,19 +94,32 @@
     }
 
     protected boolean updateZenRule(String id, AutomaticZenRule rule) {
-        return NotificationManager.from(mContext).updateAutomaticZenRule(id, rule);
+        if (android.app.Flags.modesApi()) {
+            return mNotificationManager.updateAutomaticZenRule(id, rule, /* fromUser= */ true);
+        } else {
+            return NotificationManager.from(mContext).updateAutomaticZenRule(id, rule);
+        }
     }
 
     protected void setZenMode(int zenMode) {
-        NotificationManager.from(mContext).setZenMode(zenMode, null, TAG);
+        if (android.app.Flags.modesApi()) {
+            mNotificationManager.setZenMode(zenMode, null, TAG, /* fromUser= */ true);
+        } else {
+            NotificationManager.from(mContext).setZenMode(zenMode, null, TAG);
+        }
         mZenMode = getZenMode();
     }
 
     protected void setZenModeForDuration(int minutes) {
         Uri conditionId = ZenModeConfig.toTimeCondition(mContext, minutes,
                 ActivityManager.getCurrentUser(), true).id;
-        mNotificationManager.setZenMode(Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS,
-                conditionId, TAG);
+        if (android.app.Flags.modesApi()) {
+            mNotificationManager.setZenMode(Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS,
+                        conditionId, TAG, /* fromUser= */ true);
+        } else {
+            mNotificationManager.setZenMode(Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS,
+                    conditionId, TAG);
+        }
         mZenMode = getZenMode();
     }
 
@@ -180,7 +192,11 @@
             int priorityConversationSenders) {
         mPolicy = new NotificationManager.Policy(priorityCategories, priorityCallSenders,
                 priorityMessageSenders, suppressedVisualEffects, priorityConversationSenders);
-        mNotificationManager.setNotificationPolicy(mPolicy);
+        if (android.app.Flags.modesApi()) {
+            mNotificationManager.setNotificationPolicy(mPolicy, /* fromUser= */ true);
+        } else {
+            mNotificationManager.setNotificationPolicy(mPolicy);
+        }
     }
 
 
@@ -357,7 +373,11 @@
     }
 
     public boolean removeZenRule(String ruleId) {
-        return NotificationManager.from(mContext).removeAutomaticZenRule(ruleId);
+        if (android.app.Flags.modesApi()) {
+            return mNotificationManager.removeAutomaticZenRule(ruleId, /* fromUser= */ true);
+        } else {
+            return NotificationManager.from(mContext).removeAutomaticZenRule(ruleId);
+        }
     }
 
     public NotificationManager.Policy getConsolidatedPolicy() {
@@ -366,7 +386,11 @@
 
     protected String addZenRule(AutomaticZenRule rule) {
         try {
-            return NotificationManager.from(mContext).addAutomaticZenRule(rule);
+            if (android.app.Flags.modesApi()) {
+                return mNotificationManager.addAutomaticZenRule(rule, /* fromUser= */ true);
+            } else {
+                return NotificationManager.from(mContext).addAutomaticZenRule(rule);
+            }
         } catch (Exception e) {
             return null;
         }
@@ -429,10 +453,7 @@
     }
 
     private static List<String> getDefaultRuleIds() {
-        if (mDefaultRuleIds == null) {
-            mDefaultRuleIds = ZenModeConfig.DEFAULT_RULE_IDS;
-        }
-        return mDefaultRuleIds;
+        return ZenModeConfig.DEFAULT_RULE_IDS;
     }
 
     NotificationManager.Policy toNotificationPolicy(ZenPolicy policy) {
diff --git a/src/com/android/settings/notification/zen/ZenModeSliceBuilder.java b/src/com/android/settings/notification/zen/ZenModeSliceBuilder.java
index 8082bcd..4f6f058 100644
--- a/src/com/android/settings/notification/zen/ZenModeSliceBuilder.java
+++ b/src/com/android/settings/notification/zen/ZenModeSliceBuilder.java
@@ -19,6 +19,7 @@
 import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
 
 import android.annotation.ColorInt;
+import android.app.Flags;
 import android.app.NotificationManager;
 import android.app.PendingIntent;
 import android.app.settings.SettingsEnums;
@@ -116,7 +117,12 @@
         } else {
             zenMode = Settings.Global.ZEN_MODE_OFF;
         }
-        NotificationManager.from(context).setZenMode(zenMode, null /* conditionId */, TAG);
+        if (Flags.modesApi()) {
+            NotificationManager.from(context).setZenMode(zenMode, /* conditionId= */ null, TAG,
+                    /* fromUser= */ true);
+        } else {
+            NotificationManager.from(context).setZenMode(zenMode, null /* conditionId */, TAG);
+        }
         // Do not notifyChange on Uri. The service takes longer to update the current value than it
         // does for the Slice to check the current value again. Let {@link SliceBroadcastRelay}
         // handle it.
diff --git a/src/com/android/settings/notification/zen/ZenOnboardingActivity.java b/src/com/android/settings/notification/zen/ZenOnboardingActivity.java
index 23c388b..a6e78eb 100644
--- a/src/com/android/settings/notification/zen/ZenOnboardingActivity.java
+++ b/src/com/android/settings/notification/zen/ZenOnboardingActivity.java
@@ -17,6 +17,7 @@
 package com.android.settings.notification.zen;
 
 import android.app.Activity;
+import android.app.Flags;
 import android.app.NotificationManager;
 import android.app.NotificationManager.Policy;
 import android.app.settings.SettingsEnums;
@@ -129,7 +130,11 @@
                     Policy.PRIORITY_SENDERS_STARRED,
                     policy.priorityMessageSenders,
                     NotificationManager.Policy.getAllSuppressedVisualEffects());
-            mNm.setNotificationPolicy(newPolicy);
+            if (Flags.modesApi()) {
+                mNm.setNotificationPolicy(newPolicy, /* fromUser= */ true);
+            } else {
+                mNm.setNotificationPolicy(newPolicy);
+            }
             mMetrics.action(SettingsEnums.ACTION_ZEN_ONBOARDING_OK);
         } else {
             mMetrics.action(SettingsEnums.ACTION_ZEN_ONBOARDING_KEEP_CURRENT_SETTINGS);
diff --git a/src/com/android/settings/password/ChooseLockPassword.java b/src/com/android/settings/password/ChooseLockPassword.java
index 800adb0..631c735 100644
--- a/src/com/android/settings/password/ChooseLockPassword.java
+++ b/src/com/android/settings/password/ChooseLockPassword.java
@@ -260,7 +260,6 @@
         private LockscreenCredential mFirstPassword;
         private RecyclerView mPasswordRestrictionView;
         protected boolean mIsAlphaMode;
-        protected boolean mIsManagedProfile;
         protected FooterButton mSkipOrClearButton;
         private FooterButton mNextButton;
         private TextView mMessage;
@@ -272,6 +271,14 @@
 
         private static final int CONFIRM_EXISTING_REQUEST = 58;
         static final int RESULT_FINISHED = RESULT_FIRST_USER;
+        /** Used to store the profile type for which pin/password is being set */
+        protected enum ProfileType {
+            None,
+            Managed,
+            Private,
+            Other
+        };
+        protected ProfileType mProfileType;
 
         /**
          * Keep track internally of where the user is in choosing a pattern.
@@ -285,12 +292,14 @@
                     R.string.lockpassword_choose_your_password_header_for_fingerprint,
                     R.string.lockpassword_choose_your_password_header_for_face,
                     R.string.lockpassword_choose_your_password_header_for_biometrics,
+                    R.string.private_space_choose_your_password_header, // private space password
                     R.string.lockpassword_choose_your_pin_header, // pin
                     SET_WORK_PROFILE_PIN_HEADER,
                     R.string.lockpassword_choose_your_profile_pin_header,
                     R.string.lockpassword_choose_your_pin_header_for_fingerprint,
                     R.string.lockpassword_choose_your_pin_header_for_face,
                     R.string.lockpassword_choose_your_pin_header_for_biometrics,
+                    R.string.private_space_choose_your_pin_header, // private space pin
                     R.string.lock_settings_picker_biometrics_added_security_message,
                     R.string.lock_settings_picker_biometrics_added_security_message,
                     R.string.next_label),
@@ -302,12 +311,14 @@
                     R.string.lockpassword_confirm_your_password_header,
                     R.string.lockpassword_confirm_your_password_header,
                     R.string.lockpassword_confirm_your_password_header,
+                    R.string.lockpassword_confirm_your_password_header,
                     R.string.lockpassword_confirm_your_pin_header,
                     REENTER_WORK_PROFILE_PIN_HEADER,
                     R.string.lockpassword_reenter_your_profile_pin_header,
                     R.string.lockpassword_confirm_your_pin_header,
                     R.string.lockpassword_confirm_your_pin_header,
                     R.string.lockpassword_confirm_your_pin_header,
+                    R.string.lockpassword_confirm_your_pin_header,
                     0,
                     0,
                     R.string.lockpassword_confirm_label),
@@ -319,12 +330,14 @@
                     R.string.lockpassword_confirm_passwords_dont_match,
                     R.string.lockpassword_confirm_passwords_dont_match,
                     R.string.lockpassword_confirm_passwords_dont_match,
+                    R.string.lockpassword_confirm_passwords_dont_match,
                     R.string.lockpassword_confirm_pins_dont_match,
                     UNDEFINED,
                     R.string.lockpassword_confirm_pins_dont_match,
                     R.string.lockpassword_confirm_pins_dont_match,
                     R.string.lockpassword_confirm_pins_dont_match,
                     R.string.lockpassword_confirm_pins_dont_match,
+                    R.string.lockpassword_confirm_pins_dont_match,
                     0,
                     0,
                     R.string.lockpassword_confirm_label);
@@ -335,29 +348,33 @@
                     int hintInAlphaForFingerprint,
                     int hintInAlphaForFace,
                     int hintInAlphaForBiometrics,
+                    int hintInAlphaForPrivateProfile,
                     int hintInNumeric,
                     String hintOverrideInNumericForProfile,
                     int hintInNumericForProfile,
                     int hintInNumericForFingerprint,
                     int hintInNumericForFace,
                     int hintInNumericForBiometrics,
+                    int hintInNumericForPrivateProfile,
                     int messageInAlphaForBiometrics,
                     int messageInNumericForBiometrics,
                     int nextButtonText) {
 
                 this.alphaHint = hintInAlpha;
                 this.alphaHintOverrideForProfile = hintOverrideInAlphaForProfile;
-                this.alphaHintForProfile = hintInAlphaForProfile;
+                this.alphaHintForManagedProfile = hintInAlphaForProfile;
                 this.alphaHintForFingerprint = hintInAlphaForFingerprint;
                 this.alphaHintForFace = hintInAlphaForFace;
                 this.alphaHintForBiometrics = hintInAlphaForBiometrics;
+                this.alphaHintForPrivateProfile = hintInAlphaForPrivateProfile;
 
                 this.numericHint = hintInNumeric;
                 this.numericHintOverrideForProfile = hintOverrideInNumericForProfile;
-                this.numericHintForProfile = hintInNumericForProfile;
+                this.numericHintForManagedProfile = hintInNumericForProfile;
                 this.numericHintForFingerprint = hintInNumericForFingerprint;
                 this.numericHintForFace = hintInNumericForFace;
                 this.numericHintForBiometrics = hintInNumericForBiometrics;
+                this.numericHintForPrivateProfile = hintInNumericForPrivateProfile;
 
                 this.alphaMessageForBiometrics = messageInAlphaForBiometrics;
                 this.numericMessageForBiometrics = messageInNumericForBiometrics;
@@ -372,16 +389,18 @@
 
             // Password header
             public final int alphaHint;
+            public final int alphaHintForPrivateProfile;
             public final String alphaHintOverrideForProfile;
-            public final int alphaHintForProfile;
+            public final int alphaHintForManagedProfile;
             public final int alphaHintForFingerprint;
             public final int alphaHintForFace;
             public final int alphaHintForBiometrics;
 
             // PIN header
             public final int numericHint;
+            public final int numericHintForPrivateProfile;
             public final String numericHintOverrideForProfile;
-            public final int numericHintForProfile;
+            public final int numericHintForManagedProfile;
             public final int numericHintForFingerprint;
             public final int numericHintForFace;
             public final int numericHintForBiometrics;
@@ -394,34 +413,40 @@
 
             public final int buttonText;
 
-            public String getHint(Context context, boolean isAlpha, int type, boolean isProfile) {
+            public String getHint(Context context, boolean isAlpha, int type, ProfileType profile) {
                 if (isAlpha) {
-                    if (type == TYPE_FINGERPRINT) {
+                    if (android.os.Flags.allowPrivateProfile()
+                            && profile.equals(ProfileType.Private)) {
+                        return context.getString(alphaHintForPrivateProfile);
+                    } else if (type == TYPE_FINGERPRINT) {
                         return context.getString(alphaHintForFingerprint);
                     } else if (type == TYPE_FACE) {
                         return context.getString(alphaHintForFace);
                     } else if (type == TYPE_BIOMETRIC) {
                         return context.getString(alphaHintForBiometrics);
-                    } else if (isProfile) {
+                    } else if (profile.equals(ProfileType.Managed)) {
                         return context.getSystemService(DevicePolicyManager.class).getResources()
                                 .getString(alphaHintOverrideForProfile,
-                                        () -> context.getString(alphaHintForProfile));
+                                        () -> context.getString(alphaHintForManagedProfile));
                     } else {
                         return context.getString(alphaHint);
                     }
                 } else {
-                    if (type == TYPE_FINGERPRINT) {
+                    if (android.os.Flags.allowPrivateProfile()
+                            && profile.equals(ProfileType.Private)) {
+                        return context.getString(numericHintForPrivateProfile);
+                    } else if (type == TYPE_FINGERPRINT) {
                         return context.getString(numericHintForFingerprint);
                     } else if (type == TYPE_FACE) {
                         return context.getString(numericHintForFace);
                     } else if (type == TYPE_BIOMETRIC) {
                         return context.getString(numericHintForBiometrics);
-                    } else if (isProfile) {
+                    } else if (profile.equals(ProfileType.Managed)) {
                         return context.getSystemService(DevicePolicyManager.class).getResources()
                                 .getString(numericHintOverrideForProfile,
-                                        () -> context.getString(numericHintForProfile));
+                                        () -> context.getString(numericHintForManagedProfile));
                     } else {
-                        return  context.getString(numericHint);
+                        return context.getString(numericHint);
                     }
                 }
             }
@@ -455,7 +480,7 @@
             }
             // Only take this argument into account if it belongs to the current profile.
             mUserId = Utils.getUserIdFromBundle(getActivity(), intent.getExtras());
-            mIsManagedProfile = UserManager.get(getActivity()).isManagedProfile(mUserId);
+            mProfileType = getProfileType();
             mForFingerprint = intent.getBooleanExtra(
                     ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, false);
             mForFace = intent.getBooleanExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE, false);
@@ -602,7 +627,7 @@
             if (activity instanceof SettingsActivity) {
                 final SettingsActivity sa = (SettingsActivity) activity;
                 String title = Stage.Introduction.getHint(
-                        getContext(), mIsAlphaMode, getStageType(), mIsManagedProfile);
+                        getContext(), mIsAlphaMode, getStageType(), mProfileType);
                 sa.setTitle(title);
                 mLayout.setHeaderText(title);
             }
@@ -938,7 +963,7 @@
                 // Hide password requirement view when we are just asking user to confirm the pw.
                 mPasswordRestrictionView.setVisibility(View.GONE);
                 setHeaderText(mUiStage.getHint(getContext(), mIsAlphaMode, getStageType(),
-                        mIsManagedProfile));
+                        mProfileType));
                 setNextEnabled(canInput && length >= LockPatternUtils.MIN_LOCK_PASSWORD_SIZE);
                 mSkipOrClearButton.setVisibility(toVisibility(canInput && length > 0));
 
@@ -1084,6 +1109,12 @@
                     startActivity(intent);
                 }
             }
+
+            if (mLayout != null) {
+                mLayout.announceForAccessibility(
+                        getString(R.string.accessibility_setup_password_complete));
+            }
+
             getActivity().finish();
         }
 
@@ -1110,5 +1141,18 @@
                 }
             }
         }
+
+        private ProfileType getProfileType() {
+            UserManager userManager = getContext().createContextAsUser(UserHandle.of(mUserId),
+                    /*flags=*/0).getSystemService(UserManager.class);
+            if (userManager.isManagedProfile()) {
+                return ProfileType.Managed;
+            } else if (android.os.Flags.allowPrivateProfile() && userManager.isPrivateProfile()) {
+                return ProfileType.Private;
+            } else if (userManager.isProfile()) {
+                return ProfileType.Other;
+            }
+            return ProfileType.None;
+        }
     }
 }
diff --git a/src/com/android/settings/password/ChooseLockPattern.java b/src/com/android/settings/password/ChooseLockPattern.java
index 20d1e7d..b24a27e 100644
--- a/src/com/android/settings/password/ChooseLockPattern.java
+++ b/src/com/android/settings/password/ChooseLockPattern.java
@@ -478,6 +478,8 @@
                         .getString(SET_WORK_PROFILE_PATTERN_HEADER,
                                 () -> getString(
                                         R.string.lockpassword_choose_your_profile_pattern_header));
+            } else if (android.os.Flags.allowPrivateProfile() && isPrivateProfile()) {
+                msg = getString(R.string.private_space_choose_your_pattern_header);
             } else {
                 msg = getString(R.string.lockpassword_choose_your_pattern_header);
             }
@@ -871,7 +873,19 @@
                     startActivity(intent);
                 }
             }
+
+            if (mSudContent != null) {
+                mSudContent.announceForAccessibility(
+                        getString(R.string.accessibility_setup_password_complete));
+            }
+
             getActivity().finish();
         }
+
+        private boolean isPrivateProfile() {
+            UserManager userManager = getContext().createContextAsUser(UserHandle.of(mUserId),
+                    /*flags=*/0).getSystemService(UserManager.class);
+            return userManager.isPrivateProfile();
+        }
     }
 }
diff --git a/src/com/android/settings/privatespace/PrivateSpaceAuthenticationActivity.java b/src/com/android/settings/privatespace/PrivateSpaceAuthenticationActivity.java
index a118221..69c4d9d 100644
--- a/src/com/android/settings/privatespace/PrivateSpaceAuthenticationActivity.java
+++ b/src/com/android/settings/privatespace/PrivateSpaceAuthenticationActivity.java
@@ -20,6 +20,7 @@
 
 import android.app.AlertDialog;
 import android.app.KeyguardManager;
+import android.app.PendingIntent;
 import android.app.settings.SettingsEnums;
 import android.content.Context;
 import android.content.DialogInterface;
@@ -53,11 +54,12 @@
     private KeyguardManager mKeyguardManager;
 
     private final ActivityResultLauncher<Intent> mSetDeviceLock =
-            registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
+            registerForActivityResult(
+                    new ActivityResultContracts.StartActivityForResult(),
                     this::onSetDeviceLockResult);
     private final ActivityResultLauncher<Intent> mVerifyDeviceLock =
-            registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
-                    this::onVerifyDeviceLock);
+            registerForActivityResult(
+                    new ActivityResultContracts.StartActivityForResult(), this::onVerifyDeviceLock);
 
     static class Injector {
         PrivateSpaceMaintainer injectPrivateSpaceMaintainer(Context context) {
@@ -71,17 +73,14 @@
 
         if (Flags.allowPrivateProfile()) {
             ThemeHelper.trySetDynamicColor(this);
-            mPrivateSpaceMaintainer = new Injector().injectPrivateSpaceMaintainer(
-                    getApplicationContext());
+            mPrivateSpaceMaintainer =
+                    new Injector().injectPrivateSpaceMaintainer(getApplicationContext());
             if (getKeyguardManager().isDeviceSecure()) {
                 if (savedInstanceState == null) {
-                    Intent credentialIntent =
-                            mPrivateSpaceMaintainer.getPrivateProfileLockCredentialIntent();
-                    if (credentialIntent != null) {
-                        mVerifyDeviceLock.launch(credentialIntent);
+                    if (mPrivateSpaceMaintainer.doesPrivateSpaceExist()) {
+                        unlockAndLaunchPrivateSpaceSettings(this);
                     } else {
-                        Log.e(TAG, "verifyCredentialIntent is null even though device lock is set");
-                        finish();
+                        authenticatePrivateSpaceEntry();
                     }
                 }
             } else {
@@ -96,14 +95,10 @@
     @VisibleForTesting
     public void onLockAuthentication(Context context) {
         if (mPrivateSpaceMaintainer.doesPrivateSpaceExist()) {
-            new SubSettingLauncher(context)
-                    .setDestination(PrivateSpaceDashboardFragment.class.getName())
-                    .setTransitionType(
-                            SettingsTransitionHelper.TransitionType.TRANSITION_SLIDE)
-                    .setSourceMetricsCategory(SettingsEnums.PRIVATE_SPACE_SETTINGS)
-                    .launch();
+            unlockAndLaunchPrivateSpaceSettings(context);
         } else {
             startActivity(new Intent(context, PrivateSpaceSetupActivity.class));
+            finish();
         }
     }
 
@@ -135,22 +130,54 @@
         if (mKeyguardManager == null) {
             mKeyguardManager = getSystemService(KeyguardManager.class);
         }
-        return  mKeyguardManager;
+        return mKeyguardManager;
     }
 
     private void onSetDeviceLockResult(@Nullable ActivityResult result) {
         if (result != null) {
             if (getKeyguardManager().isDeviceSecure()) {
                 onLockAuthentication(this);
+            } else {
+                finish();
             }
-            finish();
         }
     }
 
     private void onVerifyDeviceLock(@Nullable ActivityResult result) {
         if (result != null && result.getResultCode() == RESULT_OK) {
             onLockAuthentication(this);
+        } else {
+            finish();
+        }
+    }
+
+    private void unlockAndLaunchPrivateSpaceSettings(Context context) {
+        SubSettingLauncher privateSpaceSettings =
+                new SubSettingLauncher(context)
+                        .setDestination(PrivateSpaceDashboardFragment.class.getName())
+                        .setTransitionType(SettingsTransitionHelper.TransitionType.TRANSITION_SLIDE)
+                        .setSourceMetricsCategory(SettingsEnums.PRIVATE_SPACE_SETTINGS);
+        if (mPrivateSpaceMaintainer.isPrivateSpaceLocked()) {
+            mPrivateSpaceMaintainer.unlockPrivateSpace(
+                    PendingIntent.getActivity(
+                                    context, /* requestCode */
+                                    0,
+                                    privateSpaceSettings.toIntent(),
+                                    PendingIntent.FLAG_IMMUTABLE)
+                            .getIntentSender());
+        } else {
+            privateSpaceSettings.launch();
         }
         finish();
     }
+
+    private void authenticatePrivateSpaceEntry() {
+        Intent credentialIntent = mPrivateSpaceMaintainer.getPrivateProfileLockCredentialIntent();
+        if (credentialIntent != null) {
+            mVerifyDeviceLock.launch(credentialIntent);
+        } else {
+            Log.e(TAG, "verifyCredentialIntent is null even though device lock is set");
+            finish();
+        }
+    }
 }
diff --git a/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java b/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java
index b8f140f..c565ace 100644
--- a/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java
+++ b/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java
@@ -25,6 +25,7 @@
 import android.app.KeyguardManager;
 import android.content.Context;
 import android.content.Intent;
+import android.content.IntentSender;
 import android.content.pm.UserInfo;
 import android.os.Flags;
 import android.os.RemoteException;
@@ -241,6 +242,17 @@
         return false;
     }
 
+    /**
+     * Checks if private space exists and requests to disable quiet mode.
+     *
+     * @param intentSender target to start when the user is unlocked
+     */
+    public synchronized void unlockPrivateSpace(IntentSender intentSender) {
+        if (mUserHandle != null) {
+            mUserManager.requestQuietModeEnabled(false, mUserHandle, intentSender);
+        }
+    }
+
     /** Returns true if private space exists and is running, otherwise returns false */
     @VisibleForTesting
     synchronized boolean isPrivateProfileRunning() {
diff --git a/src/com/android/settings/privatespace/PrivateSpaceSetLockFragment.java b/src/com/android/settings/privatespace/PrivateSpaceSetLockFragment.java
index a256ea6..6495a41 100644
--- a/src/com/android/settings/privatespace/PrivateSpaceSetLockFragment.java
+++ b/src/com/android/settings/privatespace/PrivateSpaceSetLockFragment.java
@@ -97,6 +97,8 @@
             mMetricsFeatureProvider.action(
                     getContext(), SettingsEnums.ACTION_PRIVATE_SPACE_SETUP_USE_SCREEN_LOCK);
             // Simply Use default screen lock. No need to handle
+            mMetricsFeatureProvider.action(
+                    getContext(), SettingsEnums.ACTION_PRIVATE_SPACE_SETUP_ACCOUNT_LOGIN_START);
             launchActivityForAction(ACCOUNT_LOGIN_ACTION);
         };
     }
diff --git a/src/com/android/settings/privatespace/PrivateSpaceSetupActivity.java b/src/com/android/settings/privatespace/PrivateSpaceSetupActivity.java
index 21224ff..da0a805 100644
--- a/src/com/android/settings/privatespace/PrivateSpaceSetupActivity.java
+++ b/src/com/android/settings/privatespace/PrivateSpaceSetupActivity.java
@@ -66,6 +66,8 @@
             if (userHandle != null) {
                 Intent intent = new Intent(this, PrivateProfileContextHelperActivity.class);
                 intent.putExtra(EXTRA_ACTION_TYPE, ACCOUNT_LOGIN_ACTION);
+                mMetricsFeatureProvider.action(
+                        this, SettingsEnums.ACTION_PRIVATE_SPACE_SETUP_ACCOUNT_LOGIN_START);
                 startActivityForResultAsUser(intent, ACCOUNT_LOGIN_ACTION, userHandle);
             } else {
                 Log.w(TAG, "Private profile user handle is null");
diff --git a/src/com/android/settings/privatespace/onelock/PrivateSpaceLockController.java b/src/com/android/settings/privatespace/onelock/PrivateSpaceLockController.java
index 20298a1..efbe9f9 100644
--- a/src/com/android/settings/privatespace/onelock/PrivateSpaceLockController.java
+++ b/src/com/android/settings/privatespace/onelock/PrivateSpaceLockController.java
@@ -20,6 +20,7 @@
 import static com.android.internal.widget.LockPatternUtils.CREDENTIAL_TYPE_PATTERN;
 import static com.android.internal.widget.LockPatternUtils.CREDENTIAL_TYPE_PIN;
 import static com.android.settings.password.ChooseLockGeneric.ChooseLockGenericFragment.HIDE_INSECURE_OPTIONS;
+import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_CHOOSE_LOCK_SCREEN_TITLE;
 
 import android.content.Context;
 import android.content.Intent;
@@ -94,6 +95,7 @@
         final Bundle extras = new Bundle();
         extras.putInt(Intent.EXTRA_USER_ID, mProfileUserId);
         extras.putBoolean(HIDE_INSECURE_OPTIONS, true);
+        extras.putInt(EXTRA_KEY_CHOOSE_LOCK_SCREEN_TITLE, R.string.private_space_lock_setup_title);
         new SubSettingLauncher(mContext)
                 .setDestination(ChooseLockGeneric.ChooseLockGenericFragment.class.getName())
                 .setSourceMetricsCategory(mHost.getMetricsCategory())
diff --git a/src/com/android/settings/spa/app/appinfo/AppButtons.kt b/src/com/android/settings/spa/app/appinfo/AppButtons.kt
index 403263c..c0fa313 100644
--- a/src/com/android/settings/spa/app/appinfo/AppButtons.kt
+++ b/src/com/android/settings/spa/app/appinfo/AppButtons.kt
@@ -63,7 +63,7 @@
 
     @Composable
     private fun getActionButtons(app: ApplicationInfo): List<ActionButton> = listOfNotNull(
-        if (featureFlags.archiving()) {
+        if (isArchivingEnabled(featureFlags)) {
             if (app.isArchived) {
                 appRestoreButton.getActionButton(app)
             } else {
diff --git a/src/com/android/settings/spa/app/appinfo/AppInfoSettings.kt b/src/com/android/settings/spa/app/appinfo/AppInfoSettings.kt
index 85e59de..9291892 100644
--- a/src/com/android/settings/spa/app/appinfo/AppInfoSettings.kt
+++ b/src/com/android/settings/spa/app/appinfo/AppInfoSettings.kt
@@ -125,7 +125,7 @@
         title = stringResource(R.string.application_info_label),
         actions = {
             packageInfoState.value?.applicationInfo?.let { app ->
-                if (featureFlags.archiving()) TopBarAppLaunchButton(packageInfoPresenter, app)
+                if (isArchivingEnabled(featureFlags)) TopBarAppLaunchButton(packageInfoPresenter, app)
                 AppInfoSettingsMoreOptions(packageInfoPresenter, app)
             }
         }
@@ -174,3 +174,6 @@
         appInfoProvider.FooterAppVersion()
     }
 }
+
+fun isArchivingEnabled(featureFlags: FeatureFlags) =
+        featureFlags.archiving() || "true" == System.getProperty("pm.archiving.enabled")
diff --git a/src/com/android/settings/spa/app/appinfo/PackageInfoPresenter.kt b/src/com/android/settings/spa/app/appinfo/PackageInfoPresenter.kt
index 8c802d1..230ccb9 100644
--- a/src/com/android/settings/spa/app/appinfo/PackageInfoPresenter.kt
+++ b/src/com/android/settings/spa/app/appinfo/PackageInfoPresenter.kt
@@ -166,7 +166,7 @@
             flags = PackageManager.MATCH_ANY_USER.toLong() or
                 PackageManager.MATCH_DISABLED_COMPONENTS.toLong() or
                 PackageManager.GET_PERMISSIONS.toLong() or
-                if (featureFlags.archiving()) PackageManager.MATCH_ARCHIVED_PACKAGES else 0,
+                if (isArchivingEnabled(featureFlags)) PackageManager.MATCH_ARCHIVED_PACKAGES else 0,
             userId = userId,
         )
 }
diff --git a/src/com/android/settings/webview/WebViewUpdateServiceWrapper.java b/src/com/android/settings/webview/WebViewUpdateServiceWrapper.java
index ff4ae41..05855e4 100644
--- a/src/com/android/settings/webview/WebViewUpdateServiceWrapper.java
+++ b/src/com/android/settings/webview/WebViewUpdateServiceWrapper.java
@@ -22,11 +22,14 @@
 import android.content.pm.PackageManager;
 import android.os.RemoteException;
 import android.util.Log;
+import android.webkit.IWebViewUpdateService;
 import android.webkit.UserPackage;
 import android.webkit.WebViewFactory;
 import android.webkit.WebViewProviderInfo;
 import android.widget.Toast;
 
+import androidx.annotation.Nullable;
+
 import java.util.ArrayList;
 import java.util.List;
 
@@ -104,5 +107,24 @@
         toast.show();
     }
 
+    /**
+     * Fetch the package name of the default WebView provider.
+     */
+    @Nullable
+    public String getDefaultWebViewPackageName() {
+        try {
+            IWebViewUpdateService service = WebViewFactory.getUpdateService();
+            if (service != null) {
+                WebViewProviderInfo provider = service.getDefaultWebViewPackage();
+                if (provider != null) {
+                    return provider.packageName;
+                }
+            }
+        } catch (RemoteException e) {
+            Log.e(TAG, "RemoteException when trying to fetch default WebView package Name", e);
+        }
+        return null;
+    }
+
     static final int PACKAGE_FLAGS = PackageManager.MATCH_ANY_USER;
 }
diff --git a/tests/robotests/Android.bp b/tests/robotests/Android.bp
index 95a78c7..d313878 100644
--- a/tests/robotests/Android.bp
+++ b/tests/robotests/Android.bp
@@ -57,6 +57,7 @@
         "Settings_robolectric_meta_service_file",
         "SettingsLib-robo-testutils",
         "Settings-robo-testutils",
+        "android.webkit.flags-aconfig-java",
         "androidx.test.core",
         "androidx.test.espresso.core",
         "androidx.test.ext.junit",
diff --git a/tests/robotests/src/com/android/settings/applications/ApplicationFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/applications/ApplicationFeatureProviderImplTest.java
index 6bed1bc..bac0de9 100644
--- a/tests/robotests/src/com/android/settings/applications/ApplicationFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/applications/ApplicationFeatureProviderImplTest.java
@@ -37,13 +37,20 @@
 import android.os.Build;
 import android.os.UserHandle;
 import android.os.UserManager;
+import android.platform.test.annotations.RequiresFlagsDisabled;
+import android.platform.test.annotations.RequiresFlagsEnabled;
+import android.platform.test.flag.junit.CheckFlagsRule;
+import android.platform.test.flag.junit.DeviceFlagsValueProvider;
+import android.webkit.Flags;
 
 import com.android.settings.testutils.ApplicationTestUtils;
+import com.android.settings.webview.WebViewUpdateServiceWrapper;
 import com.android.settingslib.testutils.shadow.ShadowDefaultDialerManager;
 import com.android.settingslib.testutils.shadow.ShadowSmsApplication;
 
 import org.junit.Before;
 import org.junit.Ignore;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
@@ -67,6 +74,9 @@
 @LooperMode(LooperMode.Mode.LEGACY)
 public final class ApplicationFeatureProviderImplTest {
 
+    @Rule
+    public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
+
     private final int MAIN_USER_ID = 0;
     private final int MANAGED_PROFILE_ID = 10;
 
@@ -91,6 +101,8 @@
     private DevicePolicyManager mDevicePolicyManager;
     @Mock
     private LocationManager mLocationManager;
+    @Mock
+    private WebViewUpdateServiceWrapper mWebViewUpdateServiceWrapper;
 
     private ApplicationFeatureProvider mProvider;
 
@@ -106,7 +118,7 @@
         when(mContext.getSystemService(Context.LOCATION_SERVICE)).thenReturn(mLocationManager);
 
         mProvider = new ApplicationFeatureProviderImpl(mContext, mPackageManager,
-                mPackageManagerService, mDevicePolicyManager);
+                mPackageManagerService, mDevicePolicyManager, mWebViewUpdateServiceWrapper);
     }
 
     private void verifyCalculateNumberOfPolicyInstalledApps(boolean async) {
@@ -342,6 +354,26 @@
     }
 
     @Test
+    @RequiresFlagsEnabled(Flags.FLAG_UPDATE_SERVICE_V2)
+    public void getKeepEnabledPackages_shouldContainWebViewPackage() {
+        final String testWebViewPackageName = "com.android.webview";
+        when(mWebViewUpdateServiceWrapper.getDefaultWebViewPackageName())
+                .thenReturn(testWebViewPackageName);
+        final Set<String> allowlist = mProvider.getKeepEnabledPackages();
+        assertThat(allowlist).contains(testWebViewPackageName);
+    }
+
+    @Test
+    @RequiresFlagsDisabled(Flags.FLAG_UPDATE_SERVICE_V2)
+    public void getKeepEnabledPackages_shouldNotContainWebViewPackageIfFlagDisabled() {
+        final String testWebViewPackageName = "com.android.webview";
+        when(mWebViewUpdateServiceWrapper.getDefaultWebViewPackageName())
+                .thenReturn(testWebViewPackageName);
+        final Set<String> allowlist = mProvider.getKeepEnabledPackages();
+        assertThat(allowlist).doesNotContain(testWebViewPackageName);
+    }
+
+    @Test
     @Config(shadows = {ShadowSmsApplication.class, ShadowDefaultDialerManager.class})
     public void getKeepEnabledPackages_shouldContainPackageInstaller() {
         final String testDialer = "com.android.test.defaultdialer";
diff --git a/tests/robotests/src/com/android/settings/datausage/DataUsageListTest.kt b/tests/robotests/src/com/android/settings/datausage/DataUsageListTest.kt
deleted file mode 100644
index 39b8446..0000000
--- a/tests/robotests/src/com/android/settings/datausage/DataUsageListTest.kt
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * 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.datausage
-
-import android.content.Context
-import android.content.Intent
-import android.net.NetworkTemplate
-import android.os.Bundle
-import android.os.UserManager
-import android.provider.Settings
-import androidx.preference.Preference
-import androidx.test.core.app.ApplicationProvider
-import com.android.settings.datausage.DataUsageListTest.ShadowDataUsageBaseFragment
-import com.android.settings.datausage.TemplatePreference.NetworkServices
-import com.android.settings.datausage.lib.BillingCycleRepository
-import com.android.settings.testutils.FakeFeatureFactory
-import com.android.settingslib.NetworkPolicyEditor
-import com.android.settingslib.core.AbstractPreferenceController
-import com.google.common.truth.Truth.assertThat
-import org.junit.Before
-import org.junit.Rule
-import org.junit.Test
-import org.junit.runner.RunWith
-import org.mockito.Mock
-import org.mockito.Mockito.doNothing
-import org.mockito.Mockito.doReturn
-import org.mockito.Mockito.mock
-import org.mockito.Mockito.never
-import org.mockito.Mockito.verify
-import org.mockito.Mockito.`when`
-import org.mockito.Spy
-import org.mockito.junit.MockitoJUnit
-import org.mockito.junit.MockitoRule
-import org.robolectric.RobolectricTestRunner
-import org.robolectric.annotation.Config
-import org.robolectric.annotation.Implementation
-import org.robolectric.annotation.Implements
-import org.robolectric.util.ReflectionHelpers
-
-@RunWith(RobolectricTestRunner::class)
-@Config(shadows = [ShadowDataUsageBaseFragment::class])
-class DataUsageListTest {
-    @get:Rule
-    val mockito: MockitoRule = MockitoJUnit.rule()
-
-    @Mock
-    private lateinit var networkServices: NetworkServices
-
-    @Mock
-    private lateinit var userManager: UserManager
-
-    @Mock
-    private lateinit var billingCycleRepository: BillingCycleRepository
-
-    @Mock
-    private lateinit var dataUsageListHeaderController: DataUsageListHeaderController
-
-    @Spy
-    private val context: Context = ApplicationProvider.getApplicationContext()
-
-    @Spy
-    private val dataUsageList = TestDataUsageList()
-
-    @Before
-    fun setUp() {
-        FakeFeatureFactory.setupForTest()
-        networkServices.mPolicyEditor = mock(NetworkPolicyEditor::class.java)
-        doReturn(context).`when`(dataUsageList).context
-        doReturn(userManager).`when`(context).getSystemService(UserManager::class.java)
-        doReturn(false).`when`(userManager).isGuestUser
-        ReflectionHelpers.setField(dataUsageList, "services", networkServices)
-        doNothing().`when`(dataUsageList).updateSubscriptionInfoEntity()
-        `when`(billingCycleRepository.isBandwidthControlEnabled()).thenReturn(true)
-        dataUsageList.dataUsageListHeaderController = dataUsageListHeaderController
-    }
-
-    @Test
-    fun onCreate_isNotGuestUser_shouldNotFinish() {
-        dataUsageList.template = mock<NetworkTemplate>(NetworkTemplate::class.java)
-        doReturn(false).`when`(userManager).isGuestUser
-        doNothing().`when`(dataUsageList).processArgument()
-        dataUsageList.onCreate(null)
-        verify(dataUsageList, never()).finish()
-    }
-
-    @Test
-    fun onCreate_isGuestUser_shouldFinish() {
-        doReturn(true).`when`(userManager).isGuestUser
-        dataUsageList.onCreate(null)
-        verify(dataUsageList).finish()
-    }
-
-    @Test
-    fun processArgument_shouldGetTemplateFromArgument() {
-        val args = Bundle()
-        args.putParcelable(
-            DataUsageList.EXTRA_NETWORK_TEMPLATE, mock(
-                NetworkTemplate::class.java
-            )
-        )
-        args.putInt(DataUsageList.EXTRA_SUB_ID, 3)
-        dataUsageList.arguments = args
-        dataUsageList.processArgument()
-        assertThat(dataUsageList.template).isNotNull()
-        assertThat(dataUsageList.subId).isEqualTo(3)
-    }
-
-    @Test
-    fun processArgument_fromIntent_shouldGetTemplateFromIntent() {
-        val intent = Intent()
-        intent.putExtra(
-            Settings.EXTRA_NETWORK_TEMPLATE, mock(
-                NetworkTemplate::class.java
-            )
-        )
-        intent.putExtra(Settings.EXTRA_SUB_ID, 3)
-        doReturn(intent).`when`(dataUsageList).intent
-        dataUsageList.processArgument()
-        assertThat(dataUsageList.template).isNotNull()
-        assertThat(dataUsageList.subId).isEqualTo(3)
-    }
-
-    @Test
-    fun updatePolicy_setConfigButtonVisible() {
-        dataUsageList.template = mock(NetworkTemplate::class.java)
-        dataUsageList.onCreate(null)
-
-        dataUsageList.updatePolicy()
-
-        verify(dataUsageListHeaderController).setConfigButtonVisible(true)
-    }
-
-    @Implements(DataUsageBaseFragment::class)
-    class ShadowDataUsageBaseFragment {
-        @Implementation
-        fun onCreate(@Suppress("UNUSED_PARAMETER") icicle: Bundle?) {
-            // do nothing
-        }
-    }
-
-    open inner class TestDataUsageList : DataUsageList() {
-        override fun <T : AbstractPreferenceController?> use(clazz: Class<T>): T = mock(clazz)
-
-        @Suppress("UNCHECKED_CAST")
-        override fun <T : Preference?> findPreference(key: CharSequence): T =
-            mock(Preference::class.java) as T
-
-        public override fun getIntent() = Intent()
-
-        override fun createBillingCycleRepository() = billingCycleRepository
-
-        override fun isBillingCycleModifiable() = true
-    }
-}
diff --git a/tests/spa_unit/Android.bp b/tests/spa_unit/Android.bp
index c3e99f7..4df6254 100644
--- a/tests/spa_unit/Android.bp
+++ b/tests/spa_unit/Android.bp
@@ -34,6 +34,7 @@
         "androidx.compose.runtime_runtime",
         "androidx.test.ext.junit",
         "androidx.test.runner",
+        "androidx.fragment_fragment-testing",
         "flag-junit",
         "mockito-target-extended-minus-junit4",
     ],
diff --git a/tests/spa_unit/src/com/android/settings/datausage/DataUsageListTest.kt b/tests/spa_unit/src/com/android/settings/datausage/DataUsageListTest.kt
new file mode 100644
index 0000000..29ec0ee
--- /dev/null
+++ b/tests/spa_unit/src/com/android/settings/datausage/DataUsageListTest.kt
@@ -0,0 +1,131 @@
+/*
+ * 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.datausage
+
+import android.content.Context
+import android.content.Intent
+import android.net.NetworkTemplate
+import android.os.UserManager
+import android.provider.Settings
+import android.telephony.SubscriptionManager
+import androidx.core.os.bundleOf
+import androidx.fragment.app.testing.launchFragment
+import androidx.fragment.app.testing.withFragment
+import androidx.lifecycle.Lifecycle
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settingslib.spaprivileged.framework.common.userManager
+import com.google.common.truth.Truth.assertThat
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.kotlin.doReturn
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.spy
+import org.mockito.kotlin.stub
+
+private val mockUserManager: UserManager = mock<UserManager>()
+
+private val mockContext: Context = spy(ApplicationProvider.getApplicationContext()) {
+    on { userManager } doReturn mockUserManager
+}
+
+private var fakeIntent = Intent()
+
+@RunWith(AndroidJUnit4::class)
+class DataUsageListTest {
+
+    @Before
+    fun setUp() {
+        mockUserManager.stub {
+            on { isGuestUser } doReturn false
+        }
+        fakeIntent = Intent()
+    }
+
+    @Test
+    fun launchFragment_withoutArguments_finish() {
+        val scenario = launchFragment<TestDataUsageList>(initialState = Lifecycle.State.CREATED)
+
+        scenario.withFragment {
+            assertThat(template).isNull()
+            assertThat(subId).isEqualTo(SubscriptionManager.INVALID_SUBSCRIPTION_ID)
+            assertThat(activity!!.isFinishing).isTrue()
+        }
+    }
+
+    @Test
+    fun launchFragment_isGuestUser_finish() {
+        mockUserManager.stub {
+            on { isGuestUser } doReturn true
+        }
+        val fragmentArgs = bundleOf(
+            DataUsageList.EXTRA_NETWORK_TEMPLATE to mock<NetworkTemplate>(),
+            DataUsageList.EXTRA_SUB_ID to 3,
+        )
+
+        val scenario = launchFragment<TestDataUsageList>(
+            fragmentArgs = fragmentArgs,
+            initialState = Lifecycle.State.CREATED,
+        )
+
+        scenario.withFragment {
+            assertThat(activity!!.isFinishing).isTrue()
+        }
+    }
+
+    @Test
+    fun launchFragment_withArguments_getTemplateFromArgument() {
+        val fragmentArgs = bundleOf(
+            DataUsageList.EXTRA_NETWORK_TEMPLATE to mock<NetworkTemplate>(),
+            DataUsageList.EXTRA_SUB_ID to 3,
+        )
+
+        val scenario = launchFragment<TestDataUsageList>(
+            fragmentArgs = fragmentArgs,
+            initialState = Lifecycle.State.CREATED,
+        )
+
+        scenario.withFragment {
+            assertThat(template).isNotNull()
+            assertThat(subId).isEqualTo(3)
+            assertThat(activity!!.isFinishing).isFalse()
+        }
+    }
+
+    @Test
+    fun launchFragment_withIntent_getTemplateFromIntent() {
+        fakeIntent = Intent().apply {
+            putExtra(Settings.EXTRA_NETWORK_TEMPLATE, mock<NetworkTemplate>())
+            putExtra(Settings.EXTRA_SUB_ID, 2)
+        }
+
+        val scenario = launchFragment<TestDataUsageList>(initialState = Lifecycle.State.CREATED)
+
+        scenario.withFragment {
+            assertThat(template).isNotNull()
+            assertThat(subId).isEqualTo(2)
+            assertThat(activity!!.isFinishing).isFalse()
+        }
+    }
+}
+
+class TestDataUsageList : DataUsageList() {
+    override fun getContext() = mockContext
+
+    override fun getIntent() = fakeIntent
+}
diff --git a/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceControllerTest.java b/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceControllerTest.java
index 4601a1c..fa5af6d 100644
--- a/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceControllerTest.java
@@ -20,6 +20,7 @@
 
 import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
@@ -27,12 +28,15 @@
 import static org.mockito.Mockito.when;
 
 import android.app.AppOpsManager;
+import android.app.Flags;
 import android.app.NotificationManager;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
+import android.platform.test.annotations.EnableFlags;
+import android.platform.test.flag.junit.SetFlagsRule;
 
 import androidx.test.core.app.ApplicationProvider;
 import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -42,6 +46,7 @@
 import com.android.settingslib.RestrictedSwitchPreference;
 
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
@@ -50,6 +55,10 @@
 @RunWith(AndroidJUnit4.class)
 public class ApprovalPreferenceControllerTest {
 
+    @Rule
+    public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(
+            SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT);
+
     private Context mContext;
     private FakeFeatureFactory mFeatureFactory;
     @Mock
@@ -80,7 +89,6 @@
         mController.setNm(mNm);
         mController.setParent(mFragment);
         mController.setPkgInfo(mPkgInfo);
-
     }
 
     @Test
@@ -165,6 +173,7 @@
     }
 
     @Test
+    @EnableFlags(Flags.FLAG_MODES_API)
     public void disable() {
         mController.disable(mCn);
         verify(mFeatureFactory.metricsFeatureProvider).action(
@@ -172,6 +181,7 @@
                 MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_NOTIVIEW_ALLOW,
                 "a");
 
+        verify(mNm).removeAutomaticZenRules(eq(mCn.getPackageName()), eq(true));
         verify(mNm).setNotificationListenerAccessGranted(mCn, false);
     }
 }