2 * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "alias-appid/appsvc_db.hh"
18 #include "alias-appid/plugin_manager.hh"
19 #include "common/exception.hh"
20 #include "common/log_private.hh"
24 PluginManager::PluginManager()
25 : MetadataPlugin(std::unique_ptr<Database>(
26 new AppSvcDB(MetadataPlugin::GetUid()))) {
29 PluginManager::~PluginManager() = default;
31 PluginManager& PluginManager::GetInst() {
32 static PluginManager inst;
36 bool PluginManager::StepBackup(const std::unique_ptr<AppEventArgs>& args) {
37 auto* db = dynamic_cast<AppSvcDB*>(GetDB());
39 _E("MetadataPlugin is not prepared");
44 auto info_arr = db->Select(args->GetAppId());
45 if (info_arr.size() != 0)
46 infos_.insert(infos_.end(), info_arr.begin(), info_arr.end());
47 } catch (Exception& e) {
48 _E("Exception(%d) occurs", e.GetErrorCode());
55 bool PluginManager::StepInstall(const std::unique_ptr<AppEventArgs>& args) {
56 auto* db = dynamic_cast<AppSvcDB*>(GetDB());
58 _E("MetadataPlugin is not prepared");
62 for (auto& metadata : args->GetMetadataList()) {
64 db->Insert(metadata->GetValue(), args->GetAppId());
65 } catch (Exception& e) {
72 bool PluginManager::StepUninstall(const std::unique_ptr<AppEventArgs>& args) {
73 auto* db = dynamic_cast<AppSvcDB*>(GetDB());
75 _E("MetadataPlugin is not prepared");
79 if (args->GetMetadataList().empty()) {
81 db->Delete(args->GetAppId());
82 } catch (Exception& e) {
83 _W("Failed to delete alias info. appid(%s)", args->GetAppId().c_str());
88 for (auto& metadata : args->GetMetadataList()) {
90 db->Delete(metadata->GetValue(), args->GetAppId());
91 } catch (Exception& e) {
98 bool PluginManager::StepUpgrade(const std::unique_ptr<AppEventArgs>& args) {
99 auto* db = dynamic_cast<AppSvcDB*>(GetDB());
101 _E("MetadataPlugin is not prepared");
106 db->Delete(args->GetAppId());
107 } catch (Exception& e) {
108 _W("Failed to delete alias info. appid(%s)", args->GetAppId().c_str());
111 return StepInstall(args);
114 bool PluginManager::StepRestore() {
116 auto* db = dynamic_cast<AppSvcDB*>(GetDB());
118 _E("MetadataPlugin is not prepared");
122 for (auto& info : infos_) {
124 db->Insert(info->GetAliasAppId(), info->GetAppId());
125 } catch (Exception& e) {
126 _E("Exception(%d) occurs", e.GetErrorCode());
134 } // namespace plugin