summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/CarrierNetworkConfig.java17
-rw-r--r--service/java/com/android/server/wifi/WifiInjector.java3
-rw-r--r--tests/wifitests/src/com/android/server/wifi/CarrierNetworkConfigTest.java33
3 files changed, 50 insertions, 3 deletions
diff --git a/service/java/com/android/server/wifi/CarrierNetworkConfig.java b/service/java/com/android/server/wifi/CarrierNetworkConfig.java
index db107bf6c..91e22afe1 100644
--- a/service/java/com/android/server/wifi/CarrierNetworkConfig.java
+++ b/service/java/com/android/server/wifi/CarrierNetworkConfig.java
@@ -16,12 +16,17 @@
package com.android.server.wifi;
+import android.annotation.NonNull;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.database.ContentObserver;
+import android.net.Uri;
import android.net.wifi.EAPConstants;
import android.net.wifi.WifiEnterpriseConfig;
+import android.os.Handler;
+import android.os.Looper;
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.ImsiEncryptionInfo;
@@ -45,11 +50,13 @@ public class CarrierNetworkConfig {
private static final int ENCODED_SSID_INDEX = 0;
private static final int EAP_TYPE_INDEX = 1;
private static final int CONFIG_ELEMENT_SIZE = 2;
+ private static final Uri CONTENT_URI = Uri.parse("content://carrier_information/carrier");
private final Map<String, NetworkInfo> mCarrierNetworkMap;
private boolean mIsCarrierImsiEncryptionInfoAvailable = false;
- public CarrierNetworkConfig(Context context) {
+ public CarrierNetworkConfig(@NonNull Context context, @NonNull Looper looper,
+ @NonNull FrameworkFacade framework) {
mCarrierNetworkMap = new HashMap<>();
updateNetworkConfig(context);
@@ -62,6 +69,14 @@ public class CarrierNetworkConfig {
updateNetworkConfig(context);
}
}, filter);
+
+ framework.registerContentObserver(context, CONTENT_URI, false,
+ new ContentObserver(new Handler(looper)) {
+ @Override
+ public void onChange(boolean selfChange) {
+ updateNetworkConfig(context);
+ }
+ });
}
/**
diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java
index 6e14822ef..04bb3f48c 100644
--- a/service/java/com/android/server/wifi/WifiInjector.java
+++ b/service/java/com/android/server/wifi/WifiInjector.java
@@ -167,13 +167,14 @@ public class WifiInjector {
mBatteryStats = IBatteryStats.Stub.asInterface(mFrameworkFacade.getService(
BatteryStats.SERVICE_NAME));
mWifiStateTracker = new WifiStateTracker(mBatteryStats);
- mCarrierNetworkConfig = new CarrierNetworkConfig(mContext);
// Now create and start handler threads
mWifiServiceHandlerThread = new HandlerThread("WifiService");
mWifiServiceHandlerThread.start();
mWifiStateMachineHandlerThread = new HandlerThread("WifiStateMachine");
mWifiStateMachineHandlerThread.start();
Looper wifiStateMachineLooper = mWifiStateMachineHandlerThread.getLooper();
+ mCarrierNetworkConfig = new CarrierNetworkConfig(mContext,
+ mWifiServiceHandlerThread.getLooper(), mFrameworkFacade);
WifiAwareMetrics awareMetrics = new WifiAwareMetrics(mClock);
mWifiMetrics = new WifiMetrics(mClock, wifiStateMachineLooper, awareMetrics);
// Modules interacting with Native.
diff --git a/tests/wifitests/src/com/android/server/wifi/CarrierNetworkConfigTest.java b/tests/wifitests/src/com/android/server/wifi/CarrierNetworkConfigTest.java
index e8eb6cebb..d45edcdc4 100644
--- a/tests/wifitests/src/com/android/server/wifi/CarrierNetworkConfigTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/CarrierNetworkConfigTest.java
@@ -23,9 +23,12 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.database.ContentObserver;
+import android.net.Uri;
import android.net.wifi.EAPConstants;
import android.net.wifi.WifiEnterpriseConfig;
import android.os.PersistableBundle;
+import android.os.test.TestLooper;
import android.support.test.filters.SmallTest;
import android.telephony.CarrierConfigManager;
import android.telephony.ImsiEncryptionInfo;
@@ -62,8 +65,11 @@ public class CarrierNetworkConfigTest {
@Mock SubscriptionManager mSubscriptionManager;
@Mock TelephonyManager mTelephonyManager;
@Mock PublicKey mPublicKey;
+ @Mock FrameworkFacade mFrameworkFacade;
BroadcastReceiver mBroadcastReceiver;
CarrierNetworkConfig mCarrierNetworkConfig;
+ TestLooper mLooper;
+ ContentObserver mContentObserver;
private ImsiEncryptionInfo mImsiEncryptionInfo = new ImsiEncryptionInfo(null, null, 0, null,
mPublicKey, null);
@@ -101,11 +107,18 @@ public class CarrierNetworkConfigTest {
.thenReturn(Arrays.asList(new SubscriptionInfo[] {TEST_SUBSCRIPTION_INFO}));
when(mTelephonyManager.getCarrierInfoForImsiEncryption(TelephonyManager.KEY_TYPE_WLAN))
.thenReturn(mImsiEncryptionInfo);
- mCarrierNetworkConfig = new CarrierNetworkConfig(mContext);
+ mLooper = new TestLooper();
+ mCarrierNetworkConfig = new CarrierNetworkConfig(mContext, mLooper.getLooper(),
+ mFrameworkFacade);
ArgumentCaptor<BroadcastReceiver> receiver =
ArgumentCaptor.forClass(BroadcastReceiver.class);
verify(mContext).registerReceiver(receiver.capture(), any(IntentFilter.class));
mBroadcastReceiver = receiver.getValue();
+ ArgumentCaptor<ContentObserver> observerCaptor =
+ ArgumentCaptor.forClass(ContentObserver.class);
+ verify(mFrameworkFacade).registerContentObserver(eq(mContext), any(Uri.class), eq(false),
+ observerCaptor.capture());
+ mContentObserver = observerCaptor.getValue();
reset(mCarrierConfigManager);
}
@@ -209,4 +222,22 @@ public class CarrierNetworkConfigTest {
mBroadcastReceiver.onReceive(mContext, new Intent("dummyIntent"));
verify(mCarrierConfigManager, never()).getConfig();
}
+
+ /**
+ * Verify that updateNetworkConfig is called when carrier networks certificates are downloaded.
+ */
+ @Test
+ public void onFeatureDisable_setWifiNetworksAvailableNotificationSettingDisabled() {
+ when(mTelephonyManager.getCarrierInfoForImsiEncryption(TelephonyManager.KEY_TYPE_WLAN))
+ .thenReturn(null);
+ mBroadcastReceiver.onReceive(mContext,
+ new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED));
+ // make sure the initial value is false
+ assertFalse(mCarrierNetworkConfig.isCarrierEncryptionInfoAvailable());
+
+ when(mTelephonyManager.getCarrierInfoForImsiEncryption(TelephonyManager.KEY_TYPE_WLAN))
+ .thenReturn(mImsiEncryptionInfo);
+ mContentObserver.onChange(false);
+ assertTrue(mCarrierNetworkConfig.isCarrierEncryptionInfoAvailable());
+ }
}