我正在使用 Android 作为操作系统的 TI OMAP 平台上工作。对于一个用例,我们必须切换设备中的 LED 之一。 LED 有许多“设备属性”,我们想从应用层 [.java] 读取“设备属性”。

当我们在 adb 提示符下运行 cat 命令时:

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

我们得到错误“长度无效”。因此,我想知道是否有一种方法可以读取“设备属性”,以便应用程序层也可以访问它。

我在另一个论坛 http://android.modaco.com/topic/312770-possible-solution-for-lack-of-notification-light-developers-needed 上发现了一个类似的问题,但也没有得到解答。

感谢您的回复!!!

解决方案
该设备只有“set_device_attribute”,但由于缺少“get_device_attribute”,当对该设备属性发出“读取”命令时,我们遇到了“长度无效”的问题。

我添加了一个名为的新 API:
static ssize_t get_device_attribute(struct device *dev, struct device_attribute *attr,
char *buf)
{
 .........................
 .........................
 .........................
}

并更新了设备属性
static DEVICE_ATTR(device_property, 0777,get_device_attribute, set_device_attribute);

最佳答案

无效长度通常表示目录。尝试 cd 进入最后一个“device_attribute”。

或者,您还可以在“/proc”中搜索设备信息。

关于Android - 读取 "device attribute"失败,错误为 "invalid length",我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7306202/

10-11 22:21
查看更多