提交 9cb8c97b 编写于 作者: L liangshenglin1

MakeRemoteBinder with sa id

Signed-off-by: Nliangshenglin1 <liangshenglin1@huawei.com>
上级 fc8fa9f1
......@@ -105,7 +105,6 @@ public:
const std::string &deviceID, binder_uintptr_t binderObject, uint64_t pid = 0);
bool RegisterRemoteProxy(std::u16string serviceName, sptr<IRemoteObject> binderObject);
bool RegisterRemoteProxy(std::u16string serviceName, int32_t systemAbilityId);
bool RegisterRemoteProxyInner(std::u16string serviceName, binder_uintptr_t binder);
bool OnRemoteMessageTask(const struct DHandleEntryTxRx *message);
std::shared_ptr<struct SessionInfo> QuerySessionObject(binder_uintptr_t stub);
bool DetachDeathRecipient(sptr<IRemoteObject> object);
......@@ -137,7 +136,7 @@ private:
sptr<IRemoteObject> QueryProxyObject(binder_uintptr_t binderObject);
bool DetachSessionObject(binder_uintptr_t stub);
bool AttachSessionObject(std::shared_ptr<struct SessionInfo> object, binder_uintptr_t stub);
sptr<IRemoteObject> FindOrNewProxy(binder_uintptr_t binderObject);
sptr<IRemoteObject> FindOrNewProxy(binder_uintptr_t binderObject, int32_t systemAbilityId);
bool SendEntryToRemote(const sptr<DBinderServiceStub> stub, uint32_t seqNumber);
uint16_t AllocFreeSocketPort();
std::string GetLocalDeviceID();
......@@ -161,6 +160,8 @@ private:
std::string QueryBusNameObject(IPCObjectProxy *proxy);
std::string GetDatabusNameByProxy(IPCObjectProxy *proxy);
uint32_t GetSeqNumber();
bool RegisterRemoteProxyInner(std::u16string serviceName, binder_uintptr_t binder);
bool CheckSystemAbilityId(int32_t systemAbilityId);
private:
DISALLOW_COPY_AND_MOVE(DBinderService);
......@@ -191,6 +192,8 @@ private:
std::map<sptr<IRemoteObject>, DBinderServiceStub *> noticeProxy_;
std::map<sptr<IRemoteObject>, sptr<IRemoteObject::DeathRecipient>> deathRecipients_;
std::map<IPCObjectProxy *, std::string> busNameObject_;
static constexpr int32_t FIRST_SYS_ABILITY_ID = 0x00000001;
static constexpr int32_t LAST_SYS_ABILITY_ID = 0x00ffffff;
};
} // namespace OHOS
#endif // OHOS_IPC_SERVICES_DBINDER_DBINDER_SERVICE_H
......@@ -244,7 +244,7 @@ sptr<DBinderServiceStub> DBinderService::FindOrNewDBinderStub(const std::u16stri
sptr<DBinderServiceStub> DBinderService::MakeRemoteBinder(const std::u16string &serviceName,
const std::string &deviceID, binder_uintptr_t binderObject, uint64_t pid)
{
if (IsDeviceIdIllegal(deviceID) || serviceName.length() == 0 || binderObject == 0) {
if (IsDeviceIdIllegal(deviceID) || serviceName.length() == 0) {
DBINDER_LOGE("para is wrong device id length = %zu, service name length = %zu", deviceID.length(),
serviceName.length());
return nullptr;
......@@ -295,7 +295,7 @@ bool DBinderService::SendEntryToRemote(const sptr<DBinderServiceStub> stub, uint
message->transType = GetRemoteTransType();
message->fromPort = 0;
message->toPort = 0;
message->stubIndex = 0;
message->stubIndex = static_cast<uint64_t>(std::atoi(stub->GetServiceName().c_str()));
message->seqNumber = seqNumber;
message->binderObject = stub->GetBinderObject();
message->stub = reinterpret_cast<binder_uintptr_t>(stub.GetRefPtr());
......@@ -360,7 +360,12 @@ bool DBinderService::InvokerRemoteDBinder(const sptr<DBinderServiceStub> stub, u
return true;
}
sptr<IRemoteObject> DBinderService::FindOrNewProxy(binder_uintptr_t binderObject)
bool DBinderService::CheckSystemAbilityId(int32_t systemAbilityId)
{
return systemAbilityId >= FIRST_SYS_ABILITY_ID && systemAbilityId <= LAST_SYS_ABILITY_ID;
}
sptr<IRemoteObject> DBinderService::FindOrNewProxy(binder_uintptr_t binderObject, int32_t systemAbilityId)
{
sptr<IRemoteObject> proxy = QueryProxyObject(binderObject);
if (proxy != nullptr) {
......@@ -369,20 +374,18 @@ sptr<IRemoteObject> DBinderService::FindOrNewProxy(binder_uintptr_t binderObject
}
/* proxy is null, attempt to get a new proxy */
std::u16string serviceName = GetRegisterService(binderObject);
if (serviceName.empty()) {
DBINDER_LOGE("service is not registered in this device");
if (serviceName.empty() && !CheckSystemAbilityId(systemAbilityId)) {
DBINDER_LOGE("service is not registered in this device, saId:%{public}d", systemAbilityId);
return nullptr;
}
DBINDER_LOGI("new proxy serviceName = %s", Str16ToStr8(serviceName).c_str());
auto manager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (manager == nullptr) {
DBINDER_LOGE("when new proxy, find samgr fail!");
return nullptr;
}
int digitalName = std::atoi(Str16ToStr8(serviceName).c_str());
int digitalName = !serviceName.empty() ? std::atoi(Str16ToStr8(serviceName).c_str()) : systemAbilityId;
proxy = manager->GetSystemAbility(digitalName);
if (proxy != nullptr) {
/* When the stub object dies, you need to delete the corresponding busName information */
......@@ -397,6 +400,8 @@ sptr<IRemoteObject> DBinderService::FindOrNewProxy(binder_uintptr_t binderObject
DBINDER_LOGE("attach proxy object fail");
return nullptr;
}
} else {
DBINDER_LOGW("GetSystemAbility from samgr error, saId:%{public}d", digitalName);
}
return proxy;
}
......@@ -408,7 +413,7 @@ uint16_t DBinderService::AllocFreeSocketPort()
bool DBinderService::OnRemoteInvokerMessage(const struct DHandleEntryTxRx *message)
{
sptr<IRemoteObject> proxy = FindOrNewProxy(message->binderObject);
sptr<IRemoteObject> proxy = FindOrNewProxy(message->binderObject, static_cast<int32_t>(message->stubIndex));
if (proxy == nullptr) {
DBINDER_LOGE("find and new proxy fail");
return false;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册