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 "allowed-appid/appsvc_db.hh"
18 #include "allowed-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 std::vector<std::string> PluginManager::Split(const std::string& str,
37 const std::string& delim) {
38 std::string string(str);
39 std::vector<std::string> result;
41 while ((pos = string.find(delim)) != std::string::npos) {
42 std::string token = string.substr(0, pos);
43 result.push_back(token);
44 string.erase(0, pos + delim.length());
46 result.push_back(string);
50 bool PluginManager::StepInstall(const std::unique_ptr<AppEventArgs>& args) {
51 auto* db = dynamic_cast<AppSvcDB*>(GetDB());
53 _E("MetadataPlugin is not prepared");
57 for (auto& metadata : args->GetMetadataList()) {
58 for (auto& app_id : Split(metadata->GetValue(), "|")) {
60 db->Insert(args->GetAppId(), app_id);
61 } catch (Exception& e) {
69 bool PluginManager::StepUninstall(const std::unique_ptr<AppEventArgs>& args) {
70 auto* db = dynamic_cast<AppSvcDB*>(GetDB());
72 _E("MetadataPlugin is not prepared");
77 db->Delete(args->GetAppId());
78 } catch (Exception& e) {
79 _W("Failed to delete alias info. appid(%s)", args->GetAppId().c_str());
84 bool PluginManager::StepUpgrade(const std::unique_ptr<AppEventArgs>& args) {
85 if (!StepUninstall(args))
88 return StepInstall(args);