Merge "Revert "Use mockito-extended in FrameworksNetTests""
This commit is contained in:
@@ -116,7 +116,6 @@ public class MultipathPolicyTrackerTest {
|
||||
private <T> void mockService(String serviceName, Class<T> serviceClass, T service) {
|
||||
when(mContext.getSystemServiceName(serviceClass)).thenReturn(serviceName);
|
||||
when(mContext.getSystemService(serviceName)).thenReturn(service);
|
||||
when(mContext.getSystemService(serviceClass)).thenReturn(service);
|
||||
}
|
||||
|
||||
@Before
|
||||
|
||||
@@ -139,7 +139,6 @@ public class PermissionMonitorTest {
|
||||
.thenReturn(Context.SYSTEM_CONFIG_SERVICE);
|
||||
when(mContext.getSystemService(Context.SYSTEM_CONFIG_SERVICE))
|
||||
.thenReturn(mSystemConfigManager);
|
||||
when(mContext.getSystemService(SystemConfigManager.class)).thenReturn(mSystemConfigManager);
|
||||
when(mSystemConfigManager.getSystemPermissionUids(anyString())).thenReturn(new int[0]);
|
||||
final Context asUserCtx = mock(Context.class, AdditionalAnswers.delegatesTo(mContext));
|
||||
doReturn(UserHandle.ALL).when(asUserCtx).getUser();
|
||||
|
||||
@@ -219,11 +219,19 @@ public class VpnTest {
|
||||
|
||||
when(mContext.getPackageName()).thenReturn(TEST_VPN_PKG);
|
||||
when(mContext.getOpPackageName()).thenReturn(TEST_VPN_PKG);
|
||||
mockService(UserManager.class, Context.USER_SERVICE, mUserManager);
|
||||
mockService(AppOpsManager.class, Context.APP_OPS_SERVICE, mAppOps);
|
||||
mockService(NotificationManager.class, Context.NOTIFICATION_SERVICE, mNotificationManager);
|
||||
mockService(ConnectivityManager.class, Context.CONNECTIVITY_SERVICE, mConnectivityManager);
|
||||
mockService(IpSecManager.class, Context.IPSEC_SERVICE, mIpSecManager);
|
||||
when(mContext.getSystemServiceName(UserManager.class))
|
||||
.thenReturn(Context.USER_SERVICE);
|
||||
when(mContext.getSystemService(eq(Context.USER_SERVICE))).thenReturn(mUserManager);
|
||||
when(mContext.getSystemService(eq(Context.APP_OPS_SERVICE))).thenReturn(mAppOps);
|
||||
when(mContext.getSystemServiceName(NotificationManager.class))
|
||||
.thenReturn(Context.NOTIFICATION_SERVICE);
|
||||
when(mContext.getSystemService(eq(Context.NOTIFICATION_SERVICE)))
|
||||
.thenReturn(mNotificationManager);
|
||||
when(mContext.getSystemService(eq(Context.CONNECTIVITY_SERVICE)))
|
||||
.thenReturn(mConnectivityManager);
|
||||
when(mContext.getSystemServiceName(eq(ConnectivityManager.class)))
|
||||
.thenReturn(Context.CONNECTIVITY_SERVICE);
|
||||
when(mContext.getSystemService(eq(Context.IPSEC_SERVICE))).thenReturn(mIpSecManager);
|
||||
when(mContext.getString(R.string.config_customVpnAlwaysOnDisconnectedDialogComponent))
|
||||
.thenReturn(Resources.getSystem().getString(
|
||||
R.string.config_customVpnAlwaysOnDisconnectedDialogComponent));
|
||||
@@ -251,12 +259,6 @@ public class VpnTest {
|
||||
.thenReturn(tunnelResp);
|
||||
}
|
||||
|
||||
private <T> void mockService(Class<T> clazz, String name, T service) {
|
||||
doReturn(service).when(mContext).getSystemService(clazz);
|
||||
doReturn(service).when(mContext).getSystemService(name);
|
||||
doReturn(name).when(mContext).getSystemServiceName(clazz);
|
||||
}
|
||||
|
||||
private Set<Range<Integer>> rangeSet(Range<Integer> ... ranges) {
|
||||
final Set<Range<Integer>> range = new ArraySet<>();
|
||||
for (Range<Integer> r : ranges) range.add(r);
|
||||
|
||||
@@ -16,16 +16,12 @@
|
||||
|
||||
package com.android.server.net;
|
||||
|
||||
import static android.Manifest.permission.READ_NETWORK_USAGE_HISTORY;
|
||||
import static android.Manifest.permission.UPDATE_DEVICE_STATS;
|
||||
import static android.content.Intent.ACTION_UID_REMOVED;
|
||||
import static android.content.Intent.EXTRA_UID;
|
||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
||||
import static android.net.ConnectivityManager.TYPE_WIFI;
|
||||
import static android.net.NetworkIdentity.OEM_PAID;
|
||||
import static android.net.NetworkIdentity.OEM_PRIVATE;
|
||||
import static android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK;
|
||||
import static android.net.NetworkStats.DEFAULT_NETWORK_ALL;
|
||||
import static android.net.NetworkStats.DEFAULT_NETWORK_NO;
|
||||
import static android.net.NetworkStats.DEFAULT_NETWORK_YES;
|
||||
@@ -110,7 +106,6 @@ import android.os.SimpleClock;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
@@ -204,26 +199,6 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
||||
if (Context.TELEPHONY_SERVICE.equals(name)) return mTelephonyManager;
|
||||
return mBaseContext.getSystemService(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enforceCallingOrSelfPermission(String permission, @Nullable String message) {
|
||||
if (checkCallingOrSelfPermission(permission) != PERMISSION_GRANTED) {
|
||||
super.enforceCallingOrSelfPermission(permission, message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int checkCallingOrSelfPermission(String permission) {
|
||||
switch (permission) {
|
||||
case PERMISSION_MAINLINE_NETWORK_STACK:
|
||||
case READ_NETWORK_USAGE_HISTORY:
|
||||
case UPDATE_DEVICE_STATS:
|
||||
return PERMISSION_GRANTED;
|
||||
default:
|
||||
return super.checkCallingOrSelfPermission(permission);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private final Clock mClock = new SimpleClock(ZoneOffset.UTC) {
|
||||
|
||||
Reference in New Issue
Block a user