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:
Remi NGUYEN VAN
2021-03-19 17:41:48 +09:00
parent 5ab962df61
commit a4bef5d40b
7 changed files with 108 additions and 37 deletions

View File

@@ -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());

View File

@@ -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));