1

I am trying to monitor the "/sys/class/udc" folder by using FileObserver. My app is a system-priv app, so there should not be a permission issue. I am unable to detect the change event.

String path = "/sys/class/udc";
static final int mask = (
    FileObserver.CREATE |
    FileObserver.DELETE |
    FileObserver.DELETE_SELF |
    FileObserver.MODIFY |
    FileObserver.MOVED_FROM |
    FileObserver.MOVED_TO |
    FileObserver.MOVE_SELF
);

public UsbCableDisconncetEvent(String path) {
    super(path, mask);
    Log.d(TAG, "DisconnectEventHandler modified");
}

public void onEvent(int event, String path) {
    Log.d(TAG, "recieved moified event " + event);
}

Does FileObserver support the monitoring of "/sys/class" files?

1 Answers1

3

I am able to find out the answer to my question after going through the Android Framework Code. Those who want to monitor the kernel event(uevent) by using FileObesever can refer to the following code :

private static final String STATE_PATH = "/sys/class/android_usb/android0/state";
public final UEventObserver mUEventObserver = new UEventObserver() {
       @Override
        public void onUEvent(UEventObserver.UEvent event) {
            Log.d(TAG, "USB UEVENT: " + event.toString());
        }
    };
mUEventObserver.startObserving(USB_STATE_MATCH);

You will start receiving events and should be able to see the same in the logs.