From: Ilho Kim Date: Mon, 4 Dec 2023 04:42:04 +0000 (+0900) Subject: Remove the cache when language change event occurs X-Git-Tag: accepted/tizen/unified/20231211.095404~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=14c243cb1f44f347aa663da5fe11310aec2e1f23;p=platform%2Fcore%2Fappfw%2Fpkgmgr-info.git Remove the cache when language change event occurs Change-Id: If58b4eb6465e7d1c9bfc254ee33b418eb0dc5a43 Signed-off-by: Ilho Kim (cherry picked from commit dbc0e94134bfa8c35a13899cb8bfedd1d5149512) --- diff --git a/src/common/request_type.cc b/src/common/request_type.cc index 7f3bee9c..e80c5006 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 4f3ba0c5..51182713 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 5576c67b..a97f0f54 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 00000000..17559178 --- /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 00000000..f174b4bb --- /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 5a4ecc5d..79e5dfb3 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 00000000..48acdd8b --- /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 00000000..a0fbc859 --- /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 00000000..0c9a75f3 --- /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 00000000..21006d78 --- /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 0da69567..6beb6cd9 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 85d3acf1..db909a0f 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) {