added codes about AndroidVersion and SOC
This commit is contained in:
parent
151401f105
commit
37fa338586
18
inc/hgl/platform/Android.h
Normal file
18
inc/hgl/platform/Android.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace hgl
|
||||||
|
{
|
||||||
|
struct AndroidVersion
|
||||||
|
{
|
||||||
|
unsigned int major;
|
||||||
|
unsigned int minor;
|
||||||
|
unsigned int patch;
|
||||||
|
|
||||||
|
char postfix;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据版本号取得Android的APILevel,如若出错返回-1
|
||||||
|
*/
|
||||||
|
const int GetAndroidAPILevel(const AndroidVersion &);
|
||||||
|
}//namespace hgl
|
35
inc/hgl/platform/SOC.h
Normal file
35
inc/hgl/platform/SOC.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include<hgl/TypeFunc.h>
|
||||||
|
|
||||||
|
namespace hgl
|
||||||
|
{
|
||||||
|
enum class SOCVendor
|
||||||
|
{
|
||||||
|
Unknow=0,
|
||||||
|
|
||||||
|
Qualcomm, ///<高通
|
||||||
|
Hisilicon, ///<海思
|
||||||
|
Samsung, ///<三星
|
||||||
|
MediaTek, ///<联发科
|
||||||
|
//Rockchip, ///<瑞芯微
|
||||||
|
//Intel, ///<英特尔
|
||||||
|
Unisoc, ///<展锐
|
||||||
|
Spreadtrum, ///<展讯
|
||||||
|
JLQ, ///<瓴盛
|
||||||
|
//TI, ///<德州仪器
|
||||||
|
|
||||||
|
ENUM_CLASS_RANGE(Unknow,JLQ)
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SOCInfo
|
||||||
|
{
|
||||||
|
SOCVendor vendor;
|
||||||
|
char model[16];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据收集到的SOC信息,解晰具体的SOC厂商和主要型号
|
||||||
|
*/
|
||||||
|
bool ParseSOCInfo(SOCInfo &,const char *);
|
||||||
|
}//namespace hgl
|
63
src/Android/AndroidVersion.cpp
Normal file
63
src/Android/AndroidVersion.cpp
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
#include<hgl/platform/Android.h>
|
||||||
|
|
||||||
|
namespace hgl
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
https://apilevels.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
const int GetAndroidAPILevel(const AndroidVersion &av)
|
||||||
|
{
|
||||||
|
int api_level=-1;
|
||||||
|
|
||||||
|
if(av.major==1)
|
||||||
|
{
|
||||||
|
if(av.minor==0)api_level=1;else
|
||||||
|
if(av.minor==1)api_level=2;else
|
||||||
|
if(av.minor==5)api_level=3;else
|
||||||
|
if(av.minor==6)api_level=4;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if(av.major==2)
|
||||||
|
{
|
||||||
|
if(av.minor==0)api_level=(av.patch>=1)?6:5;else
|
||||||
|
if(av.minor==1)api_level=7;else
|
||||||
|
if(av.minor==2)api_level=8;else
|
||||||
|
if(av.minor==3)api_level=(av.patch>=3)?10:9;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if(av.major==3)
|
||||||
|
{
|
||||||
|
if(av.minor==0)api_level=11;else
|
||||||
|
if(av.minor==1)api_level=12;else
|
||||||
|
api_level=13;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if(av.major==4)
|
||||||
|
{
|
||||||
|
if(av.minor==0)api_level=(av.patch>=3)?15:14;else
|
||||||
|
if(av.minor==1)api_level=16;else
|
||||||
|
if(av.minor==2)api_level=17;else
|
||||||
|
if(av.minor==3)api_level=18;else
|
||||||
|
if(av.minor==4)api_level=(av.postfix=='W')?20:19;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if(av.major==5)
|
||||||
|
{
|
||||||
|
if(av.minor==0)api_level=21;else
|
||||||
|
if(av.minor==1)api_level=22;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if(av.major==6)api_level=23;else
|
||||||
|
if(av.major==7)api_level=(av.minor==0)?24:25;else
|
||||||
|
if(av.major==8)api_level=(av.minor==0)?26:27;else
|
||||||
|
if(av.major==9)api_level=28;else
|
||||||
|
if(av.major==10)api_level=29;else
|
||||||
|
if(av.major==11)api_level=30;else
|
||||||
|
if(av.major==12)api_level=(av.postfix=='L')?32:31;else
|
||||||
|
if(av.major==13)api_level=33;else
|
||||||
|
if(av.major>=14)api_level=34;
|
||||||
|
|
||||||
|
return(api_level);
|
||||||
|
}
|
||||||
|
}//namespace hgl
|
@ -120,6 +120,16 @@ SOURCE_GROUP("Window" FILES ${PLATFORM_WINDOW_SOURCE})
|
|||||||
|
|
||||||
SOURCE_GROUP("Hardware\\Cpuinfo" FILES ${CPU_INFO_HEADER} ${CPU_INFO_SOURCE})
|
SOURCE_GROUP("Hardware\\Cpuinfo" FILES ${CPU_INFO_HEADER} ${CPU_INFO_SOURCE})
|
||||||
|
|
||||||
|
SET(ANDROID_ABOUT_SOURCE ${CMPLATFORM_ROOT_INCLUDE_PATH}/hgl/platform/Android.h
|
||||||
|
Android/AndroidVersion.cpp)
|
||||||
|
|
||||||
|
SOURCE_GROUP("Android\\Version" FILES ${ANDROID_ABOUT_SOURCE})
|
||||||
|
|
||||||
|
SET(SOC_SOURCE ${CMPLATFORM_ROOT_INCLUDE_PATH}/hgl/platform/SOC.h
|
||||||
|
SOC.cpp)
|
||||||
|
|
||||||
|
SOURCE_GROUP("SOC" FILES ${SOC_SOURCE})
|
||||||
|
|
||||||
SET(PLATFORM_SOURCE ${PLATFORM_SOURCE}
|
SET(PLATFORM_SOURCE ${PLATFORM_SOURCE}
|
||||||
${PLATFORM_FILE_SOURCE}
|
${PLATFORM_FILE_SOURCE}
|
||||||
${PLATFORM_CODEPAGE_SOURCE}
|
${PLATFORM_CODEPAGE_SOURCE}
|
||||||
@ -135,6 +145,8 @@ SET(PLATFORM_SOURCE ${PLATFORM_SOURCE}
|
|||||||
|
|
||||||
${CPU_INFO_HEADER}
|
${CPU_INFO_HEADER}
|
||||||
${CPU_INFO_SOURCE}
|
${CPU_INFO_SOURCE}
|
||||||
|
${ANDROID_ABOUT_SOURCE}
|
||||||
|
${SOC_SOURCE}
|
||||||
)
|
)
|
||||||
|
|
||||||
add_cm_library(CMPlatform "CM" ${PLATFORM_SOURCE})
|
add_cm_library(CMPlatform "CM" ${PLATFORM_SOURCE})
|
||||||
|
159
src/SOC.cpp
Normal file
159
src/SOC.cpp
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
#include<hgl/type/StrChar.h>
|
||||||
|
#include<hgl/platform/SOC.h>
|
||||||
|
|
||||||
|
using namespace hgl;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
bool isQualcomm(SOCInfo &soc,const char *soc_name)
|
||||||
|
{
|
||||||
|
const char *p=hgl::stristr(soc_name,hgl::strlen(soc_name),"Qualcomm ",9);
|
||||||
|
|
||||||
|
if(!p)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
soc.vendor=SOCVendor::Qualcomm;
|
||||||
|
|
||||||
|
p+=9;
|
||||||
|
if(*p=='T') //"Qualcomm Technologies, Inc" 但是里面有写逗号的有写句号的,所以我找最后的Inc
|
||||||
|
{
|
||||||
|
p=hgl::stristr(p,hgl::strlen(p),"Inc ",4);
|
||||||
|
|
||||||
|
if(!p)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
p+=4;
|
||||||
|
|
||||||
|
hgl::strcpy(soc.model,sizeof(soc.model),p);
|
||||||
|
}
|
||||||
|
else //如“Qualcomm APQ8084”这种
|
||||||
|
{
|
||||||
|
hgl::strcpy(soc.model,sizeof(soc.model),p);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isMediaTek(SOCInfo &soc,const char *soc_name)
|
||||||
|
{
|
||||||
|
const char *p=hgl::stristr(soc_name,hgl::strlen(soc_name),"MT",2);
|
||||||
|
|
||||||
|
if(!p)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
soc.vendor=SOCVendor::MediaTek;
|
||||||
|
|
||||||
|
p+=2;
|
||||||
|
|
||||||
|
hgl::strcpy(soc.model,sizeof(soc.model),p,4);
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isUnisoc(SOCInfo &soc,const char *soc_name)
|
||||||
|
{
|
||||||
|
const char *p=hgl::stristr(soc_name,hgl::strlen(soc_name),"Unisoc",6);
|
||||||
|
|
||||||
|
if(!p)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
soc.vendor=SOCVendor::Unisoc;
|
||||||
|
|
||||||
|
if(p==soc_name) //就在最前面,"Unisoc ...."结构
|
||||||
|
{
|
||||||
|
hgl::strcpy(soc.model,sizeof(soc.model),p+7);
|
||||||
|
}
|
||||||
|
else //在型号后面,"Txxx-Unisoc"结构
|
||||||
|
{
|
||||||
|
hgl::strcpy(soc.model,sizeof(soc.model),soc_name,p-soc_name-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isKirin(SOCInfo &soc,const char *soc_name)
|
||||||
|
{
|
||||||
|
const char *p=hgl::stristr(soc_name,hgl::strlen(soc_name),"Kirin",5);
|
||||||
|
|
||||||
|
if(!p)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
soc.vendor=SOCVendor::Hisilicon;
|
||||||
|
|
||||||
|
hgl::strcpy(soc.model,sizeof(soc.model),p+5);
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isExynos(SOCInfo &soc,const char *soc_name)
|
||||||
|
{
|
||||||
|
const char *p=hgl::stristr(soc_name,hgl::strlen(soc_name),"Exynos",6);
|
||||||
|
|
||||||
|
if(!p)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
soc.vendor=SOCVendor::Samsung;
|
||||||
|
|
||||||
|
p+=6;
|
||||||
|
|
||||||
|
if(*p==' ')++p;
|
||||||
|
|
||||||
|
hgl::strcpy(soc.model,sizeof(soc.model),p);
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isSpreadtrum(SOCInfo &soc,const char *soc_name)
|
||||||
|
{
|
||||||
|
const char *p=hgl::stristr(soc_name,hgl::strlen(soc_name),"Spreadtrum",10);
|
||||||
|
|
||||||
|
if(!p)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
soc.vendor=SOCVendor::Spreadtrum;
|
||||||
|
|
||||||
|
p+=10;
|
||||||
|
|
||||||
|
if(*p==' ')++p;
|
||||||
|
|
||||||
|
hgl::strcpy(soc.model,sizeof(soc.model),p);
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isJLQ(SOCInfo &soc,const char *soc_name)
|
||||||
|
{
|
||||||
|
const char *p=hgl::stristr(soc_name,hgl::strlen(soc_name),"JLQ ",4);
|
||||||
|
|
||||||
|
if(!p)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
soc.vendor=SOCVendor::JLQ;
|
||||||
|
|
||||||
|
p+=4;
|
||||||
|
|
||||||
|
hgl::strcpy(soc.model,sizeof(soc.model),p);
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
}//namespace
|
||||||
|
|
||||||
|
namespace hgl
|
||||||
|
{
|
||||||
|
bool ParseSOCInfo(SOCInfo &soc,const char *soc_name)
|
||||||
|
{
|
||||||
|
if(hgl::strlen(soc_name)>0)
|
||||||
|
{
|
||||||
|
if(isQualcomm (soc,soc_name))return(true);
|
||||||
|
if(isKirin (soc,soc_name))return(true);
|
||||||
|
if(isMediaTek (soc,soc_name))return(true);
|
||||||
|
if(isUnisoc (soc,soc_name))return(true);
|
||||||
|
if(isExynos (soc,soc_name))return(true);
|
||||||
|
if(isSpreadtrum (soc,soc_name))return(true);
|
||||||
|
if(isJLQ (soc,soc_name))return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
soc.vendor=SOCVendor::Unknow;
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
}//namespace hgl
|
Loading…
x
Reference in New Issue
Block a user