Android各个平台下的serialno的设置流程,并⽤cpu串号固定
制作android软件流程serialno以。。。
⼀、:
A33 Android4.4平台的序列号,可以通过设置->关于平板电脑->状态信息→序列号 进⾏查看,也可以通过adb指令getprop ro.serialno 进⾏查看。
A33 Android4.4固定序列号的⽅法为通过获取CPU串号,根据CPU串号换算出⼀个设备序列号,再写⼊到设备⾥,具体的源码如下:system/core/init/init.c
static void export_kernel_boot_props(void)
{
char tmp[PROP_VALUE_MAX];
char cpuinfobuf[1024] = {0};
int ret;
unsigned i;
struct {
const char *src_prop;
const char *dest_prop;
const char *def_val;
} prop_map[] = {
{ "ro.boot.serialno", "ro.serialno", "", },
{ "de", "ro.bootmode", "unknown", },
{ "ro.boot.baseband", "ro.baseband", "unknown", },
{ "ro.boot.bootloader", "ro.bootloader", "unknown", },
};
get_cpu_id(cpuinfobuf, sizeof(cpuinfobuf));//louhn:获取CPU串号
i = 0;
property_set(prop_map[i].dest_prop, cpuinfobuf); //louhn:根据CPU串号设置ro.serialno
for (i = 1; i < ARRAY_SIZE(prop_map); i++) {
ret = property_get(prop_map[i].src_prop, tmp);
if (ret > 0)
property_set(prop_map[i].dest_prop, tmp);
else
property_set(prop_map[i].dest_prop, prop_map[i].def_val);
}
ret = property_get("sole", tmp);
if (ret)
strlcpy(console, tmp, sizeof(console));
... ...
}
⼆、:
A33 Android6.0/MS8909 Android7.1平台的序列号,可以通过设置->关于平板电脑->状态信息→序列号 进⾏查看,也可以通过adb指令getprop ro.serialno 进⾏查看。
A33 Android6.0/MS8909 Android7.1固定序列号的⽅法为通过获取ro.boot.serialno的值,如果ro.boot.serialno的值存在则把这个值也赋给 ro.serialno,如果不存在,则为空
⽽ro.boot.serialno的值是在uboot上通过getenv("sunxi_serial")获取的
具体的源码如下:
system/core/init/init.cpp
static void export_kernel_boot_props() {
struct {
const char *src_prop;
const char *dst_prop;
const char *default_value;
} prop_map[] = {
{ "ro.boot.serialno", "ro.serialno", "", },
{ "de", "ro.bootmode", "unknown", },
{ "ro.boot.baseband", "ro.baseband", "unknown", },
{ "ro.boot.bootloader", "ro.bootloader", "unknown", },
{ "ro.boot.hardware", "ro.hardware", "unknown", },
{ "vision", "ro.revision", "0", },
};
for (size_t i = 0; i < ARRAY_SIZE(prop_map); i++) {
char value[PROP_VALUE_MAX];
int rc = property_get(prop_map[i].src_prop, value);
property_set(prop_map[i].dst_prop, (rc > 0) ? value : prop_map[i].default_value);//如果ro.boot.serialno有值,则把这个值赋给ro.serialno,⽽ro.boot.serialno是 }
}
由于A33 Android6.0系统有出现serialno相同的情况,这⾥我对serialno的设定进⾏了修改,与A33 Android4.4保持⼀致,⽤CPU串号
去固定serialno,修改⽅法如下:
diff --git a/android/system/core/init/init.cpp b/android/system/core/init/init.cpp
index 671580a003..8169fbda01 100755
--- a/android/system/core/init/init.cpp
+++ b/android/system/core/init/init.cpp
@@ -794,6 +794,8 @@ static void import_kernel_nv(char *name, bool for_emulator)
}
static void export_kernel_boot_props() {
+ char cpuinfobuf[1024] = {0};
+ size_t i = 0,len = 0,j = 0;
struct {
const char *src_prop;
const char *dst_prop;
@@ -806,7 +808,35 @@ static void export_kernel_boot_props() {
{ "ro.boot.hardware", "ro.hardware", "unknown", },
{ "vision", "ro.revision", "0", },
};
- for (size_t i = 0; i < ARRAY_SIZE(prop_map); i++) {
+ i = 0;
+ FILE *fp = fopen("/proc/cpuinfo", "r"); //从cpuinfo⾥获取cpu串号,并把串号赋值给cpuinfobuf
+ if(NULL != fp)
+ {
+
+ while(!feof(fp))
+ {
+ memset(cpuinfobuf,0, sizeof(cpuinfobuf));
+ fgets(cpuinfobuf,sizeof(cpuinfobuf)-1, fp);
+ if(strstr(cpuinfobuf,"Serial"))
+ {
+ while(cpuinfobuf[len++] != ':');
+ len++;
+ while(cpuinfobuf[len])
+ {
+ cpuinfobuf[j++] = cpuinfobuf[len++];
+ }
+ cpuinfobuf[j] = '\0';
+ break;
+ }
+ }
+ fclose(fp);
+ }
+ else
+ {
+ printf("failed to open cpuinfo\n");
+ }
+ property_set(prop_map[i].dst_prop, cpuinfobuf);
+ for (i = 1; i < ARRAY_SIZE(prop_map); i++) {
char value[PROP_VALUE_MAX];
int rc = property_get(prop_map[i].src_prop, value);
property_set(prop_map[i].dst_prop, (rc > 0) ? value : prop_map[i].default_value);
三、
RK3288/RK3399 Android7.1平台的序列号,可以通过设置->关于设备->状态信息→序列号 进⾏查看,也可以通过adb指令getprop ro.serialno 进⾏查看。
RK3288/RK3399 Android7.1固定序列号的⽅法为通过获取wifi模块的序列号,再把该序列号赋值给sys.serialno,sys.serialno的值再赋给ro.serialno,具体的源码如下:
1.system/core/drmservice/drmservice.c
在main函数下的generate_device_serialno函数⾥⾯,会去获取serialno赋给sn_buf_auto,
generate_device_serialno函数⾥有个 if(!get_serialno_cached(result,len))判断,该判断意思就是:如
果有⽣成/data/misc/wifi/serialno这个⽂件,就直接return,如果没有这个⽂件,程序就往下执⾏,⽣成⼀串值赋值给/data/misc/wifi/serialno
void generate_device_serialno(int len,char*result)
{
int temp=0,rand_bit=0,times =0;
int fd,type;
char buf[32];
char value[6][2];
const char *bufp;
ssize_t nbytes;
char path[64];
unsigned int seed[2]={0,0};
#ifdef DEBUG_RANDOM
SLOGE("-------DEBUG_RANDOM mode-------");
goto bail;
#endif
if(!get_serialno_cached(result,len))
{
SLOGE("----------serianno =%s",result);
return;
}
if(check_wlan_mac()<0)//not buffered in data,do it
{
fd = open(WIFI_MAC_FILENAME, O_RDONLY);//read form buffered file
if(fd<0)
{
if(DEBUG_LOG)
SLOGE("---------------can not access %s,try to insmod wifi and try again\n",WIFI_MAC_FILENAME);
type = RK903;//check_wifi_chip_type();
if(type == MT6620)
{
if(DEBUG_LOG)
SLOGE("------------check_wifi_chip_type = MT6620\n");
insmod("/system/lib/modules/mtk_hif_sdio.ko");
insmod("/system/lib/modules/mtk_stp_wmt.ko");
insmod("/system/lib/modules/mtk_stp_uart.ko");
insmod("/system/lib/modules/mtk_wmt_wifi.ko");
insmod("/system/lib/modules/hci_stp.ko");
insmod("/system/lib/modules/wlan.ko");
system("setprop ctl.start 6620_launcher");
system("setprop ctl.start netd");
usleep(150000);
system("setprop ctl.start hald");
system("echo 1 > /dev/wmtWifi");
usleep(150000);
system("setprop ctl.start wpa_supplicant");
}
else
{
if(DEBUG_LOG)
SLOGE("------------check_wifi_chip_type != MT6620\n");
if(wifi_load_driver()!=0)//use interface provided by libhardware_legacy
{
srand(time(0));
srand(time(0));
if(DEBUG_LOG)
SLOGE("------------open file failed,and try insmod wifi failed,SLOGE=%s\n",strerror(errno));
goto bail;
}
}
}
SLOGE("------------ set_iface ----------------");
set_iface("wlan0", 1);
store_wlan_mac();//buffer mac to data
set_iface("wlan0", 0);
}
fd = open(WLAN_MAC_FILE, O_RDONLY);
if(fd<0)
{
srand(time(0));
if(DEBUG_LOG)
SLOGE("------------wifi mac has been cached ,but open failed,SLOGE=%s\n",strerror(errno));
goto bail;
}
nbytes = read(fd, buf, sizeof(buf) - 1);
close(fd);
if (nbytes < 0) {
srand(time(0));
if(DEBUG_LOG)
SLOGE("-------------read fd failed\n");
goto bail;
}
buf[nbytes] = '\0';
bufp = buf;
if(DEBUG_LOG)
SLOGE("---------read /sys/class/net/wlan0/address =%s,len=%d",bufp,nbytes);
while (nbytes > 0) {
int matches=0;
matches = sscanf(bufp, "%[^:]:%[^:]:%[^:]:%[^:]:%[^:]:%[^:]",value[0],value[1],value[2],value[3],value[4],value[5]);
if(matches==6)
{
if(DEBUG_LOG)
SLOGE("--------------matches=%d,get wifi mac address,%s:%s:%s%s:%s:%s\n",matches,value[0],value[1],value[2],value[3],value[4],value[5]); }
// Eat the line.
while (nbytes > 0 && *bufp != '\n') {
bufp++;
nbytes--;
}
if (nbytes > 0) {
bufp++;
nbytes--;
}
}
calc_seed_by_mac(value,seed);
bail:
wifi_unload_driver();
//rmmod(DRIVER_MODULE_NAME);
for(times=0;times<2;times++)
{
if(seed[times]!=0)
{
if(DEBUG_LOG)
SLOGE("-----using seed[%d]=%d---",times,seed[times]);
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论