android problems with native property_set method
I am trying to use the native property_set method from a java app using jni. I can read the value from the property but i am not able to set it. Do i miss something here? Do i need special rights?
#include <cutils/properties.h>
char key[PROPERTY_KEY_MAX];
char value[PROPERTY_VALUE_MAX];
strncpy(key, "test.rate", PROPERTY_KEY_MAX);
property_get(key, value, "");
int rate = 0;
rate = atoi(value);
TRACE("####### Got %d from property test.rate", rate);
strncpy(value, "15", PROPERTY_VALUE_MAX);
int ret = property_set(key, value);
TRACE("####### property_set(%s)for test.rate, retVal=%d",value, ret);
property_get(key, value, "");
rate = atoi(value);
TRACE("####### Got %d from property test.rate", rate);开发者_运维技巧
returns:
Got 20 from property test.rate
property_set(15)for test.rate, retVal=0
Got 20 from property test.rate
To set the property, your process should have access to that particular type property. You generally get these permission errors in kernel logs. We miss seeing kernel logs most of the time as we perform this setting at User space/JNI and expect errors at user space logcat. you can look at the kernel logs, I am sure it should be throwing some errors.
This is generally controlled in system/core/init/property_service.c
having a structure to add permission to the property variables. will leave it up to you to figure it out further.
The issue is due to property set latency. Wait 1 seconds before getting the property. YOu will get the new set value.
精彩评论