Forráskód Böngészése

#IQRV #comment 支持普通调用版Sogou输入法识别

gifur 2 éve
szülő
commit
1c89b87ee9

+ 35 - 0
Module/mod_ResourceWatcher/mod_ResourceWatcher.cpp

@@ -303,6 +303,23 @@ void ResourceWatcherEntity::GetNetworkInfo(SpReqAnsContext<ResourceWatcherServic
     ctx->Answer(Error_Succeed);
 }
 
+std::string TryToGetSogouVersionEx()
+{
+    std::string succStr, errStr;
+    std::string runStr("cat /opt/sogouimebs/files/share/sogou-version");
+    if (SP::Module::Util::ShellExecute(runStr, succStr, errStr)) {
+        if (succStr.empty()) {
+            DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("cat sogou version return empty!");
+        } else {
+            DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("cat sogou version returned: %s", succStr.c_str());
+            return succStr;
+        }
+    } else {
+        DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("execute cmd failed: %s", errStr.c_str());
+    }
+    return "";
+}
+
 void ResourceWatcherEntity::GetThirdPartyInstallState(SpReqAnsContext<ResourceWatcherService_GetThirdPartyInstallState_Req, ResourceWatcherService_GetThirdPartyInstallState_Ans>::Pointer ctx)
 {
 
@@ -314,11 +331,17 @@ void ResourceWatcherEntity::GetThirdPartyInstallState(SpReqAnsContext<ResourceWa
         info.state.strInstallDate = Sogou_GetInstallTime();
         info.program.strInstallDir = Sogou_GetInstallPath();
         info.program.strVersion = Sogou_GetVersion();
+        if (info.program.strVersion.IsNullOrEmpty()) {
+            info.program.strVersion = TryToGetSogouVersionEx().c_str();
+        }
         const int maxTimes = 5;
         int curTimes = 0;
         while (info.state.dwInstalledStatus == 0 && info.program.strVersion.IsNullOrEmpty() && curTimes < maxTimes) {
             Sleep(1200);
             info.program.strVersion = Sogou_GetVersion();
+            if (info.program.strVersion.IsNullOrEmpty()) {
+                info.program.strVersion = TryToGetSogouVersionEx().c_str();
+            }
             curTimes++;
         }
         Dbg("%d, %s, %s, %s"
@@ -698,11 +721,17 @@ void ResourceWatcherEntity::InstallThirdPartyProgram(SpReqAnsContext<ResourceWat
                         info.state.strInstallDate = Sogou_GetInstallTime();
                         info.program.strInstallDir = Sogou_GetInstallPath();
                         info.program.strVersion = Sogou_GetVersion();
+                        if (info.program.strVersion.IsNullOrEmpty()) {
+                            info.program.strVersion = TryToGetSogouVersionEx().c_str();
+                        }
                         const int maxTimes = 5;
                         int curTimes = 0;
                         while (!doNotStartup && info.state.dwInstalledStatus == 0 && info.program.strVersion.IsNullOrEmpty() && curTimes < maxTimes) {
                             Sleep(1200);
                             info.program.strVersion = Sogou_GetVersion();
+                            if (info.program.strVersion.IsNullOrEmpty()) {
+                                info.program.strVersion = TryToGetSogouVersionEx().c_str();
+                            }
                             curTimes++;
                         }
                         Dbg("InstallTime: %s", info.state.GetInstallTime().ToTimeString().GetData());
@@ -1355,12 +1384,18 @@ ErrorCodeEnum ResourceWatcherEntity::DoCheckInstallStateJob()
     info.state.strInstallDate = Sogou_GetInstallTime();
     info.program.strInstallDir = Sogou_GetInstallPath();
     info.program.strVersion = Sogou_GetVersion();
+    if (info.program.strVersion.IsNullOrEmpty()) {
+        info.program.strVersion = TryToGetSogouVersionEx().c_str();
+    }
     /** 重试获取版本号 [Gifur@2022224]*/
     const int maxTimes = 3;
     int curTimes = 0;
     while (info.state.dwInstalledStatus == 0 && info.program.strVersion.IsNullOrEmpty() && curTimes < maxTimes) {
         Sleep(1500);
         info.program.strVersion = Sogou_GetVersion();
+        if (info.program.strVersion.IsNullOrEmpty()) {
+            info.program.strVersion = TryToGetSogouVersionEx().c_str();
+        }
         curTimes++;
     }
 

+ 24 - 20
Module/mod_healthmanager/HealthManagerFSM.h

@@ -24,26 +24,30 @@ using namespace PinPad;
 using namespace CardSwiper;
 #endif //RVC_OS_WIN
 enum HealthManger_UserErrorCode {
-	HealthManager_UserErrorCode_Start = 0x50100200,
-	HealthManager_UserErrorCode_InitForFWB_GetAuthAddr_Fail,//蓝牙多合一获取准入地址失败
-	HealthManager_UserErrorCode_InitForFWB_Init_Suc,		//蓝牙多合一初始化成功
-	HealthManager_UserErrorCode_InitForFWB_Init_Fail,		//蓝牙多合一初始化失败
-	HealthManager_UserErrorCode_Enum_OSVersion,				//枚举os版本
-	HealthManager_UserErrorCode_Enum_AsianInfo_Start,		//查询是否安装亚信
-	HealthManager_UserErrorCode_Enum_AsianInfo_End,			//查询是否安装亚信
-	HealthManager_UserErrorCode_Enter_SafeLoad_State,		//用于后台判定启动次数
-	HealthManager_UserErrorCode_PinPad_Dev_SP_SM,			//密码键盘硬件支持国密
-	HealthManager_UserErrorCode_PinPad_Dev_NOT_SP_SM,		//密码键盘硬件不支持国密
-	HealthManager_UserErrorCode_PinPad_HaveLoad_SM,			//密码键盘已加载国密密钥
-	HealthManager_UserErrorCode_PinPad_HaveNotLoad_SM,		//密码键盘未加载国密密钥
-	HealthManager_UserErrorCode_Receive_Browser_Idle,		//健康收到浏览器Idle事件
-	HealthManager_UserErrorCode_First_Info_AboutTerm,		//健康启动结束后第一次终端信息上送
-	HealthManager_UserErrorCode_AutoDoInit_Suc,				//自动初始化成功
-	HealthManager_UserErrorCode_AutoDoInit_Fail,			//自动初始化失败
-	HealthManager_UserErrorCode_Need_Guardian,				//健康需要启动guardian
-	HealthManager_UserErrorCode_Need_No_Guardian,			//健康不需要启动guardian	
-	HealthManager_UserErrorCode_WaitForAccessGrayResult,	//健康等待准入灰度结果
-	HealthManager_UserErrorCode_First_Info_AboutPC,			//健康启动结束后第一次上送计算机信息(主要是确定pad的归属厂商信息)
+    HealthManager_UserErrorCode_Start = 0x50100200,
+    HealthManager_UserErrorCode_GetAuthAddr_Fail = 0x50100201,			//获取准入地址失败
+    HealthManager_UserErrorCode_InitForFWB_Init_Suc = 0x50100202,		//蓝牙多合一初始化成功
+    HealthManager_UserErrorCode_InitForFWB_Init_Fail = 0x50100203,		//蓝牙多合一初始化失败
+    HealthManager_UserErrorCode_Enum_OSVersion = 0x50100204,				//枚举os版本
+    HealthManager_UserErrorCode_Enum_AsianInfo_Start = 0x50100205,		//查询是否安装亚信
+    HealthManager_UserErrorCode_Enum_AsianInfo_End = 0x50100206,			//查询是否安装亚信
+    HealthManager_UserErrorCode_Enter_SafeLoad_State = 0x50100207,		//用于后台判定启动次数 0x50100207
+    HealthManager_UserErrorCode_PinPad_Dev_SP_SM = 0x50100208,			//密码键盘硬件支持国密
+    HealthManager_UserErrorCode_PinPad_Dev_NOT_SP_SM = 0x50100209,		//密码键盘硬件不支持国密
+    HealthManager_UserErrorCode_PinPad_HaveLoad_SM = 0x5010020A,			//密码键盘已加载国密密钥
+    HealthManager_UserErrorCode_PinPad_HaveNotLoad_SM = 0x5010020B,		//密码键盘未加载国密密钥
+    HealthManager_UserErrorCode_Receive_Browser_Idle = 0x5010020C,		//健康收到浏览器Idle事件 0x5010020c
+    HealthManager_UserErrorCode_First_Info_AboutTerm = 0x5010020D,		//健康启动结束后第一次终端信息上送 0x5010020d
+    HealthManager_UserErrorCode_AutoDoInit_Suc = 0x5010020E,				//自动初始化成功
+    HealthManager_UserErrorCode_AutoDoInit_Fail = 0x5010020F,			//自动初始化失败
+    HealthManager_UserErrorCode_Need_Guardian = 0x50100210,				//健康需要启动guardian
+    HealthManager_UserErrorCode_Need_No_Guardian = 0x50100211,			//健康不需要启动guardian	
+    HealthManager_UserErrorCode_WaitForAccessGrayResult = 0x50100212,	//健康等待准入灰度结果
+    HealthManager_UserErrorCode_First_Info_AboutPC = 0x50100213,			//健康启动结束后第一次上送计算机信息(主要是确定pad的归属厂商信息)
+    HealthManager_UserErrorCode_Upload_PathInfo = 0x50100214,				//上送全量root中Path结点信息
+    HealthManager_UserErrorCode_PrivilegeCMD = 0x50100215,				//上送终端收到的启动、重启事件(非关门页、用户桌面?需要调查后理清楚)
+    HealthManager_UserErrorCode_SogouInput_UsingSys = 0x50100216,    // 使用普通调用的搜狗输入法
+    HealthManager_UserErrorCode_SogouInput_UsingSDK = 0x50100217    // 使用SDK版本调用的搜狗输入法
 };
 enum EvtType
 {

+ 111 - 1
Module/mod_healthmanager/mod_healthmanager.cpp

@@ -1812,7 +1812,117 @@ void CHealthManagerEntity::QueryHardwareInfo(SpReqAnsContext<HealthManagerServic
 	ctx->Ans.termLimit = __ReadCenterConfigStr("TermLimitSwitch", "IEBrowser");
 	ctx->Ans.termVersion = info.InstallVersion.ToString();
 
-	ctx->Answer(Error_Succeed);
+    CSimpleStringA deviceFct("");
+#if defined(_MSC_VER)
+    //oiltmp 备注reserved3、reserved4这是什么情况下用的?看得莫名其妙,在一个常用调用接口里面每次都取,这是不怕亚信?
+    //reserved3, 获取windows系统版本
+    DWORD dwMajorVer, dwMinorVer, dwBuildNumber;
+    BOOL bRet = FALSE;
+    HMODULE hModNtdll = NULL;
+    if (hModNtdll = ::LoadLibraryW(L"ntdll.dll")) {
+        typedef void (WINAPI* pfRTLGETNTVERSIONNUMBERS)(DWORD*, DWORD*, DWORD*);
+        pfRTLGETNTVERSIONNUMBERS pfRtlGetNtVersionNumbers;
+        pfRtlGetNtVersionNumbers = (pfRTLGETNTVERSIONNUMBERS)::GetProcAddress(hModNtdll, "RtlGetNtVersionNumbers");
+        if (pfRtlGetNtVersionNumbers) {
+            pfRtlGetNtVersionNumbers(&dwMajorVer, &dwMinorVer, &dwBuildNumber);
+            dwBuildNumber &= 0x0ffff;
+            bRet = TRUE;
+        }
+
+        ::FreeLibrary(hModNtdll);
+        hModNtdll = NULL;
+    }
+
+    //reserved4
+    char buffer[1024];
+    sprintf(buffer, "%d.%d.%d", dwMajorVer, dwMinorVer, dwBuildNumber);
+    string sysVer = "Windows ver[" + string(buffer) + "]";
+    ctx->Ans.reserved3 = CSimpleStringA(sysVer.c_str());
+
+    // pad设备厂商为Microsoft, 其他设备读取root中的pinpad字段下的vendor
+    if (info.strMachineType == "RVC.PAD") {
+        DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("This is PAD device.");
+        deviceFct = "Microsoft";
+    } else {
+        CSmartPointer<IConfigInfo> spConfig;
+        GetEntityBase()->GetFunction()->OpenConfig(Config_Root, spConfig);
+        spConfig->ReadConfigValue("Device.PinPad", "Vendor", deviceFct);
+    }
+    ctx->Ans.reserved4 = deviceFct;
+#else
+	ctx->Ans.reserved3 = "UOS";
+    CSmartPointer<IConfigInfo> spConfig;
+    GetFunction()->OpenConfig(Config_Root, spConfig);
+    spConfig->ReadConfigValue("Device.PinPad", "Vendor", deviceFct);
+#endif //_MSC_VER
+
+    //reserved1
+#ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/
+    ctx->Ans.reserved1 = 1;
+#elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/
+    ctx->Ans.reserved1 = 2;
+#elif defined(DEVOPS_ON_PRD)/*DevOps流水线编译,PRD环境*/
+    ctx->Ans.reserved1 = 3;
+#elif defined(DEVOPS_ON_DEV)/*DevOps流水线编译,Dev环境*/
+    ctx->Ans.reserved1 = 0;
+#else/*本地编译等非DevOps环境编译的版本*/
+    ctx->Ans.reserved1 = 0;
+#endif	
+
+    //oilyang@20230518 用来标注支持搜狗输入法新旧模式
+    //0:旧模式 1:新模式(TODO 待搜狗确定如何判断新旧)
+    ctx->Ans.reserved2 = 0;
+    ResourceWatcherService_ClientBase* pClient = new ResourceWatcherService_ClientBase(this);
+    ErrorCodeEnum ec = pClient->Connect();
+    if (IS_SUCCEED(ec)) {
+        DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to Connect ResourceWatcher...");
+        ResourceWatcherService_GetThirdPartyInstallState_Req req = {};
+        ResourceWatcherService_GetThirdPartyInstallState_Ans ans = {};
+        req.mode = 1;
+        ec = pClient->GetThirdPartyInstallState(req, ans, 15000);
+        if (IS_SUCCEED(ec)) {
+            DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Get Sogou version: %s", ans.version.GetData());
+            //搜狗提供的普通调用版本开始的版本号,高于或等于这个版本则为系统调用方式,低于则为SDK方式
+            CVersion sysVersionStart(2, 6, 4, 329);
+            WORD nMajor(0), nMinor(0), nRevision(0), nBulid(0);
+            if (!ans.version.IsNullOrEmpty()) {
+                CAutoArray<CSimpleStringA> versionElems = ans.version.Split('.');
+                DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Elems count: %d", versionElems.GetCount());
+                if (versionElems.GetCount() >= 1) {
+                    nMajor = atoi(versionElems[0]);
+                }
+                if (versionElems.GetCount() >= 2) {
+                    nMinor = atoi(versionElems[1]);
+                }
+                if (versionElems.GetCount() >= 3) {
+                    nRevision = atoi(versionElems[2]);
+                }
+                if (versionElems.GetCount() >= 4) {
+                    nBulid = atoi(versionElems[3]);
+                }
+            }
+            CVersion curVersion(nMajor, nMinor, nRevision, nBulid);
+            DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Get Sogou version r: %s vs %s", curVersion.ToString().GetData(),
+                                                         sysVersionStart.ToString().GetData());
+            DWORD dwUserCode(HealthManager_UserErrorCode_SogouInput_UsingSDK);
+            if (curVersion >= sysVersionStart) {
+                dwUserCode = HealthManager_UserErrorCode_SogouInput_UsingSys;
+                ctx->Ans.reserved2 = 1;
+            }
+            LogWarn(Severity_Low, Error_Debug, dwUserCode,
+                    CSimpleStringA::Format("{\"version\": %s,\"installTime\": %s}", curVersion.ToString().GetData(), ans.reserverd1.GetData()));
+        } else {
+            LogWarn(Severity_Low, ec, HealthManager_UserErrorCode_SogouInput_UsingSDK,
+                    CSimpleStringA::Format("ResourceWatcher::GetThirdPartyInstallState invoked failed: %s", SpStrError(ec)));
+        }
+        pClient->GetFunction()->CloseSession();
+    } else {
+        LogWarn(Severity_Low, ec, HealthManager_UserErrorCode_SogouInput_UsingSDK,
+                CSimpleStringA::Format("Connet to ResourceWatcher failed: %s", SpStrError(ec)));
+        pClient->SafeDelete();
+    }
+
+    ctx->Answer(Error_Succeed);
 }
 void CHealthManagerEntity::ReadCenterConfigStr(SpReqAnsContext<HealthManagerService_ReadCenterConfigStr_Req, HealthManagerService_ReadCenterConfigStr_Ans>::Pointer ctx)
 {