1

After I connect a USB network adapter to the phone I can configure it using ifconfig:

ifconfig eth0 up 192.168.1.2

Problem is that eth0 is not aviable until the USB device is connected. How can store the network config or apply it as soon as it's mounted?

Or is there any way I can set the config in kernel build process?

I know this is normally defined in ifcfg-eth0 that can be found in /etc/sysconfig/network-scripts/ or /etc/network/interfaces but it looks like android does not have this. As we use netcfg in android I looked up the netcfg profiles manual but /etc/network.d/${profile_name} also does not exist.

2

I thing this will work:

In /init.rc add

service ethernet /eth0.sh

and create /eth0.sh

#!/system/bin/sh

netcfg eth0 up 192.168.0.2

Still got problems chainging the ramdisk but that should work.

See http://elinux.org/Android_Networking


I was not able to change the ramdisk so I made a simple app the does run the netcfg command after boot and after USB device is attached.

Here are the key points for this:

<manifest ...
  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
  <uses-feature android:name="android.hardware.usb.host" />
  <uses-permission android:name="android.permission.USB_PERMISSION" />
  <application ... >
    <receiver
        android:name=".MyBroadcastReceiver"
        android:enabled="true"
        android:exported="true" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
        </intent-filter>
    </receiver>
...

and the sudo function in the receiver:

public static void sudo(String...strings) {
    try{
        Process su = Runtime.getRuntime().exec("su");
        DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());

        for (String s : strings) {
            outputStream.writeBytes(s+"\n");
            outputStream.flush();
        }

        outputStream.writeBytes("exit\n");
        outputStream.flush();
        try {
            su.waitFor();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        outputStream.close();
    }catch(IOException e){
        e.printStackTrace();
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.