5

How can I programmatically change the country & network of an Android phone's SIM without root access? I'm using this code to retrieve information:

TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

System.out.println(tm.getSimCountryIso()); // prints 'us', but I want it to be 'fr'
System.out.println(tm.getNetworkCountryIso()); // prints 'us, but I want it to be 'fr'

As my SIM card is from the USA, both of the outputs are us. How can I programmatically make the output be fr (France) for example?

Basically, I want to trick my smartphone into thinking its SIM's country & network is France, for example.

Something like this would be perfect but it doesn't exist:

tm.setSimCountryIso('fr')

tm.setNetworkCountryIso('fr')

Panjeet
  • 117
  • 1
  • 18
  • 4
    `System.out.println("fr")` ? If you're trying to permanently change the SIM card's country, that's obviously not possible. – Guy Incognito Jul 11 '20 at 14:23
  • 2
    Step one: Decrypt the sim. https://security.stackexchange.com/questions/105013/security-of-data-stored-on-sim-cards – Elliott Frisch Jul 11 '20 at 14:23
  • @GuyIncognito I want `tm.getSimCountryIso()` to be whatever country I choose. – Panjeet Jul 11 '20 at 14:38
  • 3
    Well that's obviously not possible. – Guy Incognito Jul 11 '20 at 14:42
  • @ElliottFrisch Care to give a complete answer? I added a +350 bounty. – Panjeet Jul 13 '20 at 14:41
  • See this question: [How do I change the Mobile Country Code (MCC) in the Android Emulator?](https://stackoverflow.com/questions/2637606). For an emulator (e.g. for testing purposes), you can change the SIM values at will. The "hardware": you cannot change. – paulsm4 Jul 13 '20 at 18:07
  • @paulsm4 I don't want to modify the hardware itself, I just want the phone to "think" the SIM & network are from another country. – Panjeet Jul 13 '20 at 18:09
  • You can make an emulator "think" anything you want, per the link above. Otherwise, you're basically SOL. And as Lev M. correctly explains: "For example, if you want to create a Google account from the phone for a different country, changing the SIM will not help, since Google will still look at your IP address, regardless of how you are connected to the internet." Please "upvote" and "accept" his reply, – paulsm4 Jul 13 '20 at 18:55

1 Answers1

10

What you are asking for is not possible without root.

As already stated in the comments, it is not physically possible to change the ICCID of the SIM unless it is a special writable SIM.

As for the call to getSimCountryIso and getNetworkCountryIso() those are system API's. Without root, there is no way to interfere with their operation.

Android is built with several layers of security including restricting app access based on user privileges, enforcing SELinux on by default, verity checks as part of verified boot and more.

If you do have root on device, you can create an Xposed framework module that can hook these functions and overwrite their return value.

If you are curious, the table used to translate ICCID info into a two letter country name is hardcoded here. In case that link does not open right - it starts on line 316.

So changing that would require recompiling one of the core JARs of the OS.

Also note, that depending on your real purpose, altering the result of these two functions may not work at all.

For example, if you want to create a Google account from the phone for a different country, changing the SIM will not help, since Google will still look at your IP address, regardless of how you are connected to the internet.

Lev M.
  • 6,088
  • 1
  • 10
  • 23