[RESTRICT AUTOMERGE] Restrict WifiDppConfiguratorActivity am: 0ea027a71c
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/26804708 Change-Id: I2f57a28bbc46a1f648d6ecf0a72eab3a884e69e4 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -16,12 +16,17 @@
|
|||||||
|
|
||||||
package com.android.settings.wifi;
|
package com.android.settings.wifi;
|
||||||
|
|
||||||
|
import static android.os.UserManager.DISALLOW_ADD_WIFI_CONFIG;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.wifi.WifiConfiguration;
|
import android.net.wifi.WifiConfiguration;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.UserManager;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -43,6 +48,7 @@ import com.android.settings.wifi.dpp.WifiDppUtils;
|
|||||||
*/
|
*/
|
||||||
public class AddNetworkFragment extends InstrumentedFragment implements WifiConfigUiBase2,
|
public class AddNetworkFragment extends InstrumentedFragment implements WifiConfigUiBase2,
|
||||||
View.OnClickListener {
|
View.OnClickListener {
|
||||||
|
private static final String TAG = "AddNetworkFragment";
|
||||||
|
|
||||||
public static final String WIFI_CONFIG_KEY = "wifi_config_key";
|
public static final String WIFI_CONFIG_KEY = "wifi_config_key";
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -62,6 +68,10 @@ public class AddNetworkFragment extends InstrumentedFragment implements WifiConf
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
if (!isAddWifiConfigAllowed(getContext())) {
|
||||||
|
getActivity().finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -237,4 +247,14 @@ public class AddNetworkFragment extends InstrumentedFragment implements WifiConf
|
|||||||
activity.setResult(Activity.RESULT_CANCELED);
|
activity.setResult(Activity.RESULT_CANCELED);
|
||||||
activity.finish();
|
activity.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
static boolean isAddWifiConfigAllowed(Context context) {
|
||||||
|
UserManager userManager = context.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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settings.wifi.dpp;
|
package com.android.settings.wifi.dpp;
|
||||||
|
|
||||||
|
import static android.os.UserManager.DISALLOW_ADD_WIFI_CONFIG;
|
||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -99,6 +101,10 @@ public class WifiDppConfiguratorActivity extends WifiDppBaseActivity implements
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
if (!isAddWifiConfigAllowed(getApplicationContext())) {
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
String qrCode = savedInstanceState.getString(KEY_QR_CODE);
|
String qrCode = savedInstanceState.getString(KEY_QR_CODE);
|
||||||
@@ -119,6 +125,10 @@ public class WifiDppConfiguratorActivity extends WifiDppBaseActivity implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleIntent(Intent intent) {
|
protected void handleIntent(Intent intent) {
|
||||||
|
if (!isAddWifiConfigAllowed(getApplicationContext())) {
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (isGuestUser(getApplicationContext())) {
|
if (isGuestUser(getApplicationContext())) {
|
||||||
Log.e(TAG, "Guest user is not allowed to configure Wi-Fi!");
|
Log.e(TAG, "Guest user is not allowed to configure Wi-Fi!");
|
||||||
EventLog.writeEvent(0x534e4554, "224772890", -1 /* UID */, "User is a guest");
|
EventLog.writeEvent(0x534e4554, "224772890", -1 /* UID */, "User is a guest");
|
||||||
@@ -402,4 +412,14 @@ public class WifiDppConfiguratorActivity extends WifiDppBaseActivity implements
|
|||||||
if (userManager == null) return false;
|
if (userManager == null) return false;
|
||||||
return userManager.isGuestUser();
|
return userManager.isGuestUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
static boolean isAddWifiConfigAllowed(Context context) {
|
||||||
|
UserManager userManager = context.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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.wifi;
|
||||||
|
|
||||||
|
import static android.os.UserManager.DISALLOW_ADD_WIFI_CONFIG;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.UserManager;
|
||||||
|
|
||||||
|
import androidx.test.annotation.UiThreadTest;
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.Spy;
|
||||||
|
import org.mockito.junit.MockitoJUnit;
|
||||||
|
import org.mockito.junit.MockitoRule;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
@UiThreadTest
|
||||||
|
public class AddNetworkFragmentTest {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||||
|
@Spy
|
||||||
|
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||||
|
@Mock
|
||||||
|
private UserManager mUserManager;
|
||||||
|
|
||||||
|
private AddNetworkFragment mFragment;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
|
||||||
|
|
||||||
|
mFragment = new AddNetworkFragment();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAddWifiConfigAllowed_hasNoUserRestriction_returnTrue() {
|
||||||
|
when(mUserManager.hasUserRestriction(DISALLOW_ADD_WIFI_CONFIG)).thenReturn(false);
|
||||||
|
|
||||||
|
assertThat(mFragment.isAddWifiConfigAllowed(mContext)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAddWifiConfigAllowed_hasUserRestriction_returnFalse() {
|
||||||
|
when(mUserManager.hasUserRestriction(DISALLOW_ADD_WIFI_CONFIG)).thenReturn(true);
|
||||||
|
|
||||||
|
assertThat(mFragment.isAddWifiConfigAllowed(mContext)).isFalse();
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.wifi.dpp;
|
||||||
|
|
||||||
|
import static android.os.UserManager.DISALLOW_ADD_WIFI_CONFIG;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.UserManager;
|
||||||
|
|
||||||
|
import androidx.test.annotation.UiThreadTest;
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.Spy;
|
||||||
|
import org.mockito.junit.MockitoJUnit;
|
||||||
|
import org.mockito.junit.MockitoRule;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
@UiThreadTest
|
||||||
|
public class WifiDppConfiguratorActivityTest {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||||
|
@Spy
|
||||||
|
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||||
|
@Mock
|
||||||
|
private UserManager mUserManager;
|
||||||
|
|
||||||
|
private WifiDppConfiguratorActivity mActivity;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
|
||||||
|
|
||||||
|
mActivity = new WifiDppConfiguratorActivity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAddWifiConfigAllowed_hasNoUserRestriction_returnTrue() {
|
||||||
|
when(mUserManager.hasUserRestriction(DISALLOW_ADD_WIFI_CONFIG)).thenReturn(false);
|
||||||
|
|
||||||
|
assertThat(mActivity.isAddWifiConfigAllowed(mContext)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAddWifiConfigAllowed_hasUserRestriction_returnFalse() {
|
||||||
|
when(mUserManager.hasUserRestriction(DISALLOW_ADD_WIFI_CONFIG)).thenReturn(true);
|
||||||
|
|
||||||
|
assertThat(mActivity.isAddWifiConfigAllowed(mContext)).isFalse();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user