Merge tag 'android-14.0.0_r31' into leaf-3.2

Android 14.0.0 Release 31 (AP1A.240405.002.A1)

* tag 'android-14.0.0_r31':
  Restrict WifiDialogActivity

Change-Id: Iaa34cd9f4d23aa1bc2d008e677fa7bbcd287b194
diff --git a/src/com/android/settings/wifi/WifiDialogActivity.java b/src/com/android/settings/wifi/WifiDialogActivity.java
index 7e901c2..eb3d88a 100644
--- a/src/com/android/settings/wifi/WifiDialogActivity.java
+++ b/src/com/android/settings/wifi/WifiDialogActivity.java
@@ -17,6 +17,7 @@
 package com.android.settings.wifi;
 
 import static android.Manifest.permission.ACCESS_FINE_LOCATION;
+import static android.os.UserManager.DISALLOW_ADD_WIFI_CONFIG;
 import static android.os.UserManager.DISALLOW_CONFIG_WIFI;
 
 import android.app.KeyguardManager;
@@ -122,7 +123,7 @@
         }
 
         super.onCreate(savedInstanceState);
-        if (!isConfigWifiAllowed()) {
+        if (!isConfigWifiAllowed() || !isAddWifiConfigAllowed()) {
             finish();
             return;
         }
@@ -393,6 +394,16 @@
         return isConfigWifiAllowed;
     }
 
+    @VisibleForTesting
+    boolean isAddWifiConfigAllowed() {
+        UserManager userManager = getSystemService(UserManager.class);
+        if (userManager != null && userManager.hasUserRestriction(DISALLOW_ADD_WIFI_CONFIG)) {
+            Log.e(TAG, "The user is not allowed to add Wi-Fi configuration.");
+            return false;
+        }
+        return true;
+    }
+
     private boolean hasWifiManager() {
         if (mWifiManager != null) return true;
         mWifiManager = getSystemService(WifiManager.class);
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiDialogActivityTest.java b/tests/robotests/src/com/android/settings/wifi/WifiDialogActivityTest.java
index ff0395d..d1cbd0e 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiDialogActivityTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiDialogActivityTest.java
@@ -18,6 +18,7 @@
 
 import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
 import static android.Manifest.permission.ACCESS_FINE_LOCATION;
+import static android.os.UserManager.DISALLOW_ADD_WIFI_CONFIG;
 import static android.os.UserManager.DISALLOW_CONFIG_WIFI;
 
 import static com.android.settings.wifi.WifiDialogActivity.REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER;
@@ -50,7 +51,6 @@
 import com.google.android.setupcompat.util.WizardManagerHelper;
 
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
@@ -58,7 +58,6 @@
 import org.robolectric.Robolectric;
 import org.robolectric.RobolectricTestRunner;
 
-@Ignore("b/314867581")
 @RunWith(RobolectricTestRunner.class)
 public class WifiDialogActivityTest {
 
@@ -243,6 +242,20 @@
     }
 
     @Test
+    public void isAddWifiConfigAllowed_hasNoUserRestriction_returnTrue() {
+        when(mUserManager.hasUserRestriction(DISALLOW_ADD_WIFI_CONFIG)).thenReturn(false);
+
+        assertThat(mActivity.isAddWifiConfigAllowed()).isTrue();
+    }
+
+    @Test
+    public void isAddWifiConfigAllowed_hasUserRestriction_returnFalse() {
+        when(mUserManager.hasUserRestriction(DISALLOW_ADD_WIFI_CONFIG)).thenReturn(true);
+
+        assertThat(mActivity.isAddWifiConfigAllowed()).isFalse();
+    }
+
+    @Test
     public void hasPermissionForResult_noCallingPackage_returnFalse() {
         when(mActivity.getCallingPackage()).thenReturn(null);