"COMMAND",
"CREATE_DB",
"CREATE_CACHE",
+ "REMOVE_ALL_CACHE",
"ERROR_REQ_TYPE"
};
COMMAND,
CREATE_DB,
CREATE_CACHE,
+ REMOVE_ALL_CACHE,
MAX
};
}
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;
}
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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_
+
SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB);
if (!Connect()) {
+ auto lock = CacheFlag::GetWriterLock();
database::DBHandleProvider::GetInst(GetUID()).TrimCache();
return PMINFO_R_ERROR;
}
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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_
--- /dev/null
+// 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
--- /dev/null
+// 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_
#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"
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>
#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"
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) {