aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2024-03-12 23:08:20 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2024-03-12 23:08:20 +0000
commit432d3ed6098def186a60af3b10efe6767039fa52 (patch)
tree62eb9236e84927850aa1c50716e32667146ae9e8
parent578213f534eb6f456d4d2a10a3267d91e4540454 (diff)
parent7f106852c754a476bfa545506a45d60d9276bb7d (diff)
downloadrobolectric-shadows-sdk-release.tar.gz
Snap for 11566117 from 7f106852c754a476bfa545506a45d60d9276bb7d to sdk-releaseplatform-tools-35.0.1sdk-release
Change-Id: I2e73fd10d0b24c956e034ab46be7d36dc6a281fc
-rw-r--r--robolectric/src/main/java/org/robolectric/internal/SdkConfig.java8
-rw-r--r--robolectric/src/test/java/org/robolectric/shadows/ShadowTelephonyManagerTest.java101
-rw-r--r--shadows/framework/src/main/java/org/robolectric/shadows/ShadowTelephonyManager.java15
3 files changed, 75 insertions, 49 deletions
diff --git a/robolectric/src/main/java/org/robolectric/internal/SdkConfig.java b/robolectric/src/main/java/org/robolectric/internal/SdkConfig.java
index 901d518f4..c99372a7c 100644
--- a/robolectric/src/main/java/org/robolectric/internal/SdkConfig.java
+++ b/robolectric/src/main/java/org/robolectric/internal/SdkConfig.java
@@ -30,10 +30,12 @@ public class SdkConfig implements Comparable<SdkConfig> {
addSdk(Build.VERSION_CODES.O_MR1, "8.1.0", "4611349", "REL");
addSdk(Build.VERSION_CODES.P, "9", "4913185-2", "REL");
addSdk(Build.VERSION_CODES.Q, "10", "5803371", "REL");
+ addSdk(Build.VERSION_CODES.R, "11", "6757853", "REL");
+ addSdk(Build.VERSION_CODES.S, "12", "7732740", "REL");
+ addSdk(Build.VERSION_CODES.S_V2, "12.1", "8229987", "REL");
+ addSdk(Build.VERSION_CODES.TIRAMISU, "13", "9030017", "REL");
// BEGIN-INTERNAL
- // TODO: Update jar with final R release.
- addSdk(Build.VERSION_CODES.R, "R-beta2", "6625208", "REL");
- addSdk(Build.VERSION_CODES.S, "S-beta3", "7541949", "REL");
+ // TODO: Update jar with final U release.
addSdk(Build.VERSION_CODES.CUR_DEVELOPMENT, "current", "r0", "ZZZ");
// END-INTERNAL
}
diff --git a/robolectric/src/test/java/org/robolectric/shadows/ShadowTelephonyManagerTest.java b/robolectric/src/test/java/org/robolectric/shadows/ShadowTelephonyManagerTest.java
index 5b947ceea..52ef012d1 100644
--- a/robolectric/src/test/java/org/robolectric/shadows/ShadowTelephonyManagerTest.java
+++ b/robolectric/src/test/java/org/robolectric/shadows/ShadowTelephonyManagerTest.java
@@ -34,6 +34,7 @@ import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
+import android.telephony.UiccSlotInfo;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import java.util.Collections;
@@ -47,12 +48,10 @@ import org.robolectric.annotation.Config;
public class ShadowTelephonyManagerTest {
private TelephonyManager telephonyManager;
- private ShadowTelephonyManager shadowTelephonyManager;
@Before
public void setUp() throws Exception {
telephonyManager = (TelephonyManager) application.getSystemService(TELEPHONY_SERVICE);
- shadowTelephonyManager = shadowOf(telephonyManager);
}
@Test
@@ -70,15 +69,15 @@ public class ShadowTelephonyManagerTest {
@Test
public void shouldGiveDeviceId() {
String testId = "TESTING123";
- shadowTelephonyManager.setDeviceId(testId);
+ shadowOf(telephonyManager).setDeviceId(testId);
assertEquals(testId, telephonyManager.getDeviceId());
}
@Test
@Config(minSdk = M)
public void shouldGiveDeviceIdForSlot() {
- shadowTelephonyManager.setDeviceId(1, "device in slot 1");
- shadowTelephonyManager.setDeviceId(2, "device in slot 2");
+ shadowOf(telephonyManager).setDeviceId(1, "device in slot 1");
+ shadowOf(telephonyManager).setDeviceId(2, "device in slot 2");
assertEquals("device in slot 1", telephonyManager.getDeviceId(1));
assertEquals("device in slot 2", telephonyManager.getDeviceId(2));
@@ -88,7 +87,7 @@ public class ShadowTelephonyManagerTest {
@Config(minSdk = O)
public void getImei() {
String testImei = "4test imei";
- shadowTelephonyManager.setImei(testImei);
+ shadowOf(telephonyManager).setImei(testImei);
assertEquals(testImei, telephonyManager.getImei());
}
@@ -96,45 +95,45 @@ public class ShadowTelephonyManagerTest {
@Config(minSdk = O)
public void getMeid() {
String testMeid = "4test meid";
- shadowTelephonyManager.setMeid(testMeid);
+ shadowOf(telephonyManager).setMeid(testMeid);
assertEquals(testMeid, telephonyManager.getMeid());
}
@Test
public void shouldGiveNetworkOperatorName() {
- shadowTelephonyManager.setNetworkOperatorName("SomeOperatorName");
+ shadowOf(telephonyManager).setNetworkOperatorName("SomeOperatorName");
assertEquals("SomeOperatorName", telephonyManager.getNetworkOperatorName());
}
@Test
public void shouldGiveSimOperatorName() {
- shadowTelephonyManager.setSimOperatorName("SomeSimOperatorName");
+ shadowOf(telephonyManager).setSimOperatorName("SomeSimOperatorName");
assertEquals("SomeSimOperatorName", telephonyManager.getSimOperatorName());
}
@Test(expected = SecurityException.class)
public void getSimSerialNumber_shouldThrowSecurityExceptionWhenReadPhoneStatePermissionNotGranted()
throws Exception {
- shadowTelephonyManager.setReadPhoneStatePermission(false);
+ shadowOf(telephonyManager).setReadPhoneStatePermission(false);
telephonyManager.getSimSerialNumber();
}
@Test
public void shouldGetSimSerialNumber() {
- shadowTelephonyManager.setSimSerialNumber("SomeSerialNumber");
+ shadowOf(telephonyManager).setSimSerialNumber("SomeSerialNumber");
assertEquals("SomeSerialNumber", telephonyManager.getSimSerialNumber());
}
@Test
public void shouldGiveNetworkType() {
- shadowTelephonyManager.setNetworkType(TelephonyManager.NETWORK_TYPE_CDMA);
+ shadowOf(telephonyManager).setNetworkType(TelephonyManager.NETWORK_TYPE_CDMA);
assertEquals(TelephonyManager.NETWORK_TYPE_CDMA, telephonyManager.getNetworkType());
}
@Test
@Config(minSdk = N)
public void shouldGiveVoiceNetworkType() {
- shadowTelephonyManager.setVoiceNetworkType(TelephonyManager.NETWORK_TYPE_CDMA);
+ shadowOf(telephonyManager).setVoiceNetworkType(TelephonyManager.NETWORK_TYPE_CDMA);
assertThat(telephonyManager.getVoiceNetworkType())
.isEqualTo(TelephonyManager.NETWORK_TYPE_CDMA);
}
@@ -146,48 +145,48 @@ public class ShadowTelephonyManagerTest {
telephonyManager.listen(listener, LISTEN_CELL_INFO);
List<CellInfo> allCellInfo = Collections.singletonList(mock(CellInfo.class));
- shadowTelephonyManager.setAllCellInfo(allCellInfo);
+ shadowOf(telephonyManager).setAllCellInfo(allCellInfo);
assertEquals(allCellInfo, telephonyManager.getAllCellInfo());
verify(listener).onCellInfoChanged(allCellInfo);
}
@Test
public void shouldGiveNetworkCountryIso() {
- shadowTelephonyManager.setNetworkCountryIso("SomeIso");
+ shadowOf(telephonyManager).setNetworkCountryIso("SomeIso");
assertEquals("SomeIso", telephonyManager.getNetworkCountryIso());
}
@Test
public void shouldGiveNetworkOperator() {
- shadowTelephonyManager.setNetworkOperator("SomeOperator");
+ shadowOf(telephonyManager).setNetworkOperator("SomeOperator");
assertEquals("SomeOperator", telephonyManager.getNetworkOperator());
}
@Test
public void shouldGiveLine1Number() {
- shadowTelephonyManager.setLine1Number("123-244-2222");
+ shadowOf(telephonyManager).setLine1Number("123-244-2222");
assertEquals("123-244-2222", telephonyManager.getLine1Number());
}
@Test
@Config(minSdk = JELLY_BEAN_MR2)
public void shouldGiveGroupIdLevel1() {
- shadowTelephonyManager.setGroupIdLevel1("SomeGroupId");
+ shadowOf(telephonyManager).setGroupIdLevel1("SomeGroupId");
assertEquals("SomeGroupId", telephonyManager.getGroupIdLevel1());
}
@Test(expected = SecurityException.class)
public void getDeviceId_shouldThrowSecurityExceptionWhenReadPhoneStatePermissionNotGranted()
throws Exception {
- shadowTelephonyManager.setReadPhoneStatePermission(false);
+ shadowOf(telephonyManager).setReadPhoneStatePermission(false);
telephonyManager.getDeviceId();
}
@Test
public void shouldGivePhoneType() {
- shadowTelephonyManager.setPhoneType(TelephonyManager.PHONE_TYPE_CDMA);
+ shadowOf(telephonyManager).setPhoneType(TelephonyManager.PHONE_TYPE_CDMA);
assertEquals(TelephonyManager.PHONE_TYPE_CDMA, telephonyManager.getPhoneType());
- shadowTelephonyManager.setPhoneType(TelephonyManager.PHONE_TYPE_GSM);
+ shadowOf(telephonyManager).setPhoneType(TelephonyManager.PHONE_TYPE_GSM);
assertEquals(TelephonyManager.PHONE_TYPE_GSM, telephonyManager.getPhoneType());
}
@@ -219,7 +218,7 @@ public class ShadowTelephonyManagerTest {
@Test
public void isSmsCapable() {
assertThat(telephonyManager.isSmsCapable()).isTrue();
- shadowTelephonyManager.setIsSmsCapable(false);
+ shadowOf(telephonyManager).setIsSmsCapable(false);
assertThat(telephonyManager.isSmsCapable()).isFalse();
}
@@ -228,7 +227,7 @@ public class ShadowTelephonyManagerTest {
public void shouldGiveCarrierConfigIfSet() {
PersistableBundle bundle = new PersistableBundle();
bundle.putInt("foo", 42);
- shadowTelephonyManager.setCarrierConfig(bundle);
+ shadowOf(telephonyManager).setCarrierConfig(bundle);
assertEquals(bundle, telephonyManager.getCarrierConfig());
}
@@ -241,14 +240,14 @@ public class ShadowTelephonyManagerTest {
@Test
public void shouldGiveVoiceMailNumber() {
- shadowTelephonyManager.setVoiceMailNumber("123");
+ shadowOf(telephonyManager).setVoiceMailNumber("123");
assertEquals("123", telephonyManager.getVoiceMailNumber());
}
@Test
public void shouldGiveVoiceMailAlphaTag() {
- shadowTelephonyManager.setVoiceMailAlphaTag("tag");
+ shadowOf(telephonyManager).setVoiceMailAlphaTag("tag");
assertEquals("tag", telephonyManager.getVoiceMailAlphaTag());
}
@@ -256,7 +255,7 @@ public class ShadowTelephonyManagerTest {
@Test
@Config(minSdk = M)
public void shouldGivePhoneCount() {
- shadowTelephonyManager.setPhoneCount(42);
+ shadowOf(telephonyManager).setPhoneCount(42);
assertEquals(42, telephonyManager.getPhoneCount());
}
@@ -268,7 +267,7 @@ public class ShadowTelephonyManagerTest {
new PhoneAccountHandle(
new ComponentName(ApplicationProvider.getApplicationContext(), Object.class), "handle");
- shadowTelephonyManager.setVoicemailVibrationEnabled(phoneAccountHandle, true);
+ shadowOf(telephonyManager).setVoicemailVibrationEnabled(phoneAccountHandle, true);
assertTrue(telephonyManager.isVoicemailVibrationEnabled(phoneAccountHandle));
}
@@ -281,7 +280,7 @@ public class ShadowTelephonyManagerTest {
new ComponentName(ApplicationProvider.getApplicationContext(), Object.class), "handle");
Uri ringtoneUri = Uri.fromParts("file", "ringtone.mp3", /* fragment = */ null);
- shadowTelephonyManager.setVoicemailRingtoneUri(phoneAccountHandle, ringtoneUri);
+ shadowOf(telephonyManager).setVoicemailRingtoneUri(phoneAccountHandle, ringtoneUri);
assertEquals(ringtoneUri, telephonyManager.getVoicemailRingtoneUri(phoneAccountHandle));
}
@@ -308,7 +307,8 @@ public class ShadowTelephonyManagerTest {
new ComponentName(ApplicationProvider.getApplicationContext(), Object.class), "handle");
TelephonyManager mockTelephonyManager = mock(TelephonyManager.class);
- shadowTelephonyManager.setTelephonyManagerForHandle(phoneAccountHandle, mockTelephonyManager);
+ shadowOf(telephonyManager)
+ .setTelephonyManagerForHandle(phoneAccountHandle, mockTelephonyManager);
assertEquals(
mockTelephonyManager, telephonyManager.createForPhoneAccountHandle(phoneAccountHandle));
@@ -320,8 +320,8 @@ public class ShadowTelephonyManagerTest {
int subscriptionId = 42;
TelephonyManager mockTelephonyManager = mock(TelephonyManager.class);
- shadowTelephonyManager.setTelephonyManagerForSubscriptionId(
- subscriptionId, mockTelephonyManager);
+ shadowOf(telephonyManager)
+ .setTelephonyManagerForSubscriptionId(subscriptionId, mockTelephonyManager);
assertEquals(mockTelephonyManager, telephonyManager.createForSubscriptionId(subscriptionId));
}
@@ -332,14 +332,14 @@ public class ShadowTelephonyManagerTest {
ServiceState serviceState = new ServiceState();
serviceState.setState(ServiceState.STATE_OUT_OF_SERVICE);
- shadowTelephonyManager.setServiceState(serviceState);
+ shadowOf(telephonyManager).setServiceState(serviceState);
assertEquals(serviceState, telephonyManager.getServiceState());
}
@Test
public void shouldSetIsNetworkRoaming() {
- shadowTelephonyManager.setIsNetworkRoaming(true);
+ shadowOf(telephonyManager).setIsNetworkRoaming(true);
assertTrue(telephonyManager.isNetworkRoaming());
}
@@ -354,7 +354,7 @@ public class ShadowTelephonyManagerTest {
public void shouldGetSimStateUsingSlotNumber() {
int expectedSimState = TelephonyManager.SIM_STATE_ABSENT;
int slotNumber = 3;
- shadowTelephonyManager.setSimState(slotNumber, expectedSimState);
+ shadowOf(telephonyManager).setSimState(slotNumber, expectedSimState);
assertThat(telephonyManager.getSimState(slotNumber)).isEqualTo(expectedSimState);
}
@@ -369,7 +369,7 @@ public class ShadowTelephonyManagerTest {
public void shouldGetSimIosWhenSetUsingSlotNumber() {
String expectedSimIso = "usa";
int subId = 2;
- shadowTelephonyManager.setSimCountryIso(subId, expectedSimIso);
+ shadowOf(telephonyManager).setSimCountryIso(subId, expectedSimIso);
assertThat(telephonyManager.getSimCountryIso(subId)).isEqualTo(expectedSimIso);
}
@@ -378,7 +378,7 @@ public class ShadowTelephonyManagerTest {
@Config(minSdk = P)
public void shouldGetSimCarrierId() {
int expectedCarrierId = 132;
- shadowTelephonyManager.setSimCarrierId(expectedCarrierId);
+ shadowOf(telephonyManager).setSimCarrierId(expectedCarrierId);
assertThat(telephonyManager.getSimCarrierId()).isEqualTo(expectedCarrierId);
}
@@ -388,7 +388,7 @@ public class ShadowTelephonyManagerTest {
public void shouldGetCurrentPhoneTypeGivenSubId() {
int subId = 1;
int expectedPhoneType = TelephonyManager.PHONE_TYPE_GSM;
- shadowTelephonyManager.setCurrentPhoneType(subId, expectedPhoneType);
+ shadowOf(telephonyManager).setCurrentPhoneType(subId, expectedPhoneType);
assertThat(telephonyManager.getCurrentPhoneType(subId)).isEqualTo(expectedPhoneType);
}
@@ -398,7 +398,7 @@ public class ShadowTelephonyManagerTest {
public void shouldGetCarrierPackageNamesForIntentAndPhone() {
List<String> packages = Collections.singletonList("package1");
int phoneId = 123;
- shadowTelephonyManager.setCarrierPackageNamesForPhone(phoneId, packages);
+ shadowOf(telephonyManager).setCarrierPackageNamesForPhone(phoneId, packages);
assertThat(telephonyManager.getCarrierPackageNamesForIntentAndPhone(new Intent(), phoneId))
.isEqualTo(packages);
@@ -408,15 +408,15 @@ public class ShadowTelephonyManagerTest {
@Config(minSdk = M)
public void shouldGetCarrierPackageNamesForIntent() {
List<String> packages = Collections.singletonList("package1");
- shadowTelephonyManager.setCarrierPackageNamesForPhone(
- SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, packages);
+ shadowOf(telephonyManager)
+ .setCarrierPackageNamesForPhone(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, packages);
assertThat(telephonyManager.getCarrierPackageNamesForIntent(new Intent())).isEqualTo(packages);
}
@Test
public void resetSimStates_shouldRetainDefaultState() {
- shadowTelephonyManager.resetSimStates();
+ shadowOf(telephonyManager).resetSimStates();
assertThat(telephonyManager.getSimState()).isEqualTo(TelephonyManager.SIM_STATE_READY);
}
@@ -424,16 +424,27 @@ public class ShadowTelephonyManagerTest {
@Test
@Config(minSdk = N)
public void resetSimCountryIsos_shouldRetainDefaultState() {
- shadowTelephonyManager.resetSimCountryIsos();
+ shadowOf(telephonyManager).resetSimCountryIsos();
- assertThat(shadowTelephonyManager.getSimCountryIso()).isEmpty();
+ assertThat(telephonyManager.getSimCountryIso()).isEmpty();
}
@Test
public void shouldSetSubscriberId() {
String subscriberId = "123451234512345";
- shadowTelephonyManager.setSubscriberId(subscriberId);
+ shadowOf(telephonyManager).setSubscriberId(subscriberId);
+
+ assertThat(telephonyManager.getSubscriberId()).isEqualTo(subscriberId);
+ }
+
+ @Test
+ @Config(minSdk = P)
+ public void getUiccSlotsInfo() {
+ UiccSlotInfo slotInfo1 = new UiccSlotInfo(true, true, null, 0, 0, true);
+ UiccSlotInfo slotInfo2 = new UiccSlotInfo(true, true, null, 0, 1, true);
+ UiccSlotInfo[] slotInfos = new UiccSlotInfo[] {slotInfo1, slotInfo2};
+ shadowOf(telephonyManager).setUiccSlotsInfo(slotInfos);
- assertThat(shadowTelephonyManager.getSubscriberId()).isEqualTo(subscriberId);
+ assertThat(shadowOf(telephonyManager).getUiccSlotsInfo()).isEqualTo(slotInfos);
}
}
diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowTelephonyManager.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowTelephonyManager.java
index 12b40fa79..acd0acaa9 100644
--- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowTelephonyManager.java
+++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowTelephonyManager.java
@@ -38,7 +38,7 @@ import org.robolectric.annotation.HiddenApi;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
-@Implements(TelephonyManager.class)
+@Implements(value = TelephonyManager.class, looseSignatures = true)
public class ShadowTelephonyManager {
private final Map<PhoneStateListener, Integer> phoneStateRegistrations = new HashMap<>();
@@ -85,6 +85,7 @@ public class ShadowTelephonyManager {
private final Map<Integer, String> simCountryIsoMap = new HashMap<>();
private int simCarrierId;
private String subscriberId;
+ private /*UiccSlotInfo[]*/ Object uiccSlotInfos;
{
resetSimStates();
@@ -288,6 +289,18 @@ public class ShadowTelephonyManager {
return simStates.get(slotIndex, TelephonyManager.SIM_STATE_UNKNOWN);
}
+ /** Sets the UICC slots information returned by {@link #getUiccSlotsInfo()}. */
+ public void setUiccSlotsInfo(/*UiccSlotInfo[]*/ Object uiccSlotsInfos) {
+ this.uiccSlotInfos = uiccSlotsInfos;
+ }
+
+ /** Returns the UICC slots information set by {@link #setUiccSlotsInfo}. */
+ @Implementation(minSdk = P)
+ @HiddenApi
+ protected /*UiccSlotInfo[]*/ Object getUiccSlotsInfo() {
+ return uiccSlotInfos;
+ }
+
/** Clears {@code slotIndex} to state mapping and resets to default state. */
public void resetSimStates() {
simStates.clear();