提交 1ae3427b 编写于 作者: Y YOUR_NAME

Description:ipc so support dlclose

Feature or Bugfix:Feature
Binary Source: No
Signed-off-by: NYOUR_NAME <heyingjiao@huawei.com>
上级 b1746d8e
......@@ -88,8 +88,7 @@ private:
int32_t GetSessionNameForPidUid(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
int32_t GetGrantedSessionName(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
std::string CreateSessionName(int uid, int pid);
bool IsSamgrCall(uint32_t accessToken);
bool HasDumpPermission(uint32_t accessToken) const;
bool IsSamgrCall();
#endif
private:
bool IsDeviceIdIllegal(const std::string &deviceID);
......
......@@ -18,6 +18,7 @@
#include <unordered_map>
#include <functional>
#include <vector>
#include "iremote_object.h"
#include "refbase.h"
......@@ -43,9 +44,19 @@ public:
virtual sptr<IRemoteObject> AsObject() = 0;
};
class BrokerDelegatorBase {
public:
BrokerDelegatorBase() = default;
virtual ~BrokerDelegatorBase() = default;
public:
bool isSoUnloaded = false;
std::u16string descriptor_;
};
#define DECLARE_INTERFACE_DESCRIPTOR(DESCRIPTOR) \
static inline const std::u16string metaDescriptor_ = { DESCRIPTOR }; \
static inline const std::u16string &GetDescriptor() \
static constexpr const char16_t *metaDescriptor_ = DESCRIPTOR; \
static inline const std::u16string GetDescriptor() \
{ \
return metaDescriptor_; \
}
......@@ -55,7 +66,7 @@ class BrokerRegistration {
public:
static BrokerRegistration &Get();
bool Register(const std::u16string &descriptor, const Constructor &creator);
bool Register(const std::u16string &descriptor, const Constructor &creator, const BrokerDelegatorBase *object);
void Unregister(const std::u16string &descriptor);
sptr<IRemoteBroker> NewInstance(const std::u16string &descriptor, const sptr<IRemoteObject> &object);
......@@ -70,12 +81,14 @@ private:
BrokerRegistration &operator = (BrokerRegistration &&) = delete;
std::mutex creatorMutex_;
std::unordered_map<std::u16string, Constructor> creators_;
std::vector<uintptr_t> objects_;
std::atomic<bool> isUnloading = false;
};
template <typename T> class BrokerDelegator {
template <typename T> class BrokerDelegator : public BrokerDelegatorBase {
public:
BrokerDelegator();
~BrokerDelegator();
~BrokerDelegator() override;
private:
BrokerDelegator(const BrokerDelegator &) = delete;
......@@ -88,14 +101,17 @@ template <typename T> BrokerDelegator<T>::BrokerDelegator()
{
const std::u16string descriptor = T::GetDescriptor();
BrokerRegistration &registration = BrokerRegistration::Get();
registration.Register(descriptor, BrokerCreator<T>());
if (registration.Register(descriptor, BrokerCreator<T>(), this)) {
descriptor_ = T::GetDescriptor();
}
}
template <typename T> BrokerDelegator<T>::~BrokerDelegator()
{
const std::u16string descriptor = T::GetDescriptor();
BrokerRegistration &registration = BrokerRegistration::Get();
registration.Unregister(descriptor);
if (!isSoUnloaded && !descriptor_.empty()) {
BrokerRegistration &registration = BrokerRegistration::Get();
registration.Unregister(descriptor_);
}
}
template <typename INTERFACE> inline sptr<INTERFACE> iface_cast(const sptr<IRemoteObject> &object)
......
......@@ -22,7 +22,7 @@ using Communication::SoftBus::ISessionListener;
using Communication::SoftBus::Session;
namespace OHOS {
static const std::string DBINDER_SERVER_PKG_NAME = "DBinderBus";
static constexpr const char *DBINDER_SERVER_PKG_NAME = "DBinderBus";
class DatabusSessionCallback : public ISessionListener {
public:
......
......@@ -34,8 +34,8 @@ public:
static const int KERNEL_DRIVER_ERROR = 950000607;
static const int SOCKET_DRIVER_ERROR = 950000608;
inline static const std::string ERROR_TYPE = "ErrType";
inline static const std::string ERROR_CODE = "ErrCode";
inline static constexpr const char *ERROR_TYPE = "ErrType";
inline static constexpr const char *ERROR_CODE = "ErrCode";
// 601
enum SystemEnvironmentError {
......
......@@ -43,7 +43,7 @@ public:
inline const std::string &ErrorBase::GetErrorDesc(uint32_t error)
{
static const std::string unknowCommand = "UNKNOWN COMMAND";
static constexpr const char *unknowCommand = "UNKNOWN COMMAND";
ErrorMap::iterator found = GetErrorMap().find(error);
if (found == GetErrorMap().end()) {
return unknowCommand;
......
......@@ -29,6 +29,8 @@ public:
static sptr<ProcessSkeleton> GetInstance();
sptr<IRemoteObject> GetRegistryObject();
void SetRegistryObject(sptr<IRemoteObject> &object);
void SetSamgrFlag(bool flag);
bool GetSamgrFlag();
private:
DISALLOW_COPY_AND_MOVE(ProcessSkeleton);
......@@ -38,6 +40,7 @@ private:
static sptr<ProcessSkeleton> instance_;
static std::mutex mutex_;
sptr<IRemoteObject> registryObject_ = nullptr;
bool isSamgr_ = false;
};
} // namespace OHOS
#endif // OHOS_IPC_PROCESS_SKELETON_H
......@@ -319,8 +319,9 @@ bool IPCObjectProxy::AddDeathRecipient(const sptr<DeathRecipient> &recipient)
if (!invoker->AddDeathRecipient(handle_, this)) {
ZLOGE(LABEL, "%{public}s: fail to add binder death recipient", __func__);
#ifndef BUILD_PUBLIC_VERSION
ReportDriverEvent(DbinderErrorCode::COMMON_DRIVER_ERROR, DbinderErrorCode::ERROR_TYPE,
DbinderErrorCode::IPC_DRIVER, DbinderErrorCode::ERROR_CODE, DbinderErrorCode::SET_DEATH_RECIPIENT_FAILURE);
ReportDriverEvent(DbinderErrorCode::COMMON_DRIVER_ERROR, std::string(DbinderErrorCode::ERROR_TYPE),
DbinderErrorCode::IPC_DRIVER, std::string(DbinderErrorCode::ERROR_CODE),
DbinderErrorCode::SET_DEATH_RECIPIENT_FAILURE);
#endif
return false;
}
......@@ -329,8 +330,8 @@ bool IPCObjectProxy::AddDeathRecipient(const sptr<DeathRecipient> &recipient)
if (!AddDbinderDeathRecipient()) {
ZLOGE(LABEL, "%{public}s: failed to add dbinder death recipient", __func__);
#ifndef BUILD_PUBLIC_VERSION
ReportDriverEvent(DbinderErrorCode::COMMON_DRIVER_ERROR, DbinderErrorCode::ERROR_TYPE,
DbinderErrorCode::RPC_DRIVER, DbinderErrorCode::ERROR_CODE,
ReportDriverEvent(DbinderErrorCode::COMMON_DRIVER_ERROR, std::string(DbinderErrorCode::ERROR_TYPE),
DbinderErrorCode::RPC_DRIVER, std::string(DbinderErrorCode::ERROR_CODE),
DbinderErrorCode::SET_DEATH_RECIPIENT_FAILURE);
#endif
return false;
......
......@@ -32,6 +32,7 @@
#include "log_tags.h"
#include "message_option.h"
#include "message_parcel.h"
#include "process_skeleton.h"
#include "refbase.h"
#include "string_ex.h"
#include "sys_binder.h"
......@@ -39,8 +40,6 @@
#include "vector"
#ifndef CONFIG_IPC_SINGLE
#include "accesstoken_kit.h"
#include "access_token_adapter.h"
#include "dbinder_databus_invoker.h"
#include "dbinder_error_code.h"
#include "ISessionService.h"
......@@ -49,20 +48,16 @@
namespace OHOS {
#ifdef CONFIG_IPC_SINGLE
using namespace IPC_SINGLE;
static constexpr int HIDUMPER_SERVICE_UID = 1212;
#endif
using namespace OHOS::HiviewDFX;
static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC, "IPCObjectStub" };
#ifndef CONFIG_IPC_SINGLE
using namespace OHOS::Security;
// Authentication information can be added only for processes with system permission.
static constexpr pid_t ALLOWED_UID = 10000;
static constexpr int APL_BASIC = 2;
// Only the samgr can obtain the UID and PID.
static const std::string SAMGR_PROCESS_NAME = "samgr";
#endif
static constexpr int SHELL_UID = 2000;
static constexpr int HIDUMPER_SERVICE_UID = 1212;
IPCObjectStub::IPCObjectStub(std::u16string descriptor) : IRemoteObject(descriptor)
{
......@@ -99,11 +94,6 @@ int IPCObjectStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessagePa
switch (code) {
#ifndef CONFIG_IPC_SINGLE
case DBINDER_OBITUARY_TRANSACTION: {
if (!IsSamgrCall(IPCSkeleton::GetCallingTokenID())) {
ZLOGE(LABEL, "%s: DBINDER_OBITUARY_TRANSACTION unauthenticated user ", __func__);
result = IPC_STUB_INVALID_DATA_ERR;
break;
}
if (data.ReadInt32() == IRemoteObject::DeathRecipient::NOTICE_DEATH_RECIPIENT) {
result = NoticeServiceDie(data, reply, option);
} else {
......@@ -168,14 +158,7 @@ int IPCObjectStub::SendRequest(uint32_t code, MessageParcel &data, MessageParcel
}
case DUMP_TRANSACTION: {
pid_t uid = IPCSkeleton::GetCallingUid();
#ifndef CONFIG_IPC_SINGLE
uint32_t calllingTokenID = IPCSkeleton::GetFirstTokenID();
calllingTokenID = calllingTokenID == 0 ? IPCSkeleton::GetCallingTokenID() : calllingTokenID;
if (!IPCSkeleton::IsLocalCalling() ||
(uid != 0 && uid != SHELL_UID && !HasDumpPermission(calllingTokenID))) {
#else
if (!IPCSkeleton::IsLocalCalling() || (uid != 0 && uid != SHELL_UID && uid != HIDUMPER_SERVICE_UID)) {
#endif
ZLOGE(LABEL, "do not allow dump");
break;
}
......@@ -278,8 +261,7 @@ int IPCObjectStub::SendRequest(uint32_t code, MessageParcel &data, MessageParcel
break;
}
case GET_GRANTED_SESSION_NAME: {
if (!IPCSkeleton::IsLocalCalling() ||
!IsSamgrCall(static_cast<uint32_t>(IPCSkeleton::GetSelfTokenID()))) {
if (!IPCSkeleton::IsLocalCalling() || !IsSamgrCall()) {
ZLOGE(LABEL, "GRANT_DATABUS_NAME message is excluded in sa manager");
result = IPC_STUB_INVALID_DATA_ERR;
break;
......@@ -288,8 +270,7 @@ int IPCObjectStub::SendRequest(uint32_t code, MessageParcel &data, MessageParcel
break;
}
case GET_SESSION_NAME_PID_UID: {
if (!IPCSkeleton::IsLocalCalling() ||
!IsSamgrCall(static_cast<uint32_t>(IPCSkeleton::GetSelfTokenID()))) {
if (!IPCSkeleton::IsLocalCalling() || !IsSamgrCall()) {
ZLOGE(LABEL, "TRANS_DATABUS_NAME message is excluded in sa manager");
result = IPC_STUB_INVALID_DATA_ERR;
break;
......@@ -613,43 +594,9 @@ std::string IPCObjectStub::CreateSessionName(int uid, int pid)
return sessionName;
}
bool IPCObjectStub::IsSamgrCall(uint32_t accessToken)
bool IPCObjectStub::IsSamgrCall()
{
auto tokenType = AccessToken::AccessTokenKit::GetTokenTypeFlag(accessToken);
if (tokenType != AccessToken::ATokenTypeEnum::TOKEN_NATIVE) {
ZLOGE(LABEL, "not native call");
return false;
}
AccessToken::NativeTokenInfo nativeTokenInfo;
int32_t result = AccessToken::AccessTokenKit::GetNativeTokenInfo(accessToken, nativeTokenInfo);
if (result == ERR_NONE && nativeTokenInfo.processName == SAMGR_PROCESS_NAME) {
return true;
}
ZLOGE(LABEL, "not samgr called, processName:%{private}s", nativeTokenInfo.processName.c_str());
return false;
}
bool IPCObjectStub::HasDumpPermission(uint32_t accessToken) const
{
int res = AccessToken::AccessTokenKit::VerifyAccessToken(accessToken, "ohos.permission.DUMP");
if (res == AccessToken::PermissionState::PERMISSION_GRANTED) {
return true;
}
bool ret = false;
auto tokenType = AccessToken::AccessTokenKit::GetTokenTypeFlag(accessToken);
if (tokenType == AccessToken::ATokenTypeEnum::TOKEN_NATIVE) {
AccessToken::NativeTokenInfo nativeTokenInfo;
int32_t result = AccessToken::AccessTokenKit::GetNativeTokenInfo(accessToken, nativeTokenInfo);
ret = (result == ERR_NONE && nativeTokenInfo.apl >= APL_BASIC);
} else if (tokenType == AccessToken::ATokenTypeEnum::TOKEN_HAP) {
AccessToken::HapTokenInfo hapTokenInfo;
int32_t result = AccessToken::AccessTokenKit::GetHapTokenInfo(accessToken, hapTokenInfo);
ret = (result == ERR_NONE && hapTokenInfo.apl >= APL_BASIC);
}
if (!ret) {
ZLOGD(LABEL, "No dump permission, please check!");
}
return ret;
return ProcessSkeleton::GetInstance()->GetSamgrFlag();
}
#endif
} // namespace OHOS
......@@ -106,7 +106,7 @@ IPCProcessSkeleton::~IPCProcessSkeleton()
std::shared_ptr<ISessionService> manager = ISessionService::GetInstance();
if (manager != nullptr) {
std::string pkgName = DBINDER_SERVER_PKG_NAME + "_" + std::to_string(getpid());
std::string pkgName = std::string(DBINDER_SERVER_PKG_NAME) + "_" + std::to_string(getpid());
(void)manager->RemoveSessionServer(pkgName, sessionName_);
}
#endif
......@@ -223,6 +223,7 @@ bool IPCProcessSkeleton::SetRegistryObject(sptr<IRemoteObject> &object)
bool ret = invoker->SetRegistryObject(object);
if (ret) {
current->SetRegistryObject(object);
current->SetSamgrFlag(true);
}
ZLOGI(LOG_LABEL, "%{public}s set registry result is %{public}d", __func__, ret);
return ret;
......@@ -357,7 +358,7 @@ std::string IPCProcessSkeleton::GetLocalDeviceID()
{
std::lock_guard<std::mutex> lockGuard(databusProcMutex_);
std::string pkgName = DBINDER_SERVER_PKG_NAME + "_" + std::to_string(getpid());
std::string pkgName = std::string(DBINDER_SERVER_PKG_NAME) + "_" + std::to_string(getpid());
NodeBasicInfo nodeBasicInfo;
if (GetLocalNodeDeviceInfo(pkgName.c_str(), &nodeBasicInfo) != 0) {
ZLOGE(LOG_LABEL, "Get local node device info failed");
......@@ -1025,7 +1026,7 @@ bool IPCProcessSkeleton::CreateSoftbusServer(const std::string &name)
ZLOGE(LOG_LABEL, "fail to create softbus callbacks");
return false;
}
std::string pkgName = DBINDER_SERVER_PKG_NAME + "_" + std::to_string(getpid());
std::string pkgName = std::string(DBINDER_SERVER_PKG_NAME) + "_" + std::to_string(getpid());
int ret = manager->CreateSessionServer(pkgName, name, callback);
if (ret != 0) {
ZLOGE(LOG_LABEL, "fail to create softbus server, maybe created already");
......
......@@ -21,6 +21,7 @@
#include "functional"
#include "hilog/log_c.h"
#include "hilog/log_cpp.h"
#include "ipc_debug.h"
#include "iremote_object.h"
#include "log_tags.h"
#include "refbase.h"
......@@ -38,13 +39,20 @@ BrokerRegistration &BrokerRegistration::Get()
BrokerRegistration::~BrokerRegistration()
{
isUnloading = true;
std::lock_guard<std::mutex> lockGuard(creatorMutex_);
for (auto it = creators_.begin(); it != creators_.end();) {
it = creators_.erase(it);
}
for (auto it1 = objects_.begin(); it1 != objects_.end();) {
BrokerDelegatorBase *object = reinterpret_cast<BrokerDelegatorBase *>(*it1);
object->isSoUnloaded = true;
it1 = objects_.erase(it1);
}
}
bool BrokerRegistration::Register(const std::u16string &descriptor, const Constructor &creator)
bool BrokerRegistration::Register(const std::u16string &descriptor, const Constructor &creator,
const BrokerDelegatorBase *object)
{
if (descriptor.empty()) {
return false;
......@@ -52,20 +60,39 @@ bool BrokerRegistration::Register(const std::u16string &descriptor, const Constr
std::lock_guard<std::mutex> lockGuard(creatorMutex_);
auto it = creators_.find(descriptor);
bool ret = false;
if (it == creators_.end()) {
return creators_.insert({ descriptor, creator }).second;
ret = creators_.insert({ descriptor, creator }).second;
}
auto it1 = std::find_if(objects_.begin(), objects_.end(), [descriptor](uintptr_t id) {
const BrokerDelegatorBase *object = reinterpret_cast<BrokerDelegatorBase *>(id);
return object->descriptor_ == descriptor;
});
if (it1 == objects_.end()) {
objects_.push_back(reinterpret_cast<uintptr_t>(object));
}
return false;
return ret;
}
void BrokerRegistration::Unregister(const std::u16string &descriptor)
{
if (isUnloading) {
ZLOGE(LABEL, "BrokerRegistration is Unloading");
return;
}
std::lock_guard<std::mutex> lockGuard(creatorMutex_);
if (!descriptor.empty()) {
auto it = creators_.find(descriptor);
if (it != creators_.end()) {
creators_.erase(it);
}
auto it1 = std::find_if(objects_.begin(), objects_.end(), [descriptor](uintptr_t id) {
const BrokerDelegatorBase *object = reinterpret_cast<BrokerDelegatorBase *>(id);
return object->descriptor_ == descriptor;
});
if (it1 != objects_.end()) {
objects_.erase(it1);
}
}
}
......
......@@ -50,4 +50,14 @@ void ProcessSkeleton::SetRegistryObject(sptr<IRemoteObject> &object)
std::lock_guard<std::mutex> lockGuard(mutex_);
registryObject_ = object;
}
void ProcessSkeleton::SetSamgrFlag(bool flag)
{
isSamgr_ = flag;
}
bool ProcessSkeleton::GetSamgrFlag()
{
return isSamgr_;
}
} // namespace OHOS
\ No newline at end of file
......@@ -608,8 +608,9 @@ int DBinderBaseInvoker<T>::HandleReply(uint64_t seqNumber, MessageParcel *reply,
if (messageInfo == nullptr) {
ZLOGE(LOG_LABEL, "receive buffer is nullptr");
#ifndef BUILD_PUBLIC_VERSION
ReportDriverEvent(DbinderErrorCode::COMMON_DRIVER_ERROR, DbinderErrorCode::ERROR_TYPE,
DbinderErrorCode::RPC_DRIVER, DbinderErrorCode::ERROR_CODE, DbinderErrorCode::HANDLE_RECV_DATA_FAILURE);
ReportDriverEvent(DbinderErrorCode::COMMON_DRIVER_ERROR, std::string(DbinderErrorCode::ERROR_TYPE),
DbinderErrorCode::RPC_DRIVER, std::string(DbinderErrorCode::ERROR_CODE),
DbinderErrorCode::HANDLE_RECV_DATA_FAILURE);
#endif
return RPC_BASE_INVOKER_INVALID_REPLY_ERR;
}
......@@ -732,8 +733,9 @@ int DBinderBaseInvoker<T>::SendRequest(int32_t handle, uint32_t code, MessagePar
newData.RewindWrite(oldWritePosition);
ZLOGE(LOG_LABEL, "seqNumber can not be zero,handle=%d", handle);
#ifndef BUILD_PUBLIC_VERSION
ReportDriverEvent(DbinderErrorCode::COMMON_DRIVER_ERROR, DbinderErrorCode::ERROR_TYPE,
DbinderErrorCode::RPC_DRIVER, DbinderErrorCode::ERROR_CODE, DbinderErrorCode::TRANSACT_DATA_FAILURE);
ReportDriverEvent(DbinderErrorCode::COMMON_DRIVER_ERROR, std::string(DbinderErrorCode::ERROR_TYPE),
DbinderErrorCode::RPC_DRIVER, std::string(DbinderErrorCode::ERROR_CODE),
DbinderErrorCode::TRANSACT_DATA_FAILURE);
#endif
return RPC_BASE_INVOKER_WRITE_TRANS_ERR;
}
......
......@@ -68,7 +68,6 @@ template <typename T> InvokerDelegator<T>::InvokerDelegator(int prot)
template <typename T> InvokerDelegator<T>::~InvokerDelegator()
{
InvokerFactory::Get().Unregister(prot_);
}
#ifdef CONFIG_IPC_SINGLE
} // namespace IPC_SINGLE
......
......@@ -43,8 +43,8 @@ std::mutex BinderConnector::skeletonMutex;
constexpr int SZ_1_M = 1048576;
constexpr int DOUBLE = 2;
static const int IPC_MMAP_SIZE = (SZ_1_M - sysconf(_SC_PAGE_SIZE) * DOUBLE);
static const std::string DRIVER_NAME = std::string("/dev/binder");
static const std::string TOKENID_DEVNODE = std::string("/dev/access_token_id");
static constexpr const char *DRIVER_NAME = "/dev/binder";
static constexpr const char *TOKENID_DEVNODE = "/dev/access_token_id";
BinderConnector *BinderConnector::instance_ = nullptr;
BinderConnector::BinderConnector(const std::string &deviceName)
......@@ -75,7 +75,7 @@ bool BinderConnector::OpenDriver()
if (fd < 0) {
ZLOGE(LABEL, "%{public}s:fail to open", __func__);
#ifndef BUILD_PUBLIC_VERSION
ReportEvent(DbinderErrorCode::KERNEL_DRIVER_ERROR, DbinderErrorCode::ERROR_CODE,
ReportEvent(DbinderErrorCode::KERNEL_DRIVER_ERROR, std::string(DbinderErrorCode::ERROR_CODE),
DbinderErrorCode::OPEN_IPC_DRIVER_FAILURE);
#endif
return false;
......@@ -103,7 +103,7 @@ bool BinderConnector::OpenDriver()
close(driverFD_);
driverFD_ = -1;
#ifndef BUILD_PUBLIC_VERSION
ReportEvent(DbinderErrorCode::KERNEL_DRIVER_ERROR, DbinderErrorCode::ERROR_CODE,
ReportEvent(DbinderErrorCode::KERNEL_DRIVER_ERROR, std::string(DbinderErrorCode::ERROR_CODE),
DbinderErrorCode::OPEN_IPC_DRIVER_FAILURE);
#endif
return false;
......@@ -135,7 +135,7 @@ int BinderConnector::WriteBinder(unsigned long request, void *value)
if (err == -EINTR) {
ZLOGE(LABEL, "%s:ioctl_binder returned EINTR", __func__);
#ifndef BUILD_PUBLIC_VERSION
ReportEvent(DbinderErrorCode::KERNEL_DRIVER_ERROR, DbinderErrorCode::ERROR_CODE,
ReportEvent(DbinderErrorCode::KERNEL_DRIVER_ERROR, std::string(DbinderErrorCode::ERROR_CODE),
DbinderErrorCode::WRITE_IPC_DRIVER_FAILURE);
#endif
}
......@@ -156,7 +156,7 @@ uint64_t BinderConnector::GetSelfTokenID()
if (IsAccessTokenSupported() != true) {
return 0;
}
int fd = open(TOKENID_DEVNODE.c_str(), O_RDWR);
int fd = open(TOKENID_DEVNODE, O_RDWR);
if (fd < 0) {
ZLOGE(LABEL, "%{public}s: fail to open tokenId node", __func__);
return 0;
......@@ -174,7 +174,7 @@ uint64_t BinderConnector::GetSelfFirstCallerTokenID()
if (IsAccessTokenSupported() != true) {
return 0;
}
int fd = open(TOKENID_DEVNODE.c_str(), O_RDWR);
int fd = open(TOKENID_DEVNODE, O_RDWR);
if (fd < 0) {
ZLOGE(LABEL, "%{public}s: fail to open tokenId node", __func__);
return 0;
......@@ -193,7 +193,7 @@ BinderConnector *BinderConnector::GetInstance()
if (instance_ == nullptr) {
std::lock_guard<std::mutex> lockGuard(skeletonMutex);
if (instance_ == nullptr) {
auto temp = new (std::nothrow) BinderConnector(DRIVER_NAME);
auto temp = new (std::nothrow) BinderConnector(std::string(DRIVER_NAME));
if (temp == nullptr) {
ZLOGE(LABEL, "create BinderConnector object failed");
return nullptr;
......
......@@ -105,8 +105,9 @@ int BinderInvoker::SendRequest(int handle, uint32_t code, MessageParcel &data, M
newData.RewindWrite(oldWritePosition);
ZLOGE(LABEL, "WriteTransaction ERROR");
#ifndef BUILD_PUBLIC_VERSION
ReportDriverEvent(DbinderErrorCode::COMMON_DRIVER_ERROR, DbinderErrorCode::ERROR_TYPE,
DbinderErrorCode::IPC_DRIVER, DbinderErrorCode::ERROR_CODE, DbinderErrorCode::TRANSACT_DATA_FAILURE);
ReportDriverEvent(DbinderErrorCode::COMMON_DRIVER_ERROR, std::string(DbinderErrorCode::ERROR_TYPE),
DbinderErrorCode::IPC_DRIVER, std::string(DbinderErrorCode::ERROR_CODE),
DbinderErrorCode::TRANSACT_DATA_FAILURE);
#endif
return IPC_INVOKER_WRITE_TRANS_ERR;
}
......@@ -960,8 +961,9 @@ bool BinderInvoker::FlattenObject(Parcel &parcel, const IRemoteObject *object) c
if (!status) {
ZLOGE(LABEL, "Fail to flatten object");
#ifndef BUILD_PUBLIC_VERSION
ReportDriverEvent(DbinderErrorCode::COMMON_DRIVER_ERROR, DbinderErrorCode::ERROR_TYPE,
DbinderErrorCode::IPC_DRIVER, DbinderErrorCode::ERROR_CODE, DbinderErrorCode::FLATTEN_OBJECT_FAILURE);
ReportDriverEvent(DbinderErrorCode::COMMON_DRIVER_ERROR, std::string(DbinderErrorCode::ERROR_TYPE),
DbinderErrorCode::IPC_DRIVER, std::string(DbinderErrorCode::ERROR_CODE),
DbinderErrorCode::FLATTEN_OBJECT_FAILURE);
#endif
}
return status;
......
......@@ -67,7 +67,7 @@ HWTEST_F(IPCObjectProxyTest, GetSessionNameTest001, TestSize.Level1)
IPCObjectProxy object(1);
std::string ret = object.GetSessionName();
ASSERT_TRUE(ret.size() != 0);
ASSERT_TRUE(ret.size() == 0);
}
/**
......@@ -153,7 +153,7 @@ HWTEST_F(IPCObjectProxyTest, GetPidUidTest001, TestSize.Level1)
IPCObjectProxy object(1);
MessageParcel reply;
auto ret = object.GetPidUid(reply);
ASSERT_TRUE(ret == 0);
ASSERT_TRUE(ret != 0);
}
/**
......@@ -166,7 +166,7 @@ HWTEST_F(IPCObjectProxyTest, GetInterfaceDescriptorTest001, TestSize.Level1)
IPCObjectProxy object(1);
std::u16string ret = object.GetInterfaceDescriptor();
ASSERT_TRUE(ret.size() != 0);
ASSERT_TRUE(ret.size() == 0);
}
/**
......@@ -179,7 +179,7 @@ HWTEST_F(IPCObjectProxyTest, GetObjectRefCountTest001, TestSize.Level1)
IPCObjectProxy object(1);
auto ret = object.GetObjectRefCount();
ASSERT_TRUE(ret != 0);
ASSERT_TRUE(ret == 0);
}
/**
......@@ -452,9 +452,9 @@ HWTEST_F(IPCObjectProxyTest, WaitForInitTest001, TestSize.Level1)
{
IPCObjectProxy object(1);
object.isRemoteDead_ = true;
object.isRemoteDead_ = false;
object.WaitForInit();
EXPECT_EQ(object.isRemoteDead_, false);
EXPECT_EQ(object.isRemoteDead_, true);
EXPECT_EQ(object.isFinishInit_, true);
}
......@@ -469,13 +469,12 @@ HWTEST_F(IPCObjectProxyTest, WaitForInitTest002, TestSize.Level1)
IPCObjectProxy object(1);
object.isRemoteDead_ = false;
object.isRemoteDead_ = true;
object.proto_ = IRemoteObject::IF_PROT_DATABUS;
IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
current->proxyToSession_.clear();
object.WaitForInit();
EXPECT_EQ(object.isRemoteDead_, false);
EXPECT_EQ(object.isRemoteDead_, true);
}
/**
......@@ -488,13 +487,12 @@ HWTEST_F(IPCObjectProxyTest, WaitForInitTest003, TestSize.Level1)
IPCObjectProxy object(1);
object.isRemoteDead_ = false;
object.isRemoteDead_ = true;
object.proto_ = IRemoteObject::IF_PROT_ERROR;
IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
current->proxyToSession_.clear();
object.WaitForInit();
EXPECT_NE(object.isRemoteDead_, true);
EXPECT_EQ(object.isRemoteDead_, true);
}
/**
......@@ -507,13 +505,12 @@ HWTEST_F(IPCObjectProxyTest, WaitForInitTest004, TestSize.Level1)
IPCObjectProxy object(1);
object.isRemoteDead_ = false;
object.isRemoteDead_ = true;
object.proto_ = IRemoteObject::IF_PROT_ERROR;
IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
current->proxyToSession_.clear();
object.WaitForInit();
EXPECT_NE(object.isRemoteDead_, true);
EXPECT_EQ(object.isRemoteDead_, true);
}
#endif
......@@ -679,7 +676,7 @@ HWTEST_F(IPCObjectProxyTest, NoticeServiceDieTest001, TestSize.Level1)
object->proto_ = IRemoteObject::IF_PROT_DEFAULT;
auto ret = object->NoticeServiceDie();
EXPECT_EQ(ret, ERR_NONE);
EXPECT_NE(ret, ERR_NONE);
}
/**
......@@ -711,7 +708,7 @@ HWTEST_F(IPCObjectProxyTest, IncRefToRemoteTest001, TestSize.Level1)
object->proto_ = IRemoteObject::IF_PROT_DEFAULT;
auto ret = object->IncRefToRemote();
EXPECT_EQ(ret, IPC_STUB_INVALID_DATA_ERR);
EXPECT_NE(ret, ERR_NONE);
}
/**
......
......@@ -860,22 +860,7 @@ HWTEST_F(IPCObjectStubTest, IsSamgrCallTest001, TestSize.Level1)
{
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
uint32_t accessToken = 1;
auto ret = testStub->IsSamgrCall(accessToken);
ASSERT_FALSE(ret);
}
/**
* @tc.name: HasDumpPermissionTest001
* @tc.desc: Verify the HasDumpPermission function
* @tc.type: FUNC
*/
HWTEST_F(IPCObjectStubTest, HasDumpPermissionTest001, TestSize.Level1)
{
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
uint32_t accessToken = 1;
auto ret = testStub->HasDumpPermission(accessToken);
auto ret = testStub->IsSamgrCall();
ASSERT_FALSE(ret);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册