fix crash

Signed-off-by: yanghuiqing <yanghuiqing6@huawei.com>
This commit is contained in:
yanghuiqing 2024-11-11 18:30:35 +08:00
parent f664f8678a
commit 07a4afe8ee
3 changed files with 12 additions and 3 deletions

View File

@ -154,6 +154,7 @@ private:
static constexpr int MIN_TRANMISSION_TIME = 30 * 1000; //ms
static constexpr uint64_t ONE_HOUR_MILLISECONDS = 60 * 60 * 1000;
static constexpr uint32_t GET_REMOTE_DATA_WAIT_TIME = 30000;
void InitBundles(Loader &loader);
class DelayGetterDeathRecipient final : public IRemoteObject::DeathRecipient {
public:
explicit DelayGetterDeathRecipient(int32_t userId, PasteboardService &service);
@ -291,6 +292,7 @@ private:
std::atomic<uint32_t> dataId_ = 0;
static std::mutex historyMutex_;
std::mutex bundleMutex_;
std::mutex readBundleMutex_;
static std::vector<std::string> dataHistory_;
static std::shared_ptr<Command> copyHistory;
static std::shared_ptr<Command> copyData;

View File

@ -135,6 +135,12 @@ void PasteboardService::InitScreenStatus()
#endif
}
void PasteboardService::InitBundles(Loader &loader)
{
std::lock_guard<std::mutex> lock(bundleMutex_);
bundles_ = loader.LoadBundles();
}
void PasteboardService::OnStart()
{
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "PasteboardService OnStart.");
@ -149,7 +155,7 @@ void PasteboardService::OnStart()
auto appInfo = GetAppInfo(IPCSkeleton::GetCallingTokenID());
Loader loader;
loader.LoadComponents();
bundles_ = loader.LoadBundles();
InitBundles(loader);
uid_ = loader.LoadUid();
moduleConfig_.Init();
auto ret = DATASL_OnStart();
@ -1040,7 +1046,7 @@ int32_t PasteboardService::GrantUriPermission(PasteData &data, const std::string
auto permissionCode = AAFwk::UriPermissionManagerClient::GetInstance().GrantUriPermissionPrivileged(
sendValues, AAFwk::Want::FLAG_AUTH_READ_URI_PERMISSION, targetBundleName);
if (permissionCode == 0) {
std::lock_guard<std::mutex> lock(bundleMutex_);
std::lock_guard<std::mutex> lock(readBundleMutex_);
if (readBundles_.count(targetBundleName) == 0) {
readBundles_.insert(targetBundleName);
}
@ -1087,7 +1093,7 @@ void PasteboardService::RevokeUriPermission(std::shared_ptr<PasteData> pasteData
{
std::set<std::string> bundles;
{
std::lock_guard<std::mutex> lock(bundleMutex_);
std::lock_guard<std::mutex> lock(readBundleMutex_);
bundles = std::move(readBundles_);
}
if (pasteData == nullptr || bundles.empty()) {

View File

@ -17,6 +17,7 @@
#include <thread>
#include "loader.h"
#include "message_parcel.h"
#include "pasteboard_service.h"
#include "pasteboard_serv_ipc_interface_code.h"