最近做手机切换开关机动画,一直累加,但加到第11个开关机动画的时候,发现一个问题,lk和kernel 的logo可以切换,但是动画无法切换。
查找原因:首先nvram的值肯定是写进去了的,不然logo也是无法正常切换的,问题出现在动画切换标志位的地方.
int get_logo_flag()
{
char propVal[PROPERTY_VALUE_MAX];
property_get(BOOT_LOGO_FLAG, propVal, "0");
int propInt = atoi(propVal);
XLOGD("get_logo_flag propInt = %d \n", propInt);
return propInt;
}
这段代码很简单,就是获取字符串放到字符数组中,然后转化成整数。
为了防止出错,特意还写了代码验证过。
再次,问题肯定就出现在BOOT_LOGO_FLAG的property_set的时候。
char logo_flag;
logo_flag = '10';
sprintf(propVal, "%c", logo_flag);
printf("[boot_logo_updater]update logo flag = %s", propVal);
property_set(BOOT_LOGO_FLAG, propVal);
问题就出在这里,logo_flag是char型,如果放两个字符‘10’,肯定获取到的就是后面的0.
把logo_flag定义为字符数组就可以解决问题了。
下面是写的测试代码:
#include <stdio.h>
int main(void) {
// your code goes here
// char c = '10';
char single;
char test[2];
char test1[100];
int i;
single = '157';
test[0] = '0';
test[1] = '9';
i=atoi(test);
printf("single=%c.\n",single);
//printf("i=%d .\n",i);
sprintf(test1,"%s",test);
printf("test1=%s.\n",test1);
return 0;
}