Merge "Use different exceptions for different crash reasons" into sc-v2-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index e4e1a10..0623738 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -191,6 +191,7 @@
         </receiver>
 
         <activity android:name=".SubSettings"
+                  android:configChanges="orientation|keyboard|keyboardHidden|screenSize|screenLayout|smallestScreenSize"
                   android:theme="@style/Theme.SubSettings" />
 
         <activity android:name=".Settings$CreateShortcutActivity"
@@ -299,18 +300,31 @@
             </intent-filter>
         </activity>
 
+        <receiver android:name=".search.SearchStateReceiver"
+                  android:exported="true"
+                  android:permission="android.permission.READ_SEARCH_INDEXABLES">
+            <intent-filter>
+                <action android:name="com.android.settings.SEARCH_START"/>
+                <action android:name="com.android.settings.SEARCH_EXIT"/>
+            </intent-filter>
+        </receiver>
+
         <activity
             android:name="Settings$WifiSettingsActivity"
             android:label="@string/wifi_settings"
             android:icon="@drawable/ic_homepage_network"
             android:exported="true"
             android:configChanges="orientation|keyboardHidden|screenSize">
+            <intent-filter android:priority="1">
+                <action android:name="android.settings.WIFI_SETTINGS"/>
+                <category android:name="android.intent.category.DEFAULT"/>
+            </intent-filter>
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
-                android:value="com.android.settings.wifi.WifiSettings" />
+                       android:value="com.android.settings.network.NetworkProviderSettings"/>
             <meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
-                android:value="@string/menu_key_network"/>
+                       android:value="@string/menu_key_network"/>
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
-                android:value="true" />
+                       android:value="true"/>
         </activity>
 
         <!-- Keep compatibility with old shortcuts. -->
@@ -321,9 +335,11 @@
             android:icon="@drawable/ic_homepage_network"
             android:exported="true">
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
-                android:value="com.android.settings.wifi.WifiSettings" />
+                       android:value="com.android.settings.network.NetworkProviderSettings"/>
             <meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
-                android:value="@string/menu_key_network"/>
+                       android:value="@string/menu_key_network"/>
+            <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
+                       android:value="true"/>
         </activity-alias>
 
         <activity
@@ -333,23 +349,19 @@
             android:exported="true"
             android:configChanges="orientation|keyboardHidden|screenSize">
             <intent-filter android:priority="1">
-                <action android:name="android.settings.NETWORK_PROVIDER_SETTINGS" />
-                <category android:name="android.intent.category.DEFAULT" />
+                <action android:name="android.settings.NETWORK_PROVIDER_SETTINGS"/>
+                <category android:name="android.intent.category.DEFAULT"/>
             </intent-filter>
             <intent-filter android:priority="1">
-                <action android:name="android.settings.WIFI_SETTINGS" />
-                <category android:name="android.intent.category.DEFAULT" />
-            </intent-filter>
-            <intent-filter android:priority="1">
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="com.android.settings.SHORTCUT" />
+                <action android:name="android.intent.action.MAIN"/>
+                <category android:name="com.android.settings.SHORTCUT"/>
             </intent-filter>
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
-                android:value="com.android.settings.network.NetworkProviderSettings" />
+                       android:value="com.android.settings.network.NetworkProviderSettings"/>
             <meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
-                android:value="@string/menu_key_network"/>
+                       android:value="@string/menu_key_network"/>
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
-                android:value="true" />
+                       android:value="true"/>
         </activity>
 
         <activity
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2048d5c..7262171 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -13289,6 +13289,10 @@
     <string name="lockscreen_privacy_controls_setting_toggle">Show device controls</string>
     <!-- Device controls summary [CHAR LIMIT=NONE] -->
     <string name="lockscreen_privacy_controls_summary">Access controls when locked</string>
+    <!-- Lockscreen double-line clock summary [CHAR LIMIT=NONE] -->
+    <string name="lockscreen_double_line_clock_summary">Show double-line clock when available</string>
+    <!-- Lockscreen double-line clock toggle [CHAR LIMIT=60] -->
+    <string name="lockscreen_double_line_clock_setting_toggle">Double-line clock</string>
 
     <!-- Title for RTT setting. [CHAR LIMIT=NONE] -->
     <string name="rtt_settings_title"></string>
diff --git a/res/xml/security_lockscreen_settings.xml b/res/xml/security_lockscreen_settings.xml
index 82cb860..19a1a4c 100644
--- a/res/xml/security_lockscreen_settings.xml
+++ b/res/xml/security_lockscreen_settings.xml
@@ -56,6 +56,12 @@
             android:title="@string/lockscreen_privacy_controls_setting_toggle"
             android:summary="@string/lockscreen_privacy_controls_summary"
             settings:controller="com.android.settings.display.ControlsPrivacyPreferenceController" />
+
+        <SwitchPreference
+            android:key="lockscreen_double_line_clock_switch"
+            android:title="@string/lockscreen_double_line_clock_setting_toggle"
+            android:summary="@string/lockscreen_double_line_clock_summary"
+            settings:controller="com.android.settings.display.LockscreenClockPreferenceController" />
     </PreferenceCategory>
 
     <PreferenceCategory
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index 231a149..893c0ad 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -89,7 +89,6 @@
     public static class PrivateVolumeForgetActivity extends SettingsActivity { /* empty */ }
     public static class PublicVolumeSettingsActivity extends SettingsActivity { /* empty */ }
     public static class WifiSettingsActivity extends SettingsActivity { /* empty */ }
-    public static class WifiSettings2Activity extends SettingsActivity { /* empty */ }
     public static class NetworkProviderSettingsActivity extends SettingsActivity { /* empty */ }
     /** Activity for the Wi-Fi network details settings. */
     public static class WifiDetailsSettingsActivity extends SettingsActivity { /* empty */ }
diff --git a/src/com/android/settings/SettingsApplication.java b/src/com/android/settings/SettingsApplication.java
index a2f723e..353208d 100644
--- a/src/com/android/settings/SettingsApplication.java
+++ b/src/com/android/settings/SettingsApplication.java
@@ -16,17 +16,17 @@
 
 package com.android.settings;
 
-import android.app.Activity;
 import android.app.Application;
 
 import com.android.settings.activityembedding.ActivityEmbeddingRulesController;
+import com.android.settings.homepage.SettingsHomepageActivity;
 
 import java.lang.ref.WeakReference;
 
 /** Settings application which sets up activity embedding rules for the large screen device. */
 public class SettingsApplication extends Application {
 
-    private WeakReference<Activity> mHomeActivity = new WeakReference<>(null);
+    private WeakReference<SettingsHomepageActivity> mHomeActivity = new WeakReference<>(null);
 
     @Override
     public void onCreate() {
@@ -37,11 +37,11 @@
         controller.initRules();
     }
 
-    public void setHomeActivity(Activity homeActivity) {
+    public void setHomeActivity(SettingsHomepageActivity homeActivity) {
         mHomeActivity = new WeakReference<>(homeActivity);
     }
 
-    public Activity getHomeActivity() {
+    public SettingsHomepageActivity getHomeActivity() {
         return mHomeActivity.get();
     }
 }
diff --git a/src/com/android/settings/SettingsInitialize.java b/src/com/android/settings/SettingsInitialize.java
index 500ce77..376d916 100644
--- a/src/com/android/settings/SettingsInitialize.java
+++ b/src/com/android/settings/SettingsInitialize.java
@@ -41,6 +41,7 @@
 
 import com.android.settings.Settings.CreateShortcutActivity;
 import com.android.settings.homepage.SettingsHomepageActivity;
+import com.android.settings.search.SearchStateReceiver;
 import com.android.settingslib.utils.ThreadUtils;
 
 import java.util.ArrayList;
@@ -67,7 +68,7 @@
         managedProfileSetup(context, pm, broadcast, userInfo);
         webviewSettingSetup(context, pm, userInfo);
         ThreadUtils.postOnBackgroundThread(() -> refreshExistingShortcuts(context));
-        enableTwoPaneDeepLinkActivityIfNecessary(pm, broadcast);
+        enableTwoPaneDeepLinkActivityIfNecessary(pm, context);
     }
 
     private void managedProfileSetup(Context context, final PackageManager pm, Intent broadcast,
@@ -148,12 +149,16 @@
         shortcutManager.updateShortcuts(updates);
     }
 
-    private void enableTwoPaneDeepLinkActivityIfNecessary(PackageManager pm, Intent intent) {
+    private void enableTwoPaneDeepLinkActivityIfNecessary(PackageManager pm, Context context) {
         final ComponentName deepLinkHome = new ComponentName(Utils.SETTINGS_PACKAGE_NAME,
                 SettingsHomepageActivity.ALIAS_DEEP_LINK);
+        final ComponentName searchStateReceiver = new ComponentName(context,
+                SearchStateReceiver.class);
         final int enableState = SplitController.getInstance().isSplitSupported()
                 ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
         pm.setComponentEnabledSetting(deepLinkHome, enableState, PackageManager.DONT_KILL_APP);
+        pm.setComponentEnabledSetting(searchStateReceiver, enableState,
+                PackageManager.DONT_KILL_APP);
     }
 }
diff --git a/src/com/android/settings/accessibility/AccessibilityScreenSizeForSetupWizardActivity.java b/src/com/android/settings/accessibility/AccessibilityScreenSizeForSetupWizardActivity.java
index 7894c6e..10a0bce 100644
--- a/src/com/android/settings/accessibility/AccessibilityScreenSizeForSetupWizardActivity.java
+++ b/src/com/android/settings/accessibility/AccessibilityScreenSizeForSetupWizardActivity.java
@@ -63,6 +63,9 @@
         int SCREEN_SIZE = 2;
     }
 
+    // Keep the last height of the scroll view in the {@link GlifLayout}
+    private int mLastScrollViewHeight;
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -143,11 +146,13 @@
      * Scrolls to bottom while {@link ScrollView} layout changed.
      */
     private void scrollToBottom() {
+        mLastScrollViewHeight = 0;
         final GlifLayout layout = findViewById(R.id.setup_wizard_layout);
         final ScrollView scrollView = layout.getScrollView();
         scrollView.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
             final int scrollViewHeight = scrollView.getHeight();
-            if (scrollViewHeight > 0) {
+            if (scrollViewHeight > 0 && scrollViewHeight != mLastScrollViewHeight) {
+                mLastScrollViewHeight = scrollViewHeight;
                 scrollView.post(() -> {
                     // Here is no need to show the scrolling animation. So disabled first and
                     // then enabled it after scrolling finished.
diff --git a/src/com/android/settings/activityembedding/ActivityEmbeddingRulesController.java b/src/com/android/settings/activityembedding/ActivityEmbeddingRulesController.java
index 4060e53..1540657 100644
--- a/src/com/android/settings/activityembedding/ActivityEmbeddingRulesController.java
+++ b/src/com/android/settings/activityembedding/ActivityEmbeddingRulesController.java
@@ -35,6 +35,7 @@
 import com.android.settings.SubSettings;
 import com.android.settings.Utils;
 import com.android.settings.homepage.SettingsHomepageActivity;
+import com.android.settings.homepage.SliceDeepLinkHomepageActivity;
 
 import java.util.HashSet;
 import java.util.Set;
@@ -128,6 +129,15 @@
                 true /* finishPrimaryWithSecondary */,
                 true /* finishSecondaryWithPrimary */,
                 clearTop);
+
+        registerTwoPanePairRule(
+                context,
+                getComponentName(context, SliceDeepLinkHomepageActivity.class),
+                secondaryComponent,
+                secondaryIntentAction,
+                true /* finishPrimaryWithSecondary */,
+                true /* finishSecondaryWithPrimary */,
+                clearTop);
     }
 
     /** Register a SplitPairRule for SubSettings if the device supports 2-pane. */
diff --git a/src/com/android/settings/datausage/BillingCycleSettings.java b/src/com/android/settings/datausage/BillingCycleSettings.java
index 8c433a0..57931c1 100644
--- a/src/com/android/settings/datausage/BillingCycleSettings.java
+++ b/src/com/android/settings/datausage/BillingCycleSettings.java
@@ -271,12 +271,14 @@
             mView = dialogInflater.inflate(R.layout.data_usage_bytes_editor, null, false);
             setupPicker((EditText) mView.findViewById(R.id.bytes),
                     (Spinner) mView.findViewById(R.id.size_spinner));
-            return new AlertDialog.Builder(context)
+            Dialog dialog = new AlertDialog.Builder(context)
                     .setTitle(isLimit ? R.string.data_usage_limit_editor_title
                             : R.string.data_usage_warning_editor_title)
                     .setView(mView)
                     .setPositiveButton(R.string.data_usage_cycle_editor_positive, this)
                     .create();
+            dialog.setCanceledOnTouchOutside(false);
+            return dialog;
         }
 
         private void setupPicker(EditText bytesPicker, Spinner type) {
@@ -402,10 +404,12 @@
             mCycleDayPicker.setValue(cycleDay);
             mCycleDayPicker.setWrapSelectorWheel(true);
 
-            return builder.setTitle(R.string.data_usage_cycle_editor_title)
+            Dialog dialog = builder.setTitle(R.string.data_usage_cycle_editor_title)
                     .setView(view)
                     .setPositiveButton(R.string.data_usage_cycle_editor_positive, this)
                     .create();
+            dialog.setCanceledOnTouchOutside(false);
+            return dialog;
         }
 
         @Override
@@ -466,12 +470,14 @@
         public Dialog onCreateDialog(Bundle savedInstanceState) {
             final Context context = getActivity();
 
-            return new AlertDialog.Builder(context)
+            Dialog dialog = new AlertDialog.Builder(context)
                     .setTitle(R.string.data_usage_limit_dialog_title)
                     .setMessage(R.string.data_usage_limit_dialog_mobile)
                     .setPositiveButton(android.R.string.ok, this)
                     .setNegativeButton(android.R.string.cancel, null)
                     .create();
+            dialog.setCanceledOnTouchOutside(false);
+            return dialog;
         }
 
         @Override
diff --git a/src/com/android/settings/display/LockscreenClockPreferenceController.java b/src/com/android/settings/display/LockscreenClockPreferenceController.java
new file mode 100644
index 0000000..70ae55e
--- /dev/null
+++ b/src/com/android/settings/display/LockscreenClockPreferenceController.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2021 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.display;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import androidx.preference.Preference;
+
+import com.android.settings.R;
+import com.android.settings.core.TogglePreferenceController;
+
+/**
+ * Preference to enable/disable the large double-line clock on lockscreen
+ */
+public class LockscreenClockPreferenceController extends TogglePreferenceController {
+
+    private static final String SETTING_KEY = Settings.Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK;
+
+    public LockscreenClockPreferenceController(Context context, String preferenceKey) {
+        super(context, preferenceKey);
+    }
+
+    @Override
+    public boolean isChecked() {
+        return Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 1) != 0;
+    }
+
+    @Override
+    public boolean setChecked(boolean isChecked) {
+        return Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY,
+                isChecked ? 1 : 0);
+    }
+
+    @Override
+    public CharSequence getSummary() {
+        return mContext.getText(R.string.lockscreen_double_line_clock_summary);
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return AVAILABLE;
+    }
+
+    @Override
+    public void updateState(Preference preference) {
+        super.updateState(preference);
+        preference.setEnabled(true);
+        refreshSummary(preference);
+    }
+
+    @Override
+    public int getSliceHighlightMenuRes() {
+        return R.string.menu_key_display;
+    }
+}
diff --git a/src/com/android/settings/homepage/SettingsHomepageActivity.java b/src/com/android/settings/homepage/SettingsHomepageActivity.java
index 051204d..4e843fd 100644
--- a/src/com/android/settings/homepage/SettingsHomepageActivity.java
+++ b/src/com/android/settings/homepage/SettingsHomepageActivity.java
@@ -78,6 +78,7 @@
     private static final int DEFAULT_HIGHLIGHT_MENU_KEY = R.string.menu_key_network;
     private static final long HOMEPAGE_LOADING_TIMEOUT_MS = 300;
 
+    private TopLevelSettings mMainFragment;
     private View mHomepageView;
     private View mSuggestionView;
     private CategoryMixin mCategoryMixin;
@@ -124,6 +125,11 @@
         homepageView.setVisibility(View.VISIBLE);
     }
 
+    /** Returns the main content fragment */
+    public TopLevelSettings getMainFragment() {
+        return mMainFragment;
+    }
+
     @Override
     public CategoryMixin getCategoryMixin() {
         return mCategoryMixin;
@@ -132,7 +138,6 @@
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        setHomeActivity();
         setContentView(R.layout.settings_homepage_container);
 
         final View appBar = findViewById(R.id.app_bar_container);
@@ -162,10 +167,10 @@
                 showFragment(new ContextualCardsFragment(), R.id.contextual_cards_content);
             }
         }
-        final Fragment fragment = new TopLevelSettings();
-        fragment.getArguments().putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY,
+        mMainFragment = new TopLevelSettings();
+        mMainFragment.getArguments().putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY,
                 getHighlightMenuKey());
-        showFragment(fragment, R.id.main_content);
+        showFragment(mMainFragment, R.id.main_content);
 
         ((FrameLayout) findViewById(R.id.main_content))
                 .getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
@@ -175,6 +180,12 @@
     }
 
     @Override
+    protected void onStart() {
+        ((SettingsApplication) getApplication()).setHomeActivity(this);
+        super.onStart();
+    }
+
+    @Override
     protected void onNewIntent(Intent intent) {
         super.onNewIntent(intent);
 
@@ -189,10 +200,6 @@
         launchDeepLinkIntentToRight();
     }
 
-    protected void setHomeActivity() {
-        ((SettingsApplication) getApplication()).setHomeActivity(this);
-    }
-
     private void showSuggestionFragment() {
         final Class<? extends Fragment> fragment = FeatureFactory.getFactory(this)
                 .getSuggestionFeatureProvider(this).getContextualSuggestionFragment();
@@ -314,13 +321,9 @@
     }
 
     private void reloadHighlightMenuKey() {
-        final TopLevelSettings fragment =
-                (TopLevelSettings) getSupportFragmentManager().findFragmentById(R.id.main_content);
-        if (fragment != null) {
-            fragment.getArguments().putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY,
-                    getHighlightMenuKey());
-            fragment.reloadHighlightMenuKey();
-        }
+        mMainFragment.getArguments().putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY,
+                getHighlightMenuKey());
+        mMainFragment.reloadHighlightMenuKey();
     }
 
     private void initHomepageContainer() {
diff --git a/src/com/android/settings/homepage/SliceDeepLinkHomepageActivity.java b/src/com/android/settings/homepage/SliceDeepLinkHomepageActivity.java
index 61e946d..2f83612 100644
--- a/src/com/android/settings/homepage/SliceDeepLinkHomepageActivity.java
+++ b/src/com/android/settings/homepage/SliceDeepLinkHomepageActivity.java
@@ -21,11 +21,6 @@
 /** Activity for Slices to launch Settings deep link page */
 public class SliceDeepLinkHomepageActivity extends SettingsHomepageActivity {
     @Override
-    protected void setHomeActivity() {
-        // do not overwrite homepage activity in SettingsApplication
-    }
-
-    @Override
     protected ComponentName getDeepLinkComponent() {
         return new ComponentName(getApplicationContext(), getClass());
     }
diff --git a/src/com/android/settings/homepage/TopLevelSettings.java b/src/com/android/settings/homepage/TopLevelSettings.java
index 548b3c4..193b69e 100644
--- a/src/com/android/settings/homepage/TopLevelSettings.java
+++ b/src/com/android/settings/homepage/TopLevelSettings.java
@@ -52,10 +52,12 @@
 
     private static final String TAG = "TopLevelSettings";
     private static final String SAVED_HIGHLIGHTED_PREF = "highlighted_pref";
+    private static final String SAVED_CACHED_PREF = "cached_pref";
 
     private HighlightableTopLevelPreferenceAdapter mTopLevelAdapter;
 
     private String mHighlightedPreferenceKey;
+    private String mCachedPreferenceKey;
 
     public TopLevelSettings() {
         final Bundle args = new Bundle();
@@ -125,6 +127,7 @@
         super.onCreate(icicle);
         if (icicle != null) {
             mHighlightedPreferenceKey = icicle.getString(SAVED_HIGHLIGHTED_PREF);
+            mCachedPreferenceKey = icicle.getString(SAVED_CACHED_PREF);
         }
     }
 
@@ -132,6 +135,7 @@
     public void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
         outState.putString(SAVED_HIGHLIGHTED_PREF, mHighlightedPreferenceKey);
+        outState.putString(SAVED_CACHED_PREF, mCachedPreferenceKey);
     }
 
     @Override
@@ -169,9 +173,10 @@
         }
     }
 
-    /** Highlight a preference with specified key */
+    /** Highlight a preference with specified preference key */
     public void setHighlightPreferenceKey(String prefKey) {
         if (mTopLevelAdapter != null) {
+            mCachedPreferenceKey = null;
             mHighlightedPreferenceKey = prefKey;
             mTopLevelAdapter.highlightPreference(prefKey, /* scrollNeeded= */ false);
         }
@@ -184,13 +189,38 @@
         }
     }
 
-    /** Disable highlight on the menu entry */
-    public void disableMenuHighlight() {
+    /** Show/hide the highlight on the menu entry */
+    public void setMenuHighlightShowed(boolean show) {
         if (mTopLevelAdapter == null) {
             return;
         }
-        mHighlightedPreferenceKey = null;
-        mTopLevelAdapter.highlightPreference(mHighlightedPreferenceKey, /* scrollNeeded= */ false);
+
+        if (show) {
+            mHighlightedPreferenceKey = mCachedPreferenceKey;
+            mCachedPreferenceKey = null;
+        } else {
+            if (mCachedPreferenceKey == null) {
+                mCachedPreferenceKey = mHighlightedPreferenceKey;
+            }
+            mHighlightedPreferenceKey = null;
+        }
+        mTopLevelAdapter.highlightPreference(mHighlightedPreferenceKey, /* scrollNeeded= */ show);
+    }
+
+    /** Highlight and scroll to a preference with specified menu key */
+    public void setHighlightMenuKey(String menuKey) {
+        if (mTopLevelAdapter == null) {
+            return;
+        }
+
+        final String prefKey = HighlightableMenu.lookupPreferenceKey(menuKey);
+        if (TextUtils.isEmpty(prefKey)) {
+            Log.e(TAG, "Invalid highlight menu key: " + menuKey);
+        } else {
+            Log.d(TAG, "Menu key: " + menuKey);
+            mHighlightedPreferenceKey = prefKey;
+            mTopLevelAdapter.highlightPreference(prefKey, /* scrollNeeded= */ true);
+        }
     }
 
     @Override
diff --git a/src/com/android/settings/network/telephony/NetworkSelectSettings.java b/src/com/android/settings/network/telephony/NetworkSelectSettings.java
index 813cc74..c1c0f8f 100644
--- a/src/com/android/settings/network/telephony/NetworkSelectSettings.java
+++ b/src/com/android/settings/network/telephony/NetworkSelectSettings.java
@@ -50,6 +50,7 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Optional;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
@@ -326,12 +327,19 @@
                     CellInfoUtil.getCellIdentityMccMnc(cellInfo.getCellIdentity()));
             Class className = cellInfo.getClass();
 
-            if (aggregatedList.stream().anyMatch(
+            Optional<CellInfo> itemInTheList = aggregatedList.stream().filter(
                     item -> {
                         String itemPlmn = CellInfoUtil.getNetworkTitle(item.getCellIdentity(),
                                 CellInfoUtil.getCellIdentityMccMnc(item.getCellIdentity()));
                         return itemPlmn.equals(plmn) && item.getClass().equals(className);
-                    })) {
+                    })
+                    .findFirst();
+            if (itemInTheList.isPresent()) {
+                if (cellInfo.isRegistered() && !itemInTheList.get().isRegistered()) {
+                    // Adding the registered cellinfo item into list. If there are two registered
+                    // cellinfo items, then select first one from source list.
+                    aggregatedList.set(aggregatedList.indexOf(itemInTheList.get()), cellInfo);
+                }
                 continue;
             }
             aggregatedList.add(cellInfo);
diff --git a/src/com/android/settings/network/telephony/NrAdvancedCallingPreferenceController.java b/src/com/android/settings/network/telephony/NrAdvancedCallingPreferenceController.java
index 7615fe3..b585ece 100644
--- a/src/com/android/settings/network/telephony/NrAdvancedCallingPreferenceController.java
+++ b/src/com/android/settings/network/telephony/NrAdvancedCallingPreferenceController.java
@@ -46,6 +46,7 @@
     Preference mPreference;
     private TelephonyManager mTelephonyManager;
     private PhoneCallStateTelephonyCallback mTelephonyCallback;
+    private boolean mIsVonrEnabledFromCarrierConfig = false;
     private boolean mIsVonrVisibleFromCarrierConfig = false;
     private boolean mIsNrEnableFromCarrierConfig = false;
     private boolean mHas5gCapability = false;
@@ -83,6 +84,9 @@
         if (carrierConfig == null) {
             return this;
         }
+        mIsVonrEnabledFromCarrierConfig = carrierConfig.getBoolean(
+            CarrierConfigManager.KEY_VONR_ENABLED_BOOL);
+
         mIsVonrVisibleFromCarrierConfig = carrierConfig.getBoolean(
                 CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL);
 
@@ -92,6 +96,7 @@
 
         Log.d(TAG, "mHas5gCapability: " + mHas5gCapability
                 + ",mIsNrEnabledFromCarrierConfig: " + mIsNrEnableFromCarrierConfig
+                + ",mIsVonrEnabledFromCarrierConfig: " + mIsVonrEnabledFromCarrierConfig
                 + ",mIsVonrVisibleFromCarrierConfig: " + mIsVonrVisibleFromCarrierConfig);
         return this;
     }
@@ -100,7 +105,10 @@
     public int getAvailabilityStatus(int subId) {
         init(subId);
 
-        if (mHas5gCapability && mIsNrEnableFromCarrierConfig && mIsVonrVisibleFromCarrierConfig) {
+        if (mHas5gCapability
+                && mIsNrEnableFromCarrierConfig
+                && mIsVonrEnabledFromCarrierConfig
+                && mIsVonrVisibleFromCarrierConfig) {
             return AVAILABLE;
         }
         return CONDITIONALLY_UNAVAILABLE;
diff --git a/src/com/android/settings/search/SearchFeatureProvider.java b/src/com/android/settings/search/SearchFeatureProvider.java
index 9b081e1..39e571f 100644
--- a/src/com/android/settings/search/SearchFeatureProvider.java
+++ b/src/com/android/settings/search/SearchFeatureProvider.java
@@ -33,8 +33,6 @@
 
 import com.android.settings.R;
 import com.android.settings.Utils;
-import com.android.settings.activityembedding.ActivityEmbeddingUtils;
-import com.android.settings.homepage.TopLevelSettings;
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settingslib.search.SearchIndexableResources;
 
@@ -108,18 +106,8 @@
             FeatureFactory.getFactory(context).getMetricsFeatureProvider()
                     .logSettingsTileClick(KEY_HOMEPAGE_SEARCH_BAR, pageId);
 
-            if (ActivityEmbeddingUtils.isEmbeddingActivityEnabled(context)) {
-                final TopLevelSettings fragment = (TopLevelSettings) activity
-                        .getSupportFragmentManager().findFragmentById(R.id.main_content);
-                if (fragment != null) {
-                    fragment.disableMenuHighlight();
-                }
-                activity.startActivity(intent);
-            } else {
-                final Bundle bundle = ActivityOptions.makeSceneTransitionAnimation(activity)
-                        .toBundle();
-                activity.startActivity(intent, bundle);
-            }
+            final Bundle bundle = ActivityOptions.makeSceneTransitionAnimation(activity).toBundle();
+            activity.startActivity(intent, bundle);
         });
     }
 
diff --git a/src/com/android/settings/search/SearchResultTrampoline.java b/src/com/android/settings/search/SearchResultTrampoline.java
index a770126..f9cbc36 100644
--- a/src/com/android/settings/search/SearchResultTrampoline.java
+++ b/src/com/android/settings/search/SearchResultTrampoline.java
@@ -28,9 +28,11 @@
 import android.util.Log;
 
 import com.android.settings.SettingsActivity;
+import com.android.settings.SettingsApplication;
 import com.android.settings.SubSettings;
 import com.android.settings.activityembedding.ActivityEmbeddingRulesController;
 import com.android.settings.activityembedding.ActivityEmbeddingUtils;
+import com.android.settings.homepage.SettingsHomepageActivity;
 import com.android.settings.overlay.FeatureFactory;
 
 import java.net.URISyntaxException;
@@ -99,12 +101,20 @@
             // navigation behavior.
             ActivityEmbeddingRulesController.registerSubSettingsPairRule(this,
                     false /* clearTop */);
-            // TODO: pass menu key to homepage
+
             intent.setFlags(intent.getFlags() & ~Intent.FLAG_ACTIVITY_NEW_TASK);
             startActivity(intent);
+
+            // Pass menu key to homepage
+            final SettingsHomepageActivity homeActivity =
+                    ((SettingsApplication) getApplicationContext()).getHomeActivity();
+            if (homeActivity != null) {
+                homeActivity.getMainFragment().setHighlightMenuKey(highlightMenuKey);
+            }
         } else {
             // Two-pane case
-            startActivity(SettingsActivity.getTrampolineIntent(intent, highlightMenuKey));
+            startActivity(SettingsActivity.getTrampolineIntent(intent, highlightMenuKey)
+                    .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
         }
 
         // Done.
diff --git a/src/com/android/settings/search/SearchStateReceiver.java b/src/com/android/settings/search/SearchStateReceiver.java
new file mode 100644
index 0000000..d1f6f16
--- /dev/null
+++ b/src/com/android/settings/search/SearchStateReceiver.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2021 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.search;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.text.TextUtils;
+import android.util.Log;
+
+import com.android.settings.SettingsApplication;
+import com.android.settings.homepage.SettingsHomepageActivity;
+
+/**
+ * A broadcast receiver that monitors the search state to show/hide the menu highlight
+ */
+public class SearchStateReceiver extends BroadcastReceiver {
+
+    private static final String TAG = "SearchStateReceiver";
+    private static final String ACTION_SEARCH_START = "com.android.settings.SEARCH_START";
+    private static final String ACTION_SEARCH_EXIT = "com.android.settings.SEARCH_EXIT";
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        if (intent == null) {
+            Log.w(TAG, "Null intent");
+            return;
+        }
+
+        final SettingsHomepageActivity homeActivity =
+                ((SettingsApplication) context.getApplicationContext()).getHomeActivity();
+        if (homeActivity == null) {
+            return;
+        }
+
+        final String action = intent.getAction();
+        Log.d(TAG, "action: " + action);
+        if (TextUtils.equals(ACTION_SEARCH_START, action)) {
+            homeActivity.getMainFragment().setMenuHighlightShowed(false);
+        } else if (TextUtils.equals(ACTION_SEARCH_EXIT, action)) {
+            homeActivity.getMainFragment().setMenuHighlightShowed(true);
+        }
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/display/LockscreenClockPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/LockscreenClockPreferenceControllerTest.java
new file mode 100644
index 0000000..94f2dc6
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/display/LockscreenClockPreferenceControllerTest.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2021 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.display;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.provider.Settings;
+
+import androidx.preference.Preference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class LockscreenClockPreferenceControllerTest {
+
+    private static final String TEST_KEY = "test_key";
+    private static final String SETTING_KEY = Settings.Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK;
+
+    private Context mContext;
+    private ContentResolver mContentResolver;
+    private LockscreenClockPreferenceController mController;
+
+    @Mock
+    private Preference mPreference;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mContext = RuntimeEnvironment.application;
+        mContentResolver = mContext.getContentResolver();
+        mController = new LockscreenClockPreferenceController(mContext, TEST_KEY);
+    }
+
+    @Test
+    public void isChecked_SettingIs1_returnTrue() {
+        Settings.Secure.putInt(mContentResolver, SETTING_KEY, 1);
+
+        assertThat(mController.isChecked()).isTrue();
+    }
+
+    @Test
+    public void isChecked_SettingIs0_returnFalse() {
+        Settings.Secure.putInt(mContentResolver, SETTING_KEY, 0);
+
+        assertThat(mController.isChecked()).isFalse();
+    }
+
+    @Test
+    public void isChecked_SettingIsNotSet_returnTrue() {
+        Settings.Secure.putString(mContentResolver, SETTING_KEY, null);
+
+        assertThat(mController.isChecked()).isTrue();
+    }
+
+    @Test
+    public void setChecked_true_SettingIsNot0() {
+        mController.setChecked(true);
+
+        assertThat(Settings.Secure.getInt(mContentResolver, SETTING_KEY, 0)).isNotEqualTo(0);
+    }
+
+    @Test
+    public void setChecked_false_SettingIs0() {
+        mController.setChecked(false);
+
+        assertThat(Settings.Secure.getInt(mContentResolver, SETTING_KEY, 0)).isEqualTo(0);
+    }
+}
diff --git a/tests/unit/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java b/tests/unit/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java
index 47e3ad9..02b8706 100644
--- a/tests/unit/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java
+++ b/tests/unit/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java
@@ -166,6 +166,19 @@
         assertThat(mNetworkSelectSettings.doAggregation(testList)).isEqualTo(expected);
     }
 
+    @Test
+    public void doAggregation_hasDuplicateItemsDiffMccMncCase3_removeSamePlmnRatItem() {
+        List<CellInfo> testList = Arrays.asList(
+                createLteCellInfo(false, 123, "123", "232", "CarrierA"),
+                createLteCellInfo(false, 124, "123", "233", "CarrierA"),
+                createLteCellInfo(true, 125, "123", "234", "CarrierA"),
+                createGsmCellInfo(false, 126, "456", "232", "CarrierA"));
+        List<CellInfo> expected = Arrays.asList(
+                createLteCellInfo(true, 125, "123", "234", "CarrierA"),
+                createGsmCellInfo(false, 126, "456", "232", "CarrierA"));
+        assertThat(mNetworkSelectSettings.doAggregation(testList)).isEqualTo(expected);
+    }
+
     private CellInfoLte createLteCellInfo(boolean registered, int cellId, String mcc, String mnc,
             String plmnName) {
         CellIdentityLte cil = new CellIdentityLte(
diff --git a/tests/unit/src/com/android/settings/network/telephony/NrAdvancedCallingPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/NrAdvancedCallingPreferenceControllerTest.java
index 9eb67df..fac7772 100644
--- a/tests/unit/src/com/android/settings/network/telephony/NrAdvancedCallingPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/network/telephony/NrAdvancedCallingPreferenceControllerTest.java
@@ -80,7 +80,8 @@
                 mTelephonyManager).setVoNrEnabled(anyBoolean());
         mCarrierConfig = new PersistableBundle();
         doReturn(mCarrierConfig).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
-        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, false);
+        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_ENABLED_BOOL, false);
+        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, true);
         mCarrierConfig.putIntArray(CarrierConfigManager.KEY_CARRIER_NR_AVAILABILITIES_INT_ARRAY,
                 new int[]{1, 2});
 
@@ -92,7 +93,8 @@
     }
 
     @Test
-    public void getAvailabilityStatus_vonrDisabled_returnUnavailable() {
+    public void getAvailabilityStatus_vonrEnabledAndVisibleDisable_returnUnavailable() {
+        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_ENABLED_BOOL, true);
         mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, false);
 
         mController.init(SUB_ID);
@@ -102,7 +104,30 @@
     }
 
     @Test
-    public void getAvailabilityStatus_vonrEnabled_returnAvailable() {
+    public void getAvailabilityStatus_vonrDisabledAndVisibleDisable_returnUnavailable() {
+        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_ENABLED_BOOL, false);
+        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, false);
+
+        mController.init(SUB_ID);
+
+        assertThat(mController.getAvailabilityStatus()).isEqualTo(
+                BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
+    }
+
+    @Test
+    public void getAvailabilityStatus_vonrDisabledAndVisibleEnable_returnUnavailable() {
+        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_ENABLED_BOOL, false);
+        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, true);
+
+        mController.init(SUB_ID);
+
+        assertThat(mController.getAvailabilityStatus()).isEqualTo(
+                BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
+    }
+
+    @Test
+    public void getAvailabilityStatus_vonrEnabledAndVisibleEnable_returnAvailable() {
+        mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_ENABLED_BOOL, true);
         mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, true);
 
         mController.init(SUB_ID);