From 0ae2f996c3c6550226a476caf2e1d5c0f110c1eb Mon Sep 17 00:00:00 2001 From: pkanwar Date: Thu, 22 Mar 2018 18:13:54 -0700 Subject: Adds ContentObserver for certificate downloaded notification Adds ContentObserver to receive a notification everytime carrier network certificate is downloaded. Bug: 74090333 Test: manual test and unit tests Change-Id: Ia8ac30ebbc8413d63a2b07b667ede056719e2bcd --- .../server/wifi/CarrierNetworkConfigTest.java | 33 +++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'tests') 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 receiver = ArgumentCaptor.forClass(BroadcastReceiver.class); verify(mContext).registerReceiver(receiver.capture(), any(IntentFilter.class)); mBroadcastReceiver = receiver.getValue(); + ArgumentCaptor 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()); + } } -- cgit v1.2.3