Merge "Block editing of locked down wifi network from details page."
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.testutils.shadow;
|
||||
|
||||
import android.content.ComponentName;
|
||||
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
|
||||
/**
|
||||
* Shadow for {@link DevicePolicyManagerWrapper} to allow stubbing hidden methods.
|
||||
*/
|
||||
@Implements(DevicePolicyManagerWrapper.class)
|
||||
public class ShadowDevicePolicyManagerWrapper {
|
||||
private static ComponentName deviceOComponentName = null;
|
||||
private static int deviceOwnerUserId = -1;
|
||||
|
||||
@Implementation
|
||||
public ComponentName getDeviceOwnerComponentOnAnyUser() {
|
||||
return deviceOComponentName;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public int getDeviceOwnerUserId() {
|
||||
return deviceOwnerUserId;
|
||||
}
|
||||
|
||||
public static void setDeviceOComponentName(ComponentName deviceOComponentName) {
|
||||
ShadowDevicePolicyManagerWrapper.deviceOComponentName = deviceOComponentName;
|
||||
}
|
||||
|
||||
public static void setDeviceOwnerUserId(int deviceOwnerUserId) {
|
||||
ShadowDevicePolicyManagerWrapper.deviceOwnerUserId = deviceOwnerUserId;
|
||||
}
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.testutils.shadow;
|
||||
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
|
||||
import com.android.settingslib.wrapper.PackageManagerWrapper;
|
||||
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Shadow for {@link PackageManagerWrapper} to allow stubbing hidden methods.
|
||||
*/
|
||||
@Implements(PackageManagerWrapper.class)
|
||||
public class ShadowPackageManagerWrapper {
|
||||
private static final HashMap<String, Integer> packageUids = new HashMap<>();
|
||||
|
||||
@Implementation
|
||||
public int getPackageUidAsUser(String packageName, int userId) throws NameNotFoundException {
|
||||
Integer res = packageUids.get(packageName + userId);
|
||||
if (res == null) {
|
||||
throw new NameNotFoundException();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void setPackageUidAsUser(String packageName, int userId, int uid) {
|
||||
packageUids.put(packageName + userId, uid);
|
||||
}
|
||||
}
|
@@ -33,6 +33,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
@@ -51,6 +52,7 @@ import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Handler;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceCategory;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
@@ -64,7 +66,9 @@ import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowDevicePolicyManagerWrapper;
|
||||
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
|
||||
import com.android.settings.testutils.shadow.ShadowPackageManagerWrapper;
|
||||
import com.android.settings.widget.ActionButtonPreference;
|
||||
import com.android.settings.widget.ActionButtonPreferenceTest;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
@@ -94,7 +98,11 @@ import java.util.stream.Collectors;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = ShadowEntityHeaderController.class)
|
||||
shadows = {
|
||||
ShadowDevicePolicyManagerWrapper.class,
|
||||
ShadowEntityHeaderController.class,
|
||||
ShadowPackageManagerWrapper.class,
|
||||
})
|
||||
public class WifiDetailPreferenceControllerTest {
|
||||
|
||||
private static final int LEVEL = 1;
|
||||
@@ -238,8 +246,6 @@ public class WifiDetailPreferenceControllerTest {
|
||||
when(mockHeaderController.setSummary(anyString())).thenReturn(mockHeaderController);
|
||||
when(mockIconInjector.getIcon(anyInt())).thenReturn(new ColorDrawable());
|
||||
|
||||
doReturn(null).when(mContext).getSystemService(eq(Context.DEVICE_POLICY_SERVICE));
|
||||
|
||||
setupMockedPreferenceScreen();
|
||||
mController = newWifiDetailPreferenceController();
|
||||
}
|
||||
@@ -628,6 +634,45 @@ public class WifiDetailPreferenceControllerTest {
|
||||
verify(mockButtonsPref).setButton1Visible(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canForgetNetwork_lockedDown() {
|
||||
lockDownNetwork();
|
||||
|
||||
displayAndResume();
|
||||
|
||||
verify(mockButtonsPref).setButton1Visible(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canModifyNetwork_saved() {
|
||||
assertThat(mController.canModifyNetwork()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canModifyNetwork_lockedDown() {
|
||||
lockDownNetwork();
|
||||
|
||||
assertThat(mController.canModifyNetwork()).isFalse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pretends that current network is locked down by device owner.
|
||||
*/
|
||||
private void lockDownNetwork() {
|
||||
final int doUserId = 123;
|
||||
final int doUid = 1234;
|
||||
String doPackage = "some.package";
|
||||
|
||||
mockWifiConfig.creatorUid = doUid;
|
||||
ComponentName doComponent = new ComponentName(doPackage, "some.Class");
|
||||
ShadowPackageManagerWrapper.setPackageUidAsUser(doPackage, doUserId, doUid);
|
||||
ShadowDevicePolicyManagerWrapper.setDeviceOComponentName(doComponent);
|
||||
ShadowDevicePolicyManagerWrapper.setDeviceOwnerUserId(doUserId);
|
||||
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forgetNetwork_ephemeral() {
|
||||
String ssid = "ssid";
|
||||
|
Reference in New Issue
Block a user