Prechádzať zdrojové kódy

!10685 把FrameworkState改成AppBootState,用于标识终端应用启动过程状态;调整健康相关逻辑
Merge pull request !10685 from 80174847/oilyang_fixed_everything

杨诗友80174847 6 mesiacov pred
rodič
commit
cdc35e2366

+ 9 - 16
Framework/Common/SpBase.h

@@ -114,20 +114,13 @@ enum InstallStateEnum
 	Install_Installed,			// D, only used to LightPack
 };
 
-/** framework state*/
-enum FrameworkStateEnum
+/** terminal application boot state*/
+enum AppBootStateEnum
 {
-	FrameworkState_NotInit = 0,   /** the begin state*/
-    FrameworkState_NotConfig,   /** the factory mode, not config*/
-	FrameworkState_Booting,        /** the entity is starting*/
-	FrameworkState_Running,       /** the machine has enter business page*/
-	FrameworkState_Serving,        /** the machine is providing business service*/
-	FrameworkState_Breakdown,   /** the machine is sick*/
-	FrameworkState_Repairing,     /** the machine is being maintained*/
-	FrameworkState_Upgrading,   /** the software is upgrading*/
-	FrameworkState_Rollbacking, /** the software is rollback for some reason*/
-	FrameworkState_Recoving,     /** the machine is reaching running state from other state*/
-	FrameworkState_NotDisturb  /**/
+	AppBootState_Init = 0,   /** the begin(init) state*/
+	AppBootState_StartEntity,   /** begin to start entity*/
+	AppBootState_CallAccessAuth,        /** begin to call Regist*/
+	AppBootState_FirstEnterMainPage,       /** the first time received enter main page message*/
 };
 
 /** entity state */
@@ -532,7 +525,7 @@ struct CSystemRunInfo
 {
 	CSmallDateTime tmStart;
 	DebugLevelEnum eDebugLevel;
-	FrameworkStateEnum eState;
+	AppBootStateEnum eAppBootState;
 	DWORD dwBootOption;
 	BOOL autoTest;
 	CAutoArray<CSimpleStringA> strRunningEntityNames;
@@ -651,7 +644,7 @@ struct ISysVarListener
 };
 struct ITerminalStateChangedListener
 {
-	virtual void OnStateChanged(FrameworkStateEnum oldState, FrameworkStateEnum curState, const char* triggerEntity) = 0;
+	virtual void OnStateChanged(AppBootStateEnum oldState, AppBootStateEnum curState, const char* triggerEntity) = 0;
 };
 
 struct IBroadcastListener
@@ -1073,7 +1066,7 @@ struct IEntityFunctionPrivilege
 	virtual ~IEntityFunctionPrivilege() {}
 
 	/*upate terminal current state*/
-	virtual ErrorCodeEnum RefreshFrameworkState(FrameworkStateEnum eState) = 0;
+	virtual ErrorCodeEnum RefreshAppBootState(AppBootStateEnum eState) = 0;
 
 	/** start a remote entity,if restart itself only been call in OnClose event,will ignore pAsynWaitSp,and will not wait*/
 	virtual ErrorCodeEnum StartEntity(const char* pszEntityName, const char* pszCmdLine, CSmartPointer<IAsynWaitSp>& pAsynWaitSp) = 0;

+ 1 - 1
Framework/Common/SpHelper.h

@@ -375,7 +375,7 @@ SPBASE_API LPCTSTR SpStrRebootTrigger(const RebootTriggerEnum trigger);
 
 SPBASE_API LPCTSTR SpStrRebootWay(const RebootWayEnum way);
 
-SPBASE_API LPCTSTR SpStrFrameworkState(const FrameworkStateEnum state);
+SPBASE_API LPCTSTR SpStrAppBootState(const AppBootStateEnum state);
 
 #define IS_SUCCEED(hr)	((hr) == Error_Succeed)
 

+ 3 - 3
Framework/spbase/SpEntity.cpp

@@ -61,8 +61,8 @@ static void var_callback(sp_var_listener_t *listener,
 		if(strcmp(VAR_RSERVERD_KEY_TERM_STATE, key) != 0)
 			pListener->OnSysVarEvent(key, newstr, oldstr, ent->cfg->name);
 		else {
-			FrameworkStateEnum oldState = static_cast<FrameworkStateEnum>(atoi(oldstr));
-			FrameworkStateEnum newState = static_cast<FrameworkStateEnum>(atoi(newstr));
+			AppBootStateEnum oldState = static_cast<AppBootStateEnum>(atoi(oldstr));
+			AppBootStateEnum newState = static_cast<AppBootStateEnum>(atoi(newstr));
 			(static_cast<ITerminalStateChangedListener*>(user_data))->OnStateChanged(oldState, newState, ent->cfg->name);
 		}
 	}
@@ -1490,7 +1490,7 @@ ErrorCodeEnum SpEntity::GetSystemRunInfo(CSystemRunInfo &Info)
 	}
 	array_free(arr);
 
-	Info.eState = (FrameworkStateEnum)env->cfg->shell_ini->shell_state;
+	Info.eAppBootState = (AppBootStateEnum)env->cfg->shell_ini->shell_state;
 
 	if (env == NULL || env->cfg == NULL || env->cfg->root_ini == NULL)
 	{

+ 1 - 1
Framework/spbase/SpEntityNoPrivilege.h

@@ -105,7 +105,7 @@ public:
         return Error_NoPrivilege;
     }
 
-    virtual ErrorCodeEnum RefreshFrameworkState(FrameworkStateEnum eState)
+    virtual ErrorCodeEnum RefreshAppBootState(AppBootStateEnum eState)
     {
         return Error_NoPrivilege;
     }

+ 1 - 1
Framework/spbase/SpEntityPrivilege.cpp

@@ -424,7 +424,7 @@ ErrorCodeEnum SpEntityPrivilege::SetSysDebugLevel(const char *pszEntityName,Debu
 	return Error_Succeed;
 }
 
-ErrorCodeEnum SpEntityPrivilege::RefreshFrameworkState(FrameworkStateEnum eState)
+ErrorCodeEnum SpEntityPrivilege::RefreshAppBootState(AppBootStateEnum eState)
 {
 	int rc = Error_Succeed;
 	char n[12] = { '\0' };

+ 1 - 1
Framework/spbase/SpEntityPrivilege.h

@@ -76,7 +76,7 @@ public:
 	// debug
 	virtual ErrorCodeEnum SetSysDebugLevel(const char *pszEntityName,DebugLevelEnum eDebugLevel,bool bPersist=false);
 
-	virtual ErrorCodeEnum RefreshFrameworkState(FrameworkStateEnum eState);
+	virtual ErrorCodeEnum RefreshAppBootState(AppBootStateEnum eState);
 
 private:
 

+ 6 - 13
Framework/spbase/SpHelper.cpp

@@ -864,25 +864,18 @@ SPBASE_API LPCTSTR SpStrRebootWay(const RebootWayEnum way)
 }
 
 #undef ENT_ENUM_MAP
-#define ENT_ENUM_MAP(name) case FrameworkState_##name: return #name; break;
+#define ENT_ENUM_MAP(name) case AppBootState_##name: return #name; break;
 
-SPBASE_API LPCTSTR SpStrFrameworkState(const FrameworkStateEnum state)
+SPBASE_API LPCTSTR SpStrAppBootState(const AppBootStateEnum state)
 {
 
 	static char content[128];
 
 	switch (state) {
-		ENT_ENUM_MAP(NotInit)
-		ENT_ENUM_MAP(NotConfig)
-		ENT_ENUM_MAP(Booting)
-		ENT_ENUM_MAP(Running)
-		ENT_ENUM_MAP(Serving)
-		ENT_ENUM_MAP(Breakdown)
-		ENT_ENUM_MAP(Repairing)
-		ENT_ENUM_MAP(Upgrading)
-		ENT_ENUM_MAP(Rollbacking)
-		ENT_ENUM_MAP(Recoving)
-		ENT_ENUM_MAP(NotDisturb)
+		ENT_ENUM_MAP(Init)
+		ENT_ENUM_MAP(StartEntity)
+		ENT_ENUM_MAP(CallAccessAuth)
+		ENT_ENUM_MAP(FirstEnterMainPage)
 	default:
 		sprintf(content, "UnRecorded(%d)", (int)state);
 		break;

+ 1 - 5
Framework/spbase/SpMisc.cpp

@@ -369,18 +369,14 @@ ErrorCodeEnum SpIniConfig::ReadConfigValueInt(const char *pszSection, const char
 //TODO: forbid from write cfg/entity.ini
 ErrorCodeEnum SpIniConfig::WriteConfigValue(const char *pszSection, const char *pszKey, const char *pszValue)
 {
-	if (m_type == Config_Root && (((FrameworkStateEnum)sp_get_env()->cfg->shell_ini->shell_state) == FrameworkState_NotConfig)) {
-		/** Skip and allow to modify root.ini  [Gifur@20211014]*/
-	} else if (m_type == Config_Hardware || m_type == Config_Shell || m_type == Config_Root || m_type == Config_CenterSetting) {
+	if (m_type == Config_Hardware || m_type == Config_Shell || m_type == Config_Root || m_type == Config_CenterSetting) {
 		return Error_Readonly;
 	}
-
     CSimpleStringA path;
     ErrorCodeEnum Error = _GetMappFilePath(path);
 	if (Error == Error_Succeed) {
 		Error = SpIniFileWriteString(path, pszSection, pszKey, pszValue);
 	}
-
 	return Error;
 }
 

+ 17 - 7
Framework/spbase/sp_cfg.cpp

@@ -1692,21 +1692,25 @@ static int shell_ini__load_entities_list(sp_dir_t* dir, sp_cfg_shell_ini_t* shel
 	return rc;
 }
 
-static int shell_ini__load_sysevent(sp_cfg_shell_ini_t* shell, const char* shell_var_path, std::map<std::string, std::string> &sysEventArr)
+static int shell_ini__init_sysevent(sp_cfg_shell_ini_t* shell)
 {
 	int rc = 0;
-
 	if (NULL == shell->arr_sysevent)
 	{
 		shell->arr_sysevent = shm_array_make(0, sizeof(sp_cfg_shell_sysevent_t*));
+		rc = 1;
+	}
+	else if (shell->arr_sysevent->nelts == 0) {
+		rc = 1;
+	}
+	if (rc == 1) {
 		//单独添加一个框架级别的系统变量
 		sp_cfg_shell_sysevent_t* sysevent = T_MALLOC_T(sp_cfg_shell_sysevent_t, 1);
 		memset(sysevent, 0, sizeof(sp_cfg_shell_sysevent_t));
 		sysevent->name = T_STRDUP(VAR_RSERVERD_KEY_TERM_STATE, 1);
 		sysevent->init_value[0] = '0', sysevent->init_value[1] = '\0';
-
 		sysevent->arr_owner_entity = shm_array_make(0, sizeof(sp_cfg_shell_entity_t*));
-		sp_cfg_shell_entity_t* owner_entity = find_entity(shell, "SpShell");
+		sp_cfg_shell_entity_t* owner_entity = find_entity(shell, SPSHELL_NAME);
 		if (owner_entity) {
 			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("add framework level sys val: %s", VAR_RSERVERD_KEY_TERM_STATE);
 			SHM_ARRAY_PUSH(sysevent->arr_owner_entity, sp_cfg_shell_entity_t*) = owner_entity;
@@ -1718,6 +1722,14 @@ static int shell_ini__load_sysevent(sp_cfg_shell_ini_t* shell, const char* shell
 			destroy_sysevent(sysevent);
 		}
 	}
+	return rc;
+}
+
+static int shell_ini__load_sysevent(sp_cfg_shell_ini_t* shell, const char* shell_var_path, std::map<std::string, std::string> &sysEventArr)
+{
+	int rc = 0;
+
+	shell_ini__init_sysevent(shell);
 
 	for (auto it = sysEventArr.begin(); it != sysEventArr.end(); it++)
 	{
@@ -2109,8 +2121,6 @@ ErrorCodeEnum init_shell_byHttp(sp_dir_t* dir, sp_cfg_shell_ini_t* shell, sp_cfg
 		}
 	}
 
-	
-
 	//init entity debug mode
 	if (args->debug_mode && shell->arr_entity) {
 		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("override entities' debug level!");
@@ -2172,7 +2182,7 @@ ErrorCodeEnum init_shell_byHttp(sp_dir_t* dir, sp_cfg_shell_ini_t* shell, sp_cfg
 	}	
 
 	shell->shell_debug_level = args->debug_mode ? 2 : debug_level;
-	shell->log_record_level = getEntityLogLevel("SpShell");
+	shell->log_record_level = getEntityLogLevel(SPSHELL_NAME);
 
 	if (args->telnet_port == 0)
 		shell->nConsolePort = shellConfig[SHELL_MAIN_HEAD].find(SHELL_MAIN_CONSOLEPORT) != shellConfig[SHELL_MAIN_HEAD].end() ?

+ 1 - 0
Framework/spbase/sp_var.c

@@ -125,6 +125,7 @@ int sp_var_client_set(sp_var_client_t *client, const char *key, const char *str,
 	if (!sp_var_can_write(client, key, &sysevent)) {
 
 		if (sysevent == NULL) {
+			DbgWithLinkForC(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM, "%s sysevent is not exist %s!", __FUNCTION__, key);
 			return Error_NotExist;
 		}
 		else {

+ 2 - 2
Framework/spshell/app.cpp

@@ -148,7 +148,7 @@ static unsigned int __stdcall __startlist_proc(void *param)
 		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("======================================================");
 		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("!!!!!! 部分实体启动失败,请检查dbg\\spshell日志排除故障 !!!!!!");
 		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("======================================================");
-		app_update_terminal_state(FrameworkState_Breakdown);
+		//app_update_terminal_state(FrameworkState_Breakdown);
 		
 		// 启动失败
 		app_upload_last_log();
@@ -607,7 +607,7 @@ int app_init(const sp_cfg_start_args_t* args, std::function<void(const char* msg
 
 #endif // RVC_OS_WIN && WITH_DEBUG
     
-	app_update_terminal_state(flag != 0 ? FrameworkState_NotConfig : FrameworkState_Booting);
+	//app_update_terminal_state(flag != 0 ? FrameworkState_NotConfig : FrameworkState_Booting);
 
 
 	auto shellEnv = sp_mod_mgr_find_entity_by_idx(sp_get_env()->mod_mgr, 0);

+ 1 - 0
Framework/spshell/app.h

@@ -66,6 +66,7 @@ int app_init(const sp_cfg_start_args_t* args, std::function<void(const char* msg
 int app_term();
 int app_run();
 void app_stop(int from_id);
+/** 暂时不适用,由实体去控制,否则会出现因配置SYSEVENT未拉下来导致值不统一的问题  [Gifur@2025314]*/
 int app_update_terminal_state(int state);
 
 void app_clear();

+ 3 - 3
Framework/spshell/svc.cpp

@@ -561,9 +561,9 @@ void on_terminal_stage_change(sp_rpc_server_t* server, int epid, int svc_id, int
     sp_cfg_t* cfg = env->cfg;
     iobuffer_read(*info_pkt, IOBUF_T_I4, &newStage, 0);
     iobuffer_read(*info_pkt, IOBUF_T_I4, &oldStage, 0);
-    const FrameworkStateEnum eNewStage = (FrameworkStateEnum)newStage;
-    const FrameworkStateEnum eOldStage = (FrameworkStateEnum)oldStage;
-	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("change teriminal state from %s to %s", SpStrFrameworkState(eOldStage), SpStrFrameworkState(eNewStage));
+    const AppBootStateEnum eNewStage = (AppBootStateEnum)newStage;
+    const AppBootStateEnum eOldStage = (AppBootStateEnum)oldStage;
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("change teriminal state from %s to %s", SpStrAppBootState(eOldStage), SpStrAppBootState(eNewStage));
     auto app = get_app_instance();
 #if defined(RVC_OS_LINUX)
 	if (app->bsc_gui != NULL) {

+ 1 - 3
Module/mod_chromium/mod_chromium.cpp

@@ -533,9 +533,7 @@ namespace Chromium {
 
 #if defined(RVC_OS_LINUX)
         Error = GetFunction()->SubscribeLog(m_uuidAllFault, this, Log_Notify, Severity_High, Error_IgnoreAll, -2, NULL, false);
-        if (Error_Succeed == Error) {
-            this->GetFunction()->GetPrivilegeFunction()->RefreshFrameworkState(FrameworkState_NotDisturb);
-        } else {
+        if (Error_Succeed != Error) {
 			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("subscribe log for notify failed! %s", SpStrError(Error));
         }
 #endif //RVC_OS_LINUX

+ 14 - 0
Module/mod_healthmanager/HealthManagerFSM.cpp

@@ -379,6 +379,9 @@ int CHealthManagerFSM::AccessAuthDoWork()
 		if (m_pACClient != NULL)
 		{
 			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to call accessauth regist");
+			CSystemRunInfo sysRunInfo;
+			if (GetEntityBase()->GetFunction()->GetSystemRunInfo(sysRunInfo) != Error_Succeed || sysRunInfo.eAppBootState == AppBootState_StartEntity)
+				GetEntityBase()->GetFunction()->GetPrivilegeFunction()->RefreshAppBootState(AppBootState_CallAccessAuth);
 			m_ullAuthStart = SP::Module::Comm::RVCGetTickCount();
 			eErrCode = (*m_pACClient)(EntityResource::getLink().upgradeLink())->Regist();
 			m_bHasAuthEver = true;
@@ -1333,4 +1336,15 @@ void CHealthManagerFSM::CheckIfPinPadOK()
 	m_ullWaitForPinPad = ullWaitEnd - ullWaitStart;
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501A3").setCostTime(m_ullWaitForPinPad)("finish (or time out) check  PinPad");
 	return;
+}
+bool CHealthManagerFSM::CheckIfAccessAuthSuc() 
+{
+	if (m_iAccessAuth == VtmLoad_AccessAuth_Suc)
+		return true;
+	CSimpleStringA csTmpTS("");
+	GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", csTmpTS);
+	if (csTmpTS.Compare("A") == 0)
+		return true;
+	else
+		return false;
 }

+ 2 - 1
Module/mod_healthmanager/HealthManagerFSM.h

@@ -161,9 +161,10 @@ public:
 
 	int AccessAuthDoWork();
 	void SetVtmLoadResult(int bResult);
-	bool GetAccessAuthFlag(){return m_iAccessAuth == VtmLoad_AccessAuth_Suc;}
+	bool CheckIfAccessAuthSuc();
 	int GetFSMState(){return m_fsmState;}
 	void ToReAccessAuth(bool bEver=false);
+	//oilyang@20250313 这个函数只有GetNetworkState,用来干嘛?而且在健康lost之后失效
 	int QueryAccessAuthStatus()
 	{
 		if (m_iAccessAuth == VtmLoad_AccessAuth_Suc)

+ 21 - 36
Module/mod_healthmanager/mod_healthmanager.cpp

@@ -257,7 +257,7 @@ void CHealthManagerEntity::OnCheckTimeTimeout()
 		eErrCode = GetFunction()->GetSysVar("TerminalStage", csTermStage);
 		Dbg("OnCheckTimeTimeout::ToRestartByCenterSetting to get termstage %s", csTermStage.GetData());
 		//oilyang@20250313 in Main page('UIState' is 'M') or TerminalStage is (NOT 'S') AND (NOT 'A'),that is in close page which caused by terminal app
-		if (CheckUIStateIsM() || (!CheckUIStateIsM() && csTermStage.Compare("S") != 0 && csTermStage.Compare("A") != 0) )
+		if (m_bInMainPage || (!m_bInMainPage && csTermStage.Compare("S") != 0 && csTermStage.Compare("A") != 0) )
 		{
 			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("THE key CenterSetting updated,we must restart framework right now.");
 			m_fsm.QuitFrameworkAndSaveInfo(RebootTrigger_Resource, RebootWay_Framework);
@@ -299,13 +299,9 @@ void CHealthManagerEntity::OnCheckTimeTimeout()
 		//1、AccessAuth ok
 		//2、have ever enter main page OR 
 		if (!m_bSayIdle)
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_fsm.GetAccessAuthFlag():%d, m_bEnterMainPageEver:%d, m_bInMainPage:%d", m_fsm.GetAccessAuthFlag()
-				, m_bEnterMainPageEver, CheckUIStateIsM());
-		//oilyang@20241230 check accessauth flag AND if in Main page ever
-		//oilyang@20250313 "Main page ever" has two scenes
-		//1. have enter main page ever,that is "m_bEnterMainPageEver is true"
-		//2. healthmanager have been lost at some point in the past,we check the "UIState" value if 'M'
-		if (m_fsm.GetAccessAuthFlag() && (m_bEnterMainPageEver || (!m_bEnterMainPageEver && CheckUIStateIsM())))
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_fsm.GetAccessAuthFlag():%d, CheckIfHaveEnterMainPageEver:%d", m_fsm.CheckIfAccessAuthSuc(), CheckIfHaveEnterMainPageEver());
+		//oilyang@20241230 check if have enter Main page ever
+		if (CheckIfHaveEnterMainPageEver())
 		{
 			iCheckGuardian = CheckGuardianIsRun(true);
 			if (!m_bSayIdle)
@@ -379,7 +375,7 @@ void CHealthManagerEntity::OnCheckTimeTimeout()
 		else
 		{
 			//oilyang@20190905 add if auth suc,tell guardian,for upgrade
-			if (m_fsm.GetAccessAuthFlag())
+			if (m_fsm.CheckIfAccessAuthSuc())
 			{
 				if (CheckGuardianIsRun(true) > 0)
 				{
@@ -1272,11 +1268,11 @@ void CHealthManagerEntity::OnSysVarEvent(const char *pszKey, const char *pszValu
 		if (_strnicmp(pszValue, "M", strlen("M")) == 0)
 		{
 			m_bInMainPage = true;
-			m_bEnterMainPageEver = true;
-
-			if (!m_bHaveThrowMainPage)
+			if (!CheckIfHaveEnterMainPageEver())
 			{
-				m_bHaveThrowMainPage = true;
+				CSystemRunInfo sysRunInfo;
+				if (GetFunction()->GetSystemRunInfo(sysRunInfo) != Error_Succeed || sysRunInfo.eAppBootState == AppBootState_CallAccessAuth)
+					GetFunction()->GetPrivilegeFunction()->RefreshAppBootState(AppBootState_FirstEnterMainPage);
 				
 				CSmartPointer<IConfigInfo> spConfigRun;
 				ErrorCodeEnum eErr = GetFunction()->OpenConfig(Config_Run, spConfigRun);
@@ -1302,8 +1298,6 @@ void CHealthManagerEntity::OnSysVarEvent(const char *pszKey, const char *pszValu
 		}
 		else
 			m_bInMainPage = false;
-
-
 	}
 }
 void CHealthManagerEntity::OnBroadcastEvent(CUUID SubID, const char *pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, CAutoBuffer Buffer)
@@ -1315,7 +1309,7 @@ void CHealthManagerEntity::OnTimeout(DWORD dwTimeID)
 	switch (dwTimeID)
 	{
 	case HEALTHMANAGER_WAIT_MAINPAGE_OPEN_TIMER_ID:
-		if (!m_bHaveThrowMainPage)
+		if (!CheckIfHaveEnterMainPageEver())
 			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setResultCode("RTA5101")
 			("After receive accessauth success event, havn't receive enter main page.", m_maxWaitMainpageTime / 1000);
 		break;
@@ -1455,18 +1449,6 @@ namespace
 	}
 }
 
-bool CHealthManagerEntity::IsTestMode()
-{
-	static int flag = -1;
-	if (flag == -1) {
-		CSystemRunInfo runInfo;
-		bool result = (GetFunction()->GetSystemRunInfo(runInfo) == Error_Succeed
-			&& !!(runInfo.dwBootOption & SystemBootOptionEnum::BootOption_Test));
-		flag = result ? 1 : 0;
-	}
-	return !!flag;
-}
-
 void CHealthManagerEntity::OnEntityStateHook(const char* pszEntityName, const char* pszTriggerEntity, EntityStateEnum eState, EntityStateEnum eLastState)
 {
 	CSmartPointer<IEntityFunction> pFunc = GetFunction();
@@ -1508,7 +1490,7 @@ void CHealthManagerEntity::OnEntityStateHook(const char* pszEntityName, const ch
 			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501S1").setResultCode(csResultCode.GetData())(tmpWarnMsg.GetData());
 			//doing nothing before enter main page. HandShake will take it.
 			//AND if selfcheck is doing, no action at all
-			if (m_bEnterMainPageEver && m_modRunInfo[pszEntityName].abnormalCount < m_maxAbnormalTimes && !m_modRunInfo[pszEntityName].bAbnormalBusy)
+			if (CheckIfHaveEnterMainPageEver() && m_modRunInfo[pszEntityName].abnormalCount < m_maxAbnormalTimes && !m_modRunInfo[pszEntityName].bAbnormalBusy)
 			{
 				m_modRunInfo[pszEntityName].bAbnormalBusy = true;
 				m_modRunInfo[pszEntityName].abnormalCount++;
@@ -1744,20 +1726,23 @@ void CHealthManagerEntity::EntityLostProc(CSimpleStringA entityName)
 	}
 	else
 		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("on lost start %d", eErrCode);
-	if (m_bEnterMainPageEver && _strnicmp("TokenKeeper", entityName, strlen("TokenKeeper")) == 0)
+	if (CheckIfHaveEnterMainPageEver() && _strnicmp("TokenKeeper", entityName, strlen("TokenKeeper")) == 0)
 	{
 		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("TokenKeeper lost");
 		m_fsm.ToReAccessAuth();
 	}
 	m_modRunInfo[entityName].bAbnormalBusy = false;
 }
-bool CHealthManagerEntity::CheckUIStateIsM()
+bool CHealthManagerEntity::CheckIfHaveEnterMainPageEver()
 {
-	if (m_bInMainPage)
-		return true;
-	CSimpleStringA uiState(true);
-	if (GetFunction()->GetSysVar("UIState", uiState) != Error_Succeed || uiState.Compare("M") != 0)
-		return false;
+	if (!m_bSayIdle)
+	{
+		CSystemRunInfo sysRunInfo;
+		if (GetFunction()->GetSystemRunInfo(sysRunInfo) == Error_Succeed && sysRunInfo.eAppBootState == AppBootState_FirstEnterMainPage)
+			return true;
+		else
+			return false;
+	}
 	else
 		return true;
 }

+ 3 - 7
Module/mod_healthmanager/mod_healthmanager.h

@@ -88,7 +88,6 @@ public:
 		, m_bSayIdle(false), m_bGuardianRun(false), m_ullGuardShakeCount(0)
 		, m_menuChoice(""), m_menuPre(""), m_netState("N")
 		, m_bInMainPage(false), m_stopSelfCheck(0)
-		, m_bEnterMainPageEver(false),m_bHaveThrowMainPage(false)
 		,m_bNeedAuthRetry(false), m_bNeedGuardianRestart(true), m_bNeedGuardian(true)
 		, m_bToRestartByCenterSetting(false){}
 	virtual ~CHealthManagerEntity() {}
@@ -213,7 +212,7 @@ public:
 	{
 		ctx->Ans.netDeviceState = m_netState;
 		ctx->Ans.reserved1 = m_fsm.QueryAccessAuthStatus();
-		Dbg("current net state %s,auth state:%d", (LPCTSTR)m_netState, ctx->Ans.reserved1);
+		DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_USER).setLogCode(HealthManagerService_LogCode_GetNetworkState)("current net state %s,auth state:%d", (LPCTSTR)m_netState, ctx->Ans.reserved1);
 		ctx->Answer(Error_Succeed);
 	}
 
@@ -265,8 +264,7 @@ private:
 	int m_stopSelfCheck;
 	int m_restartHour, m_restartMinute, m_lastHour, m_maxAbnormalTimes, m_rebootHourBegin, m_rebootHourEnd;;
 	bool m_bWaitRestartPC, m_bScreenLock, m_bSayIdle
-		, m_bGuardianRun
-		, m_bInMainPage, m_bEnterMainPageEver, m_bHaveThrowMainPage, m_bToRestartByCenterSetting;
+		, m_bGuardianRun, m_bInMainPage, m_bToRestartByCenterSetting;
 	bool m_bNeedAuthRetry/*需要重试准入*/, m_bNeedGuardianRestart/*需要重启*/, m_bNeedGuardian;
 	DWORD m_dwTimeOfAuthSuc;
 	int m_maxWaitMainpageTime;
@@ -296,10 +294,8 @@ private:
 	
 	CSimpleStringA __ReadCenterConfigStr(CSimpleStringA key, CSimpleStringA entityName);
 
-	bool IsTestMode();
-
 	void ToCalcRebootHourAndMinute(int restartBegin, int restartEnd);
-	bool CheckUIStateIsM();
+	bool CheckIfHaveEnterMainPageEver();
 };
 #endif // __MOD_HEALTHMANAGER_H
 

+ 13 - 1
Module/mod_vtmloader/VtmLoaderFSM.cpp

@@ -1096,6 +1096,11 @@ int CVtmLoaderFSM::EntityLoad()
 	//oilyang@20240407 add check machine model in ST/UAT test room
 	if (!CheckConfigInfoInTestRoom())
 		return -1;
+	CSystemRunInfo sysRunInfo;
+	if (GetEntityBase()->GetFunction()->GetSystemRunInfo(sysRunInfo) != Error_Succeed || sysRunInfo.eAppBootState == AppBootState_Init)
+		GetEntityBase()->GetFunction()->GetPrivilegeFunction()->RefreshAppBootState(AppBootState_StartEntity);
+	else
+		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetSystemRunInfo failed:%d");
 
 	LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "开始加载实体");
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("StartLoadEntity")("开始加载实体");
@@ -1829,8 +1834,15 @@ bool CVtmLoaderFSM::GetConfig()
 ErrorCodeEnum CVtmLoaderFSM::SubscribeEntitysEvents()
 {
 	//want to do what?
-
 	auto rc = Error_Succeed;
+	/*GifutTest20250314 begin*/
+	CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
+	rc = pFunc->RegistTerminalStateChangeEvent(dynamic_cast<ITerminalStateChangedListener*>(this->GetEntityBase()));
+	if (rc != Error_Succeed)
+	{
+		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("RegistTerminalStateChangeEvent failed: %s", SpStrError(rc));
+	}
+	/*GifutTest20250314 end*/
 	return rc;
 }
 int CVtmLoaderFSM::HttpConnCheck(CSimpleStringA csHttAddr, HttpAddrType eType)

+ 9 - 0
Module/mod_vtmloader/mod_vtmloader.h

@@ -87,6 +87,15 @@ public:
 	virtual void OnCloseConnection(const char* pszCallerEntity, const char* pszServiceEntity) { return; }
 	void EntityLostProc(CSimpleStringA entityName);
 	void SetVideoEntityOK() { m_FSM.SetVideoEntityOK(); }
+
+	/*GifutTest20250314 begin*/
+	//void OnStateChanged(AppBootStateEnum oldState, AppBootStateEnum curState, const char* triggerEntity)
+	//{
+	//	LOG_FUNCTION();
+	//	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("state changed from %s to %s by %s", SpStrAppBootState(oldState), SpStrAppBootState(curState), triggerEntity);
+	//}
+	/*GifutTest20250314 end*/
+
 protected:
 	//GUITask m_task;
 	CVtmLoaderFSM m_FSM;