[RESTRICT AUTOMERGE] Restrict WifiDialogActivity
- Don't show WifiDialogActivity if user has DISALLOW_ADD_WIFI_CONFIG
Bug: 299931761
Flag: None
Test: manual test with TestDPC
atest -c SettingsRoboTests:WifiDialogActivityTest
Merged-In: Icbb8f45922ded163208976be9c2816060dcf09f1
Change-Id: Icbb8f45922ded163208976be9c2816060dcf09f1
(cherry picked from commit 51fa3d798a
)
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
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.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
@@ -31,6 +33,7 @@ import android.os.Looper;
|
||||
import android.os.Process;
|
||||
import android.os.SimpleClock;
|
||||
import android.os.SystemClock;
|
||||
import android.os.UserManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.EventLog;
|
||||
import android.util.Log;
|
||||
@@ -115,6 +118,10 @@ public class WifiDialogActivity extends ObservableActivity implements WifiDialog
|
||||
}
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
if (!isConfigWifiAllowed() || !isAddWifiConfigAllowed()) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
mIsWifiTrackerLib = !TextUtils.isEmpty(mIntent.getStringExtra(KEY_CHOSEN_WIFIENTRY_KEY));
|
||||
|
||||
@@ -361,6 +368,29 @@ public class WifiDialogActivity extends ObservableActivity implements WifiDialog
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean isConfigWifiAllowed() {
|
||||
UserManager userManager = getSystemService(UserManager.class);
|
||||
if (userManager == null) return true;
|
||||
final boolean isConfigWifiAllowed = !userManager.hasUserRestriction(DISALLOW_CONFIG_WIFI);
|
||||
if (!isConfigWifiAllowed) {
|
||||
Log.e(TAG, "The user is not allowed to configure Wi-Fi.");
|
||||
EventLog.writeEvent(0x534e4554, "226133034", getApplicationContext().getUserId(),
|
||||
"The user is not allowed to configure Wi-Fi.");
|
||||
}
|
||||
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);
|
||||
|
@@ -18,6 +18,8 @@ package com.android.settings.wifi;
|
||||
|
||||
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;
|
||||
import static com.android.settings.wifi.WifiDialogActivity.RESULT_CONNECTED;
|
||||
@@ -36,6 +38,7 @@ import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
@@ -57,6 +60,8 @@ public class WifiDialogActivityTest {
|
||||
static final String CALLING_PACKAGE = "calling_package";
|
||||
static final int REQUEST_CODE = REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER;
|
||||
|
||||
@Mock
|
||||
UserManager mUserManager;
|
||||
@Mock
|
||||
PackageManager mPackageManager;
|
||||
@Mock
|
||||
@@ -92,6 +97,7 @@ public class WifiDialogActivityTest {
|
||||
FakeFeatureFactory.setupForTest();
|
||||
|
||||
mActivity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
|
||||
when(mActivity.getSystemService(UserManager.class)).thenReturn(mUserManager);
|
||||
when(mActivity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
|
||||
}
|
||||
|
||||
@@ -211,6 +217,34 @@ public class WifiDialogActivityTest {
|
||||
verify(mActivity).setResult(RESULT_CONNECTED, mResultData);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isConfigWifiAllowed_hasNoUserRestriction_returnTrue() {
|
||||
when(mUserManager.hasUserRestriction(DISALLOW_CONFIG_WIFI)).thenReturn(false);
|
||||
|
||||
assertThat(mActivity.isConfigWifiAllowed()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isConfigWifiAllowed_hasUserRestriction_returnFalse() {
|
||||
when(mUserManager.hasUserRestriction(DISALLOW_CONFIG_WIFI)).thenReturn(true);
|
||||
|
||||
assertThat(mActivity.isConfigWifiAllowed()).isFalse();
|
||||
}
|
||||
|
||||
@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);
|
||||
|
Reference in New Issue
Block a user