I have SABRE-AI development board and I've installed Android operating system on it. I am developing an Android application which will interface with CAN bus through FlexCAN support on Kernel. As mentioned here, How to use FlexCAN in Android, Android BSP provided by Freescale comes with FlexCAN support in kernel space with SocketCAN drivers. SocketCAN extends the classical Berkeley sockets API by introducing a new protocol family for interfacing CAN networks. Therefore, starting/stopping or configuring an existing CAN interface can be realized by using 'iproute2' utilities on command line. After that it is possible to use FlexCAN in Android by using the classical socket programming techniques in application code. However, I also want to configure and start an existing CAN interface in my application code. The only solution I've come up is that I can invoke those system commands in my application code. But it requires root access and I couldn't manage how to do it.
Following command should be run in command line in order to start can0 interface with 125kbit rate. And, it perfectly works if I run it manually in a shell window.
ip link set can0 up type can bitrate 125000
I am running following code in my application to do same thing;
Process p = Runtime.getRuntime().exec("ip link set can0 up type can bitrate 125000");
But process p gives an error that "RTNetlink answers: Operation not permitted." I have also tried to execute it under "su" process but it didn't work. Signing the application with platform keys also didn't resolve my issue. Do you have any ideas how to invoke a system command in application code for Android?
Btw, I rebuilt the linux-can-utils binaries for Android using the Android native development kit and imported them to my SABRE-AI board. I can successfully send and receive CAN messages by invoking those binaries in my application code once I configure and start the interface manually on a shell window before running my application.