Re: Create a socket in android code(not in android application) getting Permission Denied

1,014 views
Skip to first unread message

Jim Challenger

unread,
Mar 9, 2013, 1:00:00 PM3/9/13
to android-...@googlegroups.com
Just an update. I was told by someone on SO to try to compile the source code as a superuser which supposedly would fix my problem. The instructions are a little unclear though. Does anyone know if this will work or does anyone have instructions on how to go about doing this?

Thank you,
Jim

On Friday, March 8, 2013 3:58:01 PM UTC-5, Jim Challenger wrote:
I posted this on stack overflow, but wasn't appearing to have any luck. I think this might be the place to ask this kind of question.

I am trying to open a socket in the android source code. Specifically, right now, I am in the DisplayDevice.cpp file, but the location of the socket code may change. Right now after I do:

int fd = socket(AF_INET, SOCK_STREAM, 0);

fd gets returned as -1, and when i check the error message it is listed as Permission Denied. I have looked around a lot for this, most answers involve adding the internet permission to the AndroidManifest file. This will not work for me as the code I am adding is inside of the android source code.

I was wondering if there is a way to bypass the permission denied. Or if there is a better way to do this/ a different type of socket to use.

I also was looking at this other post from the google group:

https://groups.google.com/forum/?fromgroups=#!searchin/android-platform/socket/android-platform/WYYUdzprRw4/POYIC4NQyMoJ

It seemed to be related to what I am trying to do, but I wasn't sure what to follow up with. I see people mentioning modifying init.rc or  trying to set the permissions ahead of time, but was confused on how to go forward. Any help at all or a point in the right direction would be great!

Thank you,

Jim

Jim Challenger

unread,
Mar 11, 2013, 3:37:33 PM3/11/13
to android-...@googlegroups.com
I am now running a custom Android build. We have edited code in various files including DisplayDevice and have recompiled the code. In case anyone was wondering how to open a socket. I have figured out a mostly working solution. We modified code in the init folder to create a socket when everything is initialized similar to how the Android code creates the sockets of type AF_UNIX. We create our sockets through commands in the init.rc file and these socket descriptors are saved in environment variables with similar names to the other sockets(like ANDROID_SOCKET_zygote). 

The issue we have now is that I am unable to get access to the env variable in the code(specifically in DisplayDevice). If I am on the command line and run "adb shell printenv" I can see the environment variable I created. However, when in the code, I am unable to find the same env variable using getenv(). Does anyone know why this could be an issue?

Thanks

On Saturday, March 9, 2013 1:05:49 PM UTC-5, John P Masseria wrote:
Are you saying that you have recompiled surfaceflinger?  Are you running a custom Android or one with just surfaceflinger modified?

Anup Kulkarni

unread,
Mar 30, 2013, 1:06:28 PM3/30/13
to android-...@googlegroups.com

This could be some issue related to shell.

To debug how about adding this line to your code in DisplayDevice -

system("printenv > /tmp/env_in_my_code");

And later check the file by cat /tmp/env_in_my_code to see your env var is there or not.

Also, Instead of storing the fd in env variable can you try storing it in some file in /tmp and read the file back in DisplayDevice.

Thanks
Anup

--
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 android-platfo...@googlegroups.com.
To post to this group, send email to android-...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-platform?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

ajay bukan

unread,
Sep 1, 2014, 1:04:46 PM9/1/14
to android-...@googlegroups.com
HI I am stuck in same situation Can you please help me
in order to pass AF_INET socket what changes i have to do?
can you give me some hint regarding this
it will be appreciated
Thanks 
Reply all
Reply to author
Forward
0 new messages