Merge "Refactor CustomSliceManager."
diff --git a/res/layout/preference_single_target.xml b/res/layout/preference_single_target.xml
new file mode 100644
index 0000000..b4a9de0
--- /dev/null
+++ b/res/layout/preference_single_target.xml
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Copyright (C) 2019 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.
+  -->
+
+<!-- Based off preference_two_target.xml with Material ripple moved to parent for full ripple. -->
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:settings="http://schemas.android.com/apk/res-auto"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:minHeight="?android:attr/listPreferredItemHeightSmall"
+    android:gravity="center_vertical"
+    android:background="?android:attr/selectableItemBackground"
+    android:clipToPadding="false">
+
+    <LinearLayout
+        android:layout_width="0dp"
+        android:layout_height="match_parent"
+        android:layout_weight="1"
+        android:gravity="start|center_vertical"
+        android:clipToPadding="false"
+        android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+        android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
+
+        <LinearLayout
+            android:id="@+id/icon_frame"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:gravity="start|center_vertical"
+            android:minWidth="56dp"
+            android:orientation="horizontal"
+            android:clipToPadding="false"
+            android:paddingTop="4dp"
+            android:paddingBottom="4dp">
+            <androidx.preference.internal.PreferenceImageView
+                android:id="@android:id/icon"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                settings:maxWidth="48dp"
+                settings:maxHeight="48dp" />
+        </LinearLayout>
+
+        <RelativeLayout
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_weight="1"
+            android:paddingTop="16dp"
+            android:paddingBottom="16dp">
+
+            <TextView
+                android:id="@android:id/title"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:singleLine="true"
+                android:textAppearance="?android:attr/textAppearanceListItem"
+                android:ellipsize="marquee" />
+
+            <TextView
+                android:id="@android:id/summary"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_below="@android:id/title"
+                android:layout_alignStart="@android:id/title"
+                android:textAppearance="?android:attr/textAppearanceListItemSecondary"
+                android:textColor="?android:attr/textColorSecondary"
+                android:maxLines="10" />
+
+        </RelativeLayout>
+
+    </LinearLayout>
+
+    <include layout="@layout/preference_two_target_divider" />
+
+    <!-- Preference should place its actual preference widget here. -->
+    <LinearLayout
+        android:id="@android:id/widget_frame"
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent"
+        android:minWidth="64dp"
+        android:gravity="center"
+        android:orientation="vertical" />
+
+</LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b912c9d..bd67b1c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2390,8 +2390,6 @@
     <string name="wifi_hotspot_configure_ap_text_summary">AndroidAP WPA2 PSK hotspot</string>
     <!-- Default access point SSID used for tethering -->
     <string name="wifi_tether_configure_ssid_default">AndroidHotspot</string>
-    <!-- Summary text when hotspot is disabled because airplane mode is on [CHAR LIMIT=80]-->
-    <string name="wifi_tether_disabled_by_airplane">Unavailable because airplane mode is turned on</string>
 
     <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
          Wi-Fi Testing on the diagnostic screen-->
@@ -5242,8 +5240,8 @@
     <string name="battery_tip_high_usage_title" product="tablet">Tablet used more than usual</string>
     <!-- Title for the battery high usage tip [CHAR LIMIT=NONE] -->
     <string name="battery_tip_high_usage_title" product="device">Device used more than usual</string>
-    <!-- Summary for the battery high usage tip, which presents battery may run out soon [CHAR LIMIT=NONE] -->
-    <string name="battery_tip_high_usage_summary">Battery may run out soon</string>
+    <!-- Summary for the battery high usage tip, which presents battery may run out earlier [CHAR LIMIT=NONE] -->
+    <string name="battery_tip_high_usage_summary">Battery may run out earlier than usual</string>
     <!-- Message for battery tip dialog to show the status about the battery [CHAR LIMIT=NONE] -->
     <string name="battery_tip_dialog_message" product="default">Your phone has been used more than usual. Your battery may run out sooner than expected.\n\nTop <xliff:g id="number">%1$d</xliff:g> apps you used since full charge:</string>
     <!-- Message for battery tip dialog to show the status about the battery [CHAR LIMIT=NONE] -->
@@ -5632,9 +5630,9 @@
     <string name="battery_saver_turn_on_automatically_pct">at <xliff:g id="percent">%1$s</xliff:g> battery</string>
 
     <!-- [CHAR_LIMIT=40] Battery percentage: Title -->
-    <string name="battery_info">Battery Information</string>
+    <string name="battery_percentage">Battery percentage</string>
     <!-- [CHAR_LIMIT=NONE] Battery percentage: Description for preference -->
-    <string name="battery_info_description">Show percentage and time left before charge is needed</string>
+    <string name="battery_percentage_description">Show battery percentage in status bar</string>
 
     <!-- Process Stats strings -->
     <skip />
@@ -10686,6 +10684,9 @@
     <!-- Title for the Volume dialog (settings panel) with all volume streams[CHAR LIMIT=50] -->
     <string name="volume_connectivity_panel_title">Volume</string>
 
+    <!-- Subtitle explaining that mobile data cannot be used while airplane mode is on [CHAR LIMIT=50] -->
+    <string name="mobile_data_ap_mode_disabled">Unavailable during airplane mode</string>
+
     <!-- UI debug setting: force desktop mode [CHAR LIMIT=50] -->
     <string name="force_desktop_mode">Force desktop mode</string>
     <!-- UI debug setting: force desktop mode summary [CHAR LIMIT=NONE] -->
diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml
index 0f4c1d3..91fe656 100644
--- a/res/xml/display_settings.xml
+++ b/res/xml/display_settings.xml
@@ -20,7 +20,7 @@
     android:key="display_settings_screen"
     android:title="@string/display_settings"
     settings:keywords="@string/keywords_display"
-    settings:initialExpandedChildrenCount="4">
+    settings:initialExpandedChildrenCount="5">
 
     <com.android.settingslib.RestrictedPreference
         android:key="brightness"
@@ -57,6 +57,15 @@
             android:targetClass="@string/config_wallpaper_picker_class" />
     </com.android.settingslib.RestrictedPreference>
 
+    <ListPreference
+        android:key="dark_ui_mode"
+        android:title="@string/dark_ui_mode"
+        android:dialogTitle="@string/dark_ui_mode_title"
+        android:entries="@array/dark_ui_mode_entries"
+        android:entryValues="@array/dark_ui_mode_values"
+        settings:keywords="@string/keywords_dark_ui_mode"
+        settings:controller="com.android.settings.display.DarkUIPreferenceController" />
+
     <!-- Cross-listed item, if you change this, also change it in power_usage_summary.xml -->
     <com.android.settings.display.TimeoutListPreference
         android:key="screen_timeout"
@@ -136,15 +145,6 @@
         android:summary="@string/tap_to_wake_summary" />
 
     <ListPreference
-        android:key="dark_ui_mode"
-        android:title="@string/dark_ui_mode"
-        android:dialogTitle="@string/dark_ui_mode_title"
-        android:entries="@array/dark_ui_mode_entries"
-        android:entryValues="@array/dark_ui_mode_values"
-        settings:keywords="@string/keywords_dark_ui_mode"
-        settings:controller="com.android.settings.display.DarkUIPreferenceController" />
-
-    <ListPreference
         android:key="theme"
         android:title="@string/device_theme"
         android:summary="@string/summary_placeholder" />
diff --git a/res/xml/network_and_internet_v2.xml b/res/xml/network_and_internet_v2.xml
index 2451c57..44c3121 100644
--- a/res/xml/network_and_internet_v2.xml
+++ b/res/xml/network_and_internet_v2.xml
@@ -22,6 +22,7 @@
 
     <PreferenceCategory
         android:key="multi_network_header"
+        android:title="@string/summary_placeholder"
         settings:allowDividerBelow="true"
         android:order="-40"
         settings:controller="com.android.settings.network.MultiNetworkHeaderController"/>
diff --git a/res/xml/power_usage_summary.xml b/res/xml/power_usage_summary.xml
index 9be0b7d..94ead86 100644
--- a/res/xml/power_usage_summary.xml
+++ b/res/xml/power_usage_summary.xml
@@ -50,8 +50,8 @@
 
     <SwitchPreference
         android:key="battery_percentage"
-        android:title="@string/battery_info"
-        android:summary="@string/battery_info_description"
+        android:title="@string/battery_percentage"
+        android:summary="@string/battery_percentage_description"
         settings:controller="com.android.settings.display.BatteryPercentagePreferenceController" />
 
 
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 541ca3a..001e65b 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -50,6 +50,8 @@
 import com.android.internal.util.ArrayUtils;
 import com.android.settings.Settings.WifiSettingsActivity;
 import com.android.settings.applications.manageapplications.ManageApplications;
+import com.android.settings.backup.BackupSettingsHelper;
+import com.android.settings.backup.UserBackupSettingsActivity;
 import com.android.settings.core.OnActivityResultListener;
 import com.android.settings.core.SettingsBaseActivity;
 import com.android.settings.core.SubSettingLauncher;
@@ -630,6 +632,12 @@
                 showDev, isAdmin)
                 || somethingChanged;
 
+        // Enable/disable backup settings depending on whether backup is activated for the user.
+        boolean isBackupActive = new BackupSettingsHelper(this).isBackupServiceActive();
+        somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
+                UserBackupSettingsActivity.class.getName()), isBackupActive, isAdmin)
+                || somethingChanged;
+
         somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
                         Settings.WifiDisplaySettingsActivity.class.getName()),
                 WifiDisplaySettings.isAvailable(this), isAdmin)
diff --git a/src/com/android/settings/backup/BackupSettingsHelper.java b/src/com/android/settings/backup/BackupSettingsHelper.java
index fa77154..b836e55 100644
--- a/src/com/android/settings/backup/BackupSettingsHelper.java
+++ b/src/com/android/settings/backup/BackupSettingsHelper.java
@@ -209,7 +209,7 @@
     }
 
     /** Checks if backup service is enabled for this user. */
-    private boolean isBackupServiceActive() {
+    public boolean isBackupServiceActive() {
         boolean backupOkay;
         try {
             backupOkay = mBackupManager.isBackupServiceActive(UserHandle.myUserId());
diff --git a/src/com/android/settings/network/NetworkDashboardFragment.java b/src/com/android/settings/network/NetworkDashboardFragment.java
index 7672c2e..8c686a5 100644
--- a/src/com/android/settings/network/NetworkDashboardFragment.java
+++ b/src/com/android/settings/network/NetworkDashboardFragment.java
@@ -168,7 +168,12 @@
                 public List<SearchIndexableResource> getXmlResourcesToIndex(
                         Context context, boolean enabled) {
                     final SearchIndexableResource sir = new SearchIndexableResource(context);
-                    sir.xmlResId = R.xml.network_and_internet;
+                    if (FeatureFlagPersistent.isEnabled(context,
+                            FeatureFlags.NETWORK_INTERNET_V2)) {
+                        sir.xmlResId = R.xml.network_and_internet_v2;
+                    } else {
+                        sir.xmlResId = R.xml.network_and_internet;
+                    }
                     return Arrays.asList(sir);
                 }
 
diff --git a/src/com/android/settings/network/telephony/MobileDataSlice.java b/src/com/android/settings/network/telephony/MobileDataSlice.java
index 6efd8c3..5a5d6a2 100644
--- a/src/com/android/settings/network/telephony/MobileDataSlice.java
+++ b/src/com/android/settings/network/telephony/MobileDataSlice.java
@@ -74,8 +74,27 @@
         final IconCompat icon = IconCompat.createWithResource(mContext,
                 R.drawable.ic_network_cell);
         final String title = mContext.getText(R.string.mobile_data_settings_title).toString();
-        final CharSequence summary = getSummary();
         @ColorInt final int color = Utils.getColorAccentDefaultColor(mContext);
+
+        // Return a Slice without the mobile data toggle when airplane mode is on.
+        if (isAirplaneModeEnabled()) {
+            final CharSequence summary = mContext.getText(R.string.mobile_data_ap_mode_disabled);
+            // Intent does nothing, but we have to pass an intent to the Row.
+            final PendingIntent intent = PendingIntent.getActivity(mContext, 0 /* requestCode */,
+                    new Intent(), 0 /* flags */);
+            final SliceAction deadAction =
+                    SliceAction.create(intent, icon, ListBuilder.ICON_IMAGE, title);
+            final ListBuilder listBuilder = new ListBuilder(mContext, getUri(),
+                    ListBuilder.INFINITY)
+                    .setAccentColor(color)
+                    .addRow(new ListBuilder.RowBuilder()
+                            .setTitle(title)
+                            .setSubtitle(summary)
+                            .setPrimaryAction(deadAction));
+            return listBuilder.build();
+        }
+
+        final CharSequence summary = getSummary();
         final PendingIntent toggleAction = getBroadcastIntent(mContext);
         final PendingIntent primaryAction = getPrimaryAction();
         final SliceAction primarySliceAction = SliceAction.createDeeplink(primaryAction, icon,
@@ -101,11 +120,6 @@
 
     @Override
     public void onNotifyChange(Intent intent) {
-        // Don't make a change if we are in Airplane Mode.
-        if (isAirplaneModeEnabled()) {
-            return;
-        }
-
         final boolean newState = intent.getBooleanExtra(EXTRA_TOGGLE_STATE,
                     isMobileDataEnabled());
 
diff --git a/src/com/android/settings/widget/SingleTargetGearPreference.java b/src/com/android/settings/widget/SingleTargetGearPreference.java
index 48876fa..f6496ed 100644
--- a/src/com/android/settings/widget/SingleTargetGearPreference.java
+++ b/src/com/android/settings/widget/SingleTargetGearPreference.java
@@ -18,9 +18,10 @@
 
 import android.content.Context;
 import android.util.AttributeSet;
+import android.view.View;
 
-import androidx.core.content.res.TypedArrayUtils;
 import androidx.preference.Preference;
+import androidx.preference.PreferenceViewHolder;
 
 import com.android.settings.R;
 
@@ -28,23 +29,38 @@
  * A preference with single target and a gear icon on the side.
  */
 public class SingleTargetGearPreference extends Preference {
-
-    public SingleTargetGearPreference(Context context, AttributeSet attrs,
-            int defStyleAttr, int defStyleRes) {
+    public SingleTargetGearPreference(Context context, AttributeSet attrs, int defStyleAttr,
+            int defStyleRes) {
         super(context, attrs, defStyleAttr, defStyleRes);
-        setWidgetLayoutResource(R.layout.preference_widget_gear_no_bg);
+        init();
     }
 
     public SingleTargetGearPreference(Context context, AttributeSet attrs, int defStyleAttr) {
-        this(context, attrs, defStyleAttr, 0 /* defStyleRes */);
+        super(context, attrs, defStyleAttr);
+        init();
     }
 
     public SingleTargetGearPreference(Context context, AttributeSet attrs) {
-        this(context, attrs, TypedArrayUtils.getAttr(context, R.attr.preferenceStyle,
-                android.R.attr.preferenceStyle));
+        super(context, attrs);
+        init();
     }
 
     public SingleTargetGearPreference(Context context) {
-        this(context, null /* attrs */);
+        super(context);
+        init();
     }
-}
\ No newline at end of file
+
+    private void init() {
+        setLayoutResource(R.layout.preference_single_target);
+        setWidgetLayoutResource(R.layout.preference_widget_gear_optional_background);
+    }
+
+    @Override
+    public void onBindViewHolder(PreferenceViewHolder holder) {
+        super.onBindViewHolder(holder);
+        final View divider = holder.findViewById(com.android.settingslib.R.id.two_target_divider);
+        if (divider != null) {
+            divider.setVisibility(View.INVISIBLE);
+        }
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/network/telephony/MobileDataSliceTest.java b/tests/robotests/src/com/android/settings/network/telephony/MobileDataSliceTest.java
index c497cf8..e488d0c 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/MobileDataSliceTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/MobileDataSliceTest.java
@@ -24,6 +24,7 @@
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
+import android.app.PendingIntent;
 import android.content.Context;
 import android.content.Intent;
 import android.provider.Settings;
@@ -162,4 +163,27 @@
 
         assertThat(isMobileDataEnabled).isEqualTo(seed);
     }
+
+    @Test
+    public void airplaneModeEnabled_slicePrimaryActionIsEmpty() {
+        doReturn(true).when(mMobileDataSlice).isAirplaneModeEnabled();
+        doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(SUB_ID);
+        final Slice mobileData = mMobileDataSlice.getSlice();
+
+        final SliceMetadata metadata = SliceMetadata.from(mContext, mobileData);
+        assertThat(metadata.getTitle())
+                .isEqualTo(mContext.getString(R.string.mobile_data_settings_title));
+
+        assertThat(metadata.getSubtitle())
+                .isEqualTo(mContext.getString(R.string.mobile_data_ap_mode_disabled));
+
+        final List<SliceAction> toggles = metadata.getToggles();
+        assertThat(toggles).hasSize(0);
+
+        final SliceAction primaryAction = metadata.getPrimaryAction();
+        final PendingIntent pendingIntent = primaryAction.getAction();
+        final Intent actionIntent = pendingIntent.getIntent();
+
+        assertThat(actionIntent).isNull();
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSettingsTest.java b/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSettingsTest.java
index 55a4224..011bca5 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSettingsTest.java
@@ -30,6 +30,8 @@
 import android.provider.Settings;
 import android.telephony.TelephonyManager;
 
+import androidx.fragment.app.FragmentActivity;
+
 import com.android.settings.core.FeatureFlags;
 import com.android.settings.datausage.DataUsageSummaryPreferenceController;
 import com.android.settings.development.featureflags.FeatureFlagPersistent;
@@ -48,8 +50,6 @@
 
 import java.util.List;
 
-import androidx.fragment.app.FragmentActivity;
-
 @RunWith(RobolectricTestRunner.class)
 @Config(shadows = ShadowEntityHeaderController.class)
 public class MobileNetworkSettingsTest {
@@ -86,6 +86,7 @@
 
     @Test
     public void onAttach_noV2Flag_noCrash() {
+        FeatureFlagPersistent.setEnabled(mContext, FeatureFlags.NETWORK_INTERNET_V2, false);
         mFragment.onAttach(mContext);
     }
 
@@ -97,6 +98,7 @@
 
     @Test
     public void createPreferenceControllers_noV2Flag_noDataUsageSummaryController() {
+        FeatureFlagPersistent.setEnabled(mContext, FeatureFlags.NETWORK_INTERNET_V2, false);
         final List<AbstractPreferenceController> controllers =
                 mFragment.createPreferenceControllers(mContext);
         assertThat(controllers.stream().filter(
diff --git a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
index e640dee..204a0e2 100644
--- a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
@@ -758,7 +758,9 @@
     }
 
     @Test
-    public void forgetNetwork_Passpoint() {
+    public void forgetNetwork_v1_Passpoint() {
+        FeatureFlagPersistent.setEnabled(mContext, FeatureFlags.NETWORK_INTERNET_V2, false);
+
         mockWifiConfig.networkId = 5;
         when(mockWifiConfig.isPasspoint()).thenReturn(true);
 
diff --git a/tests/robotests/src/com/android/settings/wifi/savedaccesspoints/SavedAccessPointsWifiSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/savedaccesspoints/SavedAccessPointsWifiSettingsTest.java
index 6ede989..746456e 100644
--- a/tests/robotests/src/com/android/settings/wifi/savedaccesspoints/SavedAccessPointsWifiSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/savedaccesspoints/SavedAccessPointsWifiSettingsTest.java
@@ -82,6 +82,8 @@
 
     @Test
     public void onForget_isPasspointConfig_shouldRefreshAPList() {
+        FeatureFlagPersistent.setEnabled(RuntimeEnvironment.application,
+                FeatureFlags.NETWORK_INTERNET_V2, false);
         when(mAccessPoint.isPasspointConfig()).thenReturn(true);
         ReflectionHelpers.setField(mSettings, "mSelectedAccessPoint", mAccessPoint);