From bf984d2286a794e682bc458f43793dc5f1d3c02b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B8=88=E7=9A=93=E6=9D=B0?= Date: Mon, 2 Sep 2024 16:00:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=9C=8B=E6=9D=BF=E5=91=8A?= =?UTF-8?q?=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 师皓杰 --- .../distributed_event/include/dms_sa_client.h | 3 +- .../distributed_event/src/dms_sa_client.cpp | 26 +- .../distributedWant/distributed_want_params.h | 105 ++++--- .../distributed_want_params.cpp | 282 ++++++++++++------ .../src/distributed_sched_permission.cpp | 3 + 5 files changed, 289 insertions(+), 130 deletions(-) diff --git a/interfaces/innerkits/distributed_event/include/dms_sa_client.h b/interfaces/innerkits/distributed_event/include/dms_sa_client.h index 774235be..0aac9971 100644 --- a/interfaces/innerkits/distributed_event/include/dms_sa_client.h +++ b/interfaces/innerkits/distributed_event/include/dms_sa_client.h @@ -45,10 +45,11 @@ public: private: DmsSaClient() {}; ~DmsSaClient() {}; - bool hasSubscribeDmsSA_ = false; + std::atomic hasSubscribeDmsSA_ = false; OHOS::sptr saMgrProxy_; std::map> listeners_; std::mutex eventMutex_; + std::mutex saMgrMutex_; }; class DmsSystemAbilityStatusChange : public SystemAbilityStatusChangeStub { diff --git a/interfaces/innerkits/distributed_event/src/dms_sa_client.cpp b/interfaces/innerkits/distributed_event/src/dms_sa_client.cpp index a4279394..5e59042d 100644 --- a/interfaces/innerkits/distributed_event/src/dms_sa_client.cpp +++ b/interfaces/innerkits/distributed_event/src/dms_sa_client.cpp @@ -47,7 +47,10 @@ bool DmsSaClient::SubscribeDmsSA() int32_t DmsSaClient::AddDSchedEventListener(const DSchedEventType& type, const sptr& listener) { HILOGI("%{public}s called, the type is %{public}d", __func__, type); - saMgrProxy_ = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + { + std::lock_guard lock(saMgrMutex_); + saMgrProxy_ = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + } if (saMgrProxy_ == nullptr) { HILOGE("fail to get saMgrProxy."); return AAFwk::INNER_ERR; @@ -56,11 +59,13 @@ int32_t DmsSaClient::AddDSchedEventListener(const DSchedEventType& type, const s DistributedClient distributedClient; distributedClient.RegisterDSchedEventListener(type, listener); } - std::lock_guard lock(eventMutex_); if (!hasSubscribeDmsSA_) { if (SubscribeDmsSA()) { hasSubscribeDmsSA_ = true; - listeners_[type] = listener; + { + std::lock_guard lock(eventMutex_); + listeners_[type] = listener; + } } else { return AAFwk::INNER_ERR; } @@ -71,7 +76,10 @@ int32_t DmsSaClient::AddDSchedEventListener(const DSchedEventType& type, const s int32_t DmsSaClient::DelDSchedEventListener(const DSchedEventType& type, const sptr& listener) { HILOGI("%{public}s called, the type is %{public}d", __func__, type); - saMgrProxy_ = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + { + std::lock_guard lock(saMgrMutex_); + saMgrProxy_ = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + } if (saMgrProxy_ == nullptr) { HILOGE("fail to get saMgrProxy."); return AAFwk::INNER_ERR; @@ -88,7 +96,10 @@ int32_t DmsSaClient::DelDSchedEventListener(const DSchedEventType& type, const s int32_t DmsSaClient::GetContinueInfo(ContinueInfo &continueInfo) { HILOGI("%{public}s called", __func__); - saMgrProxy_ = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + { + std::lock_guard lock(saMgrMutex_); + saMgrProxy_ = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + } if (saMgrProxy_ == nullptr) { HILOGE("fail to get saMgrProxy."); return AAFwk::INNER_ERR; @@ -103,7 +114,10 @@ int32_t DmsSaClient::GetContinueInfo(ContinueInfo &continueInfo) int32_t DmsSaClient::GetDSchedEventInfo(const DSchedEventType &type, std::vector &events) { HILOGI("%{public}s called", __func__); - saMgrProxy_ = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + { + std::lock_guard lock(saMgrMutex_); + saMgrProxy_ = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + } if (saMgrProxy_ == nullptr) { HILOGE("Get SA manager proxy fail."); return AAFwk::INNER_ERR; diff --git a/services/dtbschedmgr/include/distributedWant/distributed_want_params.h b/services/dtbschedmgr/include/distributedWant/distributed_want_params.h index 57eb9dfc..95565242 100644 --- a/services/dtbschedmgr/include/distributedWant/distributed_want_params.h +++ b/services/dtbschedmgr/include/distributedWant/distributed_want_params.h @@ -19,6 +19,7 @@ #include #include #include + #include "base_interfaces.h" #include "parcel.h" #include "refbase.h" @@ -57,9 +58,6 @@ public: static bool CompareInterface(const sptr iIt1, const sptr iIt2, int typeId); - static bool CompareNumberInterface(const sptr iIt1, - const sptr iIt2, int typeId); - static int GetDataType(const sptr iIt); static int GetNumberDataType(const sptr iIt); @@ -89,39 +87,29 @@ public: AAFwk::WantParams ToWantParams(); private: - enum { - VALUE_TYPE_NULL = -1, - VALUE_TYPE_BOOLEAN = 1, - VALUE_TYPE_BYTE = 2, - VALUE_TYPE_CHAR = 3, - VALUE_TYPE_SHORT = 4, - VALUE_TYPE_INT = 5, - VALUE_TYPE_LONG = 6, - VALUE_TYPE_FLOAT = 7, - VALUE_TYPE_DOUBLE = 8, - VALUE_TYPE_STRING = 9, - VALUE_TYPE_CHARSEQUENCE = 10, - VALUE_TYPE_BOOLEANARRAY = 11, - VALUE_TYPE_BYTEARRAY = 12, - VALUE_TYPE_CHARARRAY = 13, - VALUE_TYPE_SHORTARRAY = 14, - VALUE_TYPE_INTARRAY = 15, - VALUE_TYPE_LONGARRAY = 16, - VALUE_TYPE_FLOATARRAY = 17, - VALUE_TYPE_DOUBLEARRAY = 18, - VALUE_TYPE_STRINGARRAY = 19, - VALUE_TYPE_CHARSEQUENCEARRAY = 20, + static std::string BooleanQueryToStr(const sptr iIt); + static std::string ByteQueryToStr(const sptr iIt); + static std::string CharQueryToStr(const sptr iIt); + static std::string ShortQueryToStr(const sptr iIt); + static std::string IntegerQueryToStr(const sptr iIt); + static std::string LongQueryToStr(const sptr iIt); + static std::string FloatQueryToStr(const sptr iIt); + static std::string DoubleQueryToStr(const sptr iIt); + static std::string StringQueryToStr(const sptr iIt); + static std::string ArrayQueryToStr(const sptr iIt); + static std::string DistributedWantParamsQueryToStr(const sptr iIt); - VALUE_TYPE_PARCELABLE = 21, - VALUE_TYPE_PARCELABLEARRAY = 22, - VALUE_TYPE_SERIALIZABLE = 23, - VALUE_TYPE_LIST = 50, - - VALUE_TYPE_WANTPARAMS = 101, - VALUE_TYPE_ARRAY = 102, - VALUE_TYPE_FD = 103, - VALUE_TYPE_REMOTE_OBJECT = 104 - }; + static bool BooleanQueryEquals(const sptr iIt); + static bool ByteQueryEquals(const sptr iIt); + static bool CharQueryEquals(const sptr iIt); + static bool StringQueryEquals(const sptr iIt); + static bool ArrayQueryEquals(const sptr iIt); + static bool DistributedWantParamsQueryEquals(const sptr iIt); + static bool ShortQueryEquals(const sptr iIt); + static bool IntegerQueryEquals(const sptr iIt); + static bool LongQueryEquals(const sptr iIt); + static bool FloatQueryEquals(const sptr iIt); + static bool DoubleQueryEquals(const sptr iIt); bool WriteArrayToParcel(Parcel& parcel, AAFwk::IArray* ao) const; bool ReadArrayToParcel(Parcel& parcel, int type, sptr& ao); @@ -178,11 +166,52 @@ private: bool DoMarshalling(Parcel& parcel) const; bool ReadUnsupportedData(Parcel& parcel, const std::string& key, int type); - friend class DistributedWantParamWrapper; - friend class DistributedWant; - // inner use function bool NewArrayData(AAFwk::IArray* source, sptr& dest); bool NewParams(const DistributedWantParams& source, DistributedWantParams& dest); + +private: + enum { + VALUE_TYPE_NULL = -1, + VALUE_TYPE_BOOLEAN = 1, + VALUE_TYPE_BYTE = 2, + VALUE_TYPE_CHAR = 3, + VALUE_TYPE_SHORT = 4, + VALUE_TYPE_INT = 5, + VALUE_TYPE_LONG = 6, + VALUE_TYPE_FLOAT = 7, + VALUE_TYPE_DOUBLE = 8, + VALUE_TYPE_STRING = 9, + VALUE_TYPE_CHARSEQUENCE = 10, + VALUE_TYPE_BOOLEANARRAY = 11, + VALUE_TYPE_BYTEARRAY = 12, + VALUE_TYPE_CHARARRAY = 13, + VALUE_TYPE_SHORTARRAY = 14, + VALUE_TYPE_INTARRAY = 15, + VALUE_TYPE_LONGARRAY = 16, + VALUE_TYPE_FLOATARRAY = 17, + VALUE_TYPE_DOUBLEARRAY = 18, + VALUE_TYPE_STRINGARRAY = 19, + VALUE_TYPE_CHARSEQUENCEARRAY = 20, + + VALUE_TYPE_PARCELABLE = 21, + VALUE_TYPE_PARCELABLEARRAY = 22, + VALUE_TYPE_SERIALIZABLE = 23, + VALUE_TYPE_LIST = 50, + + VALUE_TYPE_WANTPARAMS = 101, + VALUE_TYPE_ARRAY = 102, + VALUE_TYPE_FD = 103, + VALUE_TYPE_REMOTE_OBJECT = 104 + }; + + friend class DistributedWantParamWrapper; + friend class DistributedWant; + using InterfaceQueryToStrFunc = std::string (*)(const sptr iIt); + using InterfaceQueryEqualsFunc = bool (*)(const sptr iIt); + static std::map interfaceQueryToStrMap; + static std::map interfaceQueryEqualsMap; + + // inner use function std::map> params_; std::map fds_; std::vector cachedUnsupportedData_; diff --git a/services/dtbschedmgr/src/distributedWant/distributed_want_params.cpp b/services/dtbschedmgr/src/distributedWant/distributed_want_params.cpp index df2c19cb..7ae1fcb3 100644 --- a/services/dtbschedmgr/src/distributedWant/distributed_want_params.cpp +++ b/services/dtbschedmgr/src/distributedWant/distributed_want_params.cpp @@ -44,6 +44,57 @@ const char* TYPE_PROPERTY = "type"; const char* VALUE_PROPERTY = "value"; const std::string TAG = "DistributedUnsupportedData"; } + +std::map DistributedWantParams::interfaceQueryToStrMap = { + std::map::value_type( + DistributedWantParams::VALUE_TYPE_BOOLEAN, &DistributedWantParams::BooleanQueryToStr), + std::map::value_type( + DistributedWantParams::VALUE_TYPE_BYTE, &DistributedWantParams::ByteQueryToStr), + std::map::value_type( + DistributedWantParams::VALUE_TYPE_CHAR, &DistributedWantParams::CharQueryToStr), + std::map::value_type( + DistributedWantParams::VALUE_TYPE_SHORT, &DistributedWantParams::ShortQueryToStr), + std::map::value_type( + DistributedWantParams::VALUE_TYPE_INT, &DistributedWantParams::IntegerQueryToStr), + std::map::value_type( + DistributedWantParams::VALUE_TYPE_LONG, &DistributedWantParams::LongQueryToStr), + std::map::value_type( + DistributedWantParams::VALUE_TYPE_FLOAT, &DistributedWantParams::FloatQueryToStr), + std::map::value_type( + DistributedWantParams::VALUE_TYPE_DOUBLE, &DistributedWantParams::DoubleQueryToStr), + std::map::value_type( + DistributedWantParams::VALUE_TYPE_STRING, &DistributedWantParams::StringQueryToStr), + std::map::value_type( + DistributedWantParams::VALUE_TYPE_ARRAY, &DistributedWantParams::ArrayQueryToStr), + std::map::value_type( + DistributedWantParams::VALUE_TYPE_WANTPARAMS, &DistributedWantParams::DistributedWantParamsQueryToStr), +}; + +std::map DistributedWantParams::interfaceQueryEqualsMap = { + std::map::value_type( + DistributedWantParams::VALUE_TYPE_BOOLEAN, &DistributedWantParams::BooleanQueryEquals), + std::map::value_type( + DistributedWantParams::VALUE_TYPE_BYTE, &DistributedWantParams::ByteQueryEquals), + std::map::value_type( + DistributedWantParams::VALUE_TYPE_CHAR, &DistributedWantParams::CharQueryEquals), + std::map::value_type( + DistributedWantParams::VALUE_TYPE_STRING, &DistributedWantParams::StringQueryEquals), + std::map::value_type( + DistributedWantParams::VALUE_TYPE_ARRAY, &DistributedWantParams::ArrayQueryEquals), + std::map::value_type( + DistributedWantParams::VALUE_TYPE_WANTPARAMS, &DistributedWantParams::DistributedWantParamsQueryEquals), + std::map::value_type( + DistributedWantParams::VALUE_TYPE_SHORT, &DistributedWantParams::ShortQueryEquals), + std::map::value_type( + DistributedWantParams::VALUE_TYPE_INT, &DistributedWantParams::IntegerQueryEquals), + std::map::value_type( + DistributedWantParams::VALUE_TYPE_LONG, &DistributedWantParams::LongQueryEquals), + std::map::value_type( + DistributedWantParams::VALUE_TYPE_FLOAT, &DistributedWantParams::FloatQueryEquals), + std::map::value_type( + DistributedWantParams::VALUE_TYPE_DOUBLE, &DistributedWantParams::DoubleQueryEquals), +}; + DistributedUnsupportedData::~DistributedUnsupportedData() { if (buffer != nullptr) { @@ -114,32 +165,144 @@ DistributedUnsupportedData& DistributedUnsupportedData::operator=(DistributedUns return *this; } +std::string DistributedWantParams::BooleanQueryToStr(const sptr iIt) +{ + AAFwk::IBoolean* obj = AAFwk::IBoolean::Query(iIt); + return obj == nullptr ? "" : static_cast(obj)->ToString(); +} + +std::string DistributedWantParams::ByteQueryToStr(const sptr iIt) +{ + AAFwk::IByte* obj = AAFwk::IByte::Query(iIt); + return obj == nullptr ? "" : static_cast(obj)->ToString(); +} + +std::string DistributedWantParams::CharQueryToStr(const sptr iIt) +{ + AAFwk::IChar* obj = AAFwk::IChar::Query(iIt); + return obj == nullptr ? "" : static_cast(obj)->ToString(); +} + +std::string DistributedWantParams::ShortQueryToStr(const sptr iIt) +{ + AAFwk::IShort* obj = AAFwk::IShort::Query(iIt); + return obj == nullptr ? "" : static_cast(obj)->ToString(); +} + +std::string DistributedWantParams::IntegerQueryToStr(const sptr iIt) +{ + AAFwk::IInteger* obj = AAFwk::IInteger::Query(iIt); + return obj == nullptr ? "" : static_cast(obj)->ToString(); +} + +std::string DistributedWantParams::LongQueryToStr(const sptr iIt) +{ + AAFwk::ILong* obj = AAFwk::ILong::Query(iIt); + return obj == nullptr ? "" : static_cast(obj)->ToString(); +} + +std::string DistributedWantParams::FloatQueryToStr(const sptr iIt) +{ + AAFwk::IFloat* obj = AAFwk::IFloat::Query(iIt); + return obj == nullptr ? "" : static_cast(obj)->ToString(); +} + +std::string DistributedWantParams::DoubleQueryToStr(const sptr iIt) +{ + AAFwk::IDouble* obj = AAFwk::IDouble::Query(iIt); + return obj == nullptr ? "" : static_cast(obj)->ToString(); +} + +std::string DistributedWantParams::StringQueryToStr(const sptr iIt) +{ + AAFwk::IString* obj = AAFwk::IString::Query(iIt); + return obj == nullptr ? "" : static_cast(obj)->ToString(); +} + +std::string DistributedWantParams::ArrayQueryToStr(const sptr iIt) +{ + AAFwk::IArray* obj = AAFwk::IArray::Query(iIt); + return obj == nullptr ? "" : static_cast(obj)->ToString(); +} + +std::string DistributedWantParams::DistributedWantParamsQueryToStr(const sptr iIt) +{ + IDistributedWantParams* obj = IDistributedWantParams::Query(iIt); + return obj == nullptr ? "" : static_cast(obj)->ToString(); +} + +bool DistributedWantParams::BooleanQueryEquals(const sptr iIt) +{ + AAFwk::IBoolean* obj = AAFwk::IBoolean::Query(iIt); + return obj == nullptr ? false : static_cast(obj)->Equals(*static_cast(obj)); +} + +bool DistributedWantParams::ByteQueryEquals(const sptr iIt) +{ + AAFwk::IByte* obj = AAFwk::IByte::Query(iIt); + return obj == nullptr ? false : static_cast(obj)->Equals(*static_cast(obj)); +} + +bool DistributedWantParams::CharQueryEquals(const sptr iIt) +{ + AAFwk::IChar* obj = AAFwk::IChar::Query(iIt); + return obj == nullptr ? false : static_cast(obj)->Equals(*static_cast(obj)); +} + +bool DistributedWantParams::StringQueryEquals(const sptr iIt) +{ + AAFwk::IString* obj = AAFwk::IString::Query(iIt); + return obj == nullptr ? false : static_cast(obj)->Equals(*static_cast(obj)); +} + +bool DistributedWantParams::ArrayQueryEquals(const sptr iIt) +{ + AAFwk::IArray* obj = AAFwk::IArray::Query(iIt); + return obj == nullptr ? false : static_cast(obj)->Equals(*static_cast(obj)); +} + +bool DistributedWantParams::DistributedWantParamsQueryEquals(const sptr iIt) +{ + IDistributedWantParams* obj = IDistributedWantParams::Query(iIt); + return obj == nullptr ? false : static_cast(obj) + ->Equals(*static_cast(obj)); +} +bool DistributedWantParams::ShortQueryEquals(const sptr iIt) +{ + AAFwk::IShort* obj = AAFwk::IShort::Query(iIt); + return obj == nullptr ? false : static_cast(obj)->Equals(*static_cast(obj)); +} + +bool DistributedWantParams::IntegerQueryEquals(const sptr iIt) +{ + AAFwk::IInteger* obj = AAFwk::IInteger::Query(iIt); + return obj == nullptr ? false : static_cast(obj)->Equals(*static_cast(obj)); +} + +bool DistributedWantParams::LongQueryEquals(const sptr iIt) +{ + AAFwk::ILong* obj = AAFwk::ILong::Query(iIt); + return obj == nullptr ? false : static_cast(obj)->Equals(*static_cast(obj)); +} + +bool DistributedWantParams::FloatQueryEquals(const sptr iIt) +{ + AAFwk::IFloat* obj = AAFwk::IFloat::Query(iIt); + return obj == nullptr ? false : static_cast(obj)->Equals(*static_cast(obj)); +} + +bool DistributedWantParams::DoubleQueryEquals(const sptr iIt) +{ + AAFwk::IDouble* obj = AAFwk::IDouble::Query(iIt); + return obj == nullptr ? false : static_cast(obj)->Equals(*static_cast(obj)); +} + std::string DistributedWantParams::GetStringByType(const sptr iIt, int typeId) { - if (typeId == VALUE_TYPE_BOOLEAN) { - return static_cast(AAFwk::IBoolean::Query(iIt))->ToString(); - } else if (typeId == VALUE_TYPE_BYTE) { - return static_cast(AAFwk::IByte::Query(iIt))->ToString(); - } else if (typeId == VALUE_TYPE_CHAR) { - return static_cast(AAFwk::IChar::Query(iIt))->ToString(); - } else if (typeId == VALUE_TYPE_SHORT) { - return static_cast(AAFwk::IShort::Query(iIt))->ToString(); - } else if (typeId == VALUE_TYPE_INT) { - return static_cast(AAFwk::IInteger::Query(iIt))->ToString(); - } else if (typeId == VALUE_TYPE_LONG) { - return static_cast(AAFwk::ILong::Query(iIt))->ToString(); - } else if (typeId == VALUE_TYPE_FLOAT) { - return static_cast(AAFwk::IFloat::Query(iIt))->ToString(); - } else if (typeId == VALUE_TYPE_DOUBLE) { - return static_cast(AAFwk::IDouble::Query(iIt))->ToString(); - } else if (typeId == VALUE_TYPE_STRING) { - return static_cast(AAFwk::IString::Query(iIt))->ToString(); - } else if (typeId == VALUE_TYPE_ARRAY) { - return static_cast(AAFwk::IArray::Query(iIt))->ToString(); - } else if (typeId == VALUE_TYPE_WANTPARAMS) { - return static_cast(IDistributedWantParams::Query(iIt))->ToString(); - } else { - return ""; + auto iter = interfaceQueryToStrMap.find(typeId); + if (iter != interfaceQueryToStrMap.end()) { + DistributedWantParams::InterfaceQueryToStrFunc &func = iter->second; + return (*func)(iIt); } return ""; } @@ -311,68 +474,13 @@ sptr DistributedWantParams::GetInterfaceByType(int typeId, const std return nullptr; } -bool DistributedWantParams::CompareNumberInterface(const sptr iIt1, - const sptr iIt2, int typeId) -{ - bool flag = false; - switch (typeId) { - case VALUE_TYPE_SHORT: - flag = static_cast(AAFwk::IShort::Query(iIt1)) - ->Equals(*(static_cast(AAFwk::IShort::Query(iIt1)))); - break; - case VALUE_TYPE_INT: - flag = static_cast(AAFwk::IInteger::Query(iIt1)) - ->Equals(*(static_cast(AAFwk::IInteger::Query(iIt1)))); - break; - case VALUE_TYPE_LONG: - flag = static_cast(AAFwk::ILong::Query(iIt1)) - ->Equals(*(static_cast(AAFwk::ILong::Query(iIt1)))); - break; - case VALUE_TYPE_FLOAT: - flag = static_cast(AAFwk::IFloat::Query(iIt1)) - ->Equals(*(static_cast(AAFwk::IFloat::Query(iIt1)))); - break; - case VALUE_TYPE_DOUBLE: - flag = static_cast(AAFwk::IDouble::Query(iIt1)) - ->Equals(*(static_cast(AAFwk::IDouble::Query(iIt1)))); - break; - default: - break; - } - return flag; -} - bool DistributedWantParams::CompareInterface(const sptr iIt1, const sptr iIt2, int typeId) { bool flag = false; - switch (typeId) { - case VALUE_TYPE_BOOLEAN: - flag = static_cast(AAFwk::IBoolean::Query(iIt1)) - ->Equals(*(static_cast(AAFwk::IBoolean::Query(iIt1)))); - break; - case VALUE_TYPE_BYTE: - flag = static_cast(AAFwk::IByte::Query(iIt1)) - ->Equals(*(static_cast(AAFwk::IByte::Query(iIt1)))); - break; - case VALUE_TYPE_CHAR: - flag = static_cast(AAFwk::IChar::Query(iIt1)) - ->Equals(*(static_cast(AAFwk::IChar::Query(iIt1)))); - break; - case VALUE_TYPE_STRING: - flag = static_cast(AAFwk::IString::Query(iIt1)) - ->Equals(*(static_cast(AAFwk::IString::Query(iIt1)))); - break; - case VALUE_TYPE_ARRAY: - flag = static_cast(AAFwk::IArray::Query(iIt1)) - ->Equals(*(static_cast(AAFwk::IArray::Query(iIt1)))); - break; - case VALUE_TYPE_WANTPARAMS: - flag = static_cast(IDistributedWantParams::Query(iIt1)) - ->Equals(*(static_cast(IDistributedWantParams::Query(iIt1)))); - break; - default: - flag = CompareNumberInterface(iIt1, iIt2, typeId); - break; + auto iter = interfaceQueryEqualsMap.find(typeId); + if (iter != interfaceQueryEqualsMap.end()) { + DistributedWantParams::InterfaceQueryEqualsFunc &func = iter->second; + return (*func)(iIt1); } return flag; } @@ -465,8 +573,12 @@ bool DistributedWantParams::WriteToParcelWantParams(Parcel& parcel, sptr(IDistributedWantParams::Query(o))->ToString())); + + auto wantParams = static_cast(IDistributedWantParams::Query(o)); + if (wantParams == nullptr) { + return false; + } + return parcel.WriteString16(Str8ToStr16(wantParams->ToString())); } bool DistributedWantParams::WriteToParcelFD(Parcel& parcel, const DistributedWantParams& value) const diff --git a/services/dtbschedmgr/src/distributed_sched_permission.cpp b/services/dtbschedmgr/src/distributed_sched_permission.cpp index 3db25d37..5204ec16 100644 --- a/services/dtbschedmgr/src/distributed_sched_permission.cpp +++ b/services/dtbschedmgr/src/distributed_sched_permission.cpp @@ -733,6 +733,9 @@ bool DistributedSchedPermission::CheckTargetAbilityVisible(const AppExecFwk::Abi void DistributedSchedPermission::RemoveRemoteObjectFromWant(std::shared_ptr want) const { + if (want == nullptr) { + return; + } WantParams wantParams = want->GetParams(); std::map> params = wantParams.GetParams(); for (auto param : params) {