I'm developping an app which may send sensitive data and I want to be sure that i don't send them on a public or weak protected network.
That's why I'd like to get the current security used on wifi network on Android.
I found this post but I'm not sure of the accuracy of the solution.
Indeed, the allowedKeyManagement method seems to return the supported protocols, but it's not explicitely said to return the current active protocol beeing used.
Is there a sure way to get the effective protection used on the cirrent wifi network ?
Thanks
I can suggest one method
Get list of all configured network using getConfiguredNetworks API
Loop through all entries and find the current Network using WifiConfiguration.status API. The status should be CURRENT for current network
For that current network, get the allowedKeyManagement and check that it is not NONE.
Related
I want to get the PCI of both primary serving cell and secondary serving cell in 5G NSA, but it seems that I cannot get what I want using getAllCellInfo(). It seems that I need to parse the physical channel configuration as below:
{{mConnectionStatus=PrimaryServing,...,mRat=LTE,...,mPhysicalCellId=123},
{mConnectionStatus=SecondaryServing,...,mRat=NR,...}
Does anyone know how to get the (real-time) configuration? Or can I get the PCIs in another way? Thanks very much!
About PhysicalChannelConfig
The only possible way how to obtain PhysicalChannelConfig is via TelephonyManager.registerTelephonyCallback method. You can for example pass an instance of TelephonyCallback.PhysicalChannelConfigListener and you'll start obtaining what you need.
Please note that permission Manifest.permission.READ_PRECISE_PHONE_STATE is required, so your app needs to be a system app of carrier-privileged app.
There were some attempts to adjust this protection level, current status can be seen here. But as of Android 12 there's no way how to get PhysicalChannelConfig if you are a regular developer.
About PCIs
You can sometimes get PCIs of serving LTE and NR NSA cells via getAllCellInfo() as you mentioned. Sometimes there's one instance of CellInfoNr with PCI is present. This behaviour is device-specific.
Generally speaking - Android does not provide any official API you request.
The method to getConfiguredNetworks has now been deprecated in Android Q. I was using this feature in order to determine whether a Wifi network has any security such as WifiConfiguration.KeyMgmt.WPA_EAP. All of these are now deprecated and i am not sure whether there is any alternative. Google suggests to use WifiNetworkSpecifier.Builder#build() but this is for connecting to new network, not for my use case.
WiFi scanning allows you to get the list of networks in range.
Then you can parse ScanResult.capabilities, which should - among others - contain the encryption info of the network (WPA/WPA2/etc).
Granted, it would be more convenient to have a proper object rather than a string, but here we are.
I am trying to read the Preferred network type setting from the device. But nowhere android API's are available.
Use case:
Trying to read the Preferred network type and connected network type so that if the device has LTE enabled and the user is forcefully switched back to the lower network(3G,2G); then there should be a notification sent to the user.
I have checked the system setting code, But it's deprecated.
Settings.Secure.getString(getApplicationContext().getContentResolver(),
Settings.System.NETWORK_PREFERENCE);
Is there any alternate way to read the system secured settings(By reflection?).
And Also is it possible to write back the setting with the user permission?
Help is much appreciated.
I think the right code is:
Settings.Global.getString(context.getContentResolver(),Settings.Global.NETWORK_PREFERENCE)
I am building an android app that exchanges data with our server through http api calls. In many cases users are complaining that the app is slow or doesn't work at all.
The most common cause of that is bad network connectivity (low 3g/wifi signal or congested public wifi).
What is the best way to detect bad connections? Once i can detect bad connectivity an icon or toast message can be used to inform the user about the situation.
I am using HttpUrlConnection for the api calls.
I think you can make use of ConnectivityManager. Call getActiveNetworkInfo() and then call getDetailedState() on the NetworkInfo object received. You can check the state of the connection and whether it is VERIFYING_POOR_LINK, though I don't know in which conditions this state is active.
Also you might want to listen to network changes as described in Detect Connection Changes.
I'd probably use latency. Save the time when you get the request, and when the request finishes. If you're seeing numbers that are too high, pop up the warning. If you're downloading large files, you may wish to switch to throughput (how many kbps you're transfering).
as far as i remember http is "connectionless"..
you should try concentrating on minimizing the size of your traffic.. (compress, divide.. etc)
if you really want to test connectivity i guess you should do pings.. every x seconds.. then if the ping is bad you could warn the user..
In my Android application I first get the users location using either GPS, the GSM network or a text value that is manually input via a Settings screen.
At first I used the Geocoder class to get the users locale with latitude and longitude provided by GPS or GSM but it seemed unreliable, now I used Google's web API to get the locale by making a HTTP request and parsing the XML document returned. This is using the following URL:
http://maps.googleapis.com/maps/api/geocode/xmllatlng=blahblahlat,blahblahlong&sensor=true
After getting the users locale I then send another HTTP request to free.worldweatheronline.com's weather API and parse the XML returned. With a stable internet connection the application runs fine, however my house has a rubbish signal and even worse mobile data connection.
I am aware there is a simple method to check if the device has a mobile data connection, however what I want to know is whether there is a way of measuring the signal strength as the problem arises when there is a connection, but it is too bad to successfully run. For example, if there is a way to get mobile data signal strength which returns a value from 0 (no signal) to 100 (full signal), I can then only carry out the location and weather retrieval if signal strength is above a certain amount.
Would it be best to just surround the location and weather retrieval code with a try/catch so it doesn't cause a runtime exception, allowing it to just fail gracefully then update when a better signal is acquired? Any ideas on how to accomplish this, or any other suggestions to make my app more friendly for users with bad signal?
Thanks in advance!
You can check it but remember to handle, in any case, drop of connections.
In my apps I had some problems while writing files or stuff like that with an open connection, so just remember that a fail may always occur (for example switching from gprs to wifi).
If you can easily check the signal strength I would do both.
Give a look at the SignalStrength class (never used it btw). Here a nice explanation.
You can check cell service signal strength by creating a PhoneStateListener and handle the onSignalStrengthChanged callback. For more info look at this question How to get cell service signal strength in Android?
EDIT :
You can pause PhoneStateListener by calling telephony.listen(listener, PhoneStateListener.LISTEN_NONE); to not receive updates when you don't need them.