Loading src/com/android/server/connectivity/NetworkMonitor.java +10 −8 Original line number Diff line number Diff line Loading @@ -411,6 +411,7 @@ public class NetworkMonitor extends StateMachine { private String mPrivateDnsProviderHostname = ""; private final Context mContext; private final Context mCustomizedContext; private final INetworkMonitorCallbacks mCallback; private final int mCallbackVersion; private final Network mCleartextDnsNetwork; Loading Loading @@ -548,6 +549,7 @@ public class NetworkMonitor extends StateMachine { mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); mCm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); mNotifier = serviceManager.getNotifier(); mCustomizedContext = getCustomizedContextOrDefault(); // CHECKSTYLE:OFF IndentationCheck addState(mDefaultState); Loading Loading @@ -1824,10 +1826,10 @@ public class NetworkMonitor extends StateMachine { private String getCaptivePortalServerHttpsUrl() { final String testUrl = getTestUrl(TEST_CAPTIVE_PORTAL_HTTPS_URL); if (isValidTestUrl(testUrl)) return testUrl; final Context targetContext = getCustomizedContextOrDefault(); return getSettingFromResource(targetContext, return getSettingFromResource(mCustomizedContext, R.string.config_captive_portal_https_url, CAPTIVE_PORTAL_HTTPS_URL, targetContext.getResources().getString(R.string.default_captive_portal_https_url)); mCustomizedContext.getResources().getString( R.string.default_captive_portal_https_url)); } private static boolean isValidTestUrl(@Nullable String url) { Loading Loading @@ -1917,10 +1919,10 @@ public class NetworkMonitor extends StateMachine { public String getCaptivePortalServerHttpUrl() { final String testUrl = getTestUrl(TEST_CAPTIVE_PORTAL_HTTP_URL); if (isValidTestUrl(testUrl)) return testUrl; final Context targetContext = getCustomizedContextOrDefault(); return getSettingFromResource(targetContext, return getSettingFromResource(mCustomizedContext, R.string.config_captive_portal_http_url, CAPTIVE_PORTAL_HTTP_URL, targetContext.getResources().getString(R.string.default_captive_portal_http_url)); mCustomizedContext.getResources().getString( R.string.default_captive_portal_http_url)); } private int getConsecutiveDnsTimeoutThreshold() { Loading Loading @@ -2078,7 +2080,7 @@ public class NetworkMonitor extends StateMachine { */ private <T> T[] getProbeUrlArrayConfig(@NonNull T[] providerValue, @ArrayRes int configResId, @ArrayRes int defaultResId, @NonNull Function<String, T> resourceConverter) { final Resources res = getCustomizedContextOrDefault().getResources(); final Resources res = mCustomizedContext.getResources(); return getProbeUrlArrayConfig(providerValue, configResId, res.getStringArray(defaultResId), resourceConverter); } Loading @@ -2096,7 +2098,7 @@ public class NetworkMonitor extends StateMachine { */ private <T> T[] getProbeUrlArrayConfig(@NonNull T[] providerValue, @ArrayRes int configResId, String[] defaultConfig, @NonNull Function<String, T> resourceConverter) { final Resources res = getCustomizedContextOrDefault().getResources(); final Resources res = mCustomizedContext.getResources(); String[] configValue = res.getStringArray(configResId); if (configValue.length == 0) { Loading tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java +30 −11 Original line number Diff line number Diff line Loading @@ -927,6 +927,18 @@ public class NetworkMonitorTest { return info; } private void setupNoSimCardNeighborMcc() throws Exception { // Enable using neighbor resource by camping mcc feature. doReturn(true).when(mResources).getBoolean(R.bool.config_no_sim_card_uses_neighbor_mcc); final List<CellInfo> cellList = new ArrayList<CellInfo>(); final int testMcc = 460; cellList.add(makeTestCellInfoGsm(Integer.toString(testMcc))); doReturn(cellList).when(mTelephony).getAllCellInfo(); final Configuration config = mResources.getConfiguration(); config.mcc = testMcc; doReturn(mMccContext).when(mContext).createConfigurationContext(eq(config)); } @Test public void testMakeFallbackUrls() throws Exception { final WrappedNetworkMonitor wnm = makeCellNotMeteredNetworkMonitor(); Loading @@ -950,21 +962,28 @@ public class NetworkMonitorTest { assertEquals("http://testUrl1.com", urls[0].toString()); assertEquals("http://testUrl2.com", urls[1].toString()); // Value is expected to be replaced by location resource. doReturn(true).when(mResources).getBoolean(R.bool.config_no_sim_card_uses_neighbor_mcc); final List<CellInfo> cellList = new ArrayList<CellInfo>(); final int testMcc = 460; cellList.add(makeTestCellInfoGsm(Integer.toString(testMcc))); doReturn(cellList).when(mTelephony).getAllCellInfo(); final Configuration config = mResources.getConfiguration(); config.mcc = testMcc; doReturn(mMccContext).when(mContext).createConfigurationContext(eq(config)); // Even though the using neighbor resource by camping mcc feature is enabled, the // customized context has been assigned and won't change. So calling // makeCaptivePortalFallbackUrls() still gets the original value. setupNoSimCardNeighborMcc(); doReturn(new String[] {"http://testUrl3.com"}).when(mMccResource) .getStringArray(R.array.config_captive_portal_fallback_urls); urls = wnm.makeCaptivePortalFallbackUrls(); assertEquals(urls.length, 2); assertEquals("http://testUrl1.com", urls[0].toString()); assertEquals("http://testUrl2.com", urls[1].toString()); } @Test public void testMakeFallbackUrlsWithCustomizedContext() throws Exception { // Value is expected to be replaced by location resource. setupNoSimCardNeighborMcc(); doReturn(new String[] {"http://testUrl.com"}).when(mMccResource) .getStringArray(R.array.config_captive_portal_fallback_urls); final WrappedNetworkMonitor wnm = makeCellNotMeteredNetworkMonitor(); final URL[] urls = wnm.makeCaptivePortalFallbackUrls(); assertEquals(urls.length, 1); assertEquals("http://testUrl3.com", urls[0].toString()); assertEquals("http://testUrl.com", urls[0].toString()); } private static CellIdentityGsm makeCellIdentityGsm(int lac, int cid, int arfcn, int bsic, Loading Loading
src/com/android/server/connectivity/NetworkMonitor.java +10 −8 Original line number Diff line number Diff line Loading @@ -411,6 +411,7 @@ public class NetworkMonitor extends StateMachine { private String mPrivateDnsProviderHostname = ""; private final Context mContext; private final Context mCustomizedContext; private final INetworkMonitorCallbacks mCallback; private final int mCallbackVersion; private final Network mCleartextDnsNetwork; Loading Loading @@ -548,6 +549,7 @@ public class NetworkMonitor extends StateMachine { mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); mCm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); mNotifier = serviceManager.getNotifier(); mCustomizedContext = getCustomizedContextOrDefault(); // CHECKSTYLE:OFF IndentationCheck addState(mDefaultState); Loading Loading @@ -1824,10 +1826,10 @@ public class NetworkMonitor extends StateMachine { private String getCaptivePortalServerHttpsUrl() { final String testUrl = getTestUrl(TEST_CAPTIVE_PORTAL_HTTPS_URL); if (isValidTestUrl(testUrl)) return testUrl; final Context targetContext = getCustomizedContextOrDefault(); return getSettingFromResource(targetContext, return getSettingFromResource(mCustomizedContext, R.string.config_captive_portal_https_url, CAPTIVE_PORTAL_HTTPS_URL, targetContext.getResources().getString(R.string.default_captive_portal_https_url)); mCustomizedContext.getResources().getString( R.string.default_captive_portal_https_url)); } private static boolean isValidTestUrl(@Nullable String url) { Loading Loading @@ -1917,10 +1919,10 @@ public class NetworkMonitor extends StateMachine { public String getCaptivePortalServerHttpUrl() { final String testUrl = getTestUrl(TEST_CAPTIVE_PORTAL_HTTP_URL); if (isValidTestUrl(testUrl)) return testUrl; final Context targetContext = getCustomizedContextOrDefault(); return getSettingFromResource(targetContext, return getSettingFromResource(mCustomizedContext, R.string.config_captive_portal_http_url, CAPTIVE_PORTAL_HTTP_URL, targetContext.getResources().getString(R.string.default_captive_portal_http_url)); mCustomizedContext.getResources().getString( R.string.default_captive_portal_http_url)); } private int getConsecutiveDnsTimeoutThreshold() { Loading Loading @@ -2078,7 +2080,7 @@ public class NetworkMonitor extends StateMachine { */ private <T> T[] getProbeUrlArrayConfig(@NonNull T[] providerValue, @ArrayRes int configResId, @ArrayRes int defaultResId, @NonNull Function<String, T> resourceConverter) { final Resources res = getCustomizedContextOrDefault().getResources(); final Resources res = mCustomizedContext.getResources(); return getProbeUrlArrayConfig(providerValue, configResId, res.getStringArray(defaultResId), resourceConverter); } Loading @@ -2096,7 +2098,7 @@ public class NetworkMonitor extends StateMachine { */ private <T> T[] getProbeUrlArrayConfig(@NonNull T[] providerValue, @ArrayRes int configResId, String[] defaultConfig, @NonNull Function<String, T> resourceConverter) { final Resources res = getCustomizedContextOrDefault().getResources(); final Resources res = mCustomizedContext.getResources(); String[] configValue = res.getStringArray(configResId); if (configValue.length == 0) { Loading
tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java +30 −11 Original line number Diff line number Diff line Loading @@ -927,6 +927,18 @@ public class NetworkMonitorTest { return info; } private void setupNoSimCardNeighborMcc() throws Exception { // Enable using neighbor resource by camping mcc feature. doReturn(true).when(mResources).getBoolean(R.bool.config_no_sim_card_uses_neighbor_mcc); final List<CellInfo> cellList = new ArrayList<CellInfo>(); final int testMcc = 460; cellList.add(makeTestCellInfoGsm(Integer.toString(testMcc))); doReturn(cellList).when(mTelephony).getAllCellInfo(); final Configuration config = mResources.getConfiguration(); config.mcc = testMcc; doReturn(mMccContext).when(mContext).createConfigurationContext(eq(config)); } @Test public void testMakeFallbackUrls() throws Exception { final WrappedNetworkMonitor wnm = makeCellNotMeteredNetworkMonitor(); Loading @@ -950,21 +962,28 @@ public class NetworkMonitorTest { assertEquals("http://testUrl1.com", urls[0].toString()); assertEquals("http://testUrl2.com", urls[1].toString()); // Value is expected to be replaced by location resource. doReturn(true).when(mResources).getBoolean(R.bool.config_no_sim_card_uses_neighbor_mcc); final List<CellInfo> cellList = new ArrayList<CellInfo>(); final int testMcc = 460; cellList.add(makeTestCellInfoGsm(Integer.toString(testMcc))); doReturn(cellList).when(mTelephony).getAllCellInfo(); final Configuration config = mResources.getConfiguration(); config.mcc = testMcc; doReturn(mMccContext).when(mContext).createConfigurationContext(eq(config)); // Even though the using neighbor resource by camping mcc feature is enabled, the // customized context has been assigned and won't change. So calling // makeCaptivePortalFallbackUrls() still gets the original value. setupNoSimCardNeighborMcc(); doReturn(new String[] {"http://testUrl3.com"}).when(mMccResource) .getStringArray(R.array.config_captive_portal_fallback_urls); urls = wnm.makeCaptivePortalFallbackUrls(); assertEquals(urls.length, 2); assertEquals("http://testUrl1.com", urls[0].toString()); assertEquals("http://testUrl2.com", urls[1].toString()); } @Test public void testMakeFallbackUrlsWithCustomizedContext() throws Exception { // Value is expected to be replaced by location resource. setupNoSimCardNeighborMcc(); doReturn(new String[] {"http://testUrl.com"}).when(mMccResource) .getStringArray(R.array.config_captive_portal_fallback_urls); final WrappedNetworkMonitor wnm = makeCellNotMeteredNetworkMonitor(); final URL[] urls = wnm.makeCaptivePortalFallbackUrls(); assertEquals(urls.length, 1); assertEquals("http://testUrl3.com", urls[0].toString()); assertEquals("http://testUrl.com", urls[0].toString()); } private static CellIdentityGsm makeCellIdentityGsm(int lac, int cid, int arfcn, int bsic, Loading