system/corennnnn
修订版 | 8cca0a3855239e3503f861d35ab9ec108ac66123 (tree) |
---|---|
时间 | 2010-02-27 16:12:48 |
作者 | Chih-Wei Huang <cwhuang@linu...> |
Commiter | Chih-Wei Huang |
patch from Yi Sun to fix power status issue
@@ -28,7 +28,7 @@ extern "C" { | ||
28 | 28 | ** WARNING: system/bionic/include/sys/system_properties.h also defines |
29 | 29 | ** these, but with different names. (TODO: fix that) |
30 | 30 | */ |
31 | -#define PROPERTY_KEY_MAX 32 | |
31 | +#define PROPERTY_KEY_MAX 128 | |
32 | 32 | #define PROPERTY_VALUE_MAX 92 |
33 | 33 | |
34 | 34 | /* property_get: returns the length of the value which will never be |
@@ -21,6 +21,7 @@ | ||
21 | 21 | |
22 | 22 | #include <sys/types.h> |
23 | 23 | #include <sys/socket.h> |
24 | +#include <cutils/properties.h> | |
24 | 25 | |
25 | 26 | #include "vold.h" |
26 | 27 | #include "uevent.h" |
@@ -214,16 +215,31 @@ static void free_uevent(struct uevent *event) | ||
214 | 215 | } |
215 | 216 | free(event); |
216 | 217 | } |
218 | +/* | |
219 | + * This function can not find correct parameter for certain cases | |
220 | + * for example, if you have xxx_bla and xxx, you will have no way | |
221 | + * to know whether xxx_bla or xxx will be matched. | |
222 | + * So to solve this issue, try to match with "=" | |
223 | + */ | |
224 | + | |
217 | 225 | |
218 | 226 | static char *get_uevent_param(struct uevent *event, char *param_name) |
219 | 227 | { |
220 | 228 | int i; |
229 | + char buf[MAX_UEVENT_NAME_LEN]; | |
221 | 230 | |
222 | 231 | for (i = 0; i < UEVENT_PARAMS_MAX; i++) { |
223 | 232 | if (!event->param[i]) |
224 | 233 | break; |
225 | - if (!strncmp(event->param[i], param_name, strlen(param_name))) | |
226 | - return &event->param[i][strlen(param_name) + 1]; | |
234 | + if (strlen(param_name) >= (MAX_UEVENT_NAME_LEN-1)) { | |
235 | + LOGE("%s: the size of %s is to big\n", __FUNCTION__, param_name); | |
236 | + break; | |
237 | + } | |
238 | + memcpy(buf,param_name,strlen(param_name)); | |
239 | + buf[strlen(param_name)] = '='; | |
240 | + buf[strlen(param_name)+1] = '\0'; | |
241 | + if (!strncmp(event->param[i], buf, strlen(buf))) | |
242 | + return &event->param[i][strlen(buf)]; | |
227 | 243 | } |
228 | 244 | |
229 | 245 | LOGE("get_uevent_param(): No parameter '%s' found", param_name); |
@@ -239,11 +255,26 @@ static char *get_uevent_param(struct uevent *event, char *param_name) | ||
239 | 255 | static int handle_powersupply_event(struct uevent *event) |
240 | 256 | { |
241 | 257 | char *ps_type = get_uevent_param(event, "POWER_SUPPLY_TYPE"); |
258 | + char name[PROPERTY_VALUE_MAX]; | |
259 | + int nlen ; | |
260 | + int ps_cap; | |
261 | + int ps_cap_full = 0; | |
262 | + float cap; | |
263 | + int capacity; | |
242 | 264 | |
243 | 265 | if (!strcasecmp(ps_type, "battery")) { |
244 | - char *ps_cap = get_uevent_param(event, "POWER_SUPPLY_CAPACITY"); | |
245 | - int capacity = atoi(ps_cap); | |
246 | - | |
266 | + property_get(POWER_UEVENT_NAME_CHARGE_NOW,name, "POWER_SUPPLY_CAPACITY"); | |
267 | + ps_cap = atoi(get_uevent_param(event, name)); | |
268 | + nlen = property_get(POWER_UEVENT_NAME_CHARGE_FULL, name, NULL); | |
269 | + if (nlen > 0) | |
270 | + ps_cap_full = atoi(get_uevent_param(event, name)); | |
271 | + if (ps_cap_full) { | |
272 | + cap = (ps_cap/ps_cap_full)*100; | |
273 | + capacity = (int)cap; | |
274 | + } else | |
275 | + capacity = ps_cap; /* G1 battery */ | |
276 | + | |
277 | + LOGE("%s: current cap:%d\n", __FUNCTION__, capacity); | |
247 | 278 | if (capacity < 5) |
248 | 279 | low_batt = true; |
249 | 280 | else |
@@ -18,4 +18,8 @@ | ||
18 | 18 | #ifndef _UEVENT_MSG_H |
19 | 19 | #define _UEVENT_MSG_H |
20 | 20 | |
21 | +#define MAX_UEVENT_NAME_LEN 512 | |
22 | +#define POWER_UEVENT_NAME_CHARGE_NOW "ro.power_supply.uevent.name.capacity.now" | |
23 | +#define POWER_UEVENT_NAME_CHARGE_FULL "ro.power_supply.uevent.name.capacity.full" | |
24 | + | |
21 | 25 | #endif |