Is telephony manager values reliable and changeable (cdma)? - java

I want to know if I can rely on the telephony values like country, MCC, etc on Android for my app. Can I change them on the run using setprop? I tried changing using setprop it didn't seem to work. From my understanding telephony manager is a class/interface which represents Hardware configuration of GSM or CDMA. In case of GSM this could be sim and in case of CDMA it cud be a hardware. My questions are:
Who update these values in both the cases for the first time?
Are these values are saved by OS as read only?
What if a user travels to different country or zone will some of the values like country code and MCC values updated automatically?
Can I reset these values?
I have no intention of changing any of these values but want to understand its working! I would appreciate if someone can help me on this.

According to android documentation
Provides access to information about the telephony services on the
device. Applications can use the methods in this class to determine
telephony services and states, as well as to access some types of
subscriber information. Applications can also register a listener to
receive notification of telephony state changes.
TelephonyManager is used for reading phone information. Regarding your question about MCC & MNC codes: yes, they will change when phone will be in other country. You can subscribe to receive those events and determine that user now in different country.

#Bo
The way CDMA works is different from GSM. CDMA has always got one home base and many visitor base location. and you can always get to know about visitor Operator using TelephonyManager methods which is considered as unreliable for CDMA.

I decided to add it as answer as well...
I found a way to tackle this problem on CDMA phone.. if it is a CDMA phone , then the phone always has an ICC hardware comparable to SIM cards in GSM. All you gotta do is use the system properties associated with the hard ware . Programmatically you can use Java reflection to get this information . This is not changeable even system is rooted unlike GSM device. Class c=Class.forName("android.os.SystemProperties"); Method get = c.getMethod("get", String.class); String homeOperator = ((String) get.invoke(c, "ro.cdma.home.operator.numeric"));

Related

Change SIM country programmatically?

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')
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.

How to ban a specific country from using my app programmatically - android java

so let's say that i want to ban the country X from using my app, i banned it from the google play store but it can still be downloaded via VPN is there a way to ban this country using code (maybe trying to detect the user's location or something?)
my government has a very big problem with a neighboring country and i'll go to jail for like forever if i had users in it.
my government has a very big problem with a neighboring country and i'll go to jail for like forever if i had users in it.
There is no technological way that you can guarantee that your mobile application can't / won't be used by someone in another country. Anything that you do in your application can be defeated by a user with sufficient ingenuity / time.
You need to talk to a good local lawyer to find out precisely what your country's law means, and what you need to do to comply with it1. But if the law requires you to do things that are technically impossible, your safest bet may be to not write / publish any mobile apps. Seriously.
1 - It is unlikely that anyone here really knows. I certainly don't!
Locale.getDefault()
Gives you the locale information about the phone, this information come from settings and can be changed by user
but if you want ensure the user from specific country doesn't use you app just get the GPS position and in case of be that country close it
You can perform multiple checks like does a user's IP match banned country IPs, you can check mobile carrier, you can eventually make location check which of course will require user's permission.

Having problems getting Weight Data with Android from a BLE Scale

I'm currently developing an android app for a weight scale I received that transmits data through bluetooth low energy.
I was looking at documentation and if I got the information correctly, there are specific UUIDs for data. I received a BLE scale with a Chinese protocol document found here: http://www.anj.fyi/protocol.pdf
I found and was able to get a functioning scanner working that lists the device name and the UUIDs it broadcasts.
Lets say I want just the weight data to show up in the UI, nothing else and nothing more.
I don't know what UUID they used for the weight data, and there are a lot of UUIDs. Probably 20+. I checked a UUID compilation and the usual weight data UUID does not show up.
How do I get the data from those UUIDs?
I'm thinking it might be the ones that are notifications, indications or read properties.
Looking at the UUID for example, f000ffc2.
How would I get data from that characteristic? Would anyone have an example code to grab the data from those UUIDs, or tutorials because I'm terribly lost right now.
I really appreciate it.
There are no weight information on the document you list http://www.anj.fyi/protocol.pdf, it is only shows the BLE module hardware interface spec, i.e. it does not specify the detailed service and characteristic.(I an a native Chinese speaker).
Regarding to the UUID you want to know which is the one to represent the weight, yes you are right it should be the read/notification feature without write permission. Can you use the apps e.g. lightblue on iOS to receive the notification(meanwhile change the value on your device) to test it? this will help you to understand which characteristic is the one you want.

find out location of phone based on received sms

I am creating a java application to receive messages on pc using jsms API. Whenever a user sends a particular message to a no, it receives it and adds to the database, the phone number and the area/ region where it belongs.
The region can either be the area where the phone number is registered, or it can also be the current location of the device. Either of these information will help me.
I would be really glad if any one could any one guide me on how to proceed with finding out the region using java code.
Note: I'm not looking for the country. I'm looking for the state/ region. Preferable Indian states.
You could try out libphonenumber. It basically defines the region based on the number.
There is a JavaScript try page here you could perform some tests.

Get device unique ID

Is there a way to get a device's unique identification using MIDP2.0?
I assume you need to get the IMEI number of the device.
According to the information I found there is no J2ME method to do that because the Hardware API is different from a one model to another. But the device manufacturers provide APIs to get the IMEI number.
Have a look on following article.
Get device ID

Categories