aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-10-21 08:02:51 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2022-10-21 08:02:51 +0000
commit065dbcc59facab9aa415ef85ceb827629bd4f8e3 (patch)
tree57139e3d409afd5ec539f5f4cc988afb2f335ea4
parentf64b56d7a44cd9d57ff5f5b80f329c89d1ec09aa (diff)
parent2dd24ea9a4f58454e1d2b394b3bc5d3cdc8b37d3 (diff)
downloadtelephony-gki13-boot-release.tar.gz
Merge "Snap for 9203002 from 45048b96214530080f53a7039cb544bec207805d to gki13-boot-release" into gki13-boot-releasegki13-boot-release
-rw-r--r--tests/telephonytests/src/com/android/internal/telephony/TelephonyRegistryTest.java50
1 files changed, 49 insertions, 1 deletions
diff --git a/tests/telephonytests/src/com/android/internal/telephony/TelephonyRegistryTest.java b/tests/telephonytests/src/com/android/internal/telephony/TelephonyRegistryTest.java
index 16e3ac857a..cf7cadb923 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/TelephonyRegistryTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/TelephonyRegistryTest.java
@@ -43,8 +43,10 @@ import android.os.ServiceManager;
import android.os.UserHandle;
import android.telephony.AccessNetworkConstants;
import android.telephony.Annotation;
+import android.telephony.BarringInfo;
import android.telephony.CellIdentity;
import android.telephony.CellIdentityGsm;
+import android.telephony.CellIdentityLte;
import android.telephony.CellInfo;
import android.telephony.CellInfoLte;
import android.telephony.CellLocation;
@@ -64,6 +66,7 @@ import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.text.TextUtils;
+import android.util.SparseArray;
import androidx.annotation.NonNull;
@@ -104,6 +107,7 @@ public class TelephonyRegistryTest extends TelephonyTest {
private List<PhysicalChannelConfig> mPhysicalChannelConfigs;
private CellLocation mCellLocation;
private List<CellInfo> mCellInfo;
+ private BarringInfo mBarringInfo = null;
// All events contribute to TelephonyRegistry#isPhoneStatePermissionRequired
private static final Set<Integer> READ_PHONE_STATE_EVENTS;
@@ -171,7 +175,8 @@ public class TelephonyRegistryTest extends TelephonyTest {
TelephonyCallback.PhysicalChannelConfigListener,
TelephonyCallback.CellLocationListener,
TelephonyCallback.ServiceStateListener,
- TelephonyCallback.CellInfoListener {
+ TelephonyCallback.CellInfoListener,
+ TelephonyCallback.BarringInfoListener {
// This class isn't mockable to get invocation counts because the IBinder is null and
// crashes the TelephonyRegistry. Make a cheesy verify(times()) alternative.
public AtomicInteger invocationCount = new AtomicInteger(0);
@@ -239,6 +244,12 @@ public class TelephonyRegistryTest extends TelephonyTest {
invocationCount.incrementAndGet();
mCellInfo = cellInfo;
}
+
+ @Override
+ public void onBarringInfoChanged(BarringInfo barringInfo) {
+ invocationCount.incrementAndGet();
+ mBarringInfo = barringInfo;
+ }
}
private void addTelephonyRegistryService() {
@@ -885,6 +896,43 @@ public class TelephonyRegistryTest extends TelephonyTest {
assertEquals(PHYSICAL_CELL_ID_UNKNOWN, mPhysicalChannelConfigs.get(0).getPhysicalCellId());
}
+ @Test
+ public void testBarringInfoChanged() {
+ // Return a slotIndex / phoneId of 0 for all sub ids given.
+ doReturn(mMockSubInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt());
+ doReturn(0/*slotIndex*/).when(mMockSubInfo).getSimSlotIndex();
+ doReturn(true).when(mLocationManager).isLocationEnabledForUser(any(UserHandle.class));
+
+ final int subId = 1;
+ int[] events = {TelephonyCallback.EVENT_BARRING_INFO_CHANGED};
+ SparseArray<BarringInfo.BarringServiceInfo> bsi = new SparseArray(1);
+ bsi.set(BarringInfo.BARRING_SERVICE_TYPE_MO_DATA,
+ new BarringInfo.BarringServiceInfo(
+ BarringInfo.BarringServiceInfo.BARRING_TYPE_CONDITIONAL,
+ false /*isConditionallyBarred*/,
+ 30 /*conditionalBarringFactor*/,
+ 10 /*conditionalBarringTimeSeconds*/));
+ BarringInfo info = new BarringInfo(new CellIdentityLte(), bsi);
+
+ // Registering for info causes Barring Info to be sent to caller
+ mTelephonyRegistry.listenWithEventList(false, false, subId, mContext.getOpPackageName(),
+ mContext.getAttributionTag(), mTelephonyCallback.callback, events, true);
+ processAllMessages();
+ assertEquals(1, mTelephonyCallback.invocationCount.get());
+ assertNotNull(mBarringInfo);
+
+ // Updating the barring info causes Barring Info to be updated
+ mTelephonyRegistry.notifyBarringInfoChanged(0, subId, info);
+ processAllMessages();
+ assertEquals(2, mTelephonyCallback.invocationCount.get());
+ assertEquals(mBarringInfo, info);
+
+ // Duplicate BarringInfo notifications do not trigger callback
+ mTelephonyRegistry.notifyBarringInfoChanged(0, subId, info);
+ processAllMessages();
+ assertEquals(2, mTelephonyCallback.invocationCount.get());
+ }
+
/**
* Test listen to events that require READ_PHONE_STATE permission.
*/