未验证 提交 4dcd372e 编写于 作者: O openharmony_ci 提交者: Gitee

!271 Rpc remove dynamic permission bugfix

Merge pull request !271 from pilipala195/grant_permission
......@@ -16,9 +16,12 @@
#include "dbinder_death_recipient.h"
#include "dbinder_service.h"
#include "dbinder_log.h"
#include "ISessionService.h"
#include "log_tags.h"
namespace OHOS {
using Communication::SoftBus::ISessionService;
#ifndef TITLE
#define TITLE __PRETTY_FUNCTION__
#endif
......@@ -31,6 +34,7 @@ static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_RPC,
void DbinderDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
{
DBINDER_LOGE("DbinderDeathRecipient OnRemoteDied");
if (remote == nullptr) {
DBINDER_LOGE("remote object is null");
return;
......@@ -45,6 +49,18 @@ void DbinderDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
return;
}
std::shared_ptr<ISessionService> softbusManager = ISessionService::GetInstance();
if (softbusManager == nullptr) {
DBINDER_LOGE("fail to get softbus service");
return;
}
std::string sessionName = dBinderService->QueryBusNameObject(callbackProxy);
if (sessionName.empty()) {
DBINDER_LOGE("proxy sessionName not found");
return;
}
softbusManager->RemovePermission(sessionName);
sptr<IRemoteObject::DeathRecipient> death = dBinderService->QueryDeathRecipient(object);
if (death != nullptr) {
// Continue to clear subsequent data
......
......@@ -38,6 +38,7 @@ DbinderSaDeathRecipient::DbinderSaDeathRecipient(binder_uintptr_t binderObject)
void DbinderSaDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
{
DBINDER_LOGE("DbinderSaDeathRecipient OnRemoteDied");
if (remote == nullptr) {
DBINDER_LOGE("remote object is null");
return;
......@@ -52,9 +53,6 @@ void DbinderSaDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
return;
}
(void)dBinderService->DetachBusNameObject(proxy);
(void)dBinderService->DetachProxyObject(binderObject_);
std::shared_ptr<ISessionService> softbusManager = ISessionService::GetInstance();
if (softbusManager == nullptr) {
DBINDER_LOGE("fail to get softbus service");
......@@ -66,5 +64,8 @@ void DbinderSaDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
return;
}
softbusManager->RemovePermission(sessionName);
(void)dBinderService->DetachBusNameObject(proxy);
(void)dBinderService->DetachProxyObject(binderObject_);
}
} // namespace OHOS
......@@ -17,6 +17,7 @@
#define OHOS_RPC_FOO_TEST_H
#include "iremote_broker.h"
#include "iremote_object.h"
#include "iremote_proxy.h"
#include "iremote_stub.h"
#include "message_parcel.h"
......@@ -66,6 +67,13 @@ public:
private:
static inline BrokerDelegator<RpcFooProxy> delegator_;
};
class RpcDeathRecipient : public IRemoteObject::DeathRecipient {
public:
virtual void OnRemoteDied(const wptr<IRemoteObject> &remote);
RpcDeathRecipient();
virtual ~RpcDeathRecipient();
};
} // namespace OHOS
#endif // OHOS_RPC_FOO_TEST_H
......@@ -31,6 +31,7 @@ using namespace OHOS;
static std::string g_deviceId;
static sptr<IRpcFooTest> g_rpcTestProxy;
static sptr<IRpcFooTest> g_ipcTestProxy;
static IPCObjectProxy *g_proxy;
class RpcClientTest : public testing::Test {
public:
static constexpr char DBINDER_PKG_NAME[] = "DBinderService";
......@@ -62,6 +63,9 @@ HWTEST_F(RpcClientTest, function_test_001, TestSize.Level1)
g_rpcTestProxy = iface_cast<IRpcFooTest>(object);
ASSERT_TRUE(g_rpcTestProxy != nullptr);
g_proxy = reinterpret_cast<IPCObjectProxy *>(object.GetRefPtr());
ASSERT_EQ(g_proxy->GetProto(), IRemoteObject::IF_PROT_DATABUS);
}
HWTEST_F(RpcClientTest, function_test_002, TestSize.Level1)
......@@ -127,4 +131,11 @@ HWTEST_F(RpcClientTest, function_test_005, TestSize.Level1)
err = replyParcel.ReadInt32();
ASSERT_EQ(err, ERR_NONE);
}
HWTEST_F(RpcClientTest, function_test_006, TestSize.Level1)
{
sptr<IRemoteObject::DeathRecipient> death(new RpcDeathRecipient());
ASSERT_EQ(g_proxy->GetProto(), IRemoteObject::IF_PROT_DATABUS);
g_proxy->AddDeathRecipient(death.GetRefPtr());
}
}
\ No newline at end of file
......@@ -134,4 +134,17 @@ int32_t RpcFooProxy::TestAdd(MessageParcel &data, MessageParcel &reply)
}
return reply.ReadInt32() == (a + b) ? ERR_NONE : ERR_INVALID_DATA;
}
RpcDeathRecipient::RpcDeathRecipient()
{
}
RpcDeathRecipient::~RpcDeathRecipient()
{
}
void RpcDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
{
return;
}
} // namespace OHOS
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册