LTE signal ASU level always 97 - android

I am capturing the RSSI values of LTE signals using the below code:
cInfoList = telephony_manager.getAllCellInfo()
for (CellInfo info : cInfoList){
if (info instanceof CellInfoLte) {
CellSignalStrengthLte signalstrength_lte = ((CellInfoLte) info).getCellSignalStrength();
displayAsu.setText(signalstrength_lte.getAsuLevel() + "");
displayDbm.setText(signalstrength_lte.getDbm() + "");
}
}
(*note: I just simplified my code: for-loop doesn't override text fields.)
In one phone (LG G4) I am getting meaningful vales: Asu_level=32, dbm=-108
But in another phone (Samsung Galaxy S6) I am getting invalid values: Asu_level=97, dbm=1022
In Samsung phone's Settings->AboutPhone->Status->SignalStrength I see -107dBm 33 asu (which make sense)
LG G4: Android 5.1, API 22 and
Samsung Galaxy S6: Android 5.0.2, API 21
Why does the same code show different behaviors (Asu levels) on different phones?

The S6 appears to put corrupted signal level values in its CellInfoLte objects (and unset levels in its CellInfoCdma objects). https://github.com/Tombarr/Signal-Strength-Detector is an app which uses reflection to dump out a plethora of signal level related data. On my S6, I can see that SignalStrength (which is the parameter to the PhoneStateListener.onSignalStrengthsChanged callback) includes sane looking mCdmaDbm/mLteRsrp values. It's obviously less convenient and presumably more overhead to create a TelephonyManager listener but it looks like that's what it takes on this device :-/

Related

TrafficStats API's getMobileRxBytes() and getMobileTxBytes() not working properly

The issue is known: when wifi is up, TrafficStats.getMobileRxBytes() and getMobileTxBytes() return 0 since Lollipop (https://issuetracker.google.com/issues/37009612).
I found a workaround ignoring zero values, except that on some devices (e.g Samsung 5G), when on wifi,  we get non-0 values. It brings only rmnet1 interface value traffic (rmnet1 is for VoLTE, rmnet0 for normal data).
1/ why only on Samsung devices? while it seems to be handled by Android OS
2/ another observation still on Samsung 5G devices (at least on Samsung S20): when wifi is down, cell counter (all cell traffic since boot: rmnet0 + rmnet1) is inconsistent, sometime we get a value V1, sometime a value V2 (different from V1)
A similar experience?
I haven't used 5G enabled devices, but as of i know, using NetworkStats.Bucket's object we can query for RxBytes and TxBytes with the help of querySummaryForDevice() which takes around 4 parameters
Connectivity(Mobile data, WIFI)
SubscriberID(here for OS 10+ we need to pass null and for previous versions we need to
pass subscriber id using TELEPHONY_SERVICE).
Starttime
Endtime.
you can get subscriberID using below code
private String getSubscriberId(Context context, int networkType) {
String deviceUniqueIdentifier = null;
if (ConnectivityManager.TYPE_MOBILE == networkType) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return tm.getSubscriberId();
}
return "";
}
This worked for me to get the RxBytes and TxBytes.

Measuring 5G(New Radio) data

List<CellInfo> cellInfoList = telephonyManager.getAllCellInfo();
First, I got total cellInfoList, and separated to CellInfo
cellRSRP = ((CellSignalStrengthNr) ((CellInfoNr) cellInfo).getCellSignalStrength()).getCsiRsrp();
I tried to get 5G RSRP rate for a few days, and this is the best I can approach and this doesn't work.
When It comes to LTE Cell Data,
cellRSRP = ((CellInfoLte) cellInfo).getCellSignalStrength().getRsrp();
It works like this, and It outputs the value well.
The Difference of these two Codes is:
Change CellInfoLte -> CellInfoNr
Additional CellSignalStrengthNr casting
(Because (CellInfoNr) cellInfo).getCellSignalStrength() returns CellSignalStrength,
Not CellSignalStrengthNr.)
(Deliberately casted.)
Is 5G Cell Signal Strength measurement isn't ready by now?
I've spent a lot of time in this problem, but didn't found a single solution.
I have a similar issue and the following casting seems to be working. Unfortunately, there is not possible to test it on real 5g radio in our country.
int mCsiRsrp = ((CellSignalStrengthNr) ((CellInfoNr) cellInfo).getCellSignalStrength()).getCsiRsrp();

Android get MCC + MNC String for neighbouring cells

The mobile country code consists of three decimal digits and the mobile network code consists of two or three decimal digits (for example: MNC of 001 is not the same as MNC of 01) https://en.wikipedia.org/wiki/Mobile_country_code
so to get MCC + MNC as a string how do you get the phone's MCC and MNC in Android? can be used for the main serving cell for an SIM-card slot.
However, instead, I need these values for neighboring cells.
telephonyManager::getAllCellInfo
returns the list of cells where each nicely holds this information (in theory), but I cannot access it.
My current minSdkVersion=26.
getAllCellInfo()!!.mapNotNull { cell ->
when (cell) {
is CellInfoGsm -> {
println(cell.cellIdentity.mcc)
println(cell.cellIdentity.mccString) // only available from 28 onwards
}
}
}
...
Where:
cell.cellIdentity.mcc is deprecated
cell.cellIdentity.mcc returns an int. I.e. I miss any of the leading 0 digits.
How can these be preserved to accurately find the right MCC/MNC?
You can use new mccString method only for Android 28 and above. On older API there is no way to get distinct representations for "01" and "001". However these values should be used only for testing purposes and should not be encountered in real life. So, you can just suppress deprecation for mcc.
telephonyManager.allCellInfo.forEach { cell ->
if (cell is CellInfoGsm) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
println(cell.cellIdentity.mccString)
} else {
#Suppress("DEPRECATION")
println(cell.cellIdentity.mcc)
}
}
}

Android microphone constantly gives 32639 or -32640 on newer devices

I've implemented code similar to this. I have a noise alert go off in the Log, but it always gives 32639 or -32640 regardless of what kind of noise is going on outside.
short[] buffer = new short[minSize];
boolean thresholdMet = false;
int threshold = sliderThreshold.getProgress();
ar.read(buffer, 0, minSize);
//Iterate through each chunk of amplitude data
//Check if amplitude is greater than threshold
for (short s : buffer) {
if (Math.abs(s) > threshold) {
thresholdMet = true;
Log.w("NoiseThreshold", String.valueOf(s));
break;
}
}
I've tested it on three phones (none of which are rooted):
Samsung Galaxy S3(API 19)
HTC One M9(API 23)
Samsung Galaxy S7(API 24)
It works on the S3, but not the others. I've tried using Sensor Sense on the HTC and it doesn't work for the mic sensor. However, it used to work, and now seems to detect one sample every five seconds or so in the graph view.
Oddly enough, the microphone still works fine for phone calls and video recording on the malfunctioning phones.
You said it works on S3, which is API 19 and doesn't on those with API>=23. So, it's possible that you have a problem with runtime permissions introduced in API 23.
New behaviour (for "old apps" which use static permission model) is to return dummy data if runtime permission is not granted.
Check out this answer:
Request permission for microphone on Android M

TrafficStats.getMobileRxBytes() and TrafficStats.getMobileTxBytes() always return 0 in Nexus 5x

I am trying to fetch mobile data usage using TrafficStats.
Example:
mobileDataUsage = TrafficStats.getMobileRxBytes() +TrafficStats.getMobileTxBytes()
totalUsage = TrafficStats.getTotalRxBytes() + TrafficStats.getTotalTxBytes()
In few devices it is working absolutely fine. In Nexus 5X I am getting totalUsage but mobileDataUsage is always 0, TrafficStats.getMobileRxBytes() and TrafficStats.getMobileTxBytes() always return 0.
You most probably are seeing the issue described at https://code.google.com/p/android/issues/detail?id=78924 .
The docs for TrafficStats says the bytes returned "always increases monotonically since device boot", but that is indeed not the case for at least Android 5-7. Often the methods return 0 and then suddenly start counting from the number they used to have.

Categories

Resources