在Android代码中创建一个套接字(不是在android应用程序中)获取权限被拒绝 [英] Create a socket in android code(not in android application) getting Permission Denied

查看:220
本文介绍了在Android代码中创建一个套接字(不是在android应用程序中)获取权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在android源代码中打开一个套接字。具体来说,现在,我在DisplayDevice.cpp文件中,但套接字代码的位置可能会更改。现在我做后:

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返回为-1,当我检查错误消息时,它被列为Permission Denied。我已经查找了很多这方面,大多数答案涉及到添加互联网权限到AndroidManifest文件。这将不是为我工作,因为我添加的代码是在Android源代码。

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(right now I am using sockets from

谢谢。

推荐答案

很自然,你得到 Permission Denied 错误, t有正确的权限:)。请查看 Android权限模式

It is quite natural that you get Permission Denied error. This is simply because you don't have correct permission :). Check out android permission model!

假设一个场景像操作系统中的普通用户,并且你编写一个程序试图打开一个像你的套接字。

Imagine a scenario like a normal user in an operating system and you write a program which tries to open a socket like yours. You would most probably face the same problem, depending on where the named socket is to be created.

由于您在 DisplayDevice.cpp (从源代码编译android),您可以有兴趣以超级用户编译源代码。 这里是由 m-ric (我从来没有测试过它)。

As you are trying to create the socket in DisplayDevice.cpp (compiling android from the source), you may be interested in compiling the source as a superuser. Here is a solution posted by m-ric (I have never tested it).

一些有用的指针/引用在类似的方向,主题是:

Some useful pointers/references in similar direction and which I found useful during research on this enthralling topic are:


  1. http://android.stackexchange.com/questions/18857/how-to-build-compile-su-from-source

  2. execv command => http: //code.google.com/p/superuser/source/browse/trunk/su/su.c?r=2#169

  3. https://github.com/ChainsDD/su-binary

  4. http://e2e.ti.com/support/omap/ f / 849 / p / 178679 / 648158.aspx#648158

  5. 来自Google I / O 2011的影片 http://www.youtube.com/watch?v=5yorhsSPFG4

  1. http://android.stackexchange.com/questions/18857/how-to-build-compile-su-from-source
  2. execv command => http://code.google.com/p/superuser/source/browse/trunk/su/su.c?r=2#169
  3. https://github.com/ChainsDD/su-binary
  4. http://e2e.ti.com/support/omap/f/849/p/178679/648158.aspx#648158
  5. A video from Google I/O 2011 http://www.youtube.com/watch?v=5yorhsSPFG4

这篇关于在Android代码中创建一个套接字(不是在android应用程序中)获取权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆