Merge tag 'android-12.1.0_r5' into staging/lineage-19.1_merge-android-12.1.0_r5

Android 12.1.0 Release 5 (SP2A.220505.002)

* tag 'android-12.1.0_r5':
  Change default USB configuration to a RestrictedPreference
  Hide private DNS settings UI in Guest mode

Change-Id: I89d1acad3ae1d83ea6eea1043d879d0ae74d6d29
diff --git a/res/xml/development_settings.xml b/res/xml/development_settings.xml
index 73885b7..b47eb69 100644
--- a/res/xml/development_settings.xml
+++ b/res/xml/development_settings.xml
@@ -300,7 +300,7 @@
             android:title="@string/tethering_hardware_offload"
             android:summary="@string/tethering_hardware_offload_summary" />
 
-        <com.android.settingslib.RestrictedSwitchPreference
+        <com.android.settingslib.RestrictedPreference
             android:key="default_usb_configuration"
             android:fragment="com.android.settings.connecteddevice.usb.UsbDefaultFragment"
             android:title="@string/usb_default_label"/>
diff --git a/src/com/android/settings/development/DefaultUsbConfigurationPreferenceController.java b/src/com/android/settings/development/DefaultUsbConfigurationPreferenceController.java
index be7704f..7c3d3b1 100644
--- a/src/com/android/settings/development/DefaultUsbConfigurationPreferenceController.java
+++ b/src/com/android/settings/development/DefaultUsbConfigurationPreferenceController.java
@@ -24,7 +24,7 @@
 import androidx.preference.Preference;
 import androidx.preference.PreferenceScreen;
 
-import com.android.settingslib.RestrictedSwitchPreference;
+import com.android.settingslib.RestrictedPreference;
 import com.android.settingslib.development.DeveloperOptionsPreferenceController;
 
 public class DefaultUsbConfigurationPreferenceController extends
@@ -32,7 +32,7 @@
 
     private static final String PREFERENCE_KEY = "default_usb_configuration";
 
-    private RestrictedSwitchPreference mPreference;
+    private RestrictedPreference mPreference;
 
     public DefaultUsbConfigurationPreferenceController(Context context) {
         super(context);
diff --git a/src/com/android/settings/network/PrivateDnsPreferenceController.java b/src/com/android/settings/network/PrivateDnsPreferenceController.java
index 07d5714..ed6f9ed 100644
--- a/src/com/android/settings/network/PrivateDnsPreferenceController.java
+++ b/src/com/android/settings/network/PrivateDnsPreferenceController.java
@@ -85,9 +85,12 @@
 
     @Override
     public int getAvailabilityStatus() {
-        return mContext.getResources().getBoolean(R.bool.config_show_private_dns_settings)
-                ? AVAILABLE
-                : UNSUPPORTED_ON_DEVICE;
+        if (!mContext.getResources().getBoolean(R.bool.config_show_private_dns_settings)) {
+            return UNSUPPORTED_ON_DEVICE;
+        }
+        final UserManager userManager = mContext.getSystemService(UserManager.class);
+        if (userManager.isGuestUser()) return DISABLED_FOR_USER;
+        return AVAILABLE;
     }
 
     @Override
diff --git a/tests/robotests/src/com/android/settings/development/DefaultUsbConfigurationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/DefaultUsbConfigurationPreferenceControllerTest.java
index c9b13e27..a386473 100644
--- a/tests/robotests/src/com/android/settings/development/DefaultUsbConfigurationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/DefaultUsbConfigurationPreferenceControllerTest.java
@@ -32,7 +32,7 @@
 import androidx.preference.PreferenceScreen;
 
 import com.android.settingslib.RestrictedLockUtils;
-import com.android.settingslib.RestrictedSwitchPreference;
+import com.android.settingslib.RestrictedPreference;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -48,7 +48,7 @@
     private static final ComponentName TEST_COMPONENT_NAME = new ComponentName("test", "test");
 
     @Mock
-    private RestrictedSwitchPreference mPreference;
+    private RestrictedPreference mPreference;
     @Mock
     private PreferenceScreen mPreferenceScreen;
     @Mock
diff --git a/tests/robotests/src/com/android/settings/network/PrivateDnsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/PrivateDnsPreferenceControllerTest.java
index e31d959..057b6cb 100644
--- a/tests/robotests/src/com/android/settings/network/PrivateDnsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/PrivateDnsPreferenceControllerTest.java
@@ -26,6 +26,7 @@
 import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
 
 import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.DISABLED_FOR_USER;
 import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
 
 import static com.google.common.truth.Truth.assertThat;
@@ -35,6 +36,7 @@
 import static org.mockito.Mockito.CALLS_REAL_METHODS;
 import static org.mockito.Mockito.atLeastOnce;
 import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.reset;
 import static org.mockito.Mockito.spy;
@@ -109,6 +111,8 @@
     private Network mNetwork;
     @Mock
     private Preference mPreference;
+    @Mock
+    private UserManager mUserManager;
     @Captor
     private ArgumentCaptor<NetworkCallback> mCallbackCaptor;
     private PrivateDnsPreferenceController mController;
@@ -127,6 +131,7 @@
         mShadowContentResolver = Shadow.extract(mContentResolver);
         when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
                 .thenReturn(mConnectivityManager);
+        when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
         doNothing().when(mConnectivityManager).registerDefaultNetworkCallback(
                 mCallbackCaptor.capture(), nullable(Handler.class));
 
@@ -174,6 +179,12 @@
     }
 
     @Test
+    public void getAvailabilityStatus_disabledForGuestUser() {
+        doReturn(true).when(mUserManager).isGuestUser();
+        assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_FOR_USER);
+    }
+
+    @Test
     public void goThroughLifecycle_shouldRegisterUnregisterSettingsObserver() {
         mLifecycle.handleLifecycleEvent(ON_START);
         verify(mContext, atLeastOnce()).getContentResolver();