From 14c243cb1f44f347aa663da5fe11310aec2e1f23 Mon Sep 17 00:00:00 2001 From: Ilho Kim Date: Mon, 4 Dec 2023 13:42:04 +0900 Subject: [PATCH] Remove the cache when language change event occurs Change-Id: If58b4eb6465e7d1c9bfc254ee33b418eb0dc5a43 Signed-off-by: Ilho Kim (cherry picked from commit dbc0e94134bfa8c35a13899cb8bfedd1d5149512) --- src/common/request_type.cc | 1 + src/common/request_type.hh | 1 + src/server/database/db_handle_provider.cc | 4 -- src/server/database/remove_all_cache_db_handler.cc | 58 ++++++++++++++++++++++ src/server/database/remove_all_cache_db_handler.hh | 44 ++++++++++++++++ .../database/update_pending_cache_handler.cc | 1 + src/server/remove_all_cache_request.cc | 56 +++++++++++++++++++++ src/server/remove_all_cache_request.hh | 49 ++++++++++++++++++ .../remove_all_cache_request_handler.cc | 35 +++++++++++++ .../remove_all_cache_request_handler.hh | 33 ++++++++++++ src/server/request_handler_factory.cc | 3 ++ src/server/runner.cc | 2 + 12 files changed, 283 insertions(+), 4 deletions(-) create mode 100644 src/server/database/remove_all_cache_db_handler.cc create mode 100644 src/server/database/remove_all_cache_db_handler.hh create mode 100644 src/server/remove_all_cache_request.cc create mode 100644 src/server/remove_all_cache_request.hh create mode 100644 src/server/request_handler/remove_all_cache_request_handler.cc create mode 100644 src/server/request_handler/remove_all_cache_request_handler.hh diff --git a/src/common/request_type.cc b/src/common/request_type.cc index 7f3bee9..e80c500 100644 --- a/src/common/request_type.cc +++ b/src/common/request_type.cc @@ -31,6 +31,7 @@ const char* ReqTypeToString(ReqType type) { "COMMAND", "CREATE_DB", "CREATE_CACHE", + "REMOVE_ALL_CACHE", "ERROR_REQ_TYPE" }; diff --git a/src/common/request_type.hh b/src/common/request_type.hh index 4f3ba0c..5118271 100644 --- a/src/common/request_type.hh +++ b/src/common/request_type.hh @@ -38,6 +38,7 @@ enum ReqType { COMMAND, CREATE_DB, CREATE_CACHE, + REMOVE_ALL_CACHE, MAX }; diff --git a/src/server/database/db_handle_provider.cc b/src/server/database/db_handle_provider.cc index 5576c67..a97f0f5 100644 --- a/src/server/database/db_handle_provider.cc +++ b/src/server/database/db_handle_provider.cc @@ -178,14 +178,10 @@ void DBHandleProvider::TrimCache() { } void DBHandleProvider::ReleaseCache() { - auto lock = CacheFlag::GetWriterLock(); - CacheFlag::SetStatus(CacheFlag::Status::PREPARING); - app_map_.clear(); pkg_map_.clear(); pending_pkg_.clear(); pkg_app_map_.clear(); - CacheFlag::SetStatus(CacheFlag::Status::UNPREPARED); released_ = true; } diff --git a/src/server/database/remove_all_cache_db_handler.cc b/src/server/database/remove_all_cache_db_handler.cc new file mode 100644 index 0000000..1755917 --- /dev/null +++ b/src/server/database/remove_all_cache_db_handler.cc @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "remove_all_cache_db_handler.hh" + +#include "cache_flag.hh" +#include "db_handle_provider.hh" +#include "utils/logging.hh" + +namespace { + +uid_t globaluser_uid = -1; + +uid_t GetGlobalUID() { + if (globaluser_uid == (uid_t)-1) + globaluser_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER); + + return globaluser_uid; +} + +} // namespace + +namespace pkgmgr_server { +namespace database { + +RemoveAllCacheDBHandler::RemoveAllCacheDBHandler(uid_t uid, int pid) + : AbstractDBHandler(uid, pid), uid_(uid) {} + +int RemoveAllCacheDBHandler::Execute() { + std::unique_lock u(lock_); + + auto lock = CacheFlag::GetWriterLock(); + if (CacheFlag::GetStatus() != CacheFlag::Status::PREPARED) + return PMINFO_R_OK; + CacheFlag::SetStatus(CacheFlag::Status::PREPARING); + database::DBHandleProvider::GetInst(GetUID()).TrimCache(); + database::DBHandleProvider::GetInst(GetGlobalUID()).TrimCache(); + + CacheFlag::SetStatus(CacheFlag::Status::UNPREPARED); + + return PMINFO_R_OK; +} + +} // namespace database +} // namespace pkgmgr_server diff --git a/src/server/database/remove_all_cache_db_handler.hh b/src/server/database/remove_all_cache_db_handler.hh new file mode 100644 index 0000000..f174b4b --- /dev/null +++ b/src/server/database/remove_all_cache_db_handler.hh @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef REMOVE_ALL_CACHE_DB_HANDLER_HH_ +#define REMOVE_ALL_CACHE_DB_HANDLER_HH_ + +#include + +#include "abstract_db_handler.hh" + +namespace pkgmgr_server { +namespace database { + +#ifndef EXPORT_API +#define EXPORT_API __attribute__((visibility("default"))) +#endif + +class EXPORT_API RemoveAllCacheDBHandler : public AbstractDBHandler { + public: + RemoveAllCacheDBHandler(uid_t uid, int pid); + int Execute() override; + + private: + uid_t uid_; +}; + +} // namespace database +} // namespace pkgmgr_server + +#endif // REMOVE_ALL_CACHE_DB_HANDLER_HH_ + diff --git a/src/server/database/update_pending_cache_handler.cc b/src/server/database/update_pending_cache_handler.cc index 5a4ecc5..79e5dfb 100644 --- a/src/server/database/update_pending_cache_handler.cc +++ b/src/server/database/update_pending_cache_handler.cc @@ -31,6 +31,7 @@ int UpdatePendingCacheHandler::Execute() { SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB); if (!Connect()) { + auto lock = CacheFlag::GetWriterLock(); database::DBHandleProvider::GetInst(GetUID()).TrimCache(); return PMINFO_R_ERROR; } diff --git a/src/server/remove_all_cache_request.cc b/src/server/remove_all_cache_request.cc new file mode 100644 index 0000000..48acdd8 --- /dev/null +++ b/src/server/remove_all_cache_request.cc @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "remove_all_cache_request.hh" + +#include +#include + +namespace pkgmgr_server { + +const unsigned char* RemoveAllCacheRequest::GetData() { + return nullptr; +} + +size_t RemoveAllCacheRequest::GetSize() { + return 0; +} + +pid_t RemoveAllCacheRequest::GetSenderPID() { + return getpid(); +} + +pid_t RemoveAllCacheRequest::GetSenderTID() { + return gettid(); +} + +uid_t RemoveAllCacheRequest::GetSenderUID() { + return uid_; +} + +pkgmgr_common::ReqType RemoveAllCacheRequest::GetRequestType() { + return pkgmgr_common::ReqType::REMOVE_ALL_CACHE; +} + +bool RemoveAllCacheRequest::SendData(const tizen_base::Parcel& parcel) { + return true; +} + +bool RemoveAllCacheRequest::GetPrivilegeChecked() { + return true; +} + +} // namespace pkgmgr_server diff --git a/src/server/remove_all_cache_request.hh b/src/server/remove_all_cache_request.hh new file mode 100644 index 0000000..a0fbc85 --- /dev/null +++ b/src/server/remove_all_cache_request.hh @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SERVER_REMOVE_ALL_CACHE_REQUEST_HH_ +#define SERVER_REMOVE_ALL_CACHE_REQUEST_HH_ + +#include + +#include "pkg_request.hh" +#include "request_type.hh" + +namespace pkgmgr_server { + +#ifndef EXPORT_API +#define EXPORT_API __attribute__((visibility("default"))) +#endif + +class EXPORT_API RemoveAllCacheRequest : public PkgRequest { + public: + RemoveAllCacheRequest(uid_t uid) : uid_(uid) {} + const unsigned char* GetData() override; + size_t GetSize() override; + pid_t GetSenderPID() override; + pid_t GetSenderTID() override; + uid_t GetSenderUID() override; + pkgmgr_common::ReqType GetRequestType() override; + bool SendData(const tizen_base::Parcel& parcel) override; + bool GetPrivilegeChecked() override; + + private: + uid_t uid_; +}; + +} // namespace pkgmgr_server + +#endif // SERVER_REMOVE_ALL_CACHE_REQUEST_HH_ diff --git a/src/server/request_handler/remove_all_cache_request_handler.cc b/src/server/request_handler/remove_all_cache_request_handler.cc new file mode 100644 index 0000000..0c9a75f --- /dev/null +++ b/src/server/request_handler/remove_all_cache_request_handler.cc @@ -0,0 +1,35 @@ +// Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by an apache-2.0 license that can be +// found in the LICENSE file. + +#include "remove_all_cache_request_handler.hh" + +#include + +#include + +#include "remove_all_cache_db_handler.hh" +#include "utils/logging.hh" + +namespace psd = pkgmgr_server::database; + +namespace pkgmgr_server { +namespace request_handler { + +bool RemoveAllCacheRequestHandler::HandleRequest(unsigned char* data, size_t size, + const std::string& locale) { + psd::RemoveAllCacheDBHandler db(GetUID(), GetPID()); + db.SetLocale(locale); + + success_ = (db.Execute() == PMINFO_R_OK); + return success_; +} + +tizen_base::Parcel RemoveAllCacheRequestHandler::ExtractResult() { + tizen_base::Parcel parcel; + parcel.WriteBool(success_); + return parcel; +} + +} // namespace request_handler +} // namespace pkgmgr_server diff --git a/src/server/request_handler/remove_all_cache_request_handler.hh b/src/server/request_handler/remove_all_cache_request_handler.hh new file mode 100644 index 0000000..21006d7 --- /dev/null +++ b/src/server/request_handler/remove_all_cache_request_handler.hh @@ -0,0 +1,33 @@ +// Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by an apache-2.0 license that can be +// found in the LICENSE file. + +#ifndef REMOVE_ALL_CACHE_REQUEST_HANDLER_HH_ +#define REMOVE_ALL_CACHE_REQUEST_HANDLER_HH_ + +#include "abstract_request_handler.hh" +#include "result_parcelable.hh" + +#include + +namespace pkgmgr_server { +namespace request_handler { + +#ifndef EXPORT_API +#define EXPORT_API __attribute__((visibility("default"))) +#endif + +class EXPORT_API RemoveAllCacheRequestHandler : public AbstractRequestHandler { + public: + bool HandleRequest(unsigned char* data, size_t size, + const std::string& locale) override; + tizen_base::Parcel ExtractResult() override; + + private: + bool success_ = false; +}; + +} // namespace request_handler +} // namespace pkgmgr_server + +#endif // REMOVE_ALL_CACHE_REQUEST_HANDLER_HH_ diff --git a/src/server/request_handler_factory.cc b/src/server/request_handler_factory.cc index 0da6956..6beb6cd 100644 --- a/src/server/request_handler_factory.cc +++ b/src/server/request_handler_factory.cc @@ -24,6 +24,7 @@ #include "server/request_handler/get_depinfo_request_handler.hh" #include "server/request_handler/get_pkginfo_request_handler.hh" #include "server/request_handler/query_request_handler.hh" +#include "server/request_handler/remove_all_cache_request_handler.hh" #include "server/request_handler/set_cert_request_handler.hh" #include "server/request_handler/set_pkginfo_request_handler.hh" #include "utils/logging.hh" @@ -53,6 +54,8 @@ RequestHandlerFactory::RequestHandlerFactory() { new request_handler::CreateDBRequestHandler()); handler[pkgmgr_common::ReqType::CREATE_CACHE].reset( new request_handler::CreateCacheRequestHandler()); + handler[pkgmgr_common::ReqType::REMOVE_ALL_CACHE].reset( + new request_handler::RemoveAllCacheRequestHandler()); } std::shared_ptr diff --git a/src/server/runner.cc b/src/server/runner.cc index 85d3acf..db909a0 100644 --- a/src/server/runner.cc +++ b/src/server/runner.cc @@ -27,6 +27,7 @@ #include "create_cache_request.hh" #include "cynara_checker.hh" #include "pkg_request.hh" +#include "remove_all_cache_request.hh" #include "runner.hh" #include "utils/logging.hh" @@ -94,6 +95,7 @@ int Runner::OnReceiveRequest(int fd, GIOCondition cond, void* user_data) { void Runner::OnChanged(const std::string& locale) { thread_pool_->SetLocale(locale); + QueueRequest(std::make_shared(default_uid_)); } bool Runner::QueueRequest(std::shared_ptr req) { -- 2.7.4