mirror of
https://gitee.com/openharmony/startup_init
synced 2025-02-17 10:28:00 +00:00
fix
Signed-off-by: yh <yanghao236@huawei.com>
This commit is contained in:
parent
c9961ee413
commit
b8f53da08b
@ -22,6 +22,7 @@
|
||||
#include "iservice_registry.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "securec.h"
|
||||
#include "sysparam_errno.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace device_info {
|
||||
@ -34,10 +35,9 @@ DeviceInfoKits &DeviceInfoKits::GetInstance()
|
||||
return DelayedRefSingleton<DeviceInfoKits>::GetInstance();
|
||||
}
|
||||
|
||||
void DeviceInfoKits::LoadDeviceInfoSa()
|
||||
void DeviceInfoKits::LoadDeviceInfoSa(std::unique_lock<std::mutex> &lock)
|
||||
{
|
||||
DINFO_LOGV("deviceInfoService_ is %d", deviceInfoService_ == nullptr);
|
||||
std::unique_lock<std::mutex> lock(lock_);
|
||||
if (deviceInfoService_ != nullptr) {
|
||||
return;
|
||||
}
|
||||
@ -70,9 +70,9 @@ void DeviceInfoKits::LoadDeviceInfoSa()
|
||||
}
|
||||
}
|
||||
|
||||
sptr<IDeviceInfo> DeviceInfoKits::GetService()
|
||||
sptr<IDeviceInfo> DeviceInfoKits::GetService(std::unique_lock<std::mutex> &lock)
|
||||
{
|
||||
LoadDeviceInfoSa();
|
||||
LoadDeviceInfoSa(lock);
|
||||
return deviceInfoService_;
|
||||
}
|
||||
|
||||
@ -96,16 +96,42 @@ void DeviceInfoKits::FinishStartSAFailed()
|
||||
|
||||
int32_t DeviceInfoKits::GetUdid(std::string& result)
|
||||
{
|
||||
auto deviceService = GetService();
|
||||
std::unique_lock<std::mutex> lock(lock_);
|
||||
static std::optional<std::pair<int32_t, std::string>> resultPair;
|
||||
if (resultPair.has_value()) {
|
||||
int32_t ret = resultPair->first;
|
||||
result = resultPair->second;
|
||||
DINFO_LOGV("GetUdid from resultPair ret = %d", ret);
|
||||
return ret;
|
||||
}
|
||||
auto deviceService = GetService(lock);
|
||||
DINFO_CHECK(deviceService != nullptr, return -1, "Failed to get deviceinfo manager");
|
||||
return deviceService->GetUdid(result);
|
||||
int ret = deviceService->GetUdid(result);
|
||||
DINFO_LOGV("GetSerialID from remote ret = %d", ret);
|
||||
if (ret == 0 || ret == SYSPARAM_PERMISSION_DENIED) {
|
||||
resultPair = std::make_optional(std::make_pair(ret, result));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DeviceInfoKits::GetSerialID(std::string& result)
|
||||
{
|
||||
auto deviceService = GetService();
|
||||
std::unique_lock<std::mutex> lock(lock_);
|
||||
static std::optional<std::pair<int32_t, std::string>> resultPair;
|
||||
if (resultPair.has_value()) {
|
||||
int32_t ret = resultPair->first;
|
||||
result = resultPair->second;
|
||||
DINFO_LOGV("GetSerialID from resultPair ret = %d", ret);
|
||||
return ret;
|
||||
}
|
||||
auto deviceService = GetService(lock);
|
||||
DINFO_CHECK(deviceService != nullptr, return -1, "Failed to get deviceinfo manager");
|
||||
return deviceService->GetSerialID(result);
|
||||
int ret = deviceService->GetSerialID(result);
|
||||
DINFO_LOGV("GetSerialID from remote ret = %d", ret);
|
||||
if (ret == 0 || ret == SYSPARAM_PERMISSION_DENIED) {
|
||||
resultPair = std::make_optional(std::make_pair(ret, result));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void DeviceInfoKits::DeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
|
||||
|
@ -49,8 +49,8 @@ private:
|
||||
}
|
||||
|
||||
static const int DEVICEINFO_LOAD_SA_TIMEOUT_MS = 60000;
|
||||
void LoadDeviceInfoSa();
|
||||
sptr<IDeviceInfo> GetService();
|
||||
void LoadDeviceInfoSa(std::unique_lock<std::mutex> &lock);
|
||||
sptr<IDeviceInfo> GetService(std::unique_lock<std::mutex> &lock);
|
||||
std::mutex lock_;
|
||||
std::condition_variable deviceInfoLoadCon_;
|
||||
sptr<IRemoteObject::DeathRecipient> deathRecipient_ {};
|
||||
|
@ -203,7 +203,9 @@ HWTEST_F(DeviceInfoUnittest, TestInterface, TestSize.Level1)
|
||||
|
||||
HWTEST_F(DeviceInfoUnittest, TestDeviceInfoProxy1, TestSize.Level1)
|
||||
{
|
||||
auto remotePtr = device_info::DeviceInfoKits::GetInstance().GetService();
|
||||
OHOS::device_info::DeviceInfoKits &kits = device_info::DeviceInfoKits::GetInstance();
|
||||
std::unique_lock<std::mutex> lock(kits.lock_);
|
||||
auto remotePtr = device_info::DeviceInfoKits::GetInstance().GetService(lock);
|
||||
ASSERT_NE(remotePtr, nullptr);
|
||||
auto remote = remotePtr->AsObject();
|
||||
sptr<device_info::DeviceInfoProxy> proxy = new(std::nothrow) device_info::DeviceInfoProxy(remote);
|
||||
|
Loading…
x
Reference in New Issue
Block a user