mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-11-23 00:39:52 +00:00
bug:wait util the datashare ready event is pulled up, create datashare helper
Signed-off-by: song-chenxi050 <songchenxi2@huawei.com>
This commit is contained in:
parent
7facb07a51
commit
046c51d346
@ -64,6 +64,8 @@ void CommonEventMonitor::OnReceiveEvent(const CommonEventData &data)
|
||||
LnnNotifyScreenLockStateChangeEvent(SOFTBUS_USER_UNLOCK);
|
||||
} else if (action == CommonEventSupport::COMMON_EVENT_SCREEN_UNLOCKED) {
|
||||
LnnNotifyScreenLockStateChangeEvent(SOFTBUS_SCREEN_UNLOCK);
|
||||
} else if (action == CommonEventSupport::COMMON_EVENT_DATA_SHARE_READY) {
|
||||
LnnNotifyDataShareStateChangeEvent(SOFTBUS_DATA_SHARE_READY);
|
||||
}
|
||||
if (screenState != SOFTBUS_SCREEN_UNKNOWN) {
|
||||
LnnNotifyScreenStateChangeEvent(screenState);
|
||||
@ -101,6 +103,7 @@ int32_t SubscribeEvent::SubscribeCommonEvent()
|
||||
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_UNLOCKED);
|
||||
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SCREEN_UNLOCKED);
|
||||
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
|
||||
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_DATA_SHARE_READY);
|
||||
CommonEventSubscribeInfo subscriberInfo(matchingSkills);
|
||||
subscriber_ = std::make_shared<CommonEventMonitor>(subscriberInfo);
|
||||
if (!CommonEventManager::SubscribeCommonEvent(subscriber_)) {
|
||||
|
@ -724,10 +724,14 @@ static void UserSwitchedHandler(const LnnEventBasicInfo *info)
|
||||
}
|
||||
const LnnMonitorHbStateChangedEvent *event = (const LnnMonitorHbStateChangedEvent *)info;
|
||||
SoftBusUserSwitchState userSwitchState = (SoftBusUserSwitchState)event->status;
|
||||
bool isDataShareInit = true;
|
||||
switch (userSwitchState) {
|
||||
case SOFTBUS_USER_SWITCHED:
|
||||
LNN_LOGI(LNN_BUILDER, "SOFTBUS_USER_SWITCHED");
|
||||
RegisterOOBEMonitor(NULL);
|
||||
LnnGetDataShareInitResult(&isDataShareInit);
|
||||
if (isDataShareInit) {
|
||||
RegisterOOBEMonitor(NULL);
|
||||
}
|
||||
LnnSetUnlockState();
|
||||
break;
|
||||
default:
|
||||
|
@ -94,6 +94,7 @@ bool LnnVisitNetif(VisitNetifCallback callback, void *data);
|
||||
bool LnnVisitProtocol(VisitProtocolCallback callback, void *data);
|
||||
int32_t RegistIPProtocolManager(void);
|
||||
void LnnSetUnlockState(void);
|
||||
void LnnGetDataShareInitResult(bool *isDataShareInit);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
@ -15,7 +15,9 @@
|
||||
|
||||
#include "lnn_network_manager.h"
|
||||
|
||||
#include <pthread.h>
|
||||
#include <securec.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "auth_interface.h"
|
||||
#include "bus_center_event.h"
|
||||
@ -30,6 +32,7 @@
|
||||
#include "lnn_log.h"
|
||||
#include "lnn_net_builder.h"
|
||||
#include "lnn_ohos_account.h"
|
||||
#include "lnn_oobe_manager.h"
|
||||
#include "lnn_physical_subnet_manager.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_def.h"
|
||||
@ -48,6 +51,9 @@
|
||||
|
||||
#define LNN_CHECK_OOBE_DELAY_LEN (5 * 60 * 1000LL)
|
||||
|
||||
static pthread_mutex_t g_dataShareMutex;
|
||||
static bool g_isDataShareInit = false;
|
||||
|
||||
typedef enum {
|
||||
LNN_ETH_TYPE = 0,
|
||||
LNN_WLAN_TYPE,
|
||||
@ -316,6 +322,68 @@ static void NetOOBEStateEventHandler(const LnnEventBasicInfo *info)
|
||||
}
|
||||
}
|
||||
|
||||
static void RetryCheckOOBEState(void *para)
|
||||
{
|
||||
(void)para;
|
||||
|
||||
if (!IsOOBEState()) {
|
||||
LNN_LOGI(LNN_BUILDER, "wifi handle SOFTBUS_OOBE_END");
|
||||
LnnNotifyOOBEStateChangeEvent(SOFTBUS_OOBE_END);
|
||||
} else {
|
||||
LNN_LOGD(LNN_BUILDER, "check OOBE again after a delay. delay=%{public}" PRIu64 "ms",
|
||||
(uint64_t)LNN_CHECK_OOBE_DELAY_LEN);
|
||||
LnnAsyncCallbackDelayHelper(GetLooper(LOOP_TYPE_DEFAULT), RetryCheckOOBEState, NULL, LNN_CHECK_OOBE_DELAY_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
static void DataShareStateEventHandler(const LnnEventBasicInfo *info)
|
||||
{
|
||||
if (info == NULL || info->event != LNN_EVENT_DATA_SHARE_STATE_CHANGE) {
|
||||
LNN_LOGE(LNN_BUILDER, "Data share get invalid param");
|
||||
return;
|
||||
}
|
||||
|
||||
const LnnMonitorHbStateChangedEvent *event = (const LnnMonitorHbStateChangedEvent *)info;
|
||||
SoftBusDataShareState state = (SoftBusDataShareState)event->status;
|
||||
switch (state) {
|
||||
case SOFTBUS_DATA_SHARE_READY:
|
||||
LNN_LOGI(LNN_BUILDER, "data share state is=%{public}d", g_isDataShareInit);
|
||||
if (g_isDataShareInit != true) {
|
||||
if (pthread_mutex_lock(&g_dataShareMutex) != 0) {
|
||||
LNN_LOGE(LNN_BUILDER, "gen data share mutex fail");
|
||||
return;
|
||||
}
|
||||
g_isDataShareInit = true;
|
||||
(void)pthread_mutex_unlock(&g_dataShareMutex);
|
||||
LnnInitOOBEStateMonitorImpl();
|
||||
RetryCheckOOBEState(NULL);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (pthread_mutex_lock(&g_dataShareMutex) != 0) {
|
||||
LNN_LOGE(LNN_BUILDER, "gen data share mutex fail");
|
||||
return;
|
||||
}
|
||||
g_isDataShareInit = false;
|
||||
(void)pthread_mutex_unlock(&g_dataShareMutex);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void LnnGetDataShareInitResult(bool *isDataShareInit)
|
||||
{
|
||||
if (isDataShareInit == NULL) {
|
||||
LNN_LOGE(LNN_BUILDER, "Data share get invalid param");
|
||||
return;
|
||||
}
|
||||
if (pthread_mutex_lock(&g_dataShareMutex) != 0) {
|
||||
LNN_LOGE(LNN_BUILDER, "gen data share mutex fail");
|
||||
return;
|
||||
}
|
||||
*isDataShareInit = g_isDataShareInit;
|
||||
(void)pthread_mutex_unlock(&g_dataShareMutex);
|
||||
}
|
||||
|
||||
int32_t LnnClearNetConfigList(void)
|
||||
{
|
||||
LnnNetIfMgr *item = NULL;
|
||||
@ -651,6 +719,10 @@ static int32_t LnnRegisterEvent(void)
|
||||
LNN_LOGE(LNN_BUILDER, "Net regist account change evt handler fail");
|
||||
return SOFTBUS_NETWORK_REG_EVENT_HANDLER_ERR;
|
||||
}
|
||||
if (LnnRegisterEventHandler(LNN_EVENT_DATA_SHARE_STATE_CHANGE, DataShareStateEventHandler) != SOFTBUS_OK) {
|
||||
LNN_LOGE(LNN_BUILDER, "Net regist data share evt handler fail");
|
||||
return SOFTBUS_NETWORK_REG_EVENT_HANDLER_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
@ -696,20 +768,6 @@ int32_t LnnInitNetworkManager(void)
|
||||
return LnnRegisterEvent();
|
||||
}
|
||||
|
||||
static void RetryCheckOOBEState(void *para)
|
||||
{
|
||||
(void)para;
|
||||
|
||||
if (!IsOOBEState()) {
|
||||
LNN_LOGI(LNN_BUILDER, "wifi handle SOFTBUS_OOBE_END");
|
||||
LnnNotifyOOBEStateChangeEvent(SOFTBUS_OOBE_END);
|
||||
} else {
|
||||
LNN_LOGD(LNN_BUILDER, "check OOBE again after a delay. delay=%{public}" PRIu64 "ms",
|
||||
(uint64_t)LNN_CHECK_OOBE_DELAY_LEN);
|
||||
LnnAsyncCallbackDelayHelper(GetLooper(LOOP_TYPE_DEFAULT), RetryCheckOOBEState, NULL, LNN_CHECK_OOBE_DELAY_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
void LnnSetUnlockState(void)
|
||||
{
|
||||
if (IsActiveOsAccountUnlocked()) {
|
||||
@ -742,7 +800,6 @@ int32_t LnnInitNetworkManagerDelay(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
RetryCheckOOBEState(NULL);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
@ -794,6 +851,7 @@ void LnnDeinitNetworkManager(void)
|
||||
LnnUnregisterEventHandler(LNN_EVENT_SCREEN_LOCK_CHANGED, NetLockStateEventHandler);
|
||||
LnnUnregisterEventHandler(LNN_EVENT_OOBE_STATE_CHANGED, NetOOBEStateEventHandler);
|
||||
LnnUnregisterEventHandler(LNN_EVENT_ACCOUNT_CHANGED, NetAccountStateChangeEventHandler);
|
||||
LnnUnregisterEventHandler(LNN_EVENT_DATA_SHARE_STATE_CHANGE, DataShareStateEventHandler);
|
||||
}
|
||||
|
||||
int32_t LnnGetNetIfTypeByName(const char *ifName, LnnNetIfType *type)
|
||||
|
@ -39,7 +39,6 @@
|
||||
#include "lnn_meta_node_ledger.h"
|
||||
#include "lnn_p2p_info.h"
|
||||
#include "lnn_settingdata_event_monitor.h"
|
||||
#include "lnn_oobe_manager.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_error_code.h"
|
||||
@ -222,7 +221,6 @@ int32_t LnnInitEventMoniterDelay(void)
|
||||
LNN_LOGE(LNN_LEDGER, "delay init LnnInitCommonEventMonitorImpl fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
LnnInitOOBEStateMonitorImpl();
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
|
@ -54,6 +54,7 @@ typedef enum {
|
||||
LNN_EVENT_NETWORKID_CHANGED,
|
||||
LNN_EVENT_LP_EVENT_REPORT,
|
||||
LNN_EVENT_LANE_VAP_CHANGE,
|
||||
LNN_EVENT_DATA_SHARE_STATE_CHANGE,
|
||||
LNN_EVENT_TYPE_MAX,
|
||||
} LnnEventType;
|
||||
|
||||
@ -112,6 +113,11 @@ typedef enum {
|
||||
SOFTBUS_USER_SWITCH_UNKNOWN,
|
||||
} SoftBusUserSwitchState;
|
||||
|
||||
typedef enum {
|
||||
SOFTBUS_DATA_SHARE_READY,
|
||||
SOFTBUS_DATA_SHARE_UNKNOWN,
|
||||
} SoftBusDataShareState;
|
||||
|
||||
typedef enum {
|
||||
SOFTBUS_DIF_ACCOUNT_DEV_CHANGE,
|
||||
SOFTBUS_DIF_ACCOUNT_UNKNOWN,
|
||||
@ -290,6 +296,8 @@ void LnnNotifyHBRepeat(void);
|
||||
|
||||
void LnnNotifyUserSwitchEvent(SoftBusUserSwitchState state);
|
||||
|
||||
void LnnNotifyDataShareStateChangeEvent(SoftBusDataShareState state);
|
||||
|
||||
void LnnNotifyVapInfoChangeEvent(int32_t preferChannel);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -566,6 +566,16 @@ void LnnNotifyScreenLockStateChangeEvent(SoftBusScreenLockState state)
|
||||
NotifyEvent((const LnnEventBasicInfo *)&event);
|
||||
}
|
||||
|
||||
void LnnNotifyDataShareStateChangeEvent(SoftBusDataShareState state)
|
||||
{
|
||||
if (state < SOFTBUS_DATA_SHARE_READY || state >= SOFTBUS_DATA_SHARE_UNKNOWN) {
|
||||
LNN_LOGE(LNN_EVENT, "bad lockState=%{public}d", state);
|
||||
return;
|
||||
}
|
||||
LnnMonitorHbStateChangedEvent event = {.basic.event = LNN_EVENT_DATA_SHARE_STATE_CHANGE, .status = state};
|
||||
NotifyEvent((const LnnEventBasicInfo *)&event);
|
||||
}
|
||||
|
||||
void LnnNotifyAccountStateChangeEvent(SoftBusAccountState state)
|
||||
{
|
||||
if (state < SOFTBUS_ACCOUNT_LOG_IN || state >= SOFTBUS_ACCOUNT_UNKNOWN) {
|
||||
|
@ -203,6 +203,7 @@ public:
|
||||
virtual void GetLnnTriggerInfo(LnnTriggerInfo *triggerInfo) = 0;
|
||||
virtual int32_t LnnSetDLConnUserIdCheckSum(const char *networkId, int32_t userIdCheckSum) = 0;
|
||||
virtual void LnnNotifyDeviceTrustedChange(int32_t type, const char *msg, uint32_t msgLen) = 0;
|
||||
virtual void LnnGetDataShareInitResult(bool *isDataShareInit) = 0;
|
||||
};
|
||||
class NetBuilderDepsInterfaceMock : public NetBuilderDepsInterface {
|
||||
public:
|
||||
@ -347,6 +348,7 @@ public:
|
||||
MOCK_METHOD1(GetLnnTriggerInfo, void (LnnTriggerInfo *));
|
||||
MOCK_METHOD2(LnnSetDLConnUserIdCheckSum, int32_t(const char *networkId, int32_t userIdCheckSum));
|
||||
MOCK_METHOD3(LnnNotifyDeviceTrustedChange, void(int32_t type, const char *msg, uint32_t msgLen));
|
||||
MOCK_METHOD1(LnnGetDataShareInitResult, void (bool *));
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // LNN_NET_BUILDER_DEPS_MOCK_H
|
||||
|
@ -741,5 +741,10 @@ void LnnNotifyDeviceTrustedChange(int32_t type, const char *msg, uint32_t msgLen
|
||||
{
|
||||
return GetNetBuilderDepsInterface()->LnnNotifyDeviceTrustedChange(type, msg, msgLen);
|
||||
}
|
||||
|
||||
void LnnGetDataShareInitResult(bool *isDataShareInit)
|
||||
{
|
||||
return GetNetBuilderDepsInterface()->LnnGetDataShareInitResult(isDataShareInit);
|
||||
}
|
||||
} // extern "C"
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user