Move ConnectivityResources to service-connectivity
The ConnectivityResources class is only usable with QUERY_ALL_PACKAGES permission, so it is not generally usable in framework-connectivity. It is also backed by the ServiceConnectivityResources APK, which is intended as resources for service-connectivity. Move the class to service-connectivity and update callers. CTS needs a way to determine the supported keepalive count as it used the resources from KeepaliveUtils as @hide API, so provide a ConnectivityManager @hide API for testing. Bug: 279108992 Test: atest Change-Id: I3c9a77c580b5ab87c922c32778bce15dc33b4d1d
This commit is contained in:
parent
e50f1464bb
commit
bee2ee14f3
25 changed files with 163 additions and 112 deletions
|
|
@ -2534,6 +2534,26 @@ public class ConnectivityManager {
|
|||
return new TcpSocketKeepalive(mService, network, dup, executor, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the supported keepalive count for each transport configured in resource overlays.
|
||||
*
|
||||
* @return An array of supported keepalive count for each transport type.
|
||||
* @hide
|
||||
*/
|
||||
@RequiresPermission(anyOf = { android.Manifest.permission.NETWORK_SETTINGS,
|
||||
// CTS 13 used QUERY_ALL_PACKAGES to get the resource value, which was implemented
|
||||
// as below in KeepaliveUtils. Also allow that permission so that KeepaliveUtils can
|
||||
// use this method and avoid breaking released CTS. Apps that have this permission
|
||||
// can query the resource themselves anyway.
|
||||
android.Manifest.permission.QUERY_ALL_PACKAGES })
|
||||
public int[] getSupportedKeepalives() {
|
||||
try {
|
||||
return mService.getSupportedKeepalives();
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that a network route exists to deliver traffic to the specified
|
||||
* host via the specified network interface. An attempt to add a route that
|
||||
|
|
|
|||
|
|
@ -195,6 +195,8 @@ interface IConnectivityManager
|
|||
|
||||
void stopKeepalive(in ISocketKeepaliveCallback cb);
|
||||
|
||||
int[] getSupportedKeepalives();
|
||||
|
||||
String getCaptivePortalServerUrl();
|
||||
|
||||
byte[] getNetworkWatchlistConfigHash();
|
||||
|
|
|
|||
|
|
@ -19,9 +19,6 @@ package android.net.apf;
|
|||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.SystemApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.net.ConnectivityResources;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
|
|
@ -36,8 +33,6 @@ import android.os.Parcelable;
|
|||
*/
|
||||
@SystemApi
|
||||
public final class ApfCapabilities implements Parcelable {
|
||||
private static ConnectivityResources sResources;
|
||||
|
||||
/**
|
||||
* Version of APF instruction set supported for packet filtering. 0 indicates no support for
|
||||
* packet filtering using APF programs.
|
||||
|
|
@ -67,15 +62,6 @@ public final class ApfCapabilities implements Parcelable {
|
|||
apfPacketFormat = in.readInt();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static synchronized ConnectivityResources getResources(@NonNull Context ctx) {
|
||||
if (sResources == null) {
|
||||
sResources = new ConnectivityResources(ctx);
|
||||
}
|
||||
return sResources;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -18,11 +18,8 @@ package android.net.util;
|
|||
|
||||
import android.annotation.NonNull;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.net.ConnectivityResources;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AndroidRuntimeException;
|
||||
|
||||
/**
|
||||
* Collection of utilities for socket keepalive offload.
|
||||
|
|
@ -33,64 +30,20 @@ public final class KeepaliveUtils {
|
|||
|
||||
public static final String TAG = "KeepaliveUtils";
|
||||
|
||||
public static class KeepaliveDeviceConfigurationException extends AndroidRuntimeException {
|
||||
public KeepaliveDeviceConfigurationException(final String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read supported keepalive count for each transport type from overlay resource. This should be
|
||||
* used to create a local variable store of resource customization, and use it as the input for
|
||||
* {@link getSupportedKeepalivesForNetworkCapabilities}.
|
||||
* {@link #getSupportedKeepalivesForNetworkCapabilities}.
|
||||
*
|
||||
* @param context The context to read resource from.
|
||||
* @return An array of supported keepalive count for each transport type.
|
||||
* @deprecated This is used by CTS 13, but can be removed after switching it to
|
||||
* {@link ConnectivityManager#getSupportedKeepalives()}.
|
||||
*/
|
||||
@NonNull
|
||||
@Deprecated
|
||||
public static int[] getSupportedKeepalives(@NonNull Context context) {
|
||||
String[] res = null;
|
||||
try {
|
||||
final ConnectivityResources connRes = new ConnectivityResources(context);
|
||||
// TODO: use R.id.config_networkSupportedKeepaliveCount directly
|
||||
final int id = connRes.get().getIdentifier("config_networkSupportedKeepaliveCount",
|
||||
"array", connRes.getResourcesContext().getPackageName());
|
||||
res = new ConnectivityResources(context).get().getStringArray(id);
|
||||
} catch (Resources.NotFoundException unused) {
|
||||
}
|
||||
if (res == null) throw new KeepaliveDeviceConfigurationException("invalid resource");
|
||||
|
||||
final int[] ret = new int[NetworkCapabilities.MAX_TRANSPORT + 1];
|
||||
for (final String row : res) {
|
||||
if (TextUtils.isEmpty(row)) {
|
||||
throw new KeepaliveDeviceConfigurationException("Empty string");
|
||||
}
|
||||
final String[] arr = row.split(",");
|
||||
if (arr.length != 2) {
|
||||
throw new KeepaliveDeviceConfigurationException("Invalid parameter length");
|
||||
}
|
||||
|
||||
int transport;
|
||||
int supported;
|
||||
try {
|
||||
transport = Integer.parseInt(arr[0]);
|
||||
supported = Integer.parseInt(arr[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new KeepaliveDeviceConfigurationException("Invalid number format");
|
||||
}
|
||||
|
||||
if (!NetworkCapabilities.isValidTransport(transport)) {
|
||||
throw new KeepaliveDeviceConfigurationException("Invalid transport " + transport);
|
||||
}
|
||||
|
||||
if (supported < 0) {
|
||||
throw new KeepaliveDeviceConfigurationException(
|
||||
"Invalid supported count " + supported + " for "
|
||||
+ NetworkCapabilities.transportNameOf(transport));
|
||||
}
|
||||
ret[transport] = supported;
|
||||
}
|
||||
return ret;
|
||||
return context.getSystemService(ConnectivityManager.class).getSupportedKeepalives();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import android.annotation.NonNull;
|
|||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.ConnectivityResources;
|
||||
import android.net.EthernetManager;
|
||||
import android.net.EthernetNetworkSpecifier;
|
||||
import android.net.IpConfiguration;
|
||||
|
|
@ -50,6 +49,7 @@ import com.android.connectivity.resources.R;
|
|||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.IndentingPrintWriter;
|
||||
import com.android.net.module.util.InterfaceParams;
|
||||
import com.android.server.connectivity.ConnectivityResources;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.util.Objects;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import static com.android.internal.annotations.VisibleForTesting.Visibility.PACK
|
|||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityResources;
|
||||
import android.net.EthernetManager;
|
||||
import android.net.IEthernetServiceListener;
|
||||
import android.net.INetd;
|
||||
|
|
@ -57,6 +56,7 @@ import com.android.net.module.util.netlink.NetlinkConstants;
|
|||
import com.android.net.module.util.netlink.NetlinkMessage;
|
||||
import com.android.net.module.util.netlink.RtNetlinkLinkMessage;
|
||||
import com.android.net.module.util.netlink.StructIfinfoMsg;
|
||||
import com.android.server.connectivity.ConnectivityResources;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.net.InetAddress;
|
||||
|
|
|
|||
|
|
@ -83,7 +83,6 @@ import android.content.pm.PackageManager;
|
|||
import android.content.res.Resources;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.ConnectivityResources;
|
||||
import android.net.DataUsageRequest;
|
||||
import android.net.INetd;
|
||||
import android.net.INetworkStatsService;
|
||||
|
|
@ -175,6 +174,7 @@ import com.android.networkstack.apishim.BroadcastOptionsShimImpl;
|
|||
import com.android.networkstack.apishim.ConstantsShim;
|
||||
import com.android.networkstack.apishim.common.UnsupportedApiLevelException;
|
||||
import com.android.server.BpfNetMaps;
|
||||
import com.android.server.connectivity.ConnectivityResources;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileDescriptor;
|
||||
|
|
|
|||
|
|
@ -134,7 +134,6 @@ import android.net.ConnectivityManager;
|
|||
import android.net.ConnectivityManager.BlockedReason;
|
||||
import android.net.ConnectivityManager.NetworkCallback;
|
||||
import android.net.ConnectivityManager.RestrictBackgroundStatus;
|
||||
import android.net.ConnectivityResources;
|
||||
import android.net.ConnectivitySettingsManager;
|
||||
import android.net.DataStallReportParcelable;
|
||||
import android.net.DnsResolverServiceManager;
|
||||
|
|
@ -281,11 +280,13 @@ import com.android.server.connectivity.AutomaticOnOffKeepaliveTracker.AutomaticO
|
|||
import com.android.server.connectivity.CarrierPrivilegeAuthenticator;
|
||||
import com.android.server.connectivity.ClatCoordinator;
|
||||
import com.android.server.connectivity.ConnectivityFlags;
|
||||
import com.android.server.connectivity.ConnectivityResources;
|
||||
import com.android.server.connectivity.DnsManager;
|
||||
import com.android.server.connectivity.DnsManager.PrivateDnsValidationUpdate;
|
||||
import com.android.server.connectivity.DscpPolicyTracker;
|
||||
import com.android.server.connectivity.FullScore;
|
||||
import com.android.server.connectivity.InvalidTagException;
|
||||
import com.android.server.connectivity.KeepaliveResourceUtil;
|
||||
import com.android.server.connectivity.KeepaliveTracker;
|
||||
import com.android.server.connectivity.LingerMonitor;
|
||||
import com.android.server.connectivity.MockableSystemProperties;
|
||||
|
|
@ -10046,6 +10047,16 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||
Objects.requireNonNull(cb).asBinder()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getSupportedKeepalives() {
|
||||
enforceAnyPermissionOf(mContext, android.Manifest.permission.NETWORK_SETTINGS,
|
||||
// Backwards compatibility with CTS 13
|
||||
android.Manifest.permission.QUERY_ALL_PACKAGES);
|
||||
|
||||
return BinderUtils.withCleanCallingIdentity(() ->
|
||||
KeepaliveResourceUtil.getSupportedKeepalives(mContext));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void factoryReset() {
|
||||
enforceSettingsPermission();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* Copyright (C) 2021 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.server.connectivity;
|
||||
|
||||
import static android.content.pm.PackageManager.MATCH_SYSTEM_ONLY;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Utility to obtain the {@link com.android.server.ConnectivityService} {@link Resources}, in the
|
||||
* ServiceConnectivityResources APK.
|
||||
* @hide
|
||||
*/
|
||||
public class ConnectivityResources {
|
||||
private static final String RESOURCES_APK_INTENT =
|
||||
"com.android.server.connectivity.intent.action.SERVICE_CONNECTIVITY_RESOURCES_APK";
|
||||
private static final String RES_PKG_DIR = "/apex/com.android.tethering/";
|
||||
|
||||
@NonNull
|
||||
private final Context mContext;
|
||||
|
||||
@Nullable
|
||||
private Context mResourcesContext = null;
|
||||
|
||||
@Nullable
|
||||
private static Context sTestResourcesContext = null;
|
||||
|
||||
public ConnectivityResources(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to mock all resources for the duration of a test.
|
||||
*
|
||||
* Call with a null context to reset after the test.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public static void setResourcesContextForTest(@Nullable Context testContext) {
|
||||
sTestResourcesContext = testContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link Context} of the resources package.
|
||||
*/
|
||||
public synchronized Context getResourcesContext() {
|
||||
if (sTestResourcesContext != null) {
|
||||
return sTestResourcesContext;
|
||||
}
|
||||
|
||||
if (mResourcesContext != null) {
|
||||
return mResourcesContext;
|
||||
}
|
||||
|
||||
final List<ResolveInfo> pkgs = mContext.getPackageManager()
|
||||
.queryIntentActivities(new Intent(RESOURCES_APK_INTENT), MATCH_SYSTEM_ONLY);
|
||||
pkgs.removeIf(pkg -> !pkg.activityInfo.applicationInfo.sourceDir.startsWith(RES_PKG_DIR));
|
||||
if (pkgs.size() > 1) {
|
||||
Log.wtf(ConnectivityResources.class.getSimpleName(),
|
||||
"More than one package found: " + pkgs);
|
||||
}
|
||||
if (pkgs.isEmpty()) {
|
||||
throw new IllegalStateException("No connectivity resource package found");
|
||||
}
|
||||
|
||||
final Context pkgContext;
|
||||
try {
|
||||
pkgContext = mContext.createPackageContext(
|
||||
pkgs.get(0).activityInfo.applicationInfo.packageName, 0 /* flags */);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
throw new IllegalStateException("Resolved package not found", e);
|
||||
}
|
||||
|
||||
mResourcesContext = pkgContext;
|
||||
return pkgContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link Resources} of the ServiceConnectivityResources APK.
|
||||
*/
|
||||
public Resources get() {
|
||||
return getResourcesContext().getResources();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright (C) 2023 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.server.connectivity;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AndroidRuntimeException;
|
||||
|
||||
import com.android.connectivity.resources.R;
|
||||
|
||||
/**
|
||||
* Utilities to fetch keepalive configuration from resources.
|
||||
*/
|
||||
public abstract class KeepaliveResourceUtil {
|
||||
|
||||
/**
|
||||
* Read supported keepalive count for each transport type from overlay resource.
|
||||
*
|
||||
* @param context The context to read resource from.
|
||||
* @return An array of supported keepalive count for each transport type.
|
||||
*/
|
||||
@NonNull
|
||||
public static int[] getSupportedKeepalives(@NonNull Context context) {
|
||||
String[] res = null;
|
||||
try {
|
||||
final ConnectivityResources connRes = new ConnectivityResources(context);
|
||||
res = connRes.get().getStringArray(R.array.config_networkSupportedKeepaliveCount);
|
||||
} catch (Resources.NotFoundException unused) {
|
||||
}
|
||||
if (res == null) throw new KeepaliveDeviceConfigurationException("invalid resource");
|
||||
|
||||
final int[] ret = new int[NetworkCapabilities.MAX_TRANSPORT + 1];
|
||||
for (final String row : res) {
|
||||
if (TextUtils.isEmpty(row)) {
|
||||
throw new KeepaliveDeviceConfigurationException("Empty string");
|
||||
}
|
||||
final String[] arr = row.split(",");
|
||||
if (arr.length != 2) {
|
||||
throw new KeepaliveDeviceConfigurationException("Invalid parameter length");
|
||||
}
|
||||
|
||||
int transport;
|
||||
int supported;
|
||||
try {
|
||||
transport = Integer.parseInt(arr[0]);
|
||||
supported = Integer.parseInt(arr[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new KeepaliveDeviceConfigurationException("Invalid number format");
|
||||
}
|
||||
|
||||
if (!NetworkCapabilities.isValidTransport(transport)) {
|
||||
throw new KeepaliveDeviceConfigurationException("Invalid transport " + transport);
|
||||
}
|
||||
|
||||
if (supported < 0) {
|
||||
throw new KeepaliveDeviceConfigurationException(
|
||||
"Invalid supported count " + supported + " for "
|
||||
+ NetworkCapabilities.transportNameOf(transport));
|
||||
}
|
||||
ret[transport] = supported;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* An exception thrown when the keepalive resource configuration is invalid.
|
||||
*/
|
||||
public static class KeepaliveDeviceConfigurationException extends AndroidRuntimeException {
|
||||
public KeepaliveDeviceConfigurationException(final String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -37,7 +37,6 @@ import static android.net.SocketKeepalive.SUCCESS_PAUSED;
|
|||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityResources;
|
||||
import android.net.ISocketKeepaliveCallback;
|
||||
import android.net.InetAddresses;
|
||||
import android.net.InvalidPacketException;
|
||||
|
|
@ -111,7 +110,7 @@ public class KeepaliveTracker {
|
|||
mTcpController = new TcpKeepaliveController(handler);
|
||||
mContext = context;
|
||||
|
||||
mSupportedKeepalives = KeepaliveUtils.getSupportedKeepalives(mContext);
|
||||
mSupportedKeepalives = KeepaliveResourceUtil.getSupportedKeepalives(context);
|
||||
|
||||
final ConnectivityResources res = new ConnectivityResources(mContext);
|
||||
mReservedPrivilegedSlots = res.get().getInteger(
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import android.content.ComponentName;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.net.ConnectivityResources;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.os.SystemClock;
|
||||
import android.os.UserHandle;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import android.content.Intent;
|
|||
import android.content.IntentFilter;
|
||||
import android.content.res.Resources;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.ConnectivityResources;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.net.ConnectivityResources;
|
||||
import android.net.NetworkSpecifier;
|
||||
import android.net.TelephonyNetworkSpecifier;
|
||||
import android.net.wifi.WifiInfo;
|
||||
|
|
|
|||
|
|
@ -37,9 +37,6 @@
|
|||
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
|
||||
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" />
|
||||
|
||||
<!-- TODO (b/186093901): remove after fixing resource querying -->
|
||||
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
|
||||
|
||||
<!-- This test also uses signature permissions through adopting the shell identity.
|
||||
The permissions acquired that way include (probably not exhaustive) :
|
||||
android.permission.MANAGE_TEST_NETWORKS
|
||||
|
|
|
|||
|
|
@ -1655,7 +1655,8 @@ public class ConnectivityManagerTest {
|
|||
final NetworkCapabilities nc = mCm.getNetworkCapabilities(network);
|
||||
|
||||
// Get number of supported concurrent keepalives for testing network.
|
||||
final int[] keepalivesPerTransport = KeepaliveUtils.getSupportedKeepalives(mContext);
|
||||
final int[] keepalivesPerTransport = runAsShell(NETWORK_SETTINGS,
|
||||
() -> mCm.getSupportedKeepalives());
|
||||
return KeepaliveUtils.getSupportedKeepalivesForNetworkCapabilities(
|
||||
keepalivesPerTransport, nc);
|
||||
}
|
||||
|
|
@ -1670,6 +1671,9 @@ public class ConnectivityManagerTest {
|
|||
* keepalives is set to 0.
|
||||
*/
|
||||
@AppModeFull(reason = "Cannot get WifiManager in instant app mode")
|
||||
// getSupportedKeepalives is available in updatable ConnectivityManager (S+)
|
||||
// Also, this feature is not mainlined before S, and it's fine to skip on R- devices.
|
||||
@DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.R) @ConnectivityModuleTest
|
||||
@Test
|
||||
public void testKeepaliveWifiUnsupported() throws Exception {
|
||||
assumeTrue(mPackageManager.hasSystemFeature(FEATURE_WIFI));
|
||||
|
|
@ -1686,6 +1690,9 @@ public class ConnectivityManagerTest {
|
|||
}
|
||||
|
||||
@AppModeFull(reason = "Cannot get WifiManager in instant app mode")
|
||||
// getSupportedKeepalives is available in updatable ConnectivityManager (S+)
|
||||
// Also, this feature is not mainlined before S, and it's fine to skip on R- devices.
|
||||
@DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.R) @ConnectivityModuleTest
|
||||
@Test
|
||||
@RequiresDevice // Keepalive is not supported on virtual hardware
|
||||
public void testCreateTcpKeepalive() throws Exception {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import android.content.Intent
|
|||
import android.content.ServiceConnection
|
||||
import android.content.res.Resources
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.ConnectivityResources
|
||||
import android.net.IDnsResolver
|
||||
import android.net.INetd
|
||||
import android.net.LinkProperties
|
||||
|
|
@ -50,11 +49,15 @@ import com.android.server.BpfNetMaps
|
|||
import com.android.server.ConnectivityService
|
||||
import com.android.server.NetworkAgentWrapper
|
||||
import com.android.server.TestNetIdManager
|
||||
import com.android.server.connectivity.ConnectivityResources
|
||||
import com.android.server.connectivity.MockableSystemProperties
|
||||
import com.android.server.connectivity.MultinetworkPolicyTracker
|
||||
import com.android.server.connectivity.ProxyTracker
|
||||
import com.android.testutils.RecorderCallback.CallbackEntry.LinkPropertiesChanged
|
||||
import com.android.testutils.TestableNetworkCallback
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
import kotlin.test.fail
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.BeforeClass
|
||||
|
|
@ -73,9 +76,6 @@ import org.mockito.Mockito.mock
|
|||
import org.mockito.Mockito.spy
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.mockito.Spy
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
import kotlin.test.fail
|
||||
|
||||
const val SERVICE_BIND_TIMEOUT_MS = 5_000L
|
||||
const val TEST_TIMEOUT_MS = 10_000L
|
||||
|
|
@ -215,8 +215,8 @@ class ConnectivityServiceIntegrationTest {
|
|||
inv.getArgument(2),
|
||||
object : MultinetworkPolicyTracker.Dependencies() {
|
||||
override fun getResourcesForActiveSubId(
|
||||
connResources: ConnectivityResources,
|
||||
activeSubId: Int
|
||||
connResources: ConnectivityResources,
|
||||
activeSubId: Int
|
||||
) = resources
|
||||
})
|
||||
}.`when`(deps).makeMultinetworkPolicyTracker(any(), any(), any())
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ package android.net.util
|
|||
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.net.ConnectivityResources
|
||||
import android.net.NetworkCapabilities
|
||||
import android.net.NetworkCapabilities.MAX_TRANSPORT
|
||||
import android.net.NetworkCapabilities.TRANSPORT_CELLULAR
|
||||
|
|
@ -27,7 +26,9 @@ import android.net.NetworkCapabilities.TRANSPORT_VPN
|
|||
import android.net.NetworkCapabilities.TRANSPORT_WIFI
|
||||
import android.os.Build
|
||||
import androidx.test.filters.SmallTest
|
||||
import com.android.internal.R
|
||||
import com.android.connectivity.resources.R
|
||||
import com.android.server.connectivity.ConnectivityResources
|
||||
import com.android.server.connectivity.KeepaliveResourceUtil
|
||||
import com.android.testutils.DevSdkIgnoreRule
|
||||
import com.android.testutils.DevSdkIgnoreRunner
|
||||
import org.junit.After
|
||||
|
|
@ -37,7 +38,6 @@ import org.junit.Assert.fail
|
|||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.ArgumentMatchers.eq
|
||||
import org.mockito.Mockito.any
|
||||
import org.mockito.Mockito.doReturn
|
||||
import org.mockito.Mockito.mock
|
||||
|
||||
|
|
@ -53,14 +53,9 @@ import org.mockito.Mockito.mock
|
|||
class KeepaliveUtilsTest {
|
||||
|
||||
// Prepare mocked context with given resource strings.
|
||||
private fun getMockedContextWithStringArrayRes(
|
||||
id: Int,
|
||||
name: String,
|
||||
res: Array<out String?>?
|
||||
): Context {
|
||||
private fun getMockedContextWithStringArrayRes(id: Int, res: Array<out String?>?): Context {
|
||||
val mockRes = mock(Resources::class.java)
|
||||
doReturn(res).`when`(mockRes).getStringArray(eq(id))
|
||||
doReturn(id).`when`(mockRes).getIdentifier(eq(name), any(), any())
|
||||
|
||||
return mock(Context::class.java).apply {
|
||||
doReturn(mockRes).`when`(this).getResources()
|
||||
|
|
@ -79,10 +74,10 @@ class KeepaliveUtilsTest {
|
|||
try {
|
||||
val mockContext = getMockedContextWithStringArrayRes(
|
||||
R.array.config_networkSupportedKeepaliveCount,
|
||||
"config_networkSupportedKeepaliveCount", res)
|
||||
KeepaliveUtils.getSupportedKeepalives(mockContext)
|
||||
res)
|
||||
KeepaliveResourceUtil.getSupportedKeepalives(mockContext)
|
||||
fail("Expected KeepaliveDeviceConfigurationException")
|
||||
} catch (expected: KeepaliveUtils.KeepaliveDeviceConfigurationException) {
|
||||
} catch (expected: KeepaliveResourceUtil.KeepaliveDeviceConfigurationException) {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -108,8 +103,8 @@ class KeepaliveUtilsTest {
|
|||
|
||||
val mockContext = getMockedContextWithStringArrayRes(
|
||||
R.array.config_networkSupportedKeepaliveCount,
|
||||
"config_networkSupportedKeepaliveCount", validRes)
|
||||
val actual = KeepaliveUtils.getSupportedKeepalives(mockContext)
|
||||
validRes)
|
||||
val actual = KeepaliveResourceUtil.getSupportedKeepalives(mockContext)
|
||||
assertArrayEquals(expectedValidRes, actual)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -256,7 +256,6 @@ import android.net.ConnectivityManager.NetworkCallback;
|
|||
import android.net.ConnectivityManager.PacketKeepalive;
|
||||
import android.net.ConnectivityManager.PacketKeepaliveCallback;
|
||||
import android.net.ConnectivityManager.TooManyRequestsException;
|
||||
import android.net.ConnectivityResources;
|
||||
import android.net.ConnectivitySettingsManager;
|
||||
import android.net.ConnectivityThread;
|
||||
import android.net.DataStallReportParcelable;
|
||||
|
|
@ -389,6 +388,7 @@ import com.android.server.connectivity.AutomaticOnOffKeepaliveTracker;
|
|||
import com.android.server.connectivity.CarrierPrivilegeAuthenticator;
|
||||
import com.android.server.connectivity.ClatCoordinator;
|
||||
import com.android.server.connectivity.ConnectivityFlags;
|
||||
import com.android.server.connectivity.ConnectivityResources;
|
||||
import com.android.server.connectivity.MultinetworkPolicyTracker;
|
||||
import com.android.server.connectivity.MultinetworkPolicyTrackerTestDependencies;
|
||||
import com.android.server.connectivity.Nat464Xlat;
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ import static org.mockito.Mockito.verify;
|
|||
import android.app.AlarmManager;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.net.ConnectivityResources;
|
||||
import android.net.INetd;
|
||||
import android.net.ISocketKeepaliveCallback;
|
||||
import android.net.KeepalivePacketData;
|
||||
|
|
@ -63,6 +62,7 @@ import android.util.Log;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.connectivity.resources.R;
|
||||
import com.android.server.connectivity.KeepaliveTracker.KeepaliveInfo;
|
||||
import com.android.testutils.DevSdkIgnoreRule;
|
||||
import com.android.testutils.DevSdkIgnoreRunner;
|
||||
|
|
@ -235,10 +235,8 @@ public class AutomaticOnOffKeepaliveTrackerTest {
|
|||
anyInt() /* pid */, anyInt() /* uid */);
|
||||
ConnectivityResources.setResourcesContextForTest(mCtx);
|
||||
final Resources mockResources = mock(Resources.class);
|
||||
doReturn(MOCK_RESOURCE_ID).when(mockResources).getIdentifier(any() /* name */,
|
||||
any() /* defType */, any() /* defPackage */);
|
||||
doReturn(new String[] { "0,3", "3,3" }).when(mockResources)
|
||||
.getStringArray(MOCK_RESOURCE_ID);
|
||||
.getStringArray(R.array.config_networkSupportedKeepaliveCount);
|
||||
doReturn(mockResources).when(mCtx).getResources();
|
||||
doReturn(mNetd).when(mDependencies).getNetd();
|
||||
doReturn(mAlarmManager).when(mDependencies).getAlarmManager(any());
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue