hjsblogger
hjsblogger

Reputation: 225

Android - Read "device attribute" fails with error "invalid length"

I am working on the TI OMAP platform with Android as the operating system. For one UseCase, we have to toggle one of the LED's in the device. The LED has number of "Device Attributes" and from the Application Layer [.java], we want to read a "Device Attribute".

When we do run the cat command on the adb prompt:

# cat /sys/devices/device_name/device_attribute
# device_attribute:invalid length

We get the error "invalid length". Hence, I wanted to know is there a way to read a "Device Property" such that it is accessible to the App Layer as well.

I found a similar question on another forum http://android.modaco.com/topic/312770-possible-solution-for-lack-of-notification-light-developers-needed but it was also unanswered.

Thanks for the replies !!!

Solution The device was only having "set_device_attribute" but since "get_device_attribute" was missing, we were getting "invalid length" issue when "read" command to that device property was issued.

I added a new API named:

static ssize_t get_device_attribute(struct device *dev, struct device_attribute *attr,
char *buf)
{
 .........................
 .........................
 .........................
}

and updated the device attribute

static DEVICE_ATTR(device_property, 0777,get_device_attribute, set_device_attribute);

Upvotes: 4

Views: 2040

Answers (2)

stdcall
stdcall

Reputation: 28900

You probably have the Linux kernel source code, search the particular sysfs implementation of the device, see how it was programmed.

Upvotes: 0

Dyonisos
Dyonisos

Reputation: 3549

invalid length often indicates a directory. Try to cd into the last "device_attribute".

Alternativeley you can also search for device info in "/proc".

Upvotes: 2

Related Questions