mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-11-27 02:40:40 +00:00
added function and capability value for querying screen status directly, and added ut code
Signed-off-by: wudj2110 <wudaijun2@huawei.com>
This commit is contained in:
parent
741d0ab9db
commit
e53978803c
@ -106,6 +106,7 @@ if (defined(ohos_lite)) {
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"init:libbeget_proxy",
|
||||
"netmanager_base:net_conn_manager_if",
|
||||
"power_manager:powermgr_client",
|
||||
]
|
||||
} else {
|
||||
bus_center_adapter_src += [
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "lnn_heartbeat_strategy.h"
|
||||
#include "want.h"
|
||||
|
||||
#include "power_mgr_client.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_errcode.h"
|
||||
|
||||
@ -111,6 +112,17 @@ int32_t SubscribeEvent::SubscribeCommonEvent()
|
||||
} // namespace EventFwk
|
||||
} // namespace OHOS
|
||||
|
||||
bool LnnQueryLocalScreenStatusOnce(bool notify)
|
||||
{
|
||||
bool isScreenOn = OHOS::PowerMgr::PowerMgrClient::GetInstance().IsScreenOn(true);
|
||||
LNN_LOGI(LNN_EVENT, "query screen status is %{public}s", isScreenOn ? "on" : "off");
|
||||
if (notify) {
|
||||
SoftBusScreenState screenState = isScreenOn ? SOFTBUS_SCREEN_ON : SOFTBUS_SCREEN_OFF;
|
||||
LnnNotifyScreenStateChangeEvent(screenState);
|
||||
}
|
||||
return isScreenOn;
|
||||
}
|
||||
|
||||
static void LnnSubscribeCommonEvent(void *para)
|
||||
{
|
||||
(void)para;
|
||||
@ -139,6 +151,7 @@ static void LnnSubscribeCommonEvent(void *para)
|
||||
}
|
||||
}
|
||||
delete subscriberPtr;
|
||||
(void)LnnQueryLocalScreenStatusOnce(true);
|
||||
}
|
||||
|
||||
int32_t LnnInitCommonEventMonitorImpl(void)
|
||||
|
@ -59,6 +59,7 @@ void LnnDeInitNetlinkMonitorImpl(void);
|
||||
|
||||
int32_t LnnSubscribeAccountBootEvent(AccountEventHandle handle);
|
||||
|
||||
bool LnnQueryLocalScreenStatusOnce(bool notify);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -84,7 +84,8 @@
|
||||
"mbedtls",
|
||||
"libcoap",
|
||||
"zlib",
|
||||
"libnl"
|
||||
"libnl",
|
||||
"power_manager"
|
||||
],
|
||||
"third_party": [
|
||||
"cJSON",
|
||||
|
@ -185,6 +185,15 @@ int32_t LnnIpcNotifyBasicInfoChanged(void *info, uint32_t infoTypeLen, int32_t t
|
||||
return LnnOnNodeBasicInfoChanged("", info, type);
|
||||
}
|
||||
|
||||
int32_t LnnIpcNotifyNodeStatusChanged(void *info, uint32_t infoTypeLen, int32_t type)
|
||||
{
|
||||
(void)info;
|
||||
(void)infoTypeLen;
|
||||
(void)type;
|
||||
LNN_LOGI(LNN_EVENT, "not implement");
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t LnnIpcLocalNetworkIdChanged(void)
|
||||
{
|
||||
LNN_LOGI(LNN_EVENT, "not implement");
|
||||
|
@ -444,6 +444,15 @@ int32_t LnnIpcNotifyBasicInfoChanged(void *info, uint32_t infoTypeLen, int32_t t
|
||||
return ClinetOnNodeBasicInfoChanged(info, infoTypeLen, type);
|
||||
}
|
||||
|
||||
int32_t LnnIpcNotifyNodeStatusChanged(void *info, uint32_t infoTypeLen, int32_t type)
|
||||
{
|
||||
(void)info;
|
||||
(void)infoTypeLen;
|
||||
(void)type;
|
||||
LNN_LOGI(LNN_EVENT, "not implement");
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t LnnIpcLocalNetworkIdChanged(void)
|
||||
{
|
||||
LNN_LOGI(LNN_EVENT, "not implement");
|
||||
|
@ -130,6 +130,7 @@ typedef struct {
|
||||
|
||||
typedef enum {
|
||||
BIT_SUPPORT_DIRECT_TRIGGER = 0,
|
||||
BIT_SUPPORT_SCREEN_STATUS = 0,
|
||||
} HeartbeatCapability;
|
||||
|
||||
#define STATE_VERSION_INVALID (-1)
|
||||
|
@ -630,5 +630,6 @@ int32_t LnnSetScreenStatus(NodeInfo *info, bool isScreenOn)
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
info->isScreenOn = isScreenOn;
|
||||
LNN_LOGI(LNN_LEDGER, "set local screen status to %{public}s", isScreenOn ? "on" : "off");
|
||||
return SOFTBUS_OK;
|
||||
}
|
@ -56,6 +56,7 @@ static int32_t DlGetDeviceUuid(const char *networkId, bool checkOnline, void *bu
|
||||
|
||||
static int32_t DlGetDeviceOfflineCode(const char *networkId, bool checkOnline, void *buf, uint32_t len)
|
||||
{
|
||||
(void)checkOnline;
|
||||
NodeInfo *info = NULL;
|
||||
RETURN_IF_GET_NODE_VALID(networkId, buf, info);
|
||||
if (memcpy_s(buf, len, info->offlineCode, OFFLINE_CODE_BYTE_SIZE) != EOK) {
|
||||
@ -116,6 +117,7 @@ static int32_t DlGetDeviceType(const char *networkId, bool checkOnline, void *bu
|
||||
static int32_t DlGetDeviceTypeId(const char *networkId, bool checkOnline, void *buf, uint32_t len)
|
||||
{
|
||||
(void)checkOnline;
|
||||
(void)len;
|
||||
NodeInfo *info = NULL;
|
||||
RETURN_IF_GET_NODE_VALID(networkId, buf, info);
|
||||
*((int32_t *)buf) = info->deviceInfo.deviceTypeId;
|
||||
@ -317,6 +319,14 @@ void LnnUpdateNodeBleMac(const char *networkId, char *bleMac, uint32_t len)
|
||||
SoftBusMutexUnlock(&(LnnGetDistributedNetLedger()->lock));
|
||||
}
|
||||
|
||||
int32_t IsNodeInfoScreenStatusSupport(const NodeInfo *info)
|
||||
{
|
||||
if (!LnnIsSupportHeartbeatCap(info->heartbeatCapacity, BIT_SUPPORT_SCREEN_STATUS)) {
|
||||
return SOFTBUS_NETWORK_NOT_SUPPORT;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
bool LnnSetRemoteScreenStatusInfo(const char *networkId, bool isScreenOn)
|
||||
{
|
||||
if (networkId == NULL) {
|
||||
@ -327,14 +337,26 @@ bool LnnSetRemoteScreenStatusInfo(const char *networkId, bool isScreenOn)
|
||||
LNN_LOGE(LNN_LEDGER, "lock mutex fail!");
|
||||
return false;
|
||||
}
|
||||
char *anonyNetworkId = NULL;
|
||||
Anonymize(networkId, &anonyNetworkId);
|
||||
NodeInfo *info = LnnGetNodeInfoById(networkId, CATEGORY_NETWORK_ID);
|
||||
if (info == NULL) {
|
||||
LNN_LOGE(LNN_LEDGER, "get node info fail.");
|
||||
LNN_LOGE(LNN_LEDGER, "networkId=%{public}s, get node info fail.", anonyNetworkId);
|
||||
SoftBusMutexUnlock(&(LnnGetDistributedNetLedger()->lock));
|
||||
AnonymizeFree(anonyNetworkId);
|
||||
return false;
|
||||
}
|
||||
if (IsNodeInfoScreenStatusSupport(info) != SOFTBUS_OK) {
|
||||
LNN_LOGE(LNN_LEDGER, "networkId=%{public}s, node screen status is not supported", anonyNetworkId);
|
||||
SoftBusMutexUnlock(&(LnnGetDistributedNetLedger()->lock));
|
||||
AnonymizeFree(anonyNetworkId);
|
||||
return false;
|
||||
}
|
||||
|
||||
info->isScreenOn = isScreenOn;
|
||||
LNN_LOGI(LNN_LEDGER, "set %{public}s screen status to %{public}s", anonyNetworkId, isScreenOn ? "on" : "off");
|
||||
SoftBusMutexUnlock(&LnnGetDistributedNetLedger()->lock);
|
||||
AnonymizeFree(anonyNetworkId);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -656,10 +678,20 @@ static int32_t DlGetNodeScreenOnFlag(const char *networkId, bool checkOnline, vo
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
RETURN_IF_GET_NODE_VALID(networkId, buf, info);
|
||||
char *anonyNetworkId = NULL;
|
||||
Anonymize(networkId, &anonyNetworkId);
|
||||
int32_t ret = IsNodeInfoScreenStatusSupport(info);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LNN_LOGI(LNN_LEDGER, "%{public}s get node screen not support", anonyNetworkId);
|
||||
AnonymizeFree(anonyNetworkId);
|
||||
return ret;
|
||||
}
|
||||
if (checkOnline && !LnnIsNodeOnline(info) && !IsMetaNode(info)) {
|
||||
LNN_LOGE(LNN_LEDGER, "node is offline");
|
||||
LNN_LOGE(LNN_LEDGER, "%{public}s node is offline", anonyNetworkId);
|
||||
AnonymizeFree(anonyNetworkId);
|
||||
return SOFTBUS_NETWORK_NODE_OFFLINE;
|
||||
}
|
||||
AnonymizeFree(anonyNetworkId);
|
||||
*((bool *)buf) = info->isScreenOn;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@
|
||||
#define SOFTBUS_BUSCENTER_DUMP_LOCALDEVICEINFO "local_device_info"
|
||||
#define ALL_GROUP_TYPE 0xF
|
||||
#define MAX_STATE_VERSION 0xFF
|
||||
#define DEFAULT_SUPPORT_HBCAPACITY 0x1
|
||||
#define DEFAULT_SUPPORT_HBCAPACITY 0x3
|
||||
#define DEFAULT_CONN_SUB_FEATURE 3
|
||||
#define CACHE_KEY_LENGTH 32
|
||||
#define STATE_VERSION_VALUE_LENGTH 8
|
||||
|
@ -121,7 +121,7 @@ static void HandleNodeBasicInfoChangedMessage(SoftBusMessage *msg)
|
||||
static void HandleNodeStatusChangedMessage(SoftBusMessage *msg)
|
||||
{
|
||||
if (msg->obj == NULL) {
|
||||
LNN_LOGE(LNN_EVENT, "invalid node basic info message");
|
||||
LNN_LOGE(LNN_EVENT, "invalid node status message");
|
||||
return;
|
||||
}
|
||||
int32_t type = (int32_t)msg->arg1;
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <pthread.h>
|
||||
#include <securec.h>
|
||||
|
||||
#include "anonymizer.h"
|
||||
#include "bus_center_server_proxy.h"
|
||||
#include "common_list.h"
|
||||
#include "lnn_log.h"
|
||||
@ -1186,14 +1187,13 @@ int32_t LnnOnNodeBasicInfoChanged(const char *pkgName, void *info, int32_t type)
|
||||
|
||||
int32_t LnnOnNodeStatusChanged(const char *pkgName, void *info, int32_t type)
|
||||
{
|
||||
if (pkgName == NULL || info == NULL) {
|
||||
LNN_LOGE(LNN_STATE, "pkgName or info is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
NodeStateCallbackItem *item = NULL;
|
||||
NodeStatus *nodeStatus = (NodeStatus *)info;
|
||||
ListNode dupList;
|
||||
|
||||
if (nodeStatus == NULL || pkgName == NULL) {
|
||||
LNN_LOGE(LNN_STATE, "info or pkgName is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (!g_busCenterClient.isInit) {
|
||||
LNN_LOGE(LNN_STATE, "buscenter client not init");
|
||||
return SOFTBUS_NO_INIT;
|
||||
@ -1213,16 +1213,19 @@ int32_t LnnOnNodeStatusChanged(const char *pkgName, void *info, int32_t type)
|
||||
if (SoftBusMutexUnlock(&g_busCenterClient.lock) != SOFTBUS_OK) {
|
||||
LNN_LOGE(LNN_STATE, "unlock node status cb list in notify");
|
||||
}
|
||||
LNN_LOGI(LNN_STATE, "LnnOnNodeStatusChanged, pkgName=%{public}s, type=%{public}d, screen=%{public}d", pkgName,
|
||||
char *anonyPkgName = NULL;
|
||||
Anonymize(pkgName, &anonyPkgName);
|
||||
LNN_LOGI(LNN_STATE, "LnnOnNodeStatusChanged, pkgName=%{public}s, type=%{public}d, screen=%{public}d", anonyPkgName,
|
||||
type, nodeStatus->reserved[0]);
|
||||
LIST_FOR_EACH_ENTRY(item, &dupList, NodeStateCallbackItem, node) {
|
||||
if (((strcmp(item->pkgName, pkgName) == 0) || (strlen(pkgName) == 0)) &&
|
||||
(item->cb.events & EVENT_NODE_STATUS_CHANGED) != 0 && item->cb.onNodeStatusChanged != NULL) {
|
||||
LNN_LOGI(LNN_STATE, "LnnOnNodeStatusChanged, pkgName=%{public}s, type=%{public}d, screen=%{public}d",
|
||||
pkgName, type, nodeStatus->reserved[0]);
|
||||
anonyPkgName, type, nodeStatus->reserved[0]);
|
||||
item->cb.onNodeStatusChanged((NodeStatusType)type, nodeStatus);
|
||||
}
|
||||
}
|
||||
AnonymizeFree(anonyPkgName);
|
||||
ClearNodeStateCbList(&dupList);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
@ -92,6 +92,7 @@ static void LocalLedgerKeyTestPackaged(void)
|
||||
EXPECT_EQ(LlUpdateStaticCapLen(nullptr), SOFTBUS_INVALID_PARAM);
|
||||
EXPECT_EQ(LlUpdateAccount(nullptr), SOFTBUS_INVALID_PARAM);
|
||||
EXPECT_EQ(LlUpdateStaticCapability(nullptr), SOFTBUS_INVALID_PARAM);
|
||||
EXPECT_EQ(LnnUpdateLocalScreenStatus(true), SOFTBUS_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -489,4 +490,28 @@ HWTEST_F(LNNLedgerMockTest, Local_Ledger_Key_Test_007, TestSize.Level1)
|
||||
SoftBusFree(buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: Local_Ledger_Key_Test_008
|
||||
* @tc.desc: local ledger key test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(LNNLedgerMockTest, Local_Ledger_Key_Test_008, TestSize.Level1)
|
||||
{
|
||||
LocalLedgerDepsInterfaceMock localLedgerMock;
|
||||
EXPECT_CALL(localLedgerMock, LnnGetNetCapabilty()).WillRepeatedly(Return(CAPABILTY));
|
||||
EXPECT_CALL(localLedgerMock, SoftBusGenerateRandomArray(_, _)).WillRepeatedly(Return(SOFTBUS_OK));
|
||||
EXPECT_CALL(localLedgerMock, LnnGetFeatureCapabilty()).WillRepeatedly(Return(FEATURE));
|
||||
EXPECT_CALL(localLedgerMock, GetCommonOsType(_)).WillRepeatedly(Return(SOFTBUS_OK));
|
||||
EXPECT_CALL(localLedgerMock, GetCommonOsVersion(_, _)).WillRepeatedly(Return(SOFTBUS_OK));
|
||||
EXPECT_CALL(localLedgerMock,
|
||||
GetCommonDevInfo(_, NotNull(), _)).WillRepeatedly(localLedgerMock.LedgerGetCommonDevInfo);
|
||||
EXPECT_CALL(localLedgerMock, LnnInitLocalP2pInfo(_))
|
||||
.WillOnce(Return(SOFTBUS_OK))
|
||||
.WillRepeatedly(Return(SOFTBUS_ERR));
|
||||
EXPECT_EQ(LnnInitLocalLedger(), SOFTBUS_OK);
|
||||
EXPECT_EQ(LnnUpdateLocalScreenStatus(true), SOFTBUS_OK);
|
||||
EXPECT_EQ(LnnUpdateLocalScreenStatus(false), SOFTBUS_OK);
|
||||
LnnDeinitLocalLedger();
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
@ -336,6 +336,28 @@ HWTEST_F(BusCenterSdkTest, BUS_CENTER_SDK_GET_NODE_KEY_INFO_Test_001, TestSize.L
|
||||
FreeNodeInfo(remoteNodeInfo);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: BUS_CENTER_SDK_GET_NODE_KEY_INFO_Test_002
|
||||
* @tc.desc: get node key info(screen status) interface test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: I5I7B9
|
||||
*/
|
||||
HWTEST_F(BusCenterSdkTest, BUS_CENTER_SDK_GET_NODE_KEY_INFO_Test_002, TestSize.Level0)
|
||||
{
|
||||
NodeBasicInfo info;
|
||||
NodeBasicInfo *remoteNodeInfo = nullptr;
|
||||
int32_t infoNum = 0;
|
||||
bool isScreenOn = false;
|
||||
(void)memset_s(&info, sizeof(NodeBasicInfo), 0, sizeof(NodeBasicInfo));
|
||||
EXPECT_TRUE(GetLocalNodeDeviceInfo(TEST_PKG_NAME, &info) == SOFTBUS_OK);
|
||||
EXPECT_TRUE(GetAllNodeDeviceInfo(TEST_PKG_NAME, &remoteNodeInfo, &infoNum) == SOFTBUS_OK);
|
||||
for (int32_t i = 0; i < infoNum; i++) {
|
||||
EXPECT_TRUE(GetNodeKeyInfo(TEST_PKG_NAME, (remoteNodeInfo + i)->networkId, NODE_KEY_DEVICE_SCREEN_STATUS,
|
||||
(uint8_t*)&isScreenOn, DATA_DEVICE_SCREEN_STATUS_LEN) == SOFTBUS_OK);
|
||||
}
|
||||
FreeNodeInfo(remoteNodeInfo);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: BUS_CENTER_SDK_START_TIME_SYNC_Test_001
|
||||
* @tc.desc: start time sync interface test
|
||||
|
@ -583,6 +583,35 @@ HWTEST_F(ClientBusCentManagerTest, LNN_ON_NODE_BASICINFO_CHANGED_Test_001, TestS
|
||||
BusCenterClientDeinit();
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: LNN_ON_NODE_STATUS_CHANGED_Test_001
|
||||
* @tc.desc: lnn on node status changed test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(ClientBusCentManagerTest, LNN_ON_NODE_STATUS_CHANGED_Test_001, TestSize.Level1)
|
||||
{
|
||||
INodeStateCb callBcak;
|
||||
(void)memset_s(&callBcak, sizeof(INodeStateCb), 0, sizeof(INodeStateCb));
|
||||
callBcak.events = EVENT_NODE_STATUS_CHANGED;
|
||||
callBcak.onNodeStatusChanged = OnNodeStatusChangedCb;
|
||||
NodeStatus info;
|
||||
ClientBusCenterManagerInterfaceMock busCentManagerMock;
|
||||
EXPECT_CALL(busCentManagerMock, SoftbusGetConfig(_, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
|
||||
EXPECT_TRUE(LnnOnNodeStatusChanged(nullptr, reinterpret_cast<void *>(&info), TYPE_SCREEN_STATUS) ==
|
||||
SOFTBUS_INVALID_PARAM);
|
||||
EXPECT_TRUE(LnnOnNodeStatusChanged("", nullptr, TYPE_STATUS_MAX + 1) == SOFTBUS_INVALID_PARAM);
|
||||
EXPECT_CALL(busCentManagerMock, BusCenterServerProxyInit()).WillRepeatedly(Return(SOFTBUS_OK));
|
||||
EXPECT_CALL(busCentManagerMock, BusCenterServerProxyDeInit()).WillRepeatedly(Return());
|
||||
EXPECT_TRUE(BusCenterClientInit() == SOFTBUS_OK);
|
||||
EXPECT_TRUE(RegNodeDeviceStateCbInner(nullptr, &callBcak) == SOFTBUS_INVALID_PARAM);
|
||||
EXPECT_TRUE(RegNodeDeviceStateCbInner(PKGNAME, &callBcak) == SOFTBUS_OK);
|
||||
EXPECT_TRUE(LnnOnNodeStatusChanged("", reinterpret_cast<void *>(&info), TYPE_STATUS_MAX + 1) ==
|
||||
SOFTBUS_INVALID_PARAM);
|
||||
EXPECT_TRUE(LnnOnNodeStatusChanged("", reinterpret_cast<void *>(&info), TYPE_SCREEN_STATUS) == SOFTBUS_OK);
|
||||
BusCenterClientDeinit();
|
||||
}
|
||||
|
||||
static void OnTimeSyncResultCb(const TimeSyncResultInfo *info, int32_t retCode)
|
||||
{
|
||||
(void)info;
|
||||
|
Loading…
Reference in New Issue
Block a user