Using QProcess Sending command "ifconfig eth0 up" in Android 7.1 causes error
-
Dear All,
I'm using QT5.9 on my Windows to build the app for my other arm-based device which is Android 7.1.
Please refer to the below code. While I sending the command "ifconfig eht0 down",Process::executeProcessSync(QString("sh"),QStringList()<<"-c"<<"ifconfig eth0 down",&wifi_client_scipt_M);
It would give the error like below.
ifconfig: ioctl 8914: Operation not permitted
However, if I only send the command
ifconfig
, I success.
Also, I tried to execute the command directly from the terminal, It success.Is the right of the QT not enough to use the command
ifconfig eth0 down
?
Or any other possibility that could cause this issue?
How can I solve it?Thanks in Advanced!
-
Hi,
As what user are you running ipconfig on your Android device ?
As what user is your Qt application run ? -
@victor-wang said in Using QProcess Sending command "ifconfig eth0 up" in Android 7.1 causes error:
How can I solve it?
root your device or use the corresponding native Android API
-
@SGaist
Thanks for the reply.
As what user are you running ipconfig on your Android device ?
=> I used root to run ipconfig
As what user is your Qt application run ?
=>Probably with the non-root. For this situation, how can I run my app with root access? -
@raven-worx
Thanks for the reply.
My device has already root access. Is there any corresponding native Android API in the QT library?
If yes which should I use? -
@victor-wang
Does your app have the Internet permission set?
Also note that Android is very vendor specific, meaning that while it works on one device it might not work on another device, because of vendor specific modifications, etc. -
@raven-worx
I don't think it has.
Maybe I have to add something in Android.mk to set the user as a system for my Application? -
@victor-wang
you would need to add the permission your AndroidManisfest.xml, or maybe even not when executing it as root, i can't tell. simply give it a try.Anyway, first try if your command works as root with adb shell:
adb shell "su -c 'ifconfig eth0 down'"