有三个方法:
1.在init.rc中提权 chmod 777 /dev/ttyUSB0
2.在device.c中提权限,这个比较隐蔽,不易发现,详细可以参考我的blog:http://blog.csdn.net/yiyaaixuexi/article/details/6803593
3.每次都在java层去提权,cmd为提权命令public void exeShell(String cmd){
try{
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader in = new BufferedReader(
new InputStreamReader(
p.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
Log.i("exeShell",line);
}
}
catch(Throwable t)
{
t.printStackTrace();
}
}
1.在init.rc中提权 chmod 777 /dev/ttyUSB0
2.在device.c中提权限,这个比较隐蔽,不易发现,详细可以参考我的blog:http://blog.csdn.net/yiyaaixuexi/article/details/6803593
3.每次都在java层去提权,cmd为提权命令public void exeShell(String cmd){
try{
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader in = new BufferedReader(
new InputStreamReader(
p.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
Log.i("exeShell",line);
}
}
catch(Throwable t)
{
t.printStackTrace();
}
}
第二种 我在system里找了 没有core...
/system # ls
bin
build.prop
media
app
framework
fonts
xbin
usr
busybox
etc
lib 第三种我也试过,我用了你的函数 加了cmd=chmod 777 /dev/ttyUSB0 可是还是没用。exec能识别这条命令吗?弄这个弄了好几天了 郁闷啊 求大神指教
原来LZ的需求是这个……我误会了,是这个意思~ 9L +1
1.如果系统运行时热插入usb转串口就不行了
2.这是唯一标准的做法:内核检测到设备插入发出uevent通知用户层--->用户层init进程收到uevent创建设备节点并赋予权限
3.chmod本身就需要root权限,java层木有,就算有这段代码加进去也奇怪
怎么在板子上运行monitor,不懂 求指教 。。