Merge "Fix flicker for Mobile data & Wi-Fi page" into tm-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 762d84d..4117b2e 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -866,6 +866,7 @@
         <activity
             android:name=".localepicker.AppLocalePickerActivity"
             android:label="@string/app_locale_picker_title"
+            android:configChanges="orientation|screenSize|keyboardHidden"
             android:exported="true" >
             <intent-filter>
                 <action android:name="android.settings.APP_LOCALE_SETTINGS" />
@@ -1451,7 +1452,8 @@
         <activity
             android:name=".datausage.AppDataUsageActivity"
             android:exported="true"
-            android:noHistory="true">
+            android:noHistory="true"
+            android:permission="android.permission.QUERY_ALL_PACKAGES">
             <intent-filter android:priority="1">
                 <action android:name="android.settings.IGNORE_BACKGROUND_DATA_RESTRICTIONS_SETTINGS" />
                 <category android:name="android.intent.category.DEFAULT" />
@@ -1521,6 +1523,7 @@
         <activity-alias android:name=".applications.InstalledAppDetails"
                 android:label="@string/application_info_label"
                 android:exported="true"
+                android:permission="android.permission.QUERY_ALL_PACKAGES"
                 android:targetActivity=".applications.InstalledAppDetailsTop">
             <intent-filter android:priority="1">
                 <action android:name="android.settings.APPLICATION_DETAILS_SETTINGS" />
@@ -1534,7 +1537,8 @@
 
         <activity android:name=".applications.InstalledAppOpenByDefaultActivity"
                   android:label="@string/application_info_label"
-                  android:exported="true">
+                  android:exported="true"
+                  android:permission="android.permission.QUERY_ALL_PACKAGES">
             <intent-filter android:priority="1">
                 <action android:name="android.settings.APP_OPEN_BY_DEFAULT_SETTINGS" />
                 <!-- Also catch legacy "com." prefixed action. -->
@@ -1905,7 +1909,8 @@
         <activity
             android:name="Settings$AppUsageAccessSettingsActivity"
             android:exported="true"
-            android:label="@string/usage_access_title">
+            android:label="@string/usage_access_title"
+            android:permission="android.permission.QUERY_ALL_PACKAGES">
             <intent-filter>
                 <action android:name="android.settings.USAGE_ACCESS_SETTINGS"/>
                 <category android:name="android.intent.category.DEFAULT"/>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index c80e42c..f11cee5 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -452,6 +452,7 @@
 
     <!-- Text padding for EmptyTextSettings -->
     <dimen name="empty_text_padding">24dp</dimen>
+    <dimen name="empty_text_layout_height">450dp</dimen>
 
     <!--  Choose SIM Activity dimens  -->
     <dimen name="subtitle_bottom_padding">24dp</dimen>
diff --git a/res/xml/accessibility_settings.xml b/res/xml/accessibility_settings.xml
index 509aed6..0287fc6 100644
--- a/res/xml/accessibility_settings.xml
+++ b/res/xml/accessibility_settings.xml
@@ -41,7 +41,8 @@
             android:icon="@drawable/ic_adaptive_font_download"
             android:key="text_reading_options"
             android:persistent="false"
-            android:title="@string/accessibility_text_reading_options_title" />
+            android:title="@string/accessibility_text_reading_options_title"
+            settings:controller="com.android.settings.accessibility.TextReadingFragmentForA11ySettingsController"/>
 
         <Preference
             android:fragment="com.android.settings.accessibility.ColorAndMotionFragment"
diff --git a/res/xml/accessibility_settings_for_setup_wizard.xml b/res/xml/accessibility_settings_for_setup_wizard.xml
index a50e7dd..6929d54 100644
--- a/res/xml/accessibility_settings_for_setup_wizard.xml
+++ b/res/xml/accessibility_settings_for_setup_wizard.xml
@@ -26,7 +26,8 @@
         android:key="text_reading_options"
         android:persistent="false"
         android:title="@string/accessibility_text_reading_options_title"
-        settings:keywords="text_reading_options" />
+        settings:keywords="text_reading_options"
+        settings:controller="com.android.settings.accessibility.TextReadingFragmentForSuwController"/>
 
     <Preference
         android:fragment="com.android.settings.accessibility.ToggleScreenMagnificationPreferenceFragmentForSetupWizard"
diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml
index 03d073b..2336c15 100644
--- a/res/xml/display_settings.xml
+++ b/res/xml/display_settings.xml
@@ -72,7 +72,8 @@
             android:fragment="com.android.settings.accessibility.TextReadingPreferenceFragment"
             android:key="text_reading_options"
             android:persistent="false"
-            android:title="@string/accessibility_text_reading_options_title" />
+            android:title="@string/accessibility_text_reading_options_title"
+            settings:controller="com.android.settings.accessibility.TextReadingFragmentForDisplaySettingsController"/>
     </PreferenceCategory>
 
     <PreferenceCategory
diff --git a/src/com/android/settings/accessibility/AccessibilityStatsLogUtils.java b/src/com/android/settings/accessibility/AccessibilityStatsLogUtils.java
index 434157d..d8a887d 100644
--- a/src/com/android/settings/accessibility/AccessibilityStatsLogUtils.java
+++ b/src/com/android/settings/accessibility/AccessibilityStatsLogUtils.java
@@ -16,6 +16,16 @@
 
 package com.android.settings.accessibility;
 
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.BOLD_TEXT_KEY;
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.DISPLAY_SIZE_KEY;
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.ACCESSIBILITY_SETTINGS;
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.DISPLAY_SETTINGS;
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.SUW_ANYTHING_ELSE;
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.SUW_VISION_SETTINGS;
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.FONT_SIZE_KEY;
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.HIGH_TEXT_CONTRAST_KEY;
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.RESET_KEY;
+
 import android.content.ComponentName;
 
 import com.android.settings.core.instrumentation.SettingsStatsLog;
@@ -58,4 +68,48 @@
                                 .ACCESSIBILITY_PRIVACY_WARNING_STATUS_SERVICE_DISABLED,
                         durationMills);
     }
+
+    /**
+     * Converts to the key name for logging.
+     *
+     * @param prefKey the preference key
+     * @return the int value which maps to the key name
+     */
+    static int convertToItemKeyName(String prefKey) {
+        switch (prefKey) {
+            case FONT_SIZE_KEY:
+                return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__NAME__TEXT_READING_FONT_SIZE;
+            case DISPLAY_SIZE_KEY:
+                return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__NAME__TEXT_READING_DISPLAY_SIZE;
+            case BOLD_TEXT_KEY:
+                return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__NAME__TEXT_READING_BOLD_TEXT;
+            case HIGH_TEXT_CONTRAST_KEY:
+                return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__NAME__TEXT_READING_HIGH_CONTRAST_TEXT;
+            case RESET_KEY:
+                return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__NAME__TEXT_READING_RESET;
+            default:
+                return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__NAME__TEXT_READING_UNKNOWN_ITEM;
+        }
+    }
+
+    /**
+     * Converts to the entry point for logging.
+     *
+     * @param entryPoint the entry point
+     * @return the int value which maps to the entry point
+     */
+    static int convertToEntryPoint(int entryPoint) {
+        switch (entryPoint) {
+            case SUW_VISION_SETTINGS:
+                return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__ENTRY_POINT__TEXT_READING_SUW_VISION_SETTINGS;
+            case SUW_ANYTHING_ELSE:
+                return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__ENTRY_POINT__TEXT_READING_SUW_ANYTHING_ELSE;
+            case DISPLAY_SETTINGS:
+                return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__ENTRY_POINT__TEXT_READING_DISPLAY_SETTINGS;
+            case ACCESSIBILITY_SETTINGS:
+                return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__ENTRY_POINT__TEXT_READING_ACCESSIBILITY_SETTINGS;
+            default:
+                return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__ENTRY_POINT__TEXT_READING_UNKNOWN_ENTRY;
+        }
+    }
 }
diff --git a/src/com/android/settings/accessibility/FontWeightAdjustmentPreferenceController.java b/src/com/android/settings/accessibility/FontWeightAdjustmentPreferenceController.java
index e3c1b9e..923e880 100644
--- a/src/com/android/settings/accessibility/FontWeightAdjustmentPreferenceController.java
+++ b/src/com/android/settings/accessibility/FontWeightAdjustmentPreferenceController.java
@@ -21,7 +21,9 @@
 import android.provider.Settings;
 
 import com.android.settings.R;
+import com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint;
 import com.android.settings.core.TogglePreferenceController;
+import com.android.settings.core.instrumentation.SettingsStatsLog;
 
 /** PreferenceController for displaying all text in bold. */
 public class FontWeightAdjustmentPreferenceController extends TogglePreferenceController implements
@@ -29,6 +31,9 @@
     static final int BOLD_TEXT_ADJUSTMENT =
             FontStyle.FONT_WEIGHT_BOLD - FontStyle.FONT_WEIGHT_NORMAL;
 
+    @EntryPoint
+    private int mEntryPoint;
+
     public FontWeightAdjustmentPreferenceController(Context context, String preferenceKey) {
         super(context, preferenceKey);
     }
@@ -46,6 +51,12 @@
 
     @Override
     public boolean setChecked(boolean isChecked) {
+        SettingsStatsLog.write(
+                SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED,
+                AccessibilityStatsLogUtils.convertToItemKeyName(getPreferenceKey()),
+                isChecked ? 1 : 0,
+                AccessibilityStatsLogUtils.convertToEntryPoint(mEntryPoint));
+
         return Settings.Secure.putInt(mContext.getContentResolver(),
                 Settings.Secure.FONT_WEIGHT_ADJUSTMENT, (isChecked ? BOLD_TEXT_ADJUSTMENT : 0));
     }
@@ -59,4 +70,13 @@
     public void resetState() {
         setChecked(false);
     }
+
+    /**
+     * The entry point is used for logging.
+     *
+     * @param entryPoint from which settings page
+     */
+    void setEntryPoint(@EntryPoint int entryPoint) {
+        mEntryPoint = entryPoint;
+    }
 }
diff --git a/src/com/android/settings/accessibility/HighTextContrastPreferenceController.java b/src/com/android/settings/accessibility/HighTextContrastPreferenceController.java
index 8c9d234..9f645f1 100644
--- a/src/com/android/settings/accessibility/HighTextContrastPreferenceController.java
+++ b/src/com/android/settings/accessibility/HighTextContrastPreferenceController.java
@@ -23,7 +23,9 @@
 import androidx.preference.SwitchPreference;
 
 import com.android.settings.R;
+import com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint;
 import com.android.settings.core.TogglePreferenceController;
+import com.android.settings.core.instrumentation.SettingsStatsLog;
 
 /**
  * PreferenceController for displaying all text in high contrast style.
@@ -32,6 +34,9 @@
         TextReadingResetController.ResetStateListener {
     private SwitchPreference mSwitchPreference;
 
+    @EntryPoint
+    private int mEntryPoint;
+
     public HighTextContrastPreferenceController(Context context, String preferenceKey) {
         super(context, preferenceKey);
     }
@@ -49,6 +54,12 @@
 
     @Override
     public boolean setChecked(boolean isChecked) {
+        SettingsStatsLog.write(
+                SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED,
+                AccessibilityStatsLogUtils.convertToItemKeyName(getPreferenceKey()),
+                isChecked ? 1 : 0,
+                AccessibilityStatsLogUtils.convertToEntryPoint(mEntryPoint));
+
         return Settings.Secure.putInt(mContext.getContentResolver(),
                 Settings.Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED, (isChecked ? 1 : 0));
     }
@@ -69,4 +80,13 @@
         setChecked(false);
         updateState(mSwitchPreference);
     }
+
+    /**
+     * The entry point is used for logging.
+     *
+     * @param entryPoint from which settings page
+     */
+    void setEntryPoint(@EntryPoint int entryPoint) {
+        mEntryPoint = entryPoint;
+    }
 }
diff --git a/src/com/android/settings/accessibility/PreviewSizeSeekBarController.java b/src/com/android/settings/accessibility/PreviewSizeSeekBarController.java
index c7dfd61..711eb0f 100644
--- a/src/com/android/settings/accessibility/PreviewSizeSeekBarController.java
+++ b/src/com/android/settings/accessibility/PreviewSizeSeekBarController.java
@@ -22,7 +22,9 @@
 import androidx.annotation.NonNull;
 import androidx.preference.PreferenceScreen;
 
+import com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint;
 import com.android.settings.core.BasePreferenceController;
+import com.android.settings.core.instrumentation.SettingsStatsLog;
 import com.android.settings.widget.LabeledSeekBarPreference;
 
 /**
@@ -36,6 +38,9 @@
     private ProgressInteractionListener mInteractionListener;
     private LabeledSeekBarPreference mSeekBarPreference;
 
+    @EntryPoint
+    private int mEntryPoint;
+
     private final SeekBar.OnSeekBarChangeListener mSeekBarChangeListener =
             new SeekBar.OnSeekBarChangeListener() {
                 @Override
@@ -45,6 +50,12 @@
                     if (!mSeekByTouch && mInteractionListener != null) {
                         mInteractionListener.onProgressChanged();
                     }
+
+                    SettingsStatsLog.write(
+                            SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED,
+                            AccessibilityStatsLogUtils.convertToItemKeyName(getPreferenceKey()),
+                            progress,
+                            AccessibilityStatsLogUtils.convertToEntryPoint(mEntryPoint));
                 }
 
                 @Override
@@ -97,6 +108,15 @@
     }
 
     /**
+     * The entry point is used for logging.
+     *
+     * @param entryPoint from which settings page
+     */
+    void setEntryPoint(@EntryPoint int entryPoint) {
+        mEntryPoint = entryPoint;
+    }
+
+    /**
      * Interface for callbacks when users interact with the seek bar.
      */
     interface ProgressInteractionListener {
diff --git a/src/com/android/settings/accessibility/TextReadingFragmentBaseController.java b/src/com/android/settings/accessibility/TextReadingFragmentBaseController.java
new file mode 100644
index 0000000..f26ca96
--- /dev/null
+++ b/src/com/android/settings/accessibility/TextReadingFragmentBaseController.java
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+
+package com.android.settings.accessibility;
+
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.EXTRA_LAUNCHED_FROM;
+
+import android.content.Context;
+import android.os.Bundle;
+
+import androidx.preference.Preference;
+
+import com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint;
+import com.android.settings.core.BasePreferenceController;
+
+/**
+ * The base controller for the fragment{@link TextReadingPreferenceFragment}.
+ */
+public class TextReadingFragmentBaseController extends BasePreferenceController {
+    @EntryPoint
+    private int mEntryPoint;
+
+    private TextReadingFragmentBaseController(Context context, String preferenceKey) {
+        super(context, preferenceKey);
+    }
+
+    TextReadingFragmentBaseController(Context context, String preferenceKey,
+            @EntryPoint int entryPoint) {
+        this(context, preferenceKey);
+        mEntryPoint = entryPoint;
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return AVAILABLE;
+    }
+
+    @Override
+    public boolean handlePreferenceTreeClick(Preference preference) {
+        if (getPreferenceKey().equals(preference.getKey())) {
+            final Bundle extras = preference.getExtras();
+            extras.putInt(EXTRA_LAUNCHED_FROM, mEntryPoint);
+        }
+
+        return super.handlePreferenceTreeClick(preference);
+    }
+}
diff --git a/src/com/android/settings/accessibility/TextReadingFragmentForA11ySettingsController.java b/src/com/android/settings/accessibility/TextReadingFragmentForA11ySettingsController.java
new file mode 100644
index 0000000..434877c
--- /dev/null
+++ b/src/com/android/settings/accessibility/TextReadingFragmentForA11ySettingsController.java
@@ -0,0 +1,32 @@
+/*
+ * 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.
+ */
+
+package com.android.settings.accessibility;
+
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.ACCESSIBILITY_SETTINGS;
+
+import android.content.Context;
+
+/**
+ * The controller for the {@link TextReadingPreferenceFragment} from the accessibility settings.
+ */
+public class TextReadingFragmentForA11ySettingsController extends
+        TextReadingFragmentBaseController {
+    public TextReadingFragmentForA11ySettingsController(Context context, String preferenceKey) {
+        // Pass the fixed entry point to the parent controller for logging.
+        super(context, preferenceKey, ACCESSIBILITY_SETTINGS);
+    }
+}
diff --git a/src/com/android/settings/accessibility/TextReadingFragmentForDisplaySettingsController.java b/src/com/android/settings/accessibility/TextReadingFragmentForDisplaySettingsController.java
new file mode 100644
index 0000000..4d603f9
--- /dev/null
+++ b/src/com/android/settings/accessibility/TextReadingFragmentForDisplaySettingsController.java
@@ -0,0 +1,32 @@
+/*
+ * 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.
+ */
+
+package com.android.settings.accessibility;
+
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.DISPLAY_SETTINGS;
+
+import android.content.Context;
+
+/**
+ * The controller for the {@link TextReadingPreferenceFragment} from the display settings.
+ */
+public class TextReadingFragmentForDisplaySettingsController extends
+        TextReadingFragmentBaseController {
+    public TextReadingFragmentForDisplaySettingsController(Context context, String preferenceKey) {
+        // Pass the fixed entry point to the parent controller for logging.
+        super(context, preferenceKey, DISPLAY_SETTINGS);
+    }
+}
diff --git a/src/com/android/settings/accessibility/TextReadingFragmentForSuwController.java b/src/com/android/settings/accessibility/TextReadingFragmentForSuwController.java
new file mode 100644
index 0000000..332d9c5
--- /dev/null
+++ b/src/com/android/settings/accessibility/TextReadingFragmentForSuwController.java
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+package com.android.settings.accessibility;
+
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.SUW_VISION_SETTINGS;
+
+import android.content.Context;
+
+/**
+ * The controller for the {@link TextReadingPreferenceFragment} during the SetupWizard.
+ */
+public class TextReadingFragmentForSuwController extends TextReadingFragmentBaseController {
+    public TextReadingFragmentForSuwController(Context context, String preferenceKey) {
+        // Pass the fixed entry point to the parent controller for logging.
+        super(context, preferenceKey, SUW_VISION_SETTINGS);
+    }
+}
diff --git a/src/com/android/settings/accessibility/TextReadingPreferenceFragment.java b/src/com/android/settings/accessibility/TextReadingPreferenceFragment.java
index a4ee961c..104be26 100644
--- a/src/com/android/settings/accessibility/TextReadingPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/TextReadingPreferenceFragment.java
@@ -22,9 +22,11 @@
 import android.app.settings.SettingsEnums;
 import android.content.Context;
 import android.content.DialogInterface;
+import android.content.Intent;
 import android.os.Bundle;
 import android.widget.Toast;
 
+import androidx.annotation.IntDef;
 import androidx.appcompat.app.AlertDialog;
 
 import com.android.settings.R;
@@ -36,8 +38,11 @@
 
 import com.google.common.annotations.VisibleForTesting;
 
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Set;
 import java.util.stream.Collectors;
 
 /**
@@ -46,15 +51,40 @@
  */
 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
 public class TextReadingPreferenceFragment extends DashboardFragment {
+    public static final String EXTRA_LAUNCHED_FROM = "launched_from";
     private static final String TAG = "TextReadingPreferenceFragment";
-    private static final String FONT_SIZE_KEY = "font_size";
-    private static final String DISPLAY_SIZE_KEY = "display_size";
+    private static final String CATEGORY_FOR_ANYTHING_ELSE =
+            "com.android.settings.suggested.category.DISPLAY_SETTINGS";
+    static final String FONT_SIZE_KEY = "font_size";
+    static final String DISPLAY_SIZE_KEY = "display_size";
+    static final String BOLD_TEXT_KEY = "toggle_force_bold_text";
+    static final String HIGH_TEXT_CONTRAST_KEY = "toggle_high_text_contrast_preference";
+    static final String RESET_KEY = "reset";
     private static final String PREVIEW_KEY = "preview";
-    private static final String RESET_KEY = "reset";
-    private static final String BOLD_TEXT_KEY = "toggle_force_bold_text";
-    private static final String HIGHT_TEXT_CONTRAST_KEY = "toggle_high_text_contrast_preference";
     private static final String NEED_RESET_SETTINGS = "need_reset_settings";
     private FontWeightAdjustmentPreferenceController mFontWeightAdjustmentController;
+    private int mEntryPoint = EntryPoint.UNKNOWN_ENTRY;
+
+    /**
+     * The entry point which launches the {@link TextReadingPreferenceFragment}.
+     *
+     * <p>This should only be used for logging.
+     */
+    @Retention(RetentionPolicy.SOURCE)
+    @IntDef({
+            EntryPoint.UNKNOWN_ENTRY,
+            EntryPoint.SUW_VISION_SETTINGS,
+            EntryPoint.SUW_ANYTHING_ELSE,
+            EntryPoint.DISPLAY_SETTINGS,
+            EntryPoint.ACCESSIBILITY_SETTINGS,
+    })
+    @interface EntryPoint {
+        int UNKNOWN_ENTRY = 0;
+        int SUW_VISION_SETTINGS = 1;
+        int SUW_ANYTHING_ELSE = 2;
+        int DISPLAY_SETTINGS = 3;
+        int ACCESSIBILITY_SETTINGS = 4;
+    }
 
     @VisibleForTesting
     List<ResetStateListener> mResetStateListeners;
@@ -91,6 +121,8 @@
 
     @Override
     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
+        updateEntryPoint();
+
         final List<AbstractPreferenceController> controllers = new ArrayList<>();
         final FontSizeData fontSizeData = new FontSizeData(context);
         final DisplaySizeData displaySizeData = createDisplaySizeData(context);
@@ -102,24 +134,29 @@
         final PreviewSizeSeekBarController fontSizeController = new PreviewSizeSeekBarController(
                 context, FONT_SIZE_KEY, fontSizeData);
         fontSizeController.setInteractionListener(previewController);
+        fontSizeController.setEntryPoint(mEntryPoint);
         controllers.add(fontSizeController);
 
         final PreviewSizeSeekBarController displaySizeController = new PreviewSizeSeekBarController(
                 context, DISPLAY_SIZE_KEY, displaySizeData);
         displaySizeController.setInteractionListener(previewController);
+        displaySizeController.setEntryPoint(mEntryPoint);
         controllers.add(displaySizeController);
 
         mFontWeightAdjustmentController =
                 new FontWeightAdjustmentPreferenceController(context, BOLD_TEXT_KEY);
+        mFontWeightAdjustmentController.setEntryPoint(mEntryPoint);
         controllers.add(mFontWeightAdjustmentController);
 
         final HighTextContrastPreferenceController highTextContrastController =
-                new HighTextContrastPreferenceController(context, HIGHT_TEXT_CONTRAST_KEY);
+                new HighTextContrastPreferenceController(context, HIGH_TEXT_CONTRAST_KEY);
+        highTextContrastController.setEntryPoint(mEntryPoint);
         controllers.add(highTextContrastController);
 
         final TextReadingResetController resetController =
                 new TextReadingResetController(context, RESET_KEY,
                         v -> showDialog(DialogEnums.DIALOG_RESET_SETTINGS));
+        resetController.setEntryPoint(mEntryPoint);
         controllers.add(resetController);
 
         return controllers;
@@ -162,6 +199,24 @@
         return new DisplaySizeData(context);
     }
 
+    private void updateEntryPoint() {
+        final Bundle bundle = getArguments();
+        if (bundle != null && bundle.containsKey(EXTRA_LAUNCHED_FROM)) {
+            mEntryPoint = bundle.getInt(EXTRA_LAUNCHED_FROM, EntryPoint.UNKNOWN_ENTRY);
+            return;
+        }
+
+        final Intent intent = getIntent();
+        if (intent == null) {
+            mEntryPoint = EntryPoint.UNKNOWN_ENTRY;
+            return;
+        }
+
+        final Set<String> categories = intent.getCategories();
+        mEntryPoint = categories != null && categories.contains(CATEGORY_FOR_ANYTHING_ELSE)
+                ? EntryPoint.SUW_ANYTHING_ELSE : EntryPoint.UNKNOWN_ENTRY;
+    }
+
     private void onPositiveButtonClicked(DialogInterface dialog, int which) {
         // To avoid showing the dialog again, probably the onDetach() of SettingsDialogFragment
         // was interrupted by unexpectedly recreating the activity.
diff --git a/src/com/android/settings/accessibility/TextReadingResetController.java b/src/com/android/settings/accessibility/TextReadingResetController.java
index 152ad5f..30a94c2 100644
--- a/src/com/android/settings/accessibility/TextReadingResetController.java
+++ b/src/com/android/settings/accessibility/TextReadingResetController.java
@@ -23,7 +23,9 @@
 import androidx.preference.PreferenceScreen;
 
 import com.android.settings.R;
+import com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint;
 import com.android.settings.core.BasePreferenceController;
+import com.android.settings.core.instrumentation.SettingsStatsLog;
 import com.android.settingslib.widget.LayoutPreference;
 
 /**
@@ -32,6 +34,9 @@
 class TextReadingResetController extends BasePreferenceController {
     private final View.OnClickListener mOnResetClickListener;
 
+    @EntryPoint
+    private int mEntryPoint;
+
     TextReadingResetController(Context context, String preferenceKey,
             @Nullable View.OnClickListener listener) {
         super(context, preferenceKey);
@@ -52,11 +57,26 @@
         view.setOnClickListener(v -> {
             if (mOnResetClickListener != null) {
                 mOnResetClickListener.onClick(v);
+
+                SettingsStatsLog.write(
+                        SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED,
+                        AccessibilityStatsLogUtils.convertToItemKeyName(getPreferenceKey()),
+                        /* reset */ -1,
+                        AccessibilityStatsLogUtils.convertToEntryPoint(mEntryPoint));
             }
         });
     }
 
     /**
+     * The entry point is used for logging.
+     *
+     * @param entryPoint from which settings page
+     */
+    void setEntryPoint(@EntryPoint int entryPoint) {
+        mEntryPoint = entryPoint;
+    }
+
+    /**
      * Interface for resetting to default state.
      */
     interface ResetStateListener {
diff --git a/src/com/android/settings/applications/manageapplications/ManageApplications.java b/src/com/android/settings/applications/manageapplications/ManageApplications.java
index 3eae885..062bfc5 100644
--- a/src/com/android/settings/applications/manageapplications/ManageApplications.java
+++ b/src/com/android/settings/applications/manageapplications/ManageApplications.java
@@ -330,8 +330,8 @@
             if (className.equals(Settings.NotificationReviewPermissionsActivity.class.getName())) {
                 // Special-case for a case where a user is directed to the all apps notification
                 // preferences page via a notification prompt to review permissions settings.
-                android.provider.Settings.Secure.putInt(getContext().getContentResolver(),
-                        android.provider.Settings.Secure.REVIEW_PERMISSIONS_NOTIFICATION_STATE,
+                android.provider.Settings.Global.putInt(getContext().getContentResolver(),
+                        android.provider.Settings.Global.REVIEW_PERMISSIONS_NOTIFICATION_STATE,
                         1);  // USER_INTERACTED
             }
         } else if (className.equals(AppLocaleDetails.class.getName())) {
diff --git a/src/com/android/settings/applications/specialaccess/premiumsms/PremiumSmsAccess.java b/src/com/android/settings/applications/specialaccess/premiumsms/PremiumSmsAccess.java
index f1c578e..3df19be 100644
--- a/src/com/android/settings/applications/specialaccess/premiumsms/PremiumSmsAccess.java
+++ b/src/com/android/settings/applications/specialaccess/premiumsms/PremiumSmsAccess.java
@@ -68,7 +68,7 @@
     @Override
     public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
         super.onViewCreated(view, savedInstanceState);
-        setLoading(true, false);
+        setEmptyText(R.string.premium_sms_none);
     }
 
     @Override
@@ -138,8 +138,6 @@
 
     private void updatePrefs(ArrayList<AppEntry> apps) {
         if (apps == null) return;
-        setEmptyText(R.string.premium_sms_none);
-        setLoading(false, true);
         final PreferenceScreen screen = getPreferenceScreen();
         screen.removeAll();
         screen.setOrderingAsAdded(true);
diff --git a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
index f3085bc..b1ffcf1 100644
--- a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
+++ b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
@@ -69,7 +69,7 @@
         mCm = cm;
         mVm = vm;
         mResources = resources;
-        mWorkPolicyUtils = new WorkPolicyUtils(mContext, mPm, mUm, mDpm);
+        mWorkPolicyUtils = new WorkPolicyUtils(mContext);
     }
 
     @Override
diff --git a/src/com/android/settings/fuelgauge/BatteryAppListPreferenceController.java b/src/com/android/settings/fuelgauge/BatteryAppListPreferenceController.java
index 8fb0d1e..db4cc53 100644
--- a/src/com/android/settings/fuelgauge/BatteryAppListPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/BatteryAppListPreferenceController.java
@@ -424,6 +424,9 @@
 
     @VisibleForTesting
     void setUsageSummary(Preference preference, BatteryEntry entry) {
+        if (entry.getUid() == Process.SYSTEM_UID) {
+          return;
+        }
         // Only show summary when usage time is longer than one minute
         final long usageTimeMs = entry.getTimeInForegroundMs();
         if (shouldShowSummary(entry) && usageTimeMs >= DateUtils.MINUTE_IN_MILLIS) {
diff --git a/src/com/android/settings/fuelgauge/BatteryInfo.java b/src/com/android/settings/fuelgauge/BatteryInfo.java
index 98f19fe..b1e4c34 100644
--- a/src/com/android/settings/fuelgauge/BatteryInfo.java
+++ b/src/com/android/settings/fuelgauge/BatteryInfo.java
@@ -153,6 +153,7 @@
         new AsyncTask<Void, Void, BatteryInfo>() {
             @Override
             protected BatteryInfo doInBackground(Void... params) {
+                boolean shouldCloseBatteryUsageStats = false;
                 BatteryUsageStats stats;
                 if (batteryUsageStats != null) {
                     stats = batteryUsageStats;
@@ -160,6 +161,7 @@
                     try {
                         stats = context.getSystemService(BatteryStatsManager.class)
                                 .getBatteryUsageStats();
+                        shouldCloseBatteryUsageStats = true;
                     } catch (RuntimeException e) {
                         Log.e(TAG, "getBatteryInfo() from getBatteryUsageStats()", e);
                         // Use default BatteryUsageStats.
@@ -168,10 +170,12 @@
                 }
                 final BatteryInfo batteryInfo =
                         getBatteryInfo(context, stats, shortString);
-                try {
-                    stats.close();
-                } catch (Exception e) {
-                    Log.e(TAG, "BatteryUsageStats.close() failed", e);
+                if (shouldCloseBatteryUsageStats) {
+                    try {
+                        stats.close();
+                    } catch (Exception e) {
+                        Log.e(TAG, "BatteryUsageStats.close() failed", e);
+                    }
                 }
                 return batteryInfo;
             }
diff --git a/src/com/android/settings/fuelgauge/PowerUsageBase.java b/src/com/android/settings/fuelgauge/PowerUsageBase.java
index e950679..6563155 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageBase.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageBase.java
@@ -83,6 +83,7 @@
     public void onStop() {
         super.onStop();
         mBatteryBroadcastReceiver.unRegister();
+        closeBatteryUsageStatsIfNeeded();
     }
 
     protected void restartBatteryStatsLoader(int refreshType) {
@@ -104,16 +105,6 @@
         final long startTime = System.currentTimeMillis();
         historyPref.setBatteryUsageStats(mBatteryUsageStats);
         BatteryUtils.logRuntime(TAG, "updatePreference", startTime);
-        if (mBatteryUsageStats == null) {
-            return;
-        }
-        try {
-            mBatteryUsageStats.close();
-        } catch (Exception e) {
-            Log.e(TAG, "BatteryUsageStats.close() failed", e);
-        } finally {
-            mBatteryUsageStats = null;
-        }
     }
 
     private class BatteryUsageStatsLoaderCallbacks
@@ -130,6 +121,7 @@
         @Override
         public void onLoadFinished(Loader<BatteryUsageStats> loader,
                 BatteryUsageStats batteryUsageStats) {
+            closeBatteryUsageStatsIfNeeded();
             mBatteryUsageStats = batteryUsageStats;
             PowerUsageBase.this.onLoadFinished(mRefreshType);
         }
@@ -138,4 +130,17 @@
         public void onLoaderReset(Loader<BatteryUsageStats> loader) {
         }
     }
+
+    private void closeBatteryUsageStatsIfNeeded() {
+        if (mBatteryUsageStats == null) {
+            return;
+        }
+        try {
+            mBatteryUsageStats.close();
+        } catch (Exception e) {
+            Log.e(TAG, "BatteryUsageStats.close() failed", e);
+        } finally {
+            mBatteryUsageStats = null;
+        }
+    }
 }
diff --git a/src/com/android/settings/localepicker/AppLocalePickerActivity.java b/src/com/android/settings/localepicker/AppLocalePickerActivity.java
index 4700f3f..1ed6f5b 100644
--- a/src/com/android/settings/localepicker/AppLocalePickerActivity.java
+++ b/src/com/android/settings/localepicker/AppLocalePickerActivity.java
@@ -30,7 +30,6 @@
 import android.widget.FrameLayout;
 import android.widget.ListView;
 
-import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.app.LocalePickerWithRegion;
 import com.android.internal.app.LocaleStore;
 import com.android.settings.R;
@@ -38,10 +37,6 @@
 import com.android.settings.applications.appinfo.AppLocaleDetails;
 import com.android.settings.core.SettingsBaseActivity;
 
-/**
- * TODO(b/223503670): Add unit test for AppLocalePickerActivity.
- * A activity to show the locale picker and information page.
- */
 public class AppLocalePickerActivity extends SettingsBaseActivity
         implements LocalePickerWithRegion.LocaleSelectedListener {
     private static final String TAG = AppLocalePickerActivity.class.getSimpleName();
@@ -128,8 +123,7 @@
         return appLocaleDetailsContainer;
     }
 
-    @VisibleForTesting
-    void launchLocalePickerPage() {
+    private void launchLocalePickerPage() {
         // LocalePickerWithRegion use android.app.ListFragment. Thus, it can not use
         // getSupportFragmentManager() to add this into container.
         android.app.FragmentManager fragmentManager = getFragmentManager();
diff --git a/src/com/android/settings/network/SubscriptionsPreferenceController.java b/src/com/android/settings/network/SubscriptionsPreferenceController.java
index 218e3ec..44ad411 100644
--- a/src/com/android/settings/network/SubscriptionsPreferenceController.java
+++ b/src/com/android/settings/network/SubscriptionsPreferenceController.java
@@ -232,11 +232,11 @@
                 connectCarrierNetwork();
                 return true;
             });
-
-            mSubsGearPref.setOnGearClickListener(p ->
-                    MobileNetworkUtils.launchMobileNetworkSettings(mContext, subInfo));
         }
 
+        mSubsGearPref.setOnGearClickListener(p ->
+                MobileNetworkUtils.launchMobileNetworkSettings(mContext, subInfo));
+
         if (!(mContext.getSystemService(UserManager.class)).isAdminUser()) {
             mSubsGearPref.setGearEnabled(false);
         }
diff --git a/src/com/android/settings/notification/MediaVolumePreferenceController.java b/src/com/android/settings/notification/MediaVolumePreferenceController.java
index 978a4b4..c0d5610 100644
--- a/src/com/android/settings/notification/MediaVolumePreferenceController.java
+++ b/src/com/android/settings/notification/MediaVolumePreferenceController.java
@@ -35,6 +35,7 @@
 import com.android.settings.slices.CustomSliceRegistry;
 import com.android.settings.slices.SliceBackgroundWorker;
 import com.android.settingslib.media.MediaDevice;
+import com.android.settingslib.media.MediaOutputConstants;
 
 public class MediaVolumePreferenceController extends VolumeSeekBarPreferenceController {
     private static final String TAG = "MediaVolumePreCtrl";
@@ -106,8 +107,10 @@
 
         final Intent intent = new Intent();
         if (getWorker().isDeviceBroadcasting()) {
-            // TODO(b/229577323) : Get the intent action for the Media Output Broadcast Dialog
-            //  in SystemUI
+            intent.setPackage(MediaOutputConstants.SYSTEMUI_PACKAGE_NAME);
+            intent.setAction(MediaOutputConstants.ACTION_LAUNCH_MEDIA_OUTPUT_BROADCAST_DIALOG);
+            intent.putExtra(MediaOutputConstants.EXTRA_PACKAGE_NAME,
+                    getWorker().getActiveLocalMediaController().getPackageName());
         } else {
             // TODO(b/229577518) : Get the intent action of the Bluetooth Broadcast Dialog
             //  for user to choose the action
diff --git a/src/com/android/settings/widget/EmptyTextSettings.java b/src/com/android/settings/widget/EmptyTextSettings.java
index 87513dd..a6e5c60 100644
--- a/src/com/android/settings/widget/EmptyTextSettings.java
+++ b/src/com/android/settings/widget/EmptyTextSettings.java
@@ -43,8 +43,10 @@
         TypedValue value = new TypedValue();
         getContext().getTheme().resolveAttribute(android.R.attr.textAppearanceMedium, value, true);
         mEmpty.setTextAppearance(value.resourceId);
+        final int layoutHeight = getContext().getResources()
+                .getDimensionPixelSize(R.dimen.empty_text_layout_height);
         ((ViewGroup) view.findViewById(android.R.id.list_container)).addView(mEmpty,
-                new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
+                new LayoutParams(LayoutParams.MATCH_PARENT, layoutHeight));
         setEmptyView(mEmpty);
     }
 
diff --git a/tests/robotests/src/com/android/settings/accessibility/TextReadingFragmentBaseControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/TextReadingFragmentBaseControllerTest.java
new file mode 100644
index 0000000..ad6a895
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accessibility/TextReadingFragmentBaseControllerTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.
+ */
+
+package com.android.settings.accessibility;
+
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.EXTRA_LAUNCHED_FROM;
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.ACCESSIBILITY_SETTINGS;
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.UNKNOWN_ENTRY;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+
+import androidx.preference.Preference;
+import androidx.test.core.app.ApplicationProvider;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+/**
+ * Tests for {@link TextReadingFragmentBaseController}.
+ */
+@RunWith(RobolectricTestRunner.class)
+public class TextReadingFragmentBaseControllerTest {
+    private static final String FRAGMENT_PREF_KEY = "FRAGMENT_PREF_KEY";
+    private final Context mContext = ApplicationProvider.getApplicationContext();
+
+    @Test
+    public void handlePreferenceClick_getExtraWithA11ySettingsEntryPoint() {
+        final Preference a11ySettingsPreference = new Preference(mContext);
+        a11ySettingsPreference.setKey(FRAGMENT_PREF_KEY);
+        final TextReadingFragmentBaseController mA11ySettingsFragmentController =
+                new TextReadingFragmentBaseController(mContext, FRAGMENT_PREF_KEY,
+                        ACCESSIBILITY_SETTINGS);
+
+        mA11ySettingsFragmentController.handlePreferenceTreeClick(a11ySettingsPreference);
+
+        assertThat(a11ySettingsPreference.getExtras().getInt(EXTRA_LAUNCHED_FROM,
+                UNKNOWN_ENTRY)).isEqualTo(ACCESSIBILITY_SETTINGS);
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
index 0005e71..87a447d 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
@@ -105,6 +105,10 @@
         when(mContext.getApplicationContext()).thenReturn(mContext);
         resetAndInitializePackageManager();
         when(mUserManager.getProfiles(mUserId)).thenReturn(mProfiles);
+        when(mContext.getSystemService(Context.DEVICE_POLICY_SERVICE))
+                .thenReturn(mDevicePolicyManager);
+        when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
+        when(mContext.getPackageManager()).thenReturn(mPackageManager);
         mProfiles.add(new UserInfo(mUserId, "", "", 0 /* flags */));
         mResources = RuntimeEnvironment.application.getResources();
 
diff --git a/tests/robotests/src/com/android/settings/localepicker/AppLocalePickerActivityTest.java b/tests/robotests/src/com/android/settings/localepicker/AppLocalePickerActivityTest.java
new file mode 100644
index 0000000..4d5e0b9
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/localepicker/AppLocalePickerActivityTest.java
@@ -0,0 +1,118 @@
+/*
+ * 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.
+ */
+
+package com.android.settings.localepicker;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.app.Activity;
+import android.app.ApplicationPackageManager;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.InstallSourceInfo;
+import android.net.Uri;
+import android.os.Process;
+import android.os.UserHandle;
+import android.telephony.TelephonyManager;
+
+import androidx.fragment.app.Fragment;
+
+import com.android.settings.R;
+import com.android.settings.applications.AppInfoBase;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import org.robolectric.Robolectric;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.Shadows;
+import org.robolectric.android.controller.ActivityController;
+import org.robolectric.annotation.Config;
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+import org.robolectric.shadows.ShadowTelephonyManager;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(
+        shadows = {
+                AppLocalePickerActivityTest.ShadowApplicationPackageManager.class,
+        })
+public class AppLocalePickerActivityTest {
+    private static final String TEST_PACKAGE_NAME = "com.android.settings";
+    private static final Uri TEST_PACKAGE_URI = Uri.parse("package:" + TEST_PACKAGE_NAME);
+
+    @Rule
+    public MockitoRule rule = MockitoJUnit.rule();
+
+    @Test
+    public void launchAppLocalePickerActivity_hasPackageName_success() {
+        ActivityController<TestAppLocalePickerActivity> controller =
+                initActivityController(true);
+
+        controller.create();
+
+        assertThat(controller.get().isFinishing()).isFalse();
+    }
+
+    @Test
+    public void launchAppLocalePickerActivity_intentWithoutPackageName_failed() {
+        ActivityController<TestAppLocalePickerActivity> controller =
+                initActivityController(false);
+
+        controller.create();
+
+        assertThat(controller.get().isFinishing()).isTrue();
+    }
+
+    private ActivityController<TestAppLocalePickerActivity> initActivityController(
+            boolean hasPackageName) {
+        Intent data = new Intent();
+        if (hasPackageName) {
+            data.setData(TEST_PACKAGE_URI);
+        }
+        data.putExtra(AppInfoBase.ARG_PACKAGE_UID, UserHandle.getUserId(Process.myUid()));
+        ActivityController<TestAppLocalePickerActivity> activityController =
+                Robolectric.buildActivity(TestAppLocalePickerActivity.class, data);
+        Activity activity = activityController.get();
+
+        ShadowTelephonyManager shadowTelephonyManager = Shadows.shadowOf(
+                activity.getSystemService(TelephonyManager.class));
+        shadowTelephonyManager.setSimCountryIso("US");
+        shadowTelephonyManager.setNetworkCountryIso("US");
+
+        return activityController;
+    }
+
+    private static class TestAppLocalePickerActivity extends AppLocalePickerActivity {
+        @Override
+        public Context createContextAsUser(UserHandle user, int flags) {
+            // return the current context as a work profile
+            return this;
+        }
+    }
+
+    @Implements(ApplicationPackageManager.class)
+    public static class ShadowApplicationPackageManager extends
+            org.robolectric.shadows.ShadowApplicationPackageManager {
+
+        @Implementation
+        protected Object getInstallSourceInfo(String packageName) {
+            return new InstallSourceInfo("", null, null, "");
+        }
+    }
+}