How do I change the Mobile Country Code (MCC) in the Android Emulator?

戏子无情 提交于 2019-12-02 21:59:13

To change what TelephonyManager.getSimCountryIso() returns, simply execute

adb shell setprop gsm.sim.operator.iso-country no

and it now returns no (Norway).

If you want to change what TelephonyManager.getSimOperator() returns (MCC+MNC) then execute

adb shell setprop gsm.sim.operator.numeric 24201

and you have changed MCC to 242 (Norway) and MNC to 01 (Telenor).

To see which other properties you can change then execute

adb shell getprop

This is verified to work on both AVD and Genymotion. However, this does not change these properties persistently.

I have observed that value for this properties varies in some API level. I have tried to address this issue.

You can use following command to change the value on API 26:

  1. adb shell
  2. su
  3. setprop gsm.operator.numeric 280701

Note: Some emulators require restart.

On some emulators the property can be different name

You can find the property name as follows:

  1. adb shell
  2. getprop

It will give you data similar to following:

...
[dalvik.vm.lockprof.threshold]: [500]
[dalvik.vm.stack-trace-file]: [/data/anr/traces.txt]
[dalvik.vm.usejit]: [true]
[dalvik.vm.usejitprofiles]: [true]
[debug.atrace.tags.enableflags]: [0]
[debug.force_rtl]: [0]
[dev.bootcomplete]: [1]
[drm.service.enabled]: [true]
[gsm.current.phone-type]: [1]
[gsm.defaultpdpcontext.active]: [true]
[gsm.network.type]: [LTE]
[gsm.nitz.time]: [1524141151210]
[gsm.operator.alpha]: [Android]
[gsm.operator.iso-country]: [us]
[gsm.operator.isroaming]: [false]
[gsm.operator.numeric]: [310260]
[gsm.sim.operator.alpha]: [Android]
[gsm.sim.operator.iso-country]: [us]
[gsm.sim.operator.numeric]: [310260]
[gsm.sim.state]: [READY]
[gsm.version.baseband]: [1.0.0.0]
[gsm.version.ril-impl]: [android reference-ril 1.0]
[hwservicemanager.ready]: [true]
[init.svc.adbd]: [running]
[init.svc.audio-hal-2-0]: [running]
[init.svc.audioserver]: [running]
[init.svc.bootanim]: [stopped]
[init.svc.camera-provider-2-4]: [running]
[init.svc.cameraserver]: [running]
...

Search for numeric by copying the output in text file. Get the property name and use setprop <property name> <new MCC MNC>

You can also use getProp to verify whether the value has been changed.

prouser135

Changing MCC+MNC in the emulator can only be done with ADB. To change the MCC+MNC in the emulator, connect to ADB do the following

adb -s 127.0.0.1:53001 shell

Then put your country code there. 23801 is danish coutry code.

setprop persist.<name of the emulator>.mccmnc 23801

For Droid4X emulator, it is

setprop persist.droid4x.mccmnc 23801

Reboot the emulator.

On emulator: go to Settings->WireLess and Network->Mobile Network->Access Point Names. Try changing MCC value in the set APN and then try your code.

Do know that relying on an MCC is not always correct in every country. Digicell for instance use one MCC+MNC in several countries. Also understand that the whole idea of an MCC is rather ludicrous from an network point of view. It is rather irrelevant to know if you're in Germany or in the Netherlands if both times you're on T-Mobile with an AT&T handset.

André Fernandes

It doesn't seem to be possible to change MCC/MNC via settings on the Android emulator, every time this is attempted the preconfigured "T-Mobile" APN will disappear from the list and network connectivity is lost. I've even had the emulator spontaneously reboot after a change.

The programmatic way doesn't work either, the APN will disappear right after:

root@generic_x86:/ # content update --uri content://telephony/carriers/ --bind name:s:'TheAPN' --bind apn:s:apn.operator.net --bind numeric:i:12345 --bind user:s: --bind password:s: --bind server:s: --bind proxy:s: --bind mmsproxy:s: --bind mmsc:s: --bind type:s: --bind mcc:i:123 --bind mnc:i:45 --bind current:i:1 --where _id=1

It could be possible by hacking the emulator in the same ways that allow to change the MSISDN or IMEI, though.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!