Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Connect to rild Socket

Tags:

android

ril

I'm trying to write an app to talk to the rild. And Yes, I know this is not politically correct, but it's an embedded industrial telemetry app so I'm not concerned about user experience, portability and all that stuff.

The problem is that when I try to connect, I get a java.io "Permission denied" exception. Can anybody help me?

The phone (Nexus One) is rooted with Cyanogenmod 7 and the app is running as superuser using the "SuperUser" app from Market.

My Code (abbreviated):

try {
  mSocket = new LocalSocket();
  mSockAddr = new LocalSocketAddress( "rild", LocalSocketAddress.Namespace.RESERVED );
  mSocket.connect( mSockAddr );
}
catch( Exception e ) {
  dbg.p( "connect failed: "+e );
}

I see the rild (and rild-debug) sockets in /dev/socket.

srw-rw----    1 root     radio            0 Feb 13 19:14 rild
srw-rw----    1 radio    system           0 Feb 13 19:14 rild-debug

Could it be that the Dialer app is already connected and hogging the socket?

BTW I initially tried to use the frameworks but got a humongus boatload of errors mostly about java and and third party classes unknown, so I gave up after days of hair-pulling. I've also STFW and this site - lot's of dancing around the issue but no concrete advice.

Any help greatly appreciated. -John

like image 793
DontPanic Avatar asked Feb 15 '12 18:02

DontPanic


2 Answers

On the java end of the rild socket is an instance of com.android.internal.telephony.RIL.java, which is owned by com.android.phone.PhoneApp.java. PhoneApp is a persistent app which, not surprisingly, provides the phone functionality. Disabling PhoneApp should kill any java-side use of the rild socket.

You also might want to try connecting to "rild-debug", which is unused (but may be ignored by the ril-daemon).

BTW - You can see the comms between the RIL layers by doing logcat -b radio.

Please post back if you come up with a workaround.

like image 69
Cesar Maiorino Avatar answered Nov 15 '22 20:11

Cesar Maiorino


In recent versions of Android (and, likely, in the earlier versions), rild-debug is not meant to accept a full range of commands; only predefined commands are accepted.

Check out ril.cpp here;

static void debugCallback (int fd, short flags, void *param)
...

    case 0:
        LOGI ("Connection on debug port: issuing reset.");
        issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0);
        break;
    case 1:
        LOGI ("Connection on debug port: issuing radio power off.");
        data = 0;
        issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int));
        // Close the socket
        close(s_fdCommand);
        s_fdCommand = -1;
        break;

UPD: also, RIL requests are incrementally numbered and it's very easy to effectively break the ril/phoneapp pairing by issuing an out-of-the-series event.

like image 31
kagali-san Avatar answered Nov 15 '22 19:11

kagali-san