Remove the cache when language change event occurs 48/302448/1
authorIlho Kim <ilho159.kim@samsung.com>
Mon, 4 Dec 2023 04:42:04 +0000 (13:42 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Thu, 7 Dec 2023 01:45:35 +0000 (10:45 +0900)
Change-Id: If58b4eb6465e7d1c9bfc254ee33b418eb0dc5a43
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
(cherry picked from commit dbc0e94134bfa8c35a13899cb8bfedd1d5149512)

12 files changed:
src/common/request_type.cc
src/common/request_type.hh
src/server/database/db_handle_provider.cc
src/server/database/remove_all_cache_db_handler.cc [new file with mode: 0644]
src/server/database/remove_all_cache_db_handler.hh [new file with mode: 0644]
src/server/database/update_pending_cache_handler.cc
src/server/remove_all_cache_request.cc [new file with mode: 0644]
src/server/remove_all_cache_request.hh [new file with mode: 0644]
src/server/request_handler/remove_all_cache_request_handler.cc [new file with mode: 0644]
src/server/request_handler/remove_all_cache_request_handler.hh [new file with mode: 0644]
src/server/request_handler_factory.cc
src/server/runner.cc

index 7f3bee9..e80c500 100644 (file)
@@ -31,6 +31,7 @@ const char* ReqTypeToString(ReqType type) {
       "COMMAND",
       "CREATE_DB",
       "CREATE_CACHE",
+      "REMOVE_ALL_CACHE",
       "ERROR_REQ_TYPE"
   };
 
index 4f3ba0c..5118271 100644 (file)
@@ -38,6 +38,7 @@ enum ReqType {
   COMMAND,
   CREATE_DB,
   CREATE_CACHE,
+  REMOVE_ALL_CACHE,
   MAX
 };
 
index 5576c67..a97f0f5 100644 (file)
@@ -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 (file)
index 0000000..1755917
--- /dev/null
@@ -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<std::shared_mutex> 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 (file)
index 0000000..f174b4b
--- /dev/null
@@ -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 <sys/types.h>
+
+#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_
+
index 5a4ecc5..79e5dfb 100644 (file)
@@ -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 (file)
index 0000000..48acdd8
--- /dev/null
@@ -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 <sys/types.h>
+#include <unistd.h>
+
+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 (file)
index 0000000..a0fbc85
--- /dev/null
@@ -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 <sys/types.h>
+
+#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 (file)
index 0000000..0c9a75f
--- /dev/null
@@ -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 <sys/resource.h>
+
+#include <string>
+
+#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 (file)
index 0000000..21006d7
--- /dev/null
@@ -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 <string>
+
+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_
index 0da6956..6beb6cd 100644 (file)
@@ -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<request_handler::AbstractRequestHandler>
index 85d3acf..db909a0 100644 (file)
@@ -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<RemoveAllCacheRequest>(default_uid_));
 }
 
 bool Runner::QueueRequest(std::shared_ptr<PkgRequest> req) {