Merge "Use FooterPreference in xml explicitly"
diff --git a/res/layout/night_display_activation_button.xml b/res/layout/night_display_activation_button.xml
index b0bfe86..df160ec 100644
--- a/res/layout/night_display_activation_button.xml
+++ b/res/layout/night_display_activation_button.xml
@@ -15,10 +15,11 @@
   limitations under the License.
   -->
 
-<FrameLayout
+<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content">
+    android:layout_height="wrap_content"
+    android:minHeight="?android:attr/listPreferredItemHeight">
 
     <Button
         android:id="@+id/night_display_turn_on_button"
@@ -26,7 +27,7 @@
         android:layout_marginStart="@dimen/screen_margin_sides"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_gravity="start" />
+        android:layout_gravity="center_vertical" />
 
     <Button
         android:id="@+id/night_display_turn_off_button"
@@ -34,6 +35,6 @@
         android:layout_marginStart="@dimen/screen_margin_sides"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_gravity="start" />
+        android:layout_gravity="center_vertical" />
 
-</FrameLayout>
\ No newline at end of file
+</LinearLayout>
\ No newline at end of file
diff --git a/res/xml/data_saver.xml b/res/xml/data_saver.xml
index 19944e2..e884d6d 100644
--- a/res/xml/data_saver.xml
+++ b/res/xml/data_saver.xml
@@ -27,4 +27,10 @@
         android:fragment="com.android.settings.datausage.UnrestrictedDataAccess"
         settings:controller="com.android.settings.applications.specialaccess.DataSaverController" />
 
+    <com.android.settingslib.widget.FooterPreference
+        android:key="data_saver_footer"
+        android:title="@*android:string/data_saver_description"
+        android:selectable="false"
+        settings:searchable="false"/>
+
 </PreferenceScreen>
diff --git a/res/xml/mobile_network_settings_v2.xml b/res/xml/mobile_network_settings_v2.xml
index a22826f..31a5ef7 100644
--- a/res/xml/mobile_network_settings_v2.xml
+++ b/res/xml/mobile_network_settings_v2.xml
@@ -34,7 +34,7 @@
         <com.android.settings.datausage.DataUsageSummaryPreference
             android:key="status_header"
             android:visibility="gone"
-            android:selectable="false" />
+            android:selectable="false"/>
 
         <ListPreference
             android:key="calls_preference"
@@ -203,16 +203,15 @@
         android:key="erase_sim"
         android:persistent="false"
         android:title="@string/mobile_network_erase_sim"
-        settings:controller="com.android.settings.network.telephony.DeleteSimProfilePreferenceController" />
+        settings:allowDividerBelow="true"
+        settings:controller="com.android.settings.network.telephony.DeleteSimProfilePreferenceController"/>
 
-    <PreferenceCategory
-        android:key="footer_container"
-        android:title="@string/summary_placeholder"
-        android:layout="@layout/preference_category_no_label"
-        settings:controller="com.android.settings.network.telephony.DisableSimFooterPreferenceController">
-        <com.android.settingslib.widget.FooterPreference
-            android:key="disable_sim_explanation"
-            android:title="@string/mobile_network_disable_sim_explanation" />
-    </PreferenceCategory>
+    <com.android.settingslib.widget.FooterPreference
+        android:key="disable_sim_explanation"
+        android:title="@string/mobile_network_disable_sim_explanation"
+        android:selectable="false"
+        settings:allowDividerAbove="true"
+        settings:searchable="false"
+        settings:controller="com.android.settings.network.telephony.DisableSimFooterPreferenceController"/>
 
 </PreferenceScreen>
diff --git a/res/xml/night_display_settings.xml b/res/xml/night_display_settings.xml
index 4bccacf..343ee42 100644
--- a/res/xml/night_display_settings.xml
+++ b/res/xml/night_display_settings.xml
@@ -49,15 +49,16 @@
         android:title="@string/night_display_title"
         android:selectable="false"
         android:layout="@layout/night_display_activation_button"
+        settings:allowDividerBelow="true"
         settings:keywords="@string/keywords_display_night_display"
         settings:controller="com.android.settings.display.NightDisplayActivationPreferenceController"/>
 
-    <PreferenceCategory android:key="night_display_footer_category">
-        <com.android.settingslib.widget.FooterPreference
-            android:key="night_display_footer"
-            android:title="@string/night_display_text"
-            android:selectable="false"
-            settings:controller="com.android.settings.display.NightDisplayFooterPreferenceController"/>
-    </PreferenceCategory>
+    <com.android.settingslib.widget.FooterPreference
+        android:key="night_display_footer"
+        android:title="@string/night_display_text"
+        android:selectable="false"
+        settings:allowDividerAbove="true"
+        settings:searchable="false"
+        settings:controller="com.android.settings.display.NightDisplayFooterPreferenceController"/>
 
 </PreferenceScreen>
\ No newline at end of file
diff --git a/res/xml/security_settings_picker.xml b/res/xml/security_settings_picker.xml
index 2e6361a..e772c38 100644
--- a/res/xml/security_settings_picker.xml
+++ b/res/xml/security_settings_picker.xml
@@ -15,6 +15,7 @@
 -->
 
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+                  xmlns:settings="http://schemas.android.com/apk/res-auto"
         android:title="@string/lock_settings_picker_title"
         android:key="lock_settings_picker">
 
@@ -57,4 +58,9 @@
             android:title="@string/face_unlock_skip_face"
             android:persistent="false"/>
 
+    <com.android.settingslib.widget.FooterPreference
+            android:key="lock_settings_footer"
+            android:selectable="false"
+            settings:searchable="false"/>
+
 </PreferenceScreen>
diff --git a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
index 1feef01..314a577 100644
--- a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
@@ -29,6 +29,7 @@
 import com.android.settings.SettingsPreferenceFragment;
 import com.android.settings.widget.SwitchBar;
 import com.android.settings.widget.ToggleSwitch;
+import com.android.settingslib.widget.FooterPreference;
 
 public abstract class ToggleFeaturePreferenceFragment extends SettingsPreferenceFragment {
 
@@ -138,11 +139,17 @@
         // Summary.
         if (arguments.containsKey(AccessibilitySettings.EXTRA_SUMMARY_RES)) {
             final int summary = arguments.getInt(AccessibilitySettings.EXTRA_SUMMARY_RES);
-            mFooterPreferenceMixin.createFooterPreference().setTitle(getText(summary));
+            createFooterPreference(getText(summary));
         } else if (arguments.containsKey(AccessibilitySettings.EXTRA_SUMMARY)) {
             final CharSequence summary = arguments.getCharSequence(
                     AccessibilitySettings.EXTRA_SUMMARY);
-            mFooterPreferenceMixin.createFooterPreference().setTitle(summary);
+            createFooterPreference(summary);
         }
     }
+
+    private void createFooterPreference(CharSequence title) {
+        final PreferenceScreen preferenceScreen = getPreferenceScreen();
+        preferenceScreen.addPreference(new FooterPreference.Builder(getActivity()).setTitle(
+                title).build());
+    }
 }
diff --git a/src/com/android/settings/datausage/DataSaverSummary.java b/src/com/android/settings/datausage/DataSaverSummary.java
index 1ab8c79..a2106d9 100644
--- a/src/com/android/settings/datausage/DataSaverSummary.java
+++ b/src/com/android/settings/datausage/DataSaverSummary.java
@@ -63,8 +63,6 @@
         super.onCreate(icicle);
 
         addPreferencesFromResource(R.xml.data_saver);
-        mFooterPreferenceMixin.createFooterPreference()
-                .setTitle(com.android.internal.R.string.data_saver_description);
         mUnrestrictedAccess = findPreference(KEY_UNRESTRICTED_ACCESS);
         mApplicationsState = ApplicationsState.getInstance(
                 (Application) getContext().getApplicationContext());
diff --git a/src/com/android/settings/password/ChooseLockGeneric.java b/src/com/android/settings/password/ChooseLockGeneric.java
index 2a7de05..4e2e90d 100644
--- a/src/com/android/settings/password/ChooseLockGeneric.java
+++ b/src/com/android/settings/password/ChooseLockGeneric.java
@@ -74,8 +74,6 @@
 import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
 import com.android.settingslib.RestrictedLockUtilsInternal;
 import com.android.settingslib.RestrictedPreference;
-import com.android.settingslib.widget.FooterPreference;
-import com.android.settingslib.widget.FooterPreferenceMixinCompat;
 
 import java.util.List;
 
@@ -112,6 +110,7 @@
         public static final String MINIMUM_QUALITY_KEY = "minimum_quality";
         public static final String HIDE_DISABLED_PREFS = "hide_disabled_prefs";
         public static final String TAG_FRP_WARNING_DIALOG = "frp_warning_dialog";
+        public static final String KEY_LOCK_SETTINGS_FOOTER ="lock_settings_footer";
 
         /**
          * Boolean extra determining whether a "screen lock options" button should be shown. This
@@ -499,11 +498,12 @@
         protected void addPreferences() {
             addPreferencesFromResource(R.xml.security_settings_picker);
 
+            final Preference footer = findPreference(KEY_LOCK_SETTINGS_FOOTER);
             if (!TextUtils.isEmpty(mCallerAppName) && !mIsCallingAppAdmin) {
-                FooterPreferenceMixinCompat footerMixin =
-                        new FooterPreferenceMixinCompat(this, getSettingsLifecycle());
-                FooterPreference footer = footerMixin.createFooterPreference();
+                footer.setVisible(true);
                 footer.setTitle(getFooterString());
+            } else {
+                footer.setVisible(false);
             }
 
             // Used for testing purposes
diff --git a/src/com/android/settings/wifi/CellularFallbackPreferenceController.java b/src/com/android/settings/wifi/CellularFallbackPreferenceController.java
index cbb8fb8..c411aba 100644
--- a/src/com/android/settings/wifi/CellularFallbackPreferenceController.java
+++ b/src/com/android/settings/wifi/CellularFallbackPreferenceController.java
@@ -17,8 +17,12 @@
 package com.android.settings.wifi;
 
 import android.content.Context;
+import android.content.res.Resources;
 import android.provider.Settings;
+import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
 
+import com.android.internal.annotations.VisibleForTesting;
 import com.android.settings.core.TogglePreferenceController;
 
 /**
@@ -49,8 +53,26 @@
     }
 
     private boolean avoidBadWifiConfig() {
-        return mContext.getResources().getInteger(
-                com.android.internal.R.integer.config_networkAvoidBadWifi) == 1;
+        boolean avoidBadWifiConfig = true;
+        final SubscriptionManager subscriptionManager =
+                mContext.getSystemService(SubscriptionManager.class);
+
+        for (SubscriptionInfo subscriptionInfo :
+                subscriptionManager.getActiveSubscriptionInfoList()) {
+            final Resources resources = getResourcesForSubId(subscriptionInfo.getSubscriptionId());
+            if (resources.getInteger(
+                    com.android.internal.R.integer.config_networkAvoidBadWifi) == 0) {
+                avoidBadWifiConfig = false;
+                break;
+            }
+        }
+        return avoidBadWifiConfig;
+    }
+
+    @VisibleForTesting
+    Resources getResourcesForSubId(int subscriptionId) {
+        return SubscriptionManager.getResourcesForSubId(mContext, subscriptionId,
+                false /* useRootLocale */);
     }
 
     private boolean avoidBadWifiCurrentSettings() {
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java
index 673c334..1bdadb2 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java
@@ -22,6 +22,7 @@
 import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_MEDIUM;
 import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_NONE;
 
+import static com.android.settings.password.ChooseLockGeneric.ChooseLockGenericFragment.KEY_LOCK_SETTINGS_FOOTER;
 import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_CALLER_APP_NAME;
 import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_IS_CALLING_APP_ADMIN;
 import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_REQUESTED_MIN_COMPLEXITY;
@@ -136,7 +137,7 @@
               mActivity.getString(R.string.unlock_footer_high_complexity_requested, "app name");
 
         mFragment.updatePreferencesOrFinish(false /* isRecreatingActivity */);
-        FooterPreference footer = mFragment.findPreference(FooterPreference.KEY_FOOTER);
+        FooterPreference footer = mFragment.findPreference(KEY_LOCK_SETTINGS_FOOTER);
 
         assertThat(footer.getTitle()).isEqualTo(expectedTitle);
     }
@@ -152,7 +153,7 @@
                 mActivity.getString(R.string.unlock_footer_medium_complexity_requested, "app name");
 
         mFragment.updatePreferencesOrFinish(false /* isRecreatingActivity */);
-        FooterPreference footer = mFragment.findPreference(FooterPreference.KEY_FOOTER);
+        FooterPreference footer = mFragment.findPreference(KEY_LOCK_SETTINGS_FOOTER);
 
         assertThat(footer.getTitle()).isEqualTo(expectedTitle);
     }
@@ -168,7 +169,7 @@
                 mActivity.getString(R.string.unlock_footer_low_complexity_requested, "app name");
 
         mFragment.updatePreferencesOrFinish(false /* isRecreatingActivity */);
-        FooterPreference footer = mFragment.findPreference(FooterPreference.KEY_FOOTER);
+        FooterPreference footer = mFragment.findPreference(KEY_LOCK_SETTINGS_FOOTER);
 
         assertThat(footer.getTitle()).isEqualTo(expectedTitle);
     }
@@ -184,19 +185,19 @@
                 mActivity.getString(R.string.unlock_footer_none_complexity_requested, "app name");
 
         mFragment.updatePreferencesOrFinish(/* isRecreatingActivity= */ false);
-        FooterPreference footer = mFragment.findPreference(FooterPreference.KEY_FOOTER);
+        FooterPreference footer = mFragment.findPreference(KEY_LOCK_SETTINGS_FOOTER);
 
         assertThat(footer.getTitle()).isEqualTo(expectedTitle);
     }
 
     @Test
-    public void updatePreferencesOrFinish_callingAppIsAdmin_noFooter() {
+    public void updatePreferencesOrFinish_callingAppIsAdmin_footerInvisible() {
         initActivity(new Intent().putExtra(EXTRA_KEY_IS_CALLING_APP_ADMIN, true));
 
         mFragment.updatePreferencesOrFinish(/* isRecreatingActivity= */ false);
 
-        FooterPreference footer = mFragment.findPreference(FooterPreference.KEY_FOOTER);
-        assertThat(footer).isNull();
+        FooterPreference footer = mFragment.findPreference(KEY_LOCK_SETTINGS_FOOTER);
+        assertThat(footer.isVisible()).isFalse();
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/wifi/CellularFallbackPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/CellularFallbackPreferenceControllerTest.java
index c5bd555..e5d5d8f 100644
--- a/tests/robotests/src/com/android/settings/wifi/CellularFallbackPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/CellularFallbackPreferenceControllerTest.java
@@ -18,36 +18,55 @@
 
 import static com.google.common.truth.Truth.assertThat;
 
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.when;
 
 import android.content.Context;
+import android.content.res.Resources;
+import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
+
+import java.util.ArrayList;
+import java.util.List;
 
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.mockito.Answers;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.shadows.ShadowApplication;
 
 @RunWith(RobolectricTestRunner.class)
 public class CellularFallbackPreferenceControllerTest {
     private static final String KEY_CELLULAR_FALLBACK = "wifi_cellular_data_fallback";
 
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private Context mContext;
+    @Mock
+    private SubscriptionManager mSubscriptionManager;
 
     private CellularFallbackPreferenceController mController;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        mController = new CellularFallbackPreferenceController(mContext, KEY_CELLULAR_FALLBACK);
+        ShadowApplication shadowApplication = ShadowApplication.getInstance();
+        shadowApplication.setSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE,
+                mSubscriptionManager);
+        mController = spy(new CellularFallbackPreferenceController(RuntimeEnvironment.application,
+                KEY_CELLULAR_FALLBACK));
     }
 
     @Test
     public void isAvailable_avoidBadWifiConfigIsFalse_shouldReturnTrue() {
-        when(mContext.getResources().getInteger(
+        setupMockIcc();
+        final Resources resources = mock(Resources.class);
+
+        doReturn(resources).when(mController).getResourcesForSubId(anyInt());
+        when(resources.getInteger(
                 com.android.internal.R.integer.config_networkAvoidBadWifi))
                 .thenReturn(0);
 
@@ -56,10 +75,24 @@
 
     @Test
     public void isAvailable_avoidBadWifiConfigIsTrue_shouldReturnFalse() {
-        when(mContext.getResources().getInteger(
+        setupMockIcc();
+        final Resources resources = mock(Resources.class);
+
+        doReturn(resources).when(mController).getResourcesForSubId(anyInt());
+        when(resources.getInteger(
                 com.android.internal.R.integer.config_networkAvoidBadWifi))
                 .thenReturn(1);
 
         assertThat(mController.isAvailable()).isFalse();
     }
+
+    private void setupMockIcc() {
+        final List<SubscriptionInfo> subscriptionInfoList = new ArrayList<>();
+        final SubscriptionInfo info1 = mock(SubscriptionInfo.class);
+        final SubscriptionInfo info2 = mock(SubscriptionInfo.class);
+        subscriptionInfoList.add(info1);
+        subscriptionInfoList.add(info2);
+        when(mSubscriptionManager.getActiveSubscriptionInfoList())
+                .thenReturn(subscriptionInfoList);
+    }
 }