Use connectivity resources in service-connectivity
Migrate resource usage to the connectivity resource package. For framework resources that have known overlays, keep a fallback until the overlays can be migrated. Bug: 182125649 Test: atest FrameworksNetTests Merged-In: I778d94a5aac0c4e20e78b1ba3a002495c17a38a0 (clean cherry-pick) Change-Id: I778d94a5aac0c4e20e78b1ba3a002495c17a38a0
This commit is contained in:
@@ -78,6 +78,11 @@
|
||||
<item>1,3</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Reserved privileged keepalive slots per transport. -->
|
||||
<integer translatable="false" name="config_reservedPrivilegedKeepaliveSlots">2</integer>
|
||||
|
||||
<!-- Allowed unprivileged keepalive slots per uid. -->
|
||||
<integer translatable="false" name="config_allowedUnprivilegedKeepalivePerUid">2</integer>
|
||||
|
||||
<!-- Default value for ConnectivityManager.getMultipathPreference() on metered networks. Actual
|
||||
device behaviour is controlled by the metered multipath preference in
|
||||
@@ -89,4 +94,33 @@
|
||||
Settings.Global.NETWORK_AVOID_BAD_WIFI. This is the default value of that setting. -->
|
||||
<integer translatable="false" name="config_networkAvoidBadWifi">1</integer>
|
||||
|
||||
<!-- Array of ConnectivityManager.TYPE_xxxx constants for networks that may only
|
||||
be controlled by systemOrSignature apps. -->
|
||||
<integer-array translatable="false" name="config_protectedNetworks">
|
||||
<item>10</item>
|
||||
<item>11</item>
|
||||
<item>12</item>
|
||||
<item>14</item>
|
||||
<item>15</item>
|
||||
</integer-array>
|
||||
|
||||
<!-- Whether the internal vehicle network should remain active even when no
|
||||
apps requested it. -->
|
||||
<bool name="config_vehicleInternalNetworkAlwaysRequested">false</bool>
|
||||
|
||||
|
||||
<!-- If the hardware supports specially marking packets that caused a wakeup of the
|
||||
main CPU, set this value to the mark used. -->
|
||||
<integer name="config_networkWakeupPacketMark">0</integer>
|
||||
|
||||
<!-- Mask to use when checking skb mark defined in config_networkWakeupPacketMark above. -->
|
||||
<integer name="config_networkWakeupPacketMask">0</integer>
|
||||
|
||||
<!-- Whether/how to notify the user on network switches. See LingerMonitor.java. -->
|
||||
<integer translatable="false" name="config_networkNotifySwitchType">0</integer>
|
||||
|
||||
<!-- What types of network switches to notify. See LingerMonitor.java. -->
|
||||
<string-array translatable="false" name="config_networkNotifySwitches">
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -26,6 +26,12 @@
|
||||
<item type="integer" name="config_networkMeteredMultipathPreference"/>
|
||||
<item type="array" name="config_networkSupportedKeepaliveCount"/>
|
||||
<item type="integer" name="config_networkAvoidBadWifi"/>
|
||||
<item type="array" name="config_protectedNetworks"/>
|
||||
<item type="bool" name="config_vehicleInternalNetworkAlwaysRequested"/>
|
||||
<item type="integer" name="config_networkWakeupPacketMark"/>
|
||||
<item type="integer" name="config_networkWakeupPacketMask"/>
|
||||
<item type="integer" name="config_networkNotifySwitchType"/>
|
||||
<item type="array" name="config_networkNotifySwitches"/>
|
||||
|
||||
</policy>
|
||||
</overlayable>
|
||||
|
||||
@@ -217,6 +217,7 @@ import android.util.Pair;
|
||||
import android.util.SparseArray;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import com.android.connectivity.resources.R;
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.IndentingPrintWriter;
|
||||
@@ -831,8 +832,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
|
||||
private ArrayMap<Integer, Integer> loadRestoreTimers() {
|
||||
final String[] configs = mService.mResources.get().getStringArray(
|
||||
com.android.connectivity.resources.R.array
|
||||
.config_legacy_networktype_restore_timers);
|
||||
R.array.config_legacy_networktype_restore_timers);
|
||||
final ArrayMap<Integer, Integer> ret = new ArrayMap<>(configs.length);
|
||||
for (final String config : configs) {
|
||||
final String[] splits = TextUtils.split(config, ",");
|
||||
@@ -1311,8 +1311,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
|
||||
mLegacyTypeTracker.loadSupportedTypes(mContext, mTelephonyManager);
|
||||
mProtectedNetworks = new ArrayList<>();
|
||||
int[] protectedNetworks = context.getResources().getIntArray(
|
||||
com.android.internal.R.array.config_protectedNetworks);
|
||||
int[] protectedNetworks = mResources.get().getIntArray(R.array.config_protectedNetworks);
|
||||
for (int p : protectedNetworks) {
|
||||
if (mLegacyTypeTracker.isTypeSupported(p) && !mProtectedNetworks.contains(p)) {
|
||||
mProtectedNetworks.add(p);
|
||||
@@ -1484,8 +1483,14 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
ConnectivitySettingsManager.MOBILE_DATA_ALWAYS_ON, true /* defaultValue */);
|
||||
handleAlwaysOnNetworkRequest(mDefaultWifiRequest,
|
||||
ConnectivitySettingsManager.WIFI_ALWAYS_REQUESTED, false /* defaultValue */);
|
||||
final boolean vehicleAlwaysRequested = mResources.get().getBoolean(
|
||||
R.bool.config_vehicleInternalNetworkAlwaysRequested);
|
||||
// TODO (b/183076074): remove legacy fallback after migrating overlays
|
||||
final boolean legacyAlwaysRequested = mContext.getResources().getBoolean(
|
||||
mContext.getResources().getIdentifier(
|
||||
"config_vehicleInternalNetworkAlwaysRequested", "bool", "android"));
|
||||
handleAlwaysOnNetworkRequest(mDefaultVehicleRequest,
|
||||
com.android.internal.R.bool.config_vehicleInternalNetworkAlwaysRequested);
|
||||
vehicleAlwaysRequested || legacyAlwaysRequested);
|
||||
}
|
||||
|
||||
private void registerSettingsCallbacks() {
|
||||
@@ -4840,7 +4845,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
mWakelockLogs.log("ACQUIRE for " + forWhom);
|
||||
Message msg = mHandler.obtainMessage(EVENT_EXPIRE_NET_TRANSITION_WAKELOCK);
|
||||
final int lockTimeout = mResources.get().getInteger(
|
||||
com.android.connectivity.resources.R.integer.config_networkTransitionTimeout);
|
||||
R.integer.config_networkTransitionTimeout);
|
||||
mHandler.sendMessageDelayed(msg, lockTimeout);
|
||||
}
|
||||
|
||||
@@ -6701,10 +6706,16 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
return;
|
||||
}
|
||||
|
||||
int mark = mContext.getResources().getInteger(
|
||||
com.android.internal.R.integer.config_networkWakeupPacketMark);
|
||||
int mask = mContext.getResources().getInteger(
|
||||
com.android.internal.R.integer.config_networkWakeupPacketMask);
|
||||
int mark = mResources.get().getInteger(R.integer.config_networkWakeupPacketMark);
|
||||
int mask = mResources.get().getInteger(R.integer.config_networkWakeupPacketMask);
|
||||
|
||||
// TODO (b/183076074): remove legacy fallback after migrating overlays
|
||||
final int legacyMark = mContext.getResources().getInteger(mContext.getResources()
|
||||
.getIdentifier("config_networkWakeupPacketMark", "integer", "android"));
|
||||
final int legacyMask = mContext.getResources().getInteger(mContext.getResources()
|
||||
.getIdentifier("config_networkWakeupPacketMask", "integer", "android"));
|
||||
mark = mark == 0 ? legacyMark : mark;
|
||||
mask = mask == 0 ? legacyMask : mask;
|
||||
|
||||
// Mask/mark of zero will not detect anything interesting.
|
||||
// Don't install rules unless both values are nonzero.
|
||||
@@ -6897,8 +6908,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
private void updateWakeOnLan(@NonNull LinkProperties lp) {
|
||||
if (mWolSupportedInterfaces == null) {
|
||||
mWolSupportedInterfaces = new ArraySet<>(mResources.get().getStringArray(
|
||||
com.android.connectivity.resources.R.array
|
||||
.config_wakeonlan_supported_interfaces));
|
||||
R.array.config_wakeonlan_supported_interfaces));
|
||||
}
|
||||
lp.setWakeOnLanSupported(mWolSupportedInterfaces.contains(lp.getInterfaceName()));
|
||||
}
|
||||
@@ -8474,7 +8484,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
public String getCaptivePortalServerUrl() {
|
||||
enforceNetworkStackOrSettingsPermission();
|
||||
String settingUrl = mResources.get().getString(
|
||||
com.android.connectivity.resources.R.string.config_networkCaptivePortalServerUrl);
|
||||
R.string.config_networkCaptivePortalServerUrl);
|
||||
|
||||
if (!TextUtils.isEmpty(settingUrl)) {
|
||||
return settingUrl;
|
||||
|
||||
@@ -37,6 +37,7 @@ import static android.net.SocketKeepalive.SUCCESS;
|
||||
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;
|
||||
@@ -57,7 +58,7 @@ import android.system.Os;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.connectivity.resources.R;
|
||||
import com.android.internal.util.IndentingPrintWriter;
|
||||
import com.android.net.module.util.HexDump;
|
||||
import com.android.net.module.util.IpUtils;
|
||||
@@ -112,10 +113,19 @@ public class KeepaliveTracker {
|
||||
mTcpController = new TcpKeepaliveController(handler);
|
||||
mContext = context;
|
||||
mSupportedKeepalives = KeepaliveUtils.getSupportedKeepalives(mContext);
|
||||
mReservedPrivilegedSlots = mContext.getResources().getInteger(
|
||||
R.integer.config_reservedPrivilegedKeepaliveSlots);
|
||||
mAllowedUnprivilegedSlotsForUid = mContext.getResources().getInteger(
|
||||
R.integer.config_allowedUnprivilegedKeepalivePerUid);
|
||||
|
||||
// TODO (b/183076074): stop reading legacy resources after migrating overlays
|
||||
final int legacyReservedSlots = mContext.getResources().getInteger(
|
||||
mContext.getResources().getIdentifier(
|
||||
"config_reservedPrivilegedKeepaliveSlots", "integer", "android"));
|
||||
final int legacyAllowedSlots = mContext.getResources().getInteger(
|
||||
mContext.getResources().getIdentifier(
|
||||
"config_allowedUnprivilegedKeepalivePerUid", "integer", "android"));
|
||||
final ConnectivityResources res = new ConnectivityResources(mContext);
|
||||
mReservedPrivilegedSlots = Math.min(legacyReservedSlots, res.get().getInteger(
|
||||
R.integer.config_reservedPrivilegedKeepaliveSlots));
|
||||
mAllowedUnprivilegedSlotsForUid = Math.min(legacyAllowedSlots, res.get().getInteger(
|
||||
R.integer.config_allowedUnprivilegedKeepalivePerUid));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,6 +24,8 @@ import android.app.PendingIntent;
|
||||
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;
|
||||
@@ -34,7 +36,7 @@ import android.util.SparseArray;
|
||||
import android.util.SparseBooleanArray;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.connectivity.resources.R;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.MessageUtils;
|
||||
import com.android.server.connectivity.NetworkNotificationManager.NotificationType;
|
||||
@@ -72,6 +74,7 @@ public class LingerMonitor {
|
||||
new Class[] { LingerMonitor.class }, new String[]{ "NOTIFY_TYPE_" });
|
||||
|
||||
private final Context mContext;
|
||||
final Resources mResources;
|
||||
private final NetworkNotificationManager mNotifier;
|
||||
private final int mDailyLimit;
|
||||
private final long mRateLimitMillis;
|
||||
@@ -89,6 +92,7 @@ public class LingerMonitor {
|
||||
public LingerMonitor(Context context, NetworkNotificationManager notifier,
|
||||
int dailyLimit, long rateLimitMillis) {
|
||||
mContext = context;
|
||||
mResources = new ConnectivityResources(mContext).get();
|
||||
mNotifier = notifier;
|
||||
mDailyLimit = dailyLimit;
|
||||
mRateLimitMillis = rateLimitMillis;
|
||||
@@ -128,8 +132,7 @@ public class LingerMonitor {
|
||||
@VisibleForTesting
|
||||
public boolean isNotificationEnabled(NetworkAgentInfo fromNai, NetworkAgentInfo toNai) {
|
||||
// TODO: Evaluate moving to CarrierConfigManager.
|
||||
String[] notifySwitches =
|
||||
mContext.getResources().getStringArray(R.array.config_networkNotifySwitches);
|
||||
String[] notifySwitches = mResources.getStringArray(R.array.config_networkNotifySwitches);
|
||||
|
||||
if (VDBG) {
|
||||
Log.d(TAG, "Notify on network switches: " + Arrays.toString(notifySwitches));
|
||||
@@ -178,8 +181,7 @@ public class LingerMonitor {
|
||||
|
||||
// Notify the user of a network switch using a notification or a toast.
|
||||
private void notify(NetworkAgentInfo fromNai, NetworkAgentInfo toNai, boolean forceToast) {
|
||||
int notifyType =
|
||||
mContext.getResources().getInteger(R.integer.config_networkNotifySwitchType);
|
||||
int notifyType = mResources.getInteger(R.integer.config_networkNotifySwitchType);
|
||||
if (notifyType == NOTIFY_TYPE_NOTIFICATION && forceToast) {
|
||||
notifyType = NOTIFY_TYPE_TOAST;
|
||||
}
|
||||
|
||||
@@ -1637,25 +1637,26 @@ public class ConnectivityServiceTest {
|
||||
}).when(deps).makeMultinetworkPolicyTracker(any(), any(), any());
|
||||
doReturn(true).when(deps).getCellular464XlatEnabled();
|
||||
|
||||
doReturn(60000).when(mResources).getInteger(
|
||||
com.android.connectivity.resources.R.integer.config_networkTransitionTimeout);
|
||||
doReturn("").when(mResources).getString(
|
||||
com.android.connectivity.resources.R.string.config_networkCaptivePortalServerUrl);
|
||||
doReturn(60000).when(mResources).getInteger(R.integer.config_networkTransitionTimeout);
|
||||
doReturn("").when(mResources).getString(R.string.config_networkCaptivePortalServerUrl);
|
||||
doReturn(new String[]{ WIFI_WOL_IFNAME }).when(mResources).getStringArray(
|
||||
com.android.connectivity.resources.R.array.config_wakeonlan_supported_interfaces);
|
||||
R.array.config_wakeonlan_supported_interfaces);
|
||||
doReturn(new String[] { "0,1", "1,3" }).when(mResources).getStringArray(
|
||||
com.android.connectivity.resources.R.array.config_networkSupportedKeepaliveCount);
|
||||
doReturn(com.android.connectivity.resources.R.array.config_networkSupportedKeepaliveCount)
|
||||
.when(mResources).getIdentifier(eq("config_networkSupportedKeepaliveCount"),
|
||||
eq("array"), any());
|
||||
doReturn(com.android.connectivity.resources.R.array.network_switch_type_name)
|
||||
.when(mResources).getIdentifier(eq("network_switch_type_name"),
|
||||
eq("array"), any());
|
||||
|
||||
R.array.config_networkSupportedKeepaliveCount);
|
||||
doReturn(new String[0]).when(mResources).getStringArray(
|
||||
R.array.config_networkNotifySwitches);
|
||||
doReturn(new int[]{10, 11, 12, 14, 15}).when(mResources).getIntArray(
|
||||
R.array.config_protectedNetworks);
|
||||
// We don't test the actual notification value strings, so just return an empty array.
|
||||
// It doesn't matter what the values are as long as it's not null.
|
||||
doReturn(new String[0]).when(mResources).getStringArray(R.array.network_switch_type_name);
|
||||
|
||||
doReturn(R.array.config_networkSupportedKeepaliveCount).when(mResources)
|
||||
.getIdentifier(eq("config_networkSupportedKeepaliveCount"), eq("array"), any());
|
||||
doReturn(R.array.network_switch_type_name).when(mResources)
|
||||
.getIdentifier(eq("network_switch_type_name"), eq("array"), any());
|
||||
|
||||
|
||||
final ConnectivityResources connRes = mock(ConnectivityResources.class);
|
||||
doReturn(mResources).when(connRes).get();
|
||||
doReturn(connRes).when(deps).getResources(any());
|
||||
|
||||
@@ -32,6 +32,7 @@ import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
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;
|
||||
@@ -47,10 +48,11 @@ import android.text.format.DateUtils;
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.connectivity.resources.R;
|
||||
import com.android.server.ConnectivityService;
|
||||
import com.android.server.connectivity.NetworkNotificationManager.NotificationType;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -84,10 +86,16 @@ public class LingerMonitorTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mCtx.getResources()).thenReturn(mResources);
|
||||
when(mCtx.getPackageName()).thenReturn("com.android.server.connectivity");
|
||||
ConnectivityResources.setResourcesContextForTest(mCtx);
|
||||
|
||||
mMonitor = new TestableLingerMonitor(mCtx, mNotifier, HIGH_DAILY_LIMIT, HIGH_RATE_LIMIT);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ConnectivityResources.setResourcesContextForTest(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransitions() {
|
||||
setNotificationSwitch(transition(WIFI, CELLULAR));
|
||||
|
||||
Reference in New Issue
Block a user