TicketNo:#IB3SV8 Description:新需求:新需求:完善service的功能

Signed-off-by: LongestDistance <cdwango@isoftstone.com>
This commit is contained in:
LongestDistance 2024-11-12 17:33:41 +08:00
parent 7bcfd324af
commit 777bc24525
11 changed files with 382 additions and 54 deletions

View File

@ -65,6 +65,7 @@ public:
void ReportDeviceFound(const std::vector<std::pair<CastRemoteDevice, bool>> &deviceList);
void ReportSessionCreate(const sptr<ICastSessionImpl> &castSession);
void ReportDeviceOffline(const std::string &deviceId);
bool LoadSinkSA(const std::string &networkId);
sptr<ICastSessionImpl> GetCastSessionInner(std::string sessionId);
class CastServiceLoadCallback : public SystemAbilityLoadCallbackStub {
@ -119,6 +120,7 @@ public:
void GrabDevice(int32_t sessionId) override;
int32_t GetSessionProtocolType(int sessionId, ProtocolType &protocolType) override;
int32_t SetSessionProtocolType(int sessionId, ProtocolType protocolType) override;
bool LoadSinkSA(const std::string &networkId) override;
private:
wptr<CastSessionManagerService> service_;

View File

@ -361,6 +361,16 @@ int32_t ConnectionManagerListener::SetSessionProtocolType(int sessionId, Protoco
return CAST_ENGINE_SUCCESS;
}
bool ConnectionManagerListener::LoadSinkSA(const std::string &networkId)
{
auto service = service_.promote();
if (!service) {
CLOGE("service is null");
return false;
}
return service->LoadSinkSA(networkId);
}
int32_t CastSessionManagerService::RegisterListener(sptr<ICastServiceListenerImpl> listener)
{
CLOGI("RegisterListener in");
@ -758,6 +768,38 @@ void CastSessionManagerService::ReportDeviceOffline(const std::string &deviceId)
}
}
bool CastSessionManagerService::LoadSinkSA(const std::string &networkId)
{
CLOGI("LoadSinkSA in");
auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (samgr == nullptr) {
CLOGE("Failed to get SA manager");
return false;
}
sptr<CastServiceLoadCallback> loadCallback = new (std::nothrow) CastServiceLoadCallback();
if (loadCallback == nullptr) {
CLOGE("Failed to new object");
return false;
}
constexpr int32_t sleepTimeMs = 30;
constexpr int32_t retryTimeMax = 150; // The service startup timeout interval is 4s.
int32_t result = samgr->LoadSystemAbility(CAST_ENGINE_SA_ID, networkId, loadCallback);
for (int32_t retryTime = 1; (result != ERR_OK) && (retryTime < retryTimeMax); ++retryTime) {
std::this_thread::sleep_for(std::chrono::milliseconds(sleepTimeMs));
result = samgr->LoadSystemAbility(CAST_ENGINE_SA_ID, networkId, loadCallback);
CLOGD("Attemp to reLoad SA for the %d time.", retryTime);
}
if (result != ERR_OK) {
CLOGE("systemAbilityId: %d load failed, result code: %d", CAST_ENGINE_SA_ID, result);
return false;
} else {
CLOGI("Load sink SA success!");
return true;
}
}
bool CastSessionManagerService::CheckAndWaitDevieManagerServiceInit()
{
auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();

View File

@ -84,9 +84,12 @@ public:
bool IsDeviceUsed(const std::string &deviceId);
int GetSessionIdByDeviceId(const std::string &deviceId);
int GetCastSessionIdByDeviceId(const std::string &deviceId);
bool UpdateDeviceByDeviceId(const std::string &deviceId);
bool IsDoubleFrameDevice(const std::string &deviceId);
std::optional<std::string> GetDeviceNameByDeviceId(const std::string &deviceId);
bool RemoveDeviceInfo(std::string deviceId, bool isWifi);
bool SetDeviceNotFresh(const std::string &deviceId);
bool IsDoubleFrameDevice(const std::string &deviceId);
private:
struct DeviceInfoCollection {

View File

@ -86,12 +86,13 @@ public:
void UpdateGrabState(bool changeState, int32_t sessionId);
int GetProtocolType() const;
void SetProtocolType(int protocols);
void SetProtocolType(ProtocolType protocol);
std::unique_ptr<CastLocalDevice> GetLocalDeviceInfo();
void NotifySessionIsReady(int transportId);
void NotifyDeviceIsOffline(const std::string &deviceId);
bool NotifyConnectStage(const CastInnerRemoteDevice &device, int result, int32_t reasonCode = REASON_DEFAULT);
bool NotifyListenerToLoadSinkSA(const std::string &networkId);
void AddSessionListener(int castSessionId, std::shared_ptr<IConnectManagerSessionListener> listener);
void RemoveSessionListener(int castSessionId);
@ -101,11 +102,13 @@ public:
void SetRTSPPort(int port);
void SendConsultInfo(const std::string &deviceId, int port);
std::string GetConnectingDeviceId();
bool IsSingle(const CastInnerRemoteDevice &device);
bool IsHuaweiDevice(const CastInnerRemoteDevice &device);
bool IsThirdDevice(const CastInnerRemoteDevice &device);
std::map<std::string, bool> isBindTargetMap_;
std::string connectingDeviceId_{};
private:
bool BindTarget(const CastInnerRemoteDevice &dev);
@ -135,7 +138,7 @@ private:
void ResetListener();
std::mutex mutex_;
int protocolType_ = 0;
ProtocolType protocolType_ = ProtocolType::CAST_PLUS_MIRROR;
std::shared_ptr<IConnectionManagerListener> listener_;
std::map<int, std::shared_ptr<IConnectManagerSessionListener>> sessionListeners_;
std::map<int, int> transIdToCastSessionIdMap_;

View File

@ -37,6 +37,7 @@ public:
virtual void GrabDevice(int32_t sessionId) = 0;
virtual int32_t GetSessionProtocolType(int sessionId, ProtocolType &protocolType) = 0;
virtual int32_t SetSessionProtocolType(int sessionId, ProtocolType protocolType) = 0;
virtual bool LoadSinkSA(const std::string &networkId) = 0;
};
class IConnectManagerSessionListener {

View File

@ -29,6 +29,9 @@
#include "cast_service_common.h"
#include "device_manager.h"
#include "event_handler.h"
#include "json.hpp"
using nlohmann::json;
namespace OHOS {
namespace CastEngine {
@ -99,34 +102,48 @@ public:
bool StopAdvertise();
int GetProtocolType() const;
void SetProtocolType(int protocols);
void OnDeviceInfoFound(uint16_t subscribeId, const DmDeviceInfo &dmDeviceInfo);
void NotifyDeviceIsFound(const CastInnerRemoteDevice &newDevice);
void NotifyDeviceIsOnline(const DmDeviceInfo &dmDeviceInfo);
std::unordered_map<std::string, std::pair<bool, bool>> reportTypeMap_;
private:
void StartDmDiscovery();
void StopDmDiscovery();
void GetAndReportTrustedDevices();
void ParseDeviceInfo(const DmDeviceInfo &dmDevice, CastInnerRemoteDevice &castDevice);
void ParseCustomData(const json &jsonObj, CastInnerRemoteDevice &castDevice);
void ParseCapability(const std::string customData, CastInnerRemoteDevice &castDevice);
void SetListener(std::shared_ptr<IDiscoveryManagerListener> listener);
std::shared_ptr<IDiscoveryManagerListener> GetListener();
bool HasListener();
void ResetListener();
void RemoveSameDeviceLocked(const CastInnerRemoteDevice &newDevice);
CastInnerRemoteDevice CreateRemoteDevice(const DmDeviceInfo &dmDeviceInfo);
void UpdateDeviceState();
void UpdateDeviceStateLocked();
void SetDeviceNotFresh();
void RecordDeviceFoundType(const DmDeviceInfo dmDeviceInfo);
std::string Mask(const std::string &str);
bool IsDrmMatch(const CastInnerRemoteDevice &newDevice);
bool IsNeedNotify(const CastInnerRemoteDevice &newDevice);
std::mutex mutex_;
int32_t uid_{ 0 };
int protocolType_ = 0;
std::vector<std::string> drmSchemes_;
std::shared_ptr<IDiscoveryManagerListener> listener_;
std::shared_ptr<EventRunner> eventRunner_;
std::shared_ptr<DiscoveryEventHandler> eventHandler_;
std::unordered_map<CastInnerRemoteDevice, int> remoteDeviceMap;
int32_t scanCount;
std::unordered_map<CastInnerRemoteDevice, int> remoteDeviceMap_;
int32_t scanCount_;
};
} // namespace CastEngineService
} // namespace CastEngine

View File

@ -410,6 +410,23 @@ int CastDeviceDataManager::GetSessionIdByDeviceId(const std::string &deviceId)
return INVALID_ID;
}
int CastDeviceDataManager::GetCastSessionIdByDeviceId(const std::string &deviceId)
{
if (deviceId.empty()) {
CLOGE("Empty device id!");
return INVALID_ID;
}
std::lock_guard<std::mutex> lock(mutex_);
for (auto it = devices_.begin(); it != devices_.end(); it++) {
if (it->device.deviceId == deviceId) {
return it->device.localCastSessionId;
}
}
return INVALID_ID;
}
bool CastDeviceDataManager::UpdateDeviceByDeviceId(const std::string &deviceId)
{
CLOGI("UpdateDeviceByDeviceId in %{public}s", Utils::Mask(deviceId).c_str());
@ -469,6 +486,48 @@ bool CastDeviceDataManager::IsDoubleFrameDevice(const std::string &deviceId)
return false;
}
bool CastDeviceDataManager::RemoveDeviceInfo(std::string deviceId, bool isWifi)
{
CLOGI("RemoveDeviceInfo in %{public}s", Utils::Mask(deviceId).c_str());
std::lock_guard<std::mutex> lock(mutex_);
auto it = GetDeviceLocked(deviceId);
if (it == devices_.end()) {
CLOGE("No device found");
return false;
}
if (isWifi) {
it->wifiDeviceInfo = {};
it->device.wifiIp = "";
it->device.wifiPort = 0;
it->device.isWifiFresh = false;
uint32_t coap = static_cast<uint32_t>(NotifyMediumType::COAP);
it->device.mediumTypes = (it->device.mediumTypes | coap) ^ coap;
} else {
it->bleDeviceInfo = {};
it->device.bleMac = "";
it->device.isBleFresh = false;
uint32_t ble = static_cast<uint32_t>(NotifyMediumType::BLE);
it->device.mediumTypes = (it->device.mediumTypes | ble) ^ ble;
}
return true;
}
bool CastDeviceDataManager::SetDeviceNotFresh(const std::string &deviceId)
{
CLOGI("in %{public}s", Utils::Mask(deviceId).c_str());
std::lock_guard<std::mutex> lock(mutex_);
auto it = GetDeviceLocked(deviceId);
if (it == devices_.end()) {
CLOGE("No device found %s", deviceId.c_str());
return false;
}
it->device.isWifiFresh = false;
it->device.isBleFresh = false;
it->device.mediumTypes = 0;
return true;
}
} // namespace CastEngineService
} // namespace CastEngine
} // namespace OHOS

View File

@ -249,16 +249,6 @@ DmDeviceInfo ConnectionManager::GetDmDeviceInfo(const std::string &deviceId)
return {};
}
void ConnectionManager::SetProtocolType(int protocols)
{
protocolType_ = protocols;
}
int ConnectionManager::GetProtocolType() const
{
return protocolType_;
}
bool ConnectionManager::ConnectDevice(const CastInnerRemoteDevice &dev, const ProtocolType &protocolType)
{
DeviceDiscoveryWriteWrap(__func__, GetAnonymousDeviceID(dev.deviceId));
@ -864,6 +854,16 @@ void ConnectionManager::UpdateGrabState(bool changeState, int32_t sessionId)
grabState_ = DeviceGrabState::NO_GRAB;
}
int ConnectionManager::GetProtocolType() const
{
return static_cast<int>(protocolType_);
}
void ConnectionManager::SetProtocolType(ProtocolType protocol)
{
protocolType_ = protocol;
}
void ConnectionManager::AddSessionListener(int castSessionId, std::shared_ptr<IConnectManagerSessionListener> listener)
{
std::lock_guard<std::mutex> lock(mutex_);
@ -966,6 +966,21 @@ bool ConnectionManager::NotifyConnectStage(const CastInnerRemoteDevice &device,
return true;
}
bool ConnectionManager::NotifyListenerToLoadSinkSA(const std::string& networkId)
{
auto listener = GetListener();
if (!listener) {
return false;
}
return listener->LoadSinkSA(networkId);
}
std::string ConnectionManager::GetConnectingDeviceId()
{
std::lock_guard<std::mutex> lock(mutex_);
return connectingDeviceId_;
}
void CastBindTargetCallback::OnBindResult(const PeerTargetId &targetId, int32_t result, int32_t status,
std::string content)
{

View File

@ -49,6 +49,22 @@ constexpr int TIMEOUT_COUNT = 40;
constexpr int EVENT_START_DISCOVERY = 1;
constexpr int EVENT_CONTINUE_DISCOVERY = 2;
const std::string DISCOVERY_TRUST_VALUE = R"({"filters": [{"type": "isTrusted", "value": 2}]})";
const std::string SINGLE_CUST_DATA = R"({"castPlus":"C020"})";
constexpr int CAST_DATA_LENGTH = 4;
constexpr int INT_THREE = 3;
constexpr int INT_FOUR = 4;
constexpr int INT_SEVEN = 7;
// Bit bit of byte 0
constexpr uint32_t BASE = 1;
constexpr uint32_t HUAWEI_IDENTIFICATION = BASE << 7;
constexpr uint32_t MIRROR_CAPABILITY = BASE << 3;
// Bit bit of byte 1
constexpr uint32_t DEVICE_COORDINATION_CAPABILITY = BASE << 7;
constexpr uint32_t DRM_CAPABILITY = BASE << 6;
constexpr uint32_t CAST_STREAM_CAPABILITY = BASE << 5;
DeviceType ConvertDeviceType(uint16_t deviceTypeId)
{
@ -146,25 +162,17 @@ void DiscoveryManager::GetAndReportTrustedDevices()
}
}
void DiscoveryManager::UpdateDeviceState()
{
auto it = std::find_if(remoteDeviceMap.begin(), remoteDeviceMap.end(), [&](const auto& pair) {
return scanCount - pair.second >=1 ;
});
if (it != remoteDeviceMap.end()) {
CastInnerRemoteDevice remoteDevice = it->first;
CLOGE("StartDmDiscovery offline: %{public}s", remoteDevice.deviceName.c_str());
ConnectionManager::GetInstance().NotifyDeviceIsOffline(remoteDevice.deviceId);
CastDeviceDataManager::GetInstance().RemoveDevice(remoteDevice.deviceId);
remoteDeviceMap.erase(it);
}
}
void DiscoveryManager::StartDmDiscovery()
{
CLOGI("StartDmDiscovery in");
UpdateDeviceState();
scanCount++;
{
std::lock_guard<std::mutex> lock(mutex_);
UpdateDeviceStateLocked();
reportTypeMap_.clear();
}
scanCount_++;
std::map<std::string, std::string> discoverParam{
{ PARAM_KEY_META_TYPE, std::to_string(5) } };
std::map<std::string, std::string> filterOptions{
@ -209,11 +217,6 @@ bool DiscoveryManager::StopAdvertise()
return true;
}
void DiscoveryManager::SetProtocolType(int protocols)
{
protocolType_ = protocols;
}
int DiscoveryManager::GetProtocolType() const
{
return protocolType_;
@ -233,8 +236,8 @@ void DiscoveryManager::StartDiscovery()
{"PEER_UDID", ""}});
CLOGI("StartDiscovery in");
scanCount = 0;
remoteDeviceMap.clear();
scanCount_ = 0;
remoteDeviceMap_.clear();
std::lock_guard<std::mutex> lock(mutex_);
uid_ = IPCSkeleton::GetCallingUid();
eventHandler_->SendEvent(EVENT_START_DISCOVERY);
@ -244,8 +247,13 @@ void DiscoveryManager::StartDiscovery()
void DiscoveryManager::StopDiscovery()
{
CLOGI("StopDiscovery in");
StopDmDiscovery();
SetDeviceNotFresh();
eventHandler_->RemoveAllEvents();
if (eventRunner_ != nullptr) {
eventRunner_->Stop();
}
StopDmDiscovery();
}
void DiscoveryManager::SetListener(std::shared_ptr<IDiscoveryManagerListener> listener)
@ -254,6 +262,12 @@ void DiscoveryManager::SetListener(std::shared_ptr<IDiscoveryManagerListener> li
listener_ = listener;
}
std::shared_ptr<IDiscoveryManagerListener> DiscoveryManager::GetListener()
{
std::lock_guard<std::mutex> lock(mutex_);
return listener_;
}
bool DiscoveryManager::HasListener()
{
std::lock_guard<std::mutex> lock(mutex_);
@ -267,11 +281,11 @@ void DiscoveryManager::ResetListener()
void DiscoveryManager::RemoveSameDeviceLocked(const CastInnerRemoteDevice &newDevice)
{
auto it = std::find_if(remoteDeviceMap.begin(), remoteDeviceMap.end(), [&](const auto& pair) {
auto it = std::find_if(remoteDeviceMap_.begin(), remoteDeviceMap_.end(), [&](const auto& pair) {
return pair.first.deviceId == newDevice.deviceId;
});
if (it != remoteDeviceMap.end()) {
remoteDeviceMap.erase(it);
if (it != remoteDeviceMap_.end()) {
remoteDeviceMap_.erase(it);
}
}
@ -301,11 +315,18 @@ void DiscoveryManager::OnDeviceInfoFound(uint16_t subscribeId, const DmDeviceInf
CastInnerRemoteDevice newDevice = CreateRemoteDevice(dmDeviceInfo);
// If the map does not exist, the notification is sent.
auto it = remoteDeviceMap.find(newDevice);
if (it == remoteDeviceMap.end()) {
// If the deviceId are the same, delete the old device.
RemoveSameDeviceLocked(newDevice);
bool isDeviceExist = true;
{
std::lock_guard<std::mutex> lock(mutex_);
auto it = remoteDeviceMap_.find(newDevice);
if (it == remoteDeviceMap_.end()) {
// If the deviceId are the same, delete the old device.
RemoveSameDeviceLocked(newDevice);
isDeviceExist = false;
}
}
if (!isDeviceExist) {
// Set subDeviceType based on isTrusted.
std::string networkId = dmDeviceInfo.networkId;
bool isTrusted = ConnectionManager::GetInstance().IsDeviceTrusted(dmDeviceInfo.deviceId, networkId);
@ -317,7 +338,9 @@ void DiscoveryManager::OnDeviceInfoFound(uint16_t subscribeId, const DmDeviceInf
NotifyDeviceIsFound(newDevice);
}
}
remoteDeviceMap[newDevice] = scanCount;
remoteDeviceMap_[newDevice] = scanCount_;
RecordDeviceFoundType(dmDeviceInfo);
}
void DiscoveryManager::NotifyDeviceIsFound(const CastInnerRemoteDevice &newDevice)
@ -332,9 +355,21 @@ void DiscoveryManager::NotifyDeviceIsFound(const CastInnerRemoteDevice &newDevic
devices.push_back(newDevice);
std::lock_guard<std::mutex> lock(mutex_);
listener_->OnDeviceFound(devices);
auto listener = GetListener();
if (listener == nullptr) {
CLOGE("listener is null");
return;
}
if (IsDrmMatch(newDevice)) {
listener->OnDeviceFound(devices);
}
if (uid_ == AV_SESSION_UID) {
listener_->OnDeviceFound(device2In1);
if (IsDrmMatch(newDevice)) {
listener->OnDeviceFound(device2In1);
}
return;
}
}
@ -380,6 +415,156 @@ void DiscoveryManager::ParseDeviceInfo(const DmDeviceInfo &dmDevice, CastInnerRe
}
}
void DiscoveryManager::ParseCustomData(const json &jsonObj, CastInnerRemoteDevice &castDevice)
{
if (jsonObj.contains(PARAM_KEY_CUSTOM_DATA) && jsonObj[PARAM_KEY_CUSTOM_DATA].is_string()) {
std::string customData = jsonObj[PARAM_KEY_CUSTOM_DATA];
json softbusCustData = json::parse(customData, nullptr, false);
if (!softbusCustData.is_discarded() && softbusCustData.contains("castPlus")
&& softbusCustData["castPlus"].is_string()) {
std::string castData = softbusCustData["castPlus"];
castDevice.customData = castData;
ParseCapability(castDevice.customData, castDevice);
}
if (!softbusCustData.is_discarded() && softbusCustData.contains("castId")
&& softbusCustData["castId"].is_string()) {
castDevice.udid = softbusCustData["castId"];
}
}
}
void DiscoveryManager::ParseCapability(const std::string castData, CastInnerRemoteDevice &newDevice)
{
auto firstByte = static_cast<uint32_t>(Utils::StringToInt(castData.substr(0, 2), 16));
auto secondByte = static_cast<uint32_t>(Utils::StringToInt(castData.substr(2), 16));
if ((firstByte & MIRROR_CAPABILITY) != 0) {
newDevice.capabilityInfo |= static_cast<uint32_t>(ProtocolType::CAST_PLUS_MIRROR);
}
std::string coordCapa;
if ((firstByte & HUAWEI_IDENTIFICATION) != 0) {
if ((secondByte & CAST_STREAM_CAPABILITY) != 0) {
newDevice.capabilityInfo |= static_cast<uint32_t>(ProtocolType::CAST_PLUS_STREAM);
}
if ((secondByte & DRM_CAPABILITY) != 0) {
newDevice.drmCapabilities.push_back(UUID_CHINADRM);
}
if ((secondByte & DEVICE_COORDINATION_CAPABILITY) != 0) {
coordCapa = " coordinationCapa = 1";
}
}
if ((newDevice.capabilityInfo & static_cast<uint32_t>(ProtocolType::CAST_PLUS_STREAM)) != 0) {
if (newDevice.capability == CapabilityType::DLNA) {
newDevice.capability = CapabilityType::CAST_AND_DLNA;
} else if (newDevice.capability != CapabilityType::CAST_AND_DLNA) {
newDevice.capability = CapabilityType::CAST_PLUS;
}
}
CLOGI("device %{public}s castData:%{public}s authVersion:%{public}s capabilityInfo:%{public}u drmCapa:%{public}d"
"%{public}s capability:0x%{public}x",
Mask(newDevice.deviceName).c_str(), castData.c_str(), newDevice.authVersion.c_str(), newDevice.capabilityInfo,
(newDevice.drmCapabilities.size() > 0), coordCapa.c_str(), newDevice.capability);
}
void DiscoveryManager::UpdateDeviceStateLocked()
{
for (auto it = remoteDeviceMap_.begin(); it != remoteDeviceMap_.end();) {
if (scanCount_ == it->second) {
std::string deviceId = it->first.deviceId;
if (!reportTypeMap_[deviceId].first) {
CastDeviceDataManager::GetInstance().RemoveDeviceInfo(deviceId, true);
}
if (!reportTypeMap_[deviceId].second) {
CastDeviceDataManager::GetInstance().RemoveDeviceInfo(deviceId, false);
}
}
if (scanCount_ - it->second > 1 &&
it->first.deviceId != ConnectionManager::GetInstance().GetConnectingDeviceId()) {
CastInnerRemoteDevice remoteDevice = it->first;
CLOGE("StartDmDiscovery offline: %{public}s", Mask(remoteDevice.deviceName).c_str());
ConnectionManager::GetInstance().NotifyDeviceIsOffline(remoteDevice.deviceId);
CastDeviceDataManager::GetInstance().RemoveDevice(remoteDevice.deviceId);
it = remoteDeviceMap_.erase(it);
} else {
it++;
}
}
}
void DiscoveryManager::SetDeviceNotFresh()
{
CLOGI("in");
std::lock_guard<std::mutex> lock(mutex_);
for (auto it = remoteDeviceMap_.begin(); it != remoteDeviceMap_.end();) {
std::string deviceId = it->first.deviceId;
CastDeviceDataManager::GetInstance().SetDeviceNotFresh(deviceId);
it++;
}
CLOGI("out");
}
void DiscoveryManager::RecordDeviceFoundType(const DmDeviceInfo dmDevice)
{
CLOGI("scanCount_ is %{public}d", scanCount_);
std::string deviceId = dmDevice.deviceId;
if (reportTypeMap_.find(deviceId) == reportTypeMap_.end()) {
reportTypeMap_.insert({ deviceId, {false, false} });
}
json jsonObj = json::parse(dmDevice.extraData, nullptr, false);
if (!jsonObj.is_discarded()) {
if (jsonObj.contains(PARAM_KEY_WIFI_IP) && jsonObj[PARAM_KEY_WIFI_IP].is_string()) {
reportTypeMap_[deviceId].first = true;
}
if (jsonObj.contains(PARAM_KEY_BLE_MAC) && jsonObj[PARAM_KEY_BLE_MAC].is_string()) {
reportTypeMap_[deviceId].second = true;
}
}
}
std::string DiscoveryManager::Mask(const std::string &str)
{
if (str.empty() || str.length() <= INT_THREE) {
return str;
} else if (str.length() < INT_SEVEN) {
return str.substr(0, INT_THREE) + "***" + str.substr(str.length() - 1);
} else {
return str.substr(0, INT_FOUR) + "***" + str.substr(str.length() - INT_THREE);
}
}
bool DiscoveryManager::IsDrmMatch(const CastInnerRemoteDevice &newDevice)
{
if (drmSchemes_.empty()) {
return true;
}
for (auto iter = drmSchemes_.begin(); iter != drmSchemes_.end(); ++iter) {
if (find(newDevice.drmCapabilities.begin(), newDevice.drmCapabilities.end(), *iter) !=
newDevice.drmCapabilities.end()) {
return true;
}
}
return false;
}
bool DiscoveryManager::IsNeedNotify(const CastInnerRemoteDevice &newDevice)
{
bool isNotifyDevice = system::GetBoolParameter(NOTIFY_DEVICE_FOUND, false);
if (isNotifyDevice) {
CLOGD("prop is true, notify %{public}s ", Mask(newDevice.deviceName).c_str());
return true;
}
if (newDevice.deviceType == DeviceType::DEVICE_HW_TV) {
if (newDevice.customData.empty() || newDevice.customData.length() < CAST_DATA_LENGTH) {
return false;
}
} else {
CLOGI("%{public}s is not huawei device, notify device", Mask(newDevice.deviceName).c_str());
return true;
}
return true;
}
void CastDiscoveryCallback::OnDiscoverySuccess(uint16_t subscribeId)
{
CLOGI("OnDiscoverySuccess, subscribe id:%{public}u", subscribeId);

View File

@ -62,7 +62,7 @@ public:
static bool StartWith(const std::string &mainStr, const std::string &subStr);
static int IntToByteArray(int num, int length, uint8_t *output);
static uint32_t ByteArrayToInt(const uint8_t *input, unsigned int length);
static int32_t StringToInt(const std::string &str);
static int32_t StringToInt(const std::string &str, int base = DECIMALISM);
static std::string GetWifiIp();
static bool IsArrayAllZero(const uint8_t *input, int length);
static std::string Mask(const std::string &str);
@ -83,6 +83,7 @@ private:
constexpr static int MASK_PRINT_POSTFIX_LEN = 2;
};
inline const std::string UUID_CHINADRM = "3d5e6d35-9b9a-41e8-b843-dd3c6e72c42c";
inline constexpr char SANDBOX_PATH[] = "/data/service/el1/public/cast_engine_service";
inline constexpr char PARAM_MEDIA_DUMP[] = "debug.cast.media.dump";
inline constexpr char PARAM_VIDEO_CACHE[] = "debug.cast.video.cache";

View File

@ -110,13 +110,13 @@ uint32_t Utils::ByteArrayToInt(const uint8_t *input, unsigned int length)
return output;
}
int32_t Utils::StringToInt(const std::string &str)
int32_t Utils::StringToInt(const std::string &str, int base)
{
if (str.size() == 0) {
return 0;
}
char *nextPtr = nullptr;
long result = strtol(str.c_str(), &nextPtr, DECIMALISM);
long result = strtol(str.c_str(), &nextPtr, base);
if (errno == ERANGE || *nextPtr != '\0') {
return 0;
}