Skip to content

Commit

Permalink
[RESTRICT AUTOMERGE] Restrict WifiDialogActivity
Browse files Browse the repository at this point in the history
- Don't show WifiDialogActivity if user has DISALLOW_ADD_WIFI_CONFIG

Bug: 299931761
Flag: None
Test: manual test with TestDPC
atest -c SettingsRoboTests:WifiDialogActivityTest

(cherry picked from commit 51fa3d7)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:a0409e582c30d2d6ff347eefd173ae169963df75)
Merged-In: Icbb8f45922ded163208976be9c2816060dcf09f1
Change-Id: Icbb8f45922ded163208976be9c2816060dcf09f1
  • Loading branch information
Weng Su authored and thestinger committed Apr 1, 2024
1 parent ad00a8d commit 9d8372e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/com/android/settings/wifi/WifiDialogActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -122,7 +123,7 @@ protected void onCreate(Bundle savedInstanceState) {
}

super.onCreate(savedInstanceState);
if (!isConfigWifiAllowed()) {
if (!isConfigWifiAllowed() || !isAddWifiConfigAllowed()) {
finish();
return;
}
Expand Down Expand Up @@ -393,6 +394,16 @@ boolean isConfigWifiAllowed() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -242,6 +243,20 @@ public void isConfigWifiAllowed_hasUserRestriction_returnFalse() {
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);
Expand Down

0 comments on commit 9d8372e

Please sign in to comment.