Skip to content

Commit

Permalink
Add support for getSubscriptionId(phoneAccountHandle) in shadowTeleph…
Browse files Browse the repository at this point in the history
…onyManager.

PiperOrigin-RevId: 538023398
  • Loading branch information
Googler authored and Copybara-Service committed Jun 6, 2023
1 parent 1f6bd45 commit adcb531
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Expand Up @@ -1137,4 +1137,16 @@ public void getEmergencyNumbersList_wasSet_returnsCorrectList() throws Exception
ImmutableMap.of(0, ImmutableList.of(emergencyNumber)));
assertThat(telephonyManager.getEmergencyNumberList().get(0)).containsExactly(emergencyNumber);
}

@Test
@Config(minSdk = R)
public void getSubscriptionIdForPhoneAccountHandle() {
int subscriptionId = 123;
PhoneAccountHandle phoneAccountHandle =
new PhoneAccountHandle(
new ComponentName(ApplicationProvider.getApplicationContext(), Object.class), "handle");
shadowOf(telephonyManager)
.setPhoneAccountHandleSubscriptionId(phoneAccountHandle, subscriptionId);
assertEquals(subscriptionId, telephonyManager.getSubscriptionId(phoneAccountHandle));
}
}
Expand Up @@ -95,6 +95,7 @@ public class ShadowTelephonyManager {
private final Map<PhoneAccountHandle, Uri> voicemailRingtoneUriMap = new HashMap<>();
private final Map<PhoneAccountHandle, TelephonyManager> phoneAccountToTelephonyManagers =
new HashMap<>();
private final Map<PhoneAccountHandle, Integer> phoneAccountHandleSubscriptionId = new HashMap<>();

private PhoneStateListener lastListener;
private /*TelephonyCallback*/ Object lastTelephonyCallback;
Expand Down Expand Up @@ -1095,6 +1096,16 @@ public void setSubscriberId(String subscriberId) {
this.subscriberId = subscriberId;
}

@Implementation(minSdk = R)
protected int getSubscriptionId(PhoneAccountHandle handle) {
checkReadPhoneStatePermission();
return phoneAccountHandleSubscriptionId.get(handle);
}

public void setPhoneAccountHandleSubscriptionId(PhoneAccountHandle handle, int subscriptionId) {
phoneAccountHandleSubscriptionId.put(handle, subscriptionId);
}

/** Returns the value set by {@link #setVisualVoicemailPackageName(String)}. */
@Implementation(minSdk = O)
protected String getVisualVoicemailPackageName() {
Expand Down

0 comments on commit adcb531

Please sign in to comment.