Re: Low level network information?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: Low level network information?

roei.r
Hello,

Is there a way to get the AFRCN in Android lower than 24?

In this code, I see that the output for AFRCN was "0"

Thank you very much,

Roei

On Monday, February 22, 2010 at 5:38:40 PM UTC+2, Joao MG wrote:
( very long post)

After a long interval, back to Android RIL.

I've managed to fetch and parse a GSM Page request from the ril.

Using invokeOemRilRequestRaw method in
com.android.internal.telephony.Phone.

The approach was:

1. retrieve sample raw responses from logcat -b radio

This was done by a small change the method retToString in RIL.java:

} else if (ret instanceof byte[]) {
    byte[] bytes = (byte[]) ret;
    s = IccUtils.bytesToHexString(bytes);

This way the invokeOemRilRequestRaw raw bytes response is written to
the log (converted to an hex string).

2. After reading the log, parse the GSM Page response:

D/RILJ    (  141): [0168]> OEM_HOOK_RAW[0200000000000000]
D/RILJ    (  141): [0168]< OEM_HOOK_RAW
000000003030303200000000000000000000000000000000326400000000000000000000000000000000000032363830310000000000000000000000000000001100000030202d393900000000000000000000000000000030202d393900000000000000000000000000000030202d393900000000000000000000000000000030202d393900000000000000000000000000000030202d393900000000000000000000000000000030202d3939000000000000000000000000000000110000000000000032363830310000000000000000000000000000003538643763626235000000000000000000000000fa050000ff000000ff0000003000000000000000000000000000000000000000ff000000

So the first line is the GSM Page request, the second is the byte
response (both byte arrays converted to hex strings).

So, now we can parse this into meaningful information using:

ByteBuffer bb = ByteBuffer.wrap(bytes);
bb.order(ByteOrder.LITTLE_ENDIAN);

System.out.println("ARFCN: " + bb.getInt());
System.out.println("LAC: " + getStringFromBytes(bb, 20));
System.out.println("RAC: " + getStringFromBytes(bb, 20));
System.out.println("MNC/MCC:" + getStringFromBytes(bb, 20));
System.out.println("RSSI:" + bb.getInt());
System.out.println("Ncell Info1:" + getStringFromBytes(bb, 20));
System.out.println("Ncell Info2:" + getStringFromBytes(bb, 20));
System.out.println("Ncell Info3:" + getStringFromBytes(bb, 20));
System.out.println("Ncell Info4:" + getStringFromBytes(bb, 20));
System.out.println("Ncell Info4:" + getStringFromBytes(bb, 20));
System.out.println("Ncell Info6:" + getStringFromBytes(bb, 20));
System.out.println("RX Quality:" + bb.getInt());
System.out.println("Frequent Hopping:" + bb.getInt());
System.out.println("Last registered network:" + getStringFromBytes(bb,
20));
System.out.println("TMSI:" + getStringFromBytes(bb, 20));
System.out.println("Periodic Location Update Value:" + bb.getInt());
System.out.println("BAND:" + bb.getInt());
System.out.println("Channel In USe:" + bb.getInt());
System.out.println("RSSI 1:" + getStringFromBytes(bb, 20));
System.out.println("Last cell release cause:" + bb.getInt());

The getStringFromBytes method:

private static String getStringFromBytes(ByteBuffer buffer, int
length)
{
   byte[] bytes = new byte[length];
   buffer.get(bytes, buffer.arrayOffset(), 20);
   return new String(bytes);
}

Fortunately HTC FieldTest displays the fields in the exact same order
as their appear in the raw byte response.

The output is something like:

ARFCN: 0
LAC: 0002
RAC: 2d
MNC/MCC:26801
RSSI:17
Ncell Info1:0 -99
Ncell Info2:0 -99
Ncell Info3:0 -99
Ncell Info4:0 -99
Ncell Info4:0 -99
Ncell Info6:0 -99
RX Quality:17
Frequent Hopping:0
Last registered network:26801
TMSI:58d7cbb5
Periodic Location Update Value:1530
BAND:255
Channel In Use:255
RSSI 1:0
Last cell release cause:255

3. Now, to actually execute invokeOemRilRequestRaw

This was accomplished by changing RadioInfo.java (in
com.android.settings, the Settings apps).

I've found no other way to access the Phone. I've tried developing a
new app,
but failed to get a reference to the phone. The following method
fails:

phone = PhoneFactory.getDefaultPhone();

It returns: "PhoneFactory.makeDefaultPhones must be called from Looper
thread".

HTC FieldTest somehow manages to do it, probably because it runs as
system (it shares user id with com.android.phone,
using the sharedUserId attribute in the manifest).

Either way, I've added a bit of code to RadioInfo.java:

byte[] init1;
byte[] init2;
byte[] gsm_page;
byte[] finish;

init1 = hexStringToBytes("0000000008000000010000005f000000");
init2 = hexStringToBytes("0100000000000000");
gsm_page = hexStringToBytes("0200000000000000");
finish = hexStringToBytes("0000000008000000000000005f000000");

phone.invokeOemRilRequestRaw(init1,
mHandler.obtainMessage(EVENT_RAW));
phone.invokeOemRilRequestRaw(init2,
mHandler.obtainMessage(EVENT_RAW));
phone.invokeOemRilRequestRaw(gsm_page,
mHandler.obtainMessage(EVENT_RAW_GSM_PAGE));
phone.invokeOemRilRequestRaw(finish,
mHandler.obtainMessage(EVENT_RAW));

And also changed the mHandler:

case EVENT_RAW:
    ar= (AsyncResult) msg.obj;
    if (ar.exception == null) {
    byte[] bytes = (byte[]) ar.result;
    updateRaw(bytes);
    } else {
    mNeighboringCids.setText("unknown");
    }
    break;
case EVENT_RAW_GSM_PAGE:
    ar= (AsyncResult) msg.obj;
    if (ar.exception == null) {
    byte[] bytes = (byte[]) ar.result;
    updateRawGsmPage(bytes);
    } else {
    mNeighboringCids.setText("unknown");
    }
    break;

And added the methods:

private final void updateRaw(byte[] bytes) {
    mNeighboringCids.append("\n" + bytesToHexString(bytes));
}

private final void updateRawGsmPage(byte[] bytes) {
    ByteBuffer bb = ByteBuffer.wrap(bytes);
    bb.order(ByteOrder.LITTLE_ENDIAN);

    mNeighboringCids.append("\nARFCN: " + bb.getInt());
    mNeighboringCids.append("\nLAC: " + getStringFromBytes(bb, 20));
    mNeighboringCids.append("\nRAC: " + getStringFromBytes(bb, 20));
    mNeighboringCids.append("\nMNC/MCC:" + getStringFromBytes(bb,
20));
    mNeighboringCids.append("\nRSSI:" + bb.getInt());
    mNeighboringCids.append("\nNcell Info1:" + getStringFromBytes(bb,
20));
    mNeighboringCids.append("\nNcell Info2:" + getStringFromBytes(bb,
20));
    mNeighboringCids.append("\nNcell Info3:" + getStringFromBytes(bb,
20));
    mNeighboringCids.append("\nNcell Info4:" + getStringFromBytes(bb,
20));
    mNeighboringCids.append("\nNcell Info4:" + getStringFromBytes(bb,
20));
    mNeighboringCids.append("\nNcell Info6:" + getStringFromBytes(bb,
20));
    mNeighboringCids.append("\nRX Quality:" + bb.getInt());
    mNeighboringCids.append("\nFrequent Hopping:" + bb.getInt());
    mNeighboringCids.append("\nLast registered network:" +
getStringFromBytes(bb, 20));
    mNeighboringCids.append("\nTMSI:" + getStringFromBytes(bb, 20));
    mNeighboringCids.append("\nPeriodic Location Update Value:" +
bb.getInt());
    mNeighboringCids.append("\nBAND:" + bb.getInt());
    mNeighboringCids.append("\nChannel In USe:" + bb.getInt());
    mNeighboringCids.append("\nRSSI 1:" + getStringFromBytes(bb, 20));
    mNeighboringCids.append("\nLast cell release cause:" +
bb.getInt());
}

So when I execute Settings (by calling *#*#4636#*#*) and go to Phone
Information I get, in the mNeighboringCids text field, the GSM Page
data.

I've checked the execution with "logcat -b radio", it's the same as
FieldTest.

Knowing that this works, we can consider changes to the Telephony API
(android.telephony).

The idea is to make this information available, through the framework,
to all apps.

Joao MG

On Feb 8, 9:03 am, Liam Alford <liamjamesalf...@googlemail.com> wrote:


> This thread was dedicated to doing so, but it appears to have gone quiet.
> What info are you after?
>
> On Fri, Feb 5, 2010 at 9:02 PM, Mark Sebik <[hidden email]> wrote:
> > Oh. Thanks. Any luck getting at this info in other ways?
>
> > On Fri, Feb 5, 2010 at 3:10 PM, Liam Alford <[hidden email]> wrote:
>
> >> Its not open source. Its a htc application.
>
> >> On 5 Feb 2010 15:45, "mobot" <[hidden email]> wrote:
>
> >> Has anyone located  the Field Test in the source? Please let me know.
>
> >> On Jan 11, 4:56 am, Ricardo Silva <[hidden email]> wrote:
> >> > I want to, for example, turn off the ...
> >> --
>
> >> You received this message because you are subscribed to the Google Groups
> >> "android-platform" group.
> >> ...
>
> >>  --
> >> You received this message because you are subscribed to the Google Groups
> >> "android-platform" group.
> >> To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="cb6AT_Jv0P8J" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">android-...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> <a href="javascript:" target="_blank" gdf-obfuscated-mailto="cb6AT_Jv0P8J" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">android-platfo...@googlegroups.com<<a href="javascript:" target="_blank" gdf-obfuscated-mailto="cb6AT_Jv0P8J" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">android-platform%2Bunsubscribe@googlegroups.com>
> >> .
> >> For more options, visit this group at
> >><a href="http://groups.google.com/group/android-platform?hl=en" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://groups.google.com/group/android-platform?hl\x3den&#39;;return true;" onclick="this.href=&#39;http://groups.google.com/group/android-platform?hl\x3den&#39;;return true;">http://groups.google.com/group/android-platform?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "android-platform" group.
> > To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="cb6AT_Jv0P8J" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">android-...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > <a href="javascript:" target="_blank" gdf-obfuscated-mailto="cb6AT_Jv0P8J" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">android-platfo...@googlegroups.com<<a href="javascript:" target="_blank" gdf-obfuscated-mailto="cb6AT_Jv0P8J" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">android-platform%2Bunsubscribe@googlegroups.com>
> > .
> > For more options, visit this group at
> ><a href="http://groups.google.com/group/android-platform?hl=en" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://groups.google.com/group/android-platform?hl\x3den&#39;;return true;" onclick="this.href=&#39;http://groups.google.com/group/android-platform?hl\x3den&#39;;return true;">http://groups.google.com/group/android-platform?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/android-platform.
For more options, visit https://groups.google.com/d/optout.