浏览代码

Z991239-6315 #comment feat: 下线旧输入法相关代码和变量

陈纪林80310970 3 月之前
父节点
当前提交
fd8bd97b0f
共有 2 个文件被更改,包括 5 次插入334 次删除
  1. 0 237
      Module/mod_ResourceWatcher/mod_ResourceWatcher.cpp
  2. 5 97
      Module/mod_ResourceWatcher/mod_ResourceWatcher.h

+ 0 - 237
Module/mod_ResourceWatcher/mod_ResourceWatcher.cpp

@@ -872,222 +872,6 @@ BOOL ResourceWatcherEntity::KillProcessFromName(const CSimpleStringA& strProcess
 
 #endif //RVC_OS_LINUX
 
-void ResourceWatcherEntity::DoCheckSogouProcessStatus()
-{
-#if defined(RVC_OS_WIN)
-    if (lastUpgradeInstallTime != 0 && lastUpgradeSwitchTime != 0 && lastUpgradeInstallTime < lastUpgradeSwitchTime) //完整记录了上一次升级的时间
-    {
-        if (sogouChangeTime.size() != 0) {
-            for (int i = 0; i < sogouChangeWarn.size(); i++) {
-                if (newestSogouInstall) //搜狗升级
-                {
-                    //正常不用告警
-                   /* LogWarn(Severity_Low, Error_Debug, LOG_RESOURCEWATCHER_SOGOU_PROCESS_STATUS_CHANGE, (sogouChangeWarn[i] + "搜狗升级切换1").GetData());
-                    DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040250A01Z102")("搜狗升级切换1");*/
-                }
-                else //非搜狗升级导致的退出
-                {
-                    LogWarn(Severity_Middle, Error_Debug, LOG_RESOURCEWATCHER_SOGOU_PROCESS_STATUS_CHANGE, (sogouChangeWarn[i] + "异常切换1").GetData());
-                    DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040250A01Z103").setResultCode("RTA5A08")("搜狗异常切换1");
-                }
-            }
-
-            sogouChangeTime.clear();
-            sogouChangeWarn.clear();
-
-            lastUpgradeInstallTime = 0;
-            lastUpgradeSwitchTime = 0;
-            newestSogouInstall = false;
-
-            return;
-        }
-    }
-
-    bool fCheck = false;
-    CAutoArray<CSimpleStringA> pName(2);
-    pName[0] = "SogouImeMon.exe";
-    pName[1] = "SogouImeWebSrv.exe";
-    int pSize = pName.GetCount();
-
-    static int old_process_id[2] = { -1, -1 };
-    static int firstCheck[2] = { -1, -1 };
-    CAutoArray<CSimpleStringA> msgs;
-    for (int i = 0; i < pSize; ++i) {
-        /*old_process_id.push_back(-1);*/
-        CSimpleStringA temp("");
-        msgs.Append(&temp, 0, 1);
-    }
-    int cnt(0);
-
-    PROCESSENTRY32 pe32;
-    pe32.dwSize = sizeof(pe32);
-    //获得系统进程快照的句柄  
-    HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
-    if (hProcessSnap == INVALID_HANDLE_VALUE) {
-        DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("CreateToolhelp32Snapshot error.");
-        return;
-    }
-    for (int i = 0; i < pSize; ++i) {
-        int position = -1;
-        BOOL bProcess = Process32First(hProcessSnap, &pe32);
-        while (bProcess) {
-            if (strcmp(pe32.szExeFile, pName[i].GetData()) == 0) {
-                position = 1;
-                break;
-            }
-            bProcess = Process32Next(hProcessSnap, &pe32);
-        }
-
-        if (position != -1 && old_process_id[i] == -1) {
-            if (firstCheck[i] == -1) {
-                DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Sougou first check!");
-                msgs[cnt++] = CSimpleStringA::Format("{\"name\":\"%s\", \"pid\":%d}"
-                    , pName[i].GetData(), pe32.th32ProcessID);
-                firstCheck[i] = 1;
-                fCheck = true;
-                sogouProcessRun = 1;
-            }
-            old_process_id[i] = pe32.th32ProcessID;
-        }
-        else if (position != -1 && (pe32.th32ProcessID != old_process_id[i])) {
-            msgs[cnt++] = CSimpleStringA::Format("{\"name\":\"%s\", \"prev\":%d, \"pid\":%d}"
-                , pName[i].GetData(), old_process_id[i], pe32.th32ProcessID);
-            old_process_id[i] = pe32.th32ProcessID;
-
-        }
-        else if (position == -1 && old_process_id[i] > 0) {
-            msgs[cnt++] = CSimpleStringA::Format("{\"name\":\"%s\", \"prev\":%d, \"pid\":%d}"
-                , pName[i].GetData(), old_process_id[i], 0);
-            old_process_id[i] = 0;
-        }
-    }
-
-    std::string uploadInfo("");
-    if (cnt > 0) {
-        if (cnt > 1) {
-            uploadInfo = "{";
-        }
-        for (int i = 0; i < cnt; ++i) {
-            if (i != 0) {
-                uploadInfo += ",";
-            }
-            uploadInfo += msgs[i].GetData();
-        }
-        if (cnt > 1) {
-            uploadInfo += "}";
-        }
-
-        if (fCheck) //首次检测
-        {
-            LogWarn(Severity_Low, Error_Debug, LOG_RESOURCEWATCHER_SOGOU_PROCESS_STATUS_FIRSTCHECK, uploadInfo.c_str()); //第一次检测
-            lastUpgradeInstallTime = 0;
-            lastUpgradeSwitchTime = 0;
-            newestSogouInstall = false;
-            DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040250A01Z101")("搜狗首次检测");
-        }
-        else if (newestSogouInstall) {
-            //LogWarn(Severity_Low, Error_Debug, LOG_RESOURCEWATCHER_SOGOU_PROCESS_STATUS_CHANGE, (uploadInfo + "搜狗升级切换2").c_str()); //升级安装导致的进程切换视为正常退出
-            lastUpgradeInstallTime = 0;
-            lastUpgradeSwitchTime = 0;
-            newestSogouInstall = false;
-            //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040250A01Z102")("搜狗升级切换2");
-        }
-        else if (time(0) <= lastSogouChangeEndTime) //lastSogouChangeEndTime为状态'I'结束后的60秒
-        {
-            //LogWarn(Severity_Low, Error_Debug, LOG_RESOURCEWATCHER_SOGOU_PROCESS_STATUS_CHANGE, (uploadInfo + "搜狗升级切换3").c_str()); //升级安装导致的进程切换视为正常退出
-            lastUpgradeInstallTime = 0;
-            lastUpgradeSwitchTime = 0;
-            newestSogouInstall = false;
-            //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040250A01Z102")("搜狗升级切换3");
-        }
-        else {
-            if (lastUpgradeInstallTime == 0 && lastUpgradeSwitchTime == 0)//非升级时段
-            {
-                LogWarn(Severity_Middle, Error_Debug, LOG_RESOURCEWATCHER_SOGOU_PROCESS_STATUS_CHANGE, (uploadInfo + "异常切换3").c_str()); //其他情况下的进程切换视为异常退出
-                DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040250A01Z103").setResultCode("RTA5A08")("搜狗异常切换3");
-            }
-            else //升级时段,'I'安装中,但是还没有'S'切换时,出现了搜狗进程切换
-            {
-                sogouChangeWarn.push_back(CSimpleStringA(uploadInfo.c_str()));
-                sogouChangeTime.push_back(time(0));
-            }
-        }
-    }
-    else {
-        SogouInstallInfo info;
-        GetSogouInstallInfo(info);
-
-        if (!info.program.IsTSFVersion()) //如果是旧版本搜狗,则检测是否启动
-        {
-            if (sogouProcessRun == 0)//进程未运行
-            {
-                LogWarn(Severity_Middle, Error_Debug, LOG_RESOURCEWATCHER_SOGOU_PROCESS_STATUS_CHANGE, "搜狗进程未启动!");
-                DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode("QLR040250A01Z101").setResultCode("RTA5A01")("搜狗未启动!");
-                sogouProcessRun = -1; //进程未启动告警一次即可
-            }
-        }
-    }
-    CloseHandle(hProcessSnap);
-
-#else
-    static int old_process_id[2] = { -1, -1 };
-    char* relate_processes[2] = { "sogouImeWebSrv", "sogouImeService" };
-
-    int count = 3;
-    alive_process_info processes[3];
-    memset(processes, 0, sizeof(processes));
-
-    osutil_detect_unique_app(relate_processes, array_size(relate_processes), &count, processes);
-
-    CAutoArray<CSimpleStringA> msgs(array_size(relate_processes));
-    int cnt(0);
-
-    for (int i = 0; i < array_size(relate_processes); ++i) {
-        int k = -1;
-        for (int j = 0; j < count; ++j) {
-            if (strcmp(processes[j].name, relate_processes[i]) == 0) {
-                k = j;
-                break;
-            }
-        }
-
-        if (k != -1 && old_process_id[i] == -1) {
-            old_process_id[i] = processes[k].pid;
-
-        }
-        else if (k != -1 && (processes[k].pid != old_process_id[i])) {
-            msgs[cnt++] = CSimpleStringA::Format("{\"name\":\"%s\", \"prev\":%d, \"pid\":%d}"
-                , relate_processes[i], old_process_id[i], processes[k].pid);
-            old_process_id[i] = processes[k].pid;
-
-        }
-        else if (k == -1 && old_process_id[i] != 0) {
-            msgs[cnt++] = CSimpleStringA::Format("{\"name\":\"%s\", \"prev\":%d, \"pid\":%d}"
-                , relate_processes[i], old_process_id[i], 0);
-            old_process_id[i] = 0;
-        }
-    }
-
-    if (cnt > 0) {
-        std::string uploadInfo("");
-        if (cnt > 1) {
-            uploadInfo = "{";
-        }
-        for (int i = 0; i < cnt; ++i) {
-            if (i != 0) {
-                uploadInfo += ",";
-            }
-            uploadInfo += msgs[i].GetData();
-        }
-        if (cnt > 1) {
-            uploadInfo += "}";
-        }
-
-        LogWarn(Severity_Low, Error_Debug, LOG_RESOURCEWATCHER_SOGOU_PROCESS_STATUS_CHANGE, uploadInfo.c_str());
-    }
-#endif //RVC_OS_WIN
-}
-
 #if defined(RVC_OS_LINUX)
 ErrorCodeEnum ResourceWatcherEntity::GetSogouPkgDirPath(CSimpleStringA& strPkgPath)
 {
@@ -2119,27 +1903,6 @@ void ResourceWatcherEntity::FilesClean(SpReqAnsContext<ResourceWatcherService_Fi
     ctx->Answer(result);
 }
 
-void ResourceWatcherEntity::OnUpgradeStateEvent(const char* pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, UpgradeManager::UpgradeStateEvent& evt)
-{
-    DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("OnUpgradeStateEvent, cInstallState:%c, strNewVersion:%s.", evt.cInstallState, evt.strNewVersion.GetData());
-    CSimpleStringA packName = evt.strPackName;
-
-    if (evt.cInstallState == 'I') {
-        lastUpgradeInstallTime = time(0);
-        DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("lastUpgradeInstallTime = %lld.", lastUpgradeInstallTime);
-    }
-
-    if (evt.cInstallState == 'S' || evt.cInstallState == 'C') {
-        lastUpgradeSwitchTime = time(0);
-        DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("lastUpgradeSwitchTime = %lld.", lastUpgradeSwitchTime);
-        if (evt.strNewVersion.GetLength() == 0) {
-            newestSogouInstall = true;
-            lastSogouChangeEndTime = lastUpgradeSwitchTime + 60;
-        }
-        DoCheckSogouProcessStatus();
-    }
-}
-
 void ResourceWatcherEntity::FetchSystemSnapshot(
     SpReqAnsContext<ResourceWatcherService_FetchSystemSnapshot_Req, ResourceWatcherService_FetchSystemSnapshot_Ans>::Pointer ctx)
 {

+ 5 - 97
Module/mod_ResourceWatcher/mod_ResourceWatcher.h

@@ -8,12 +8,6 @@
 
 class ResourceWatcherEntity;
 
-#define ENT_TIMERID_CHECK_SOGOU_INPUT_INSTALLED_STATE 1
-#define ENT_TIMERINTERVAL_CHECK_SOGOU_INPUT_INSTALLED_STATE 60 * 1000
-
-#define ENT_TIMERID_CHECK_SOGOU_INPUT_PROCESS_STATUS_CHANGE 3
-#define ENT_TIMERINTERVAL_CHECK_SOGOU_INPUT_PROCESS_STATUS_CHANGE 30 * 1000
-
 #define ENT_TIMERID_PROCESS_CHECK 66
 #define ENT_TIMERINTERVAL_PROCESS_CHECK 60 * 60 * 1000  //进程检测间隔默认一小时
 
@@ -54,7 +48,7 @@ private:
 	ResourceWatcherEntity* m_pEntity;
 };
 
-class ResourceWatcherEntity : public CEntityBase, public IBroadcastListener, public ITimerListener, public ISysVarListener
+class ResourceWatcherEntity : public CEntityBase, public ITimerListener, public ISysVarListener
 {
 public:
 	ResourceWatcherEntity(){}
@@ -74,26 +68,7 @@ public:
 
 		ErrorCodeEnum errorCode = Error_Succeed;
 
-		errorCode = m_fsm.Init(this);
-
-		if (errorCode == Error_Succeed) {
-
-            CSmartPointer<IEntityFunction> spEntityFunction = GetFunction();
-			newestSogouInstall = false;
-			lastUpgradeInstallTime = 0; //上次升级安装时间
-			lastUpgradeSwitchTime = 0;  //上次升级切换时间
-			lastSogouChangeEndTime = 0;    //上一次切换结束判定的时间
-			sogouProcessRun = 0;      //搜狗进程是否启动
-
-			errorCode = spEntityFunction->SubscribeBroadcast("UpgradeManager", NULL, this, m_uuidUpgradeStateEventListener);
-			if (errorCode != Error_Succeed)
-			{
-				LOG_TRACE("Subscribe UpgradeManager evt failed 0x%x", errorCode);
-				pTransactionContext->SendAnswer(errorCode);
-				return;
-			}
-		}
-		
+		errorCode = m_fsm.Init(this);		
 		pTransactionContext->SendAnswer(errorCode);
 	}
 
@@ -101,9 +76,9 @@ public:
 	{
 		m_fsm.AfterInit();
 
+		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to check Sogou input install state...");
 		CSmartPointer<IEntityFunction> spEntityFunction = GetFunction();
-		spEntityFunction->SetTimer(ENT_TIMERID_CHECK_SOGOU_INPUT_INSTALLED_STATE,
-			this, ENT_TIMERINTERVAL_CHECK_SOGOU_INPUT_INSTALLED_STATE);
+		ReportSogouInstallState(); //实体启动时检测搜狗输入法安装状态
 
 		CSimpleStringA uiState;
 		spEntityFunction->GetSysVar("UIState", uiState);
@@ -238,44 +213,7 @@ public:
 
 	void CheckIsFileExists(SpReqAnsContext<ResourceWatcherService_CheckIsFileExists_Req, 
 		ResourceWatcherService_CheckIsFileExists_Ans>::Pointer ctx);
-
 	int CheckMediaResource(int iFileType, const char* pFileName);
-
-#if defined(_MSC_VER)
-	SP_BEGIN_MSG_DISPATCH_MAP(ResourceWatcherEntity)
-		SP_BEGIN_ENTITY_MSG("UpgradeManager")
-		SP_MSG_HANDLE_NS(UpgradeManager, UpgradeStateEvent, OnUpgradeStateEvent)
-		SP_END_ENTITY_MSG()
-		SP_END_MSG_DISPATCH_MAP()
-#else
-	virtual void OnBroadcastEvent(CUUID SubID, const char* pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, CAutoBuffer Buffer) \
-	{
-		if (!pszEntityName) {
-			LOG_TRACE("pszEntityName cannot empty!");
-		}
-		else if (_stricmp("UpgradeManager", pszEntityName) == 0) {
-			switch (dwMessageId) {
-			case eMsg_UpgradeStateEvent:
-				if (eMsgSig_UpgradeStateEvent == dwMessageSignature) {
-					UpgradeManager::UpgradeStateEvent t;
-					ErrorCodeEnum Error = SpBuffer2Object(Buffer, t);
-					if (Error == Error_Succeed)
-						OnUpgradeStateEvent(pszEntityName, dwMessageId, dwMessageSignature, t);
-				}
-				else {
-					LOG_TRACE("%s signature mismatched!", "UpgradeStateEvent");
-				}
-				break;
-			default:
-				LOG_TRACE("msg id %d ignored!", dwMessageId);
-				break;
-			}
-		}
-		else {
-			LOG_TRACE("ignore pszEntityName");
-		}
-	}
-#endif //_MSC_VER
 	void OnSysVarEvent(const char* pszKey, const char* pszValue, const char* pszOldValue, const char* pszEntityName)
 	{
 		if ((_strnicmp(pszKey, "UIState", strlen("UIState")) == 0)) {
@@ -284,38 +222,18 @@ public:
 	}
 private:
 
-	void OnUpgradeStateEvent(const char* pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, UpgradeManager::UpgradeStateEvent& evt);
-
 	//report sogou input software install state and installed information
 	ErrorCodeEnum ReportSogouInstallState();
 
 	void OnTimeout(DWORD dwTimerID)
 	{
-		if (dwTimerID == ENT_TIMERID_CHECK_SOGOU_INPUT_INSTALLED_STATE) {
-
-			CSimpleStringA strState;
-			auto err = GetFunction()->GetSysVar("UIState", strState);
-
-			if (err == Error_Succeed && strState == "M") {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to check Sogou input install state...");
-				if (Error_Succeed == ReportSogouInstallState()) {//如果安装了搜狗输入法,就去除检测搜狗输入法安装的定时器,并设置进程检测的定时器。
-					GetFunction()->KillTimer(ENT_TIMERID_CHECK_SOGOU_INPUT_INSTALLED_STATE);
-					GetFunction()->SetTimer(ENT_TIMERID_CHECK_SOGOU_INPUT_PROCESS_STATUS_CHANGE,
-						this, ENT_TIMERINTERVAL_CHECK_SOGOU_INPUT_PROCESS_STATUS_CHANGE);
-				}
-			}
-		}
-		else if (dwTimerID == ENT_TIMERID_CHECK_SOGOU_INPUT_PROCESS_STATUS_CHANGE) {
-			DoCheckSogouProcessStatus();
-		}
-		else if (dwTimerID == ENT_TIMERID_PROCESS_CHECK) {
+		if (dwTimerID == ENT_TIMERID_PROCESS_CHECK) {
 			CheckProcessStatus();
 		}
 		else {
 			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Unkonwn timer id: %u", dwTimerID);
 		}
 	}
-	void DoCheckSogouProcessStatus();
 	std::string DoCheckCertainProcessStatus(const CAutoArray<CSimpleStringA>& pName);
 	void SecProcCheck(); //检测终端安全软件应用
 
@@ -341,16 +259,6 @@ private:
 
 private:
 	ResourceWatcherFSM m_fsm;
-	CUUID m_uuidUpgradeStateEventListener;
-	BOOL newestSogouInstall; //最近一次安装的标志
-
-	time_t lastUpgradeInstallTime; //上次升级安装时间
-	time_t lastUpgradeSwitchTime;  //上次升级切换时间
-	time_t lastSogouChangeEndTime;    //上一次进程切换时间
-	int sogouProcessRun;
-
-	vector<CSimpleStringA> sogouChangeWarn;
-	vector<time_t> sogouChangeTime;
 };
 
 struct InstallSogouTask : public ITaskSp