Skip to content

Commit

Permalink
Ensure getNetworkCountryIso & getSimCountryIso return lowercase only,…
Browse files Browse the repository at this point in the history
… to match the actual APIs.

PiperOrigin-RevId: 434820755
  • Loading branch information
Googler authored and Copybara-Service committed Mar 25, 2022
1 parent 2fd55bc commit 4d1e64b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Expand Up @@ -242,9 +242,9 @@ public void onCellInfo(List<CellInfo> list) {
}

@Test
public void shouldGiveNetworkCountryIso() {
public void shouldGiveNetworkCountryIsoInLowercase() {
shadowOf(telephonyManager).setNetworkCountryIso("SomeIso");
assertEquals("SomeIso", telephonyManager.getNetworkCountryIso());
assertEquals("someiso", telephonyManager.getNetworkCountryIso());
}

@Test
Expand Down Expand Up @@ -506,7 +506,7 @@ public void shouldGetSimIso() {

@Test
@Config(minSdk = N, maxSdk = Q)
public void shouldGetSimIosWhenSetUsingSlotNumber() {
public void shouldGetSimIsoWhenSetUsingSlotNumber() {
String expectedSimIso = "usa";
int subId = 2;
shadowOf(telephonyManager).setSimCountryIso(subId, expectedSimIso);
Expand Down
Expand Up @@ -42,6 +42,7 @@
import android.text.TextUtils;
import android.util.SparseArray;
import android.util.SparseIntArray;
import com.google.common.base.Ascii;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -319,9 +320,13 @@ public void setNetworkCountryIso(String networkCountryIso) {
this.networkCountryIso = networkCountryIso;
}

/**
* Returns the SIM country lowercase. This matches the API this shadows:
* https://developer.android.com/reference/android/telephony/TelephonyManager#getNetworkCountryIso().
*/
@Implementation
protected String getNetworkCountryIso() {
return networkCountryIso;
return networkCountryIso == null ? null : Ascii.toLowerCase(networkCountryIso);
}

/** Sets the sim locale returned by {@link #getSimLocale()}. */
Expand Down Expand Up @@ -374,9 +379,14 @@ public void setSimSerialNumber(String simSerialNumber) {
this.simSerialNumber = simSerialNumber;
}

/**
* Returns the SIM country lowercase. This matches the API it shadows:
* https://developer.android.com/reference/android/telephony/TelephonyManager#getSimCountryIso().
*/
@Implementation
protected String getSimCountryIso() {
return simCountryIsoMap.get(/* subId= */ 0);
String simCountryIso = simCountryIsoMap.get(/* subId= */ 0);
return simCountryIso == null ? simCountryIso : Ascii.toLowerCase(simCountryIso);
}

@Implementation(minSdk = N, maxSdk = Q)
Expand Down

0 comments on commit 4d1e64b

Please sign in to comment.