1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "feature/feature_system.h"
17 namespace OHOS {
18 namespace DistributedData {
GetInstance()19 FeatureSystem &FeatureSystem::GetInstance()
20 {
21 static FeatureSystem instance;
22 return instance;
23 }
24
RegisterCreator(const std::string & name,Creator creator,int32_t flag)25 int32_t FeatureSystem::RegisterCreator(const std::string &name, Creator creator, int32_t flag)
26 {
27 creators_.InsertOrAssign(name, std::pair{ std::move(creator), flag });
28 return E_OK;
29 }
30
GetCreator(const std::string & name)31 FeatureSystem::Creator FeatureSystem::GetCreator(const std::string &name)
32 {
33 auto [success, pair] = creators_.Find(name);
34 if (!success) {
35 return nullptr;
36 }
37 auto [creator, flag] = std::move(pair);
38 return creator;
39 }
40
RegisterStaticActs(const std::string & name,std::shared_ptr<StaticActs> staticActs)41 int32_t FeatureSystem::RegisterStaticActs(const std::string &name, std::shared_ptr<StaticActs> staticActs)
42 {
43 staticActs_.InsertOrAssign(name, std::move(staticActs));
44 return E_OK;
45 }
46
GetStaticActs()47 const ConcurrentMap<std::string, std::shared_ptr<StaticActs>> &FeatureSystem::GetStaticActs()
48 {
49 return staticActs_;
50 }
51
GetFeatureName(int32_t flag)52 std::vector<std::string> FeatureSystem::GetFeatureName(int32_t flag)
53 {
54 std::vector<std::string> features;
55 creators_.ForEach([flag, &features](const std::string &key, auto &pair) -> bool {
56 auto &[creator, bindFlag] = pair;
57 if (bindFlag == flag) {
58 features.push_back(key);
59 }
60 return false;
61 });
62 return features;
63 }
64
~Feature()65 FeatureSystem::Feature::~Feature()
66 {
67 }
68
OnInitialize()69 int32_t FeatureSystem::Feature::OnInitialize()
70 {
71 return E_OK;
72 }
73
OnAppExit(pid_t uid,pid_t pid,uint32_t tokenId,const std::string & bundleName)74 int32_t FeatureSystem::Feature::OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName)
75 {
76 return E_OK;
77 }
78
OnFeatureExit(pid_t uid,pid_t pid,uint32_t tokenId,const std::string & bundleName)79 int32_t FeatureSystem::Feature::OnFeatureExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName)
80 {
81 return E_OK;
82 }
OnAppUninstall(const std::string & bundleName,int32_t user,int32_t index)83 int32_t FeatureSystem::Feature::OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index)
84 {
85 return E_OK;
86 }
87
OnAppUpdate(const std::string & bundleName,int32_t user,int32_t index)88 int32_t FeatureSystem::Feature::OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index)
89 {
90 return E_OK;
91 }
92
OnAppInstall(const std::string & bundleName,int32_t user,int32_t index)93 int32_t FeatureSystem::Feature::OnAppInstall(const std::string &bundleName, int32_t user, int32_t index)
94 {
95 return E_OK;
96 }
97
ResolveAutoLaunch(const std::string & identifier,DistributedDB::AutoLaunchParam & param)98 int32_t FeatureSystem::Feature::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m)
99 {
100 return E_OK;
101 }
102
OnUserChange(uint32_t code,const std::string & user,const std::string & account)103 int32_t FeatureSystem::Feature::OnUserChange(uint32_t code, const std::string &user, const std::string &account)
104 {
105 return E_OK;
106 }
107
Online(const std::string & device)108 int32_t FeatureSystem::Feature::Online(const std::string &device)
109 {
110 return E_OK;
111 }
112
Offline(const std::string & device)113 int32_t FeatureSystem::Feature::Offline(const std::string &device)
114 {
115 return E_OK;
116 }
117
OnReady(const std::string & device)118 int32_t FeatureSystem::Feature::OnReady(const std::string &device)
119 {
120 return E_OK;
121 }
122
OnSessionReady(const std::string & device)123 int32_t FeatureSystem::Feature::OnSessionReady(const std::string &device)
124 {
125 return E_OK;
126 }
127
OnBind(const FeatureSystem::Feature::BindInfo & bindInfo)128 int32_t FeatureSystem::Feature::OnBind(const FeatureSystem::Feature::BindInfo &bindInfo)
129 {
130 return E_OK;
131 }
132
OnScreenUnlocked(int32_t user)133 int32_t FeatureSystem::Feature::OnScreenUnlocked(int32_t user)
134 {
135 return E_OK;
136 }
137 } // namespace DistributedData
138 } // namespace OHOS