Merge "[Settings] Change the way in InternetPreferenceController for getting the subscription info from room db part4"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 4257142..10df2bb 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3274,6 +3274,8 @@
     <string name="ethernet_tether_checkbox_text">Ethernet tethering</string>
     <!-- Ethernet Tethering subtext [CHAR LIMIT=NONE]-->
     <string name="ethernet_tethering_subtext" product="default">Share phone\u2019s internet connection via Ethernet</string>
+    <!-- Ethernet Tethering subtext for tablet [CHAR LIMIT=NONE]-->
+    <string name="ethernet_tethering_subtext" product="tablet">Share tablet\u2019s internet connection via Ethernet</string>
 
     <!-- Tethering footer info [CHAR LIMIT=NONE]-->
     <string name="tethering_footer_info">Use hotspot and tethering to provide internet to other devices through your mobile data connection. Apps can also create a hotspot to share content with nearby devices.</string>
@@ -6114,15 +6116,6 @@
     <!-- Body of dialog shown before user limits mobile data usage. [CHAR LIMIT=NONE] -->
     <string name="data_usage_limit_dialog_mobile" product="default">Your phone will turn off mobile data once it reaches the limit you set.\n\nSince data usage is measured by your phone, and your carrier may account for usage differently, consider setting a conservative limit.</string>
 
-    <!-- Title of dialog shown before user restricts background data usage. [CHAR LIMIT=48] -->
-    <string name="data_usage_restrict_background_title">Restrict background data?</string>
-    <!-- Body of dialog shown before user restricts background data usage. [CHAR LIMIT=NONE] -->
-    <string name="data_usage_restrict_background">If you restrict background mobile data, some apps and services won\u2019t work unless you\u2019re connected to Wi\u2011Fi.</string>
-    <!-- Body of dialog shown before user restricts background data usage. This is for multiuser tablets. [CHAR LIMIT=NONE] -->
-    <string name="data_usage_restrict_background_multiuser" product="tablet">If you restrict background mobile data, some apps and services won\u2019t work unless you\u2019re connected to Wi\u2011Fi.\n\nThis setting affects all users on this tablet.</string>
-    <!-- Body of dialog shown before user restricts background data usage. This is for multiuser phones. [CHAR LIMIT=NONE] -->
-    <string name="data_usage_restrict_background_multiuser" product="default">If you restrict background mobile data, some apps and services won\u2019t work unless you\u2019re connected to Wi\u2011Fi.\n\nThis setting affects all users on this phone.</string>
-
     <!-- Label displaying current network data usage warning threshold. [CHAR LIMIT=18] -->
     <string name="data_usage_sweep_warning"><font size="18"><xliff:g id="number" example="128">^1</xliff:g></font> <font size="9"><xliff:g id="unit" example="KB">^2</xliff:g></font>\n<font size="12">warning</font></string>
     <!-- Label displaying current network data usage limit threshold. [CHAR LIMIT=18] -->
@@ -6874,14 +6867,6 @@
     <string name="restriction_bluetooth_config_title">Bluetooth</string>
     <!-- Restrictions summary for changing bluetooth configuration [CHAR LIMIT=100] -->
     <string name="restriction_bluetooth_config_summary">Allow modification of Bluetooth pairings and settings</string>
-    <!-- Restrictions title for allowing NFC transfers [CHAR LIMIT=35] -->
-    <string name="restriction_nfc_enable_title">NFC</string>
-    <!-- Restrictions summary for allowing NFC transfers (tablet) [CHAR LIMIT=100] -->
-    <string name="restriction_nfc_enable_summary_config">Allow data exchange when this <xliff:g id="device_name">%1$s</xliff:g> touches another NFC device</string>
-    <!-- Restrictions summary for allowing NFC transfers (tablet) [CHAR LIMIT=100] -->
-    <string name="restriction_nfc_enable_summary" product="tablet">Allow data exchange when the tablet touches another device</string>
-    <!-- Restrictions summary for allowing NFC transfers (phone) [CHAR LIMIT=100] -->
-    <string name="restriction_nfc_enable_summary" product="default">Allow data exchange when the phone touches another device</string>
     <!-- Restrictions title for allowing location sharing [CHAR LIMIT=35] -->
     <string name="restriction_location_enable_title">Location</string>
     <!-- Restrictions summary for allowing location sharing [CHAR LIMIT=100] -->
@@ -6891,8 +6876,6 @@
     <string name="wizard_back">Back</string>
     <!-- Wizard next button label [CHAR LIMIT=25] -->
     <string name="wizard_next">Next</string>
-    <!-- Wizard next button label for portable [CHAR LIMIT=25] -->
-    <string name="wizard_back_portable">Switch to portable</string>
     <!-- Wizard next button label for adoptable [CHAR LIMIT=25] -->
     <string name="wizard_back_adoptable">Format another way</string>
 
@@ -10475,27 +10458,9 @@
     <!-- Explanatory text shown when no debuggable apps are available [CHAR LIMIT=NONE] -->
     <string name="platform_compat_dialog_text_no_apps">App compatibility changes can only be modified for debuggable apps. Install a debuggable app and try again.</string>
 
-    <!-- Slices Strings -->
-
-    <!-- Summary text on a card explaining that a setting does not exist / is not supported on the device [CHAR_LIMIT=NONE]-->
-    <string name="unsupported_setting_summary" product="default">Setting isn’t supported on this phone</string>
-
-    <!-- Summary text on a card explaining that a setting does not exist / is not supported on the device [CHAR_LIMIT=NONE]-->
-    <string name="unsupported_setting_summary" product="tablet">Setting isn’t supported on this tablet</string>
-
-    <!-- Summary text on a card explaining that a setting does not exist / is not supported on the device [CHAR_LIMIT=NONE]-->
-    <string name="unsupported_setting_summary" product="device">Setting isn’t supported on this device</string>
-
-    <!-- Summary text on a card explaining that a setting cannot be changed by the current user. [CHAR_LIMIT=NONE] -->
-    <string name="disabled_for_user_setting_summary">Setting can’t be changed by current user</string>
-
     <!-- Summary text on a card explaining a setting cannot be changed right now because it needs another setting to be changed. [CHAR_LIMIT=NONE] -->
     <string name="disabled_dependent_setting_summary">Depends on another setting</string>
 
-    <!-- Summary text on a card explaining a setting cannot be changed right now, but we don't know the reason. [CHAR_LIMIT=NONE] -->
-    <string name="unknown_unavailability_setting_summary">Setting unavailable</string>
-
-
     <!-- Account type associated with the backup account. Empty for AOSP. [DO NOT TRANSLATE] -->
     <string name="account_type" translatable="false"></string>
     <!-- Package to target for Account credential confirmation. This will allow users to
@@ -10591,9 +10556,6 @@
     <!-- Text to show this network is forbidden [CHAR LIMIT=NONE] -->
     <string name="forbidden_network">(forbidden)</string>
 
-    <!-- Message informs the user that has no SIM card in personalized Settings [CHAR LIMIT=30] -->
-    <string name="no_sim_card">No SIM card</string>
-
     <!-- A title for a SIM card spinner UI component which users can choose a SIM card. [CHAR LIMIT=NONE] -->
     <string name="sim_card">SIM</string>
     <!-- A label when there is no SIM card to choose. [CHAR LIMIT=NONE] -->
diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java
index c643842..a86b758 100644
--- a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java
@@ -341,7 +341,7 @@
 
     /**
      * When user disable the Le Audio profile, the system needs to do two things.
-     * 1) Disable the Le Audio profile for each of the Le Audio devices.
+     * 1) Disable the Le Audio profile, VCP and CSIP for each of the Le Audio devices.
      * 2) Enable the A2dp profile and Headset profile for the associated device. The system
      * can't enable the A2dp profile and Headset profile if the Le Audio profile is enabled.
      *
@@ -352,14 +352,23 @@
             Log.e(TAG, "There is no the LE profile or no device in mProfileDeviceMap. Do nothing.");
             return;
         }
+        LocalBluetoothProfile vcp = mProfileManager.getVolumeControlProfile();
+        LocalBluetoothProfile csip = mProfileManager.getCsipSetCoordinatorProfile();
+        LocalBluetoothProfile a2dp = mProfileManager.getA2dpProfile();
+        LocalBluetoothProfile headset = mProfileManager.getHeadsetProfile();
+
         for (CachedBluetoothDevice leAudioDevice : mProfileDeviceMap.get(profile.toString())) {
             Log.d(TAG,
                     "User disable LE device: " + leAudioDevice.getDevice().getAnonymizedAddress());
             profile.setEnabled(leAudioDevice.getDevice(), false);
+            if (vcp != null) {
+                vcp.setEnabled(leAudioDevice.getDevice(), false);
+            }
+            if (csip != null) {
+                csip.setEnabled(leAudioDevice.getDevice(), false);
+            }
         }
 
-        LocalBluetoothProfile a2dp = mProfileManager.getA2dpProfile();
-        LocalBluetoothProfile headset = mProfileManager.getHeadsetProfile();
         enableProfileAfterUserDisablesLeAudio(a2dp);
         enableProfileAfterUserDisablesLeAudio(headset);
     }
@@ -368,7 +377,7 @@
      * When user enable the Le Audio profile, the system needs to do two things.
      * 1) Disable the A2dp profile and Headset profile for the associated device. The system
      * can't enable the Le Audio if the A2dp profile and Headset profile are enabled.
-     * 2) Enable the Le Audio profile for each of the Le Audio devices.
+     * 2) Enable the Le Audio profile, VCP and CSIP for each of the Le Audio devices.
      *
      * @param profile the LeAudio profile
      */
@@ -379,6 +388,9 @@
         }
         LocalBluetoothProfile a2dp = mProfileManager.getA2dpProfile();
         LocalBluetoothProfile headset = mProfileManager.getHeadsetProfile();
+        LocalBluetoothProfile vcp = mProfileManager.getVolumeControlProfile();
+        LocalBluetoothProfile csip = mProfileManager.getCsipSetCoordinatorProfile();
+
         disableProfileBeforeUserEnablesLeAudio(a2dp);
         disableProfileBeforeUserEnablesLeAudio(headset);
 
@@ -386,6 +398,12 @@
             Log.d(TAG,
                     "User enable LE device: " + leAudioDevice.getDevice().getAnonymizedAddress());
             profile.setEnabled(leAudioDevice.getDevice(), true);
+            if (vcp != null) {
+                vcp.setEnabled(leAudioDevice.getDevice(), true);
+            }
+            if (csip != null) {
+                csip.setEnabled(leAudioDevice.getDevice(), true);
+            }
         }
     }
 
diff --git a/src/com/android/settings/network/MobileNetworkIntentConverter.java b/src/com/android/settings/network/MobileNetworkIntentConverter.java
index 648ac61..651215a 100644
--- a/src/com/android/settings/network/MobileNetworkIntentConverter.java
+++ b/src/com/android/settings/network/MobileNetworkIntentConverter.java
@@ -53,17 +53,18 @@
     private static final ComponentName sTargetComponent = ComponentName
             .createRelative("com.android.settings",
                     MobileNetworkActivity.class.getTypeName());
-
+    private static final String INTENT_TRAMPOLINE = "android.settings.SEARCH_RESULT_TRAMPOLINE";
     /**
      * These actions has better aligned with definitions within AndroidManifest.xml
      */
-    private static final String [] sPotentialActions = new String [] {
-        null,
-        Intent.ACTION_MAIN,
-        android.provider.Settings.ACTION_NETWORK_OPERATOR_SETTINGS,
-        android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS,
-        android.provider.Settings.ACTION_MMS_MESSAGE_SETTING,
-        ImsRcsManager.ACTION_SHOW_CAPABILITY_DISCOVERY_OPT_IN
+    private static final String[] sPotentialActions = new String[]{
+            null,
+            Intent.ACTION_MAIN,
+            android.provider.Settings.ACTION_NETWORK_OPERATOR_SETTINGS,
+            android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS,
+            android.provider.Settings.ACTION_MMS_MESSAGE_SETTING,
+            ImsRcsManager.ACTION_SHOW_CAPABILITY_DISCOVERY_OPT_IN,
+            INTENT_TRAMPOLINE
     };
 
     private static final String RE_ROUTE_TAG = ":reroute:" + TAG;
@@ -112,30 +113,31 @@
         if (TextUtils.equals(action,
                 android.provider.Settings.ACTION_NETWORK_OPERATOR_SETTINGS)
                 || TextUtils.equals(action,
-                        android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS)) {
+                android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS)
+                || TextUtils.equals(action, INTENT_TRAMPOLINE)) {
             // Accepted.
             ops = ops.andThen(intent -> extractArguments(intent, subId))
-                     .andThen(args -> rePackIntent(args, reqIntent))
-                     .andThen(intent -> updateFragment(intent, mAppContext, subId));
+                    .andThen(args -> rePackIntent(args, reqIntent))
+                    .andThen(intent -> updateFragment(intent, mAppContext, subId));
         } else if (TextUtils.equals(action,
                 android.provider.Settings.ACTION_MMS_MESSAGE_SETTING)) {
             ops = ops.andThen(intent -> extractArguments(intent, subId))
-                     .andThen(args -> convertMmsArguments(args))
-                     .andThen(args -> rePackIntent(args, reqIntent))
-                     .andThen(intent -> updateFragment(intent, mAppContext, subId));
+                    .andThen(args -> convertMmsArguments(args))
+                    .andThen(args -> rePackIntent(args, reqIntent))
+                    .andThen(intent -> updateFragment(intent, mAppContext, subId));
         } else if (TextUtils.equals(action,
                 ImsRcsManager.ACTION_SHOW_CAPABILITY_DISCOVERY_OPT_IN)) {
             ops = ops.andThen(intent -> extractArguments(intent, subId))
-                     .andThen(args -> supportContactDiscoveryDialog(args, mAppContext, subId))
-                     .andThen(args -> rePackIntent(args, reqIntent))
-                     .andThen(intent -> updateFragment(intent, mAppContext, subId));
+                    .andThen(args -> supportContactDiscoveryDialog(args, mAppContext, subId))
+                    .andThen(args -> rePackIntent(args, reqIntent))
+                    .andThen(intent -> updateFragment(intent, mAppContext, subId));
         } else if ((sTargetComponent.compareTo(mComponent) == 0)
                 && ((action == null) || Intent.ACTION_MAIN.equals(action))) {
             Log.d(TAG, "Support default actions direct to this component");
             ops = ops.andThen(intent -> extractArguments(intent, subId))
-                     .andThen(args -> rePackIntent(args, reqIntent))
-                     .andThen(intent -> replaceIntentAction(intent))
-                     .andThen(intent -> updateFragment(intent, mAppContext, subId));
+                    .andThen(args -> rePackIntent(args, reqIntent))
+                    .andThen(intent -> replaceIntentAction(intent))
+                    .andThen(intent -> updateFragment(intent, mAppContext, subId));
         } else {
             return null;
         }
diff --git a/src/com/android/settings/network/NetworkProviderSettings.java b/src/com/android/settings/network/NetworkProviderSettings.java
index 1f79b20..19ebd36 100644
--- a/src/com/android/settings/network/NetworkProviderSettings.java
+++ b/src/com/android/settings/network/NetworkProviderSettings.java
@@ -34,6 +34,7 @@
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.PowerManager;
+import android.os.UserHandle;
 import android.os.UserManager;
 import android.provider.Settings;
 import android.telephony.TelephonyManager;
@@ -609,10 +610,7 @@
             return;
         }
 
-        if (mSelectedWifiEntry.isSaved() && mSelectedWifiEntry.getConnectedState()
-                != WifiEntry.CONNECTED_STATE_CONNECTED) {
-            menu.add(Menu.NONE, MENU_ID_MODIFY, 0 /* order */, R.string.wifi_modify);
-        }
+        addModifyMenuIfSuitable(menu, mSelectedWifiEntry);
     }
 
     @VisibleForTesting
@@ -632,6 +630,14 @@
         }
     }
 
+    @VisibleForTesting
+    void addModifyMenuIfSuitable(ContextMenu menu, WifiEntry wifiEntry) {
+        if (mIsAdmin && wifiEntry.isSaved()
+                && wifiEntry.getConnectedState() != WifiEntry.CONNECTED_STATE_CONNECTED) {
+            menu.add(Menu.NONE, MENU_ID_MODIFY, 0 /* order */, R.string.wifi_modify);
+        }
+    }
+
     private boolean canForgetNetwork() {
         return mSelectedWifiEntry.canForget() && !WifiUtils.isNetworkLockedDown(getActivity(),
                 mSelectedWifiEntry.getWifiConfiguration());
@@ -654,6 +660,12 @@
                         () -> launchWifiDppConfiguratorActivity(mSelectedWifiEntry));
                 return true;
             case MENU_ID_MODIFY:
+                if (!mIsAdmin) {
+                    Log.e(TAG, "Can't modify Wi-Fi because the user isn't admin.");
+                    EventLog.writeEvent(0x534e4554, "237672190", UserHandle.myUserId(),
+                            "User isn't admin");
+                    return true;
+                }
                 showDialog(mSelectedWifiEntry, WifiConfigUiBase2.MODE_MODIFY);
                 return true;
             default:
diff --git a/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java b/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
index 632b6cf..b347ac0 100644
--- a/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
@@ -17,9 +17,11 @@
 
 import static com.android.settings.network.NetworkProviderSettings.MENU_ID_DISCONNECT;
 import static com.android.settings.network.NetworkProviderSettings.MENU_ID_FORGET;
+import static com.android.settings.network.NetworkProviderSettings.MENU_ID_MODIFY;
 import static com.android.settings.network.NetworkProviderSettings.MENU_ID_SHARE;
 import static com.android.settings.wifi.WifiConfigUiBase2.MODE_CONNECT;
 import static com.android.settings.wifi.WifiConfigUiBase2.MODE_MODIFY;
+import static com.android.wifitrackerlib.WifiEntry.CONNECTED_STATE_DISCONNECTED;
 
 import static com.google.common.truth.Truth.assertThat;
 
@@ -733,6 +735,28 @@
     }
 
     @Test
+    public void addModifyMenuIfSuitable_isAdmin_addMenu() {
+        mNetworkProviderSettings.mIsAdmin = true;
+        when(mWifiEntry.isSaved()).thenReturn(true);
+        when(mWifiEntry.getConnectedState()).thenReturn(CONNECTED_STATE_DISCONNECTED);
+
+        mNetworkProviderSettings.addModifyMenuIfSuitable(mContextMenu, mWifiEntry);
+
+        verify(mContextMenu).add(anyInt(), eq(MENU_ID_MODIFY), anyInt(), anyInt());
+    }
+
+    @Test
+    public void addModifyMenuIfSuitable_isNotAdmin_notAddMenu() {
+        mNetworkProviderSettings.mIsAdmin = false;
+        when(mWifiEntry.isSaved()).thenReturn(true);
+        when(mWifiEntry.getConnectedState()).thenReturn(CONNECTED_STATE_DISCONNECTED);
+
+        mNetworkProviderSettings.addModifyMenuIfSuitable(mContextMenu, mWifiEntry);
+
+        verify(mContextMenu, never()).add(anyInt(), eq(MENU_ID_MODIFY), anyInt(), anyInt());
+    }
+
+    @Test
     public void getNonIndexableKeys_allowedChangeWifiState_keyNotReturned() {
         when(mWifiRestriction.isChangeWifiStateAllowed(mContext)).thenReturn(true);
         NetworkProviderSettings.SearchIndexProvider searchIndexProvider =