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
OnAppUninstall(const std::string & bundleName,int32_t user,int32_t index)79 int32_t FeatureSystem::Feature::OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index)
80 {
81 return E_OK;
82 }
83
OnAppUpdate(const std::string & bundleName,int32_t user,int32_t index)84 int32_t FeatureSystem::Feature::OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index)
85 {
86 return E_OK;
87 }
88
OnAppInstall(const std::string & bundleName,int32_t user,int32_t index)89 int32_t FeatureSystem::Feature::OnAppInstall(const std::string &bundleName, int32_t user, int32_t index)
90 {
91 return E_OK;
92 }
93
ResolveAutoLaunch(const std::string & identifier,DistributedDB::AutoLaunchParam & param)94 int32_t FeatureSystem::Feature::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m)
95 {
96 return E_OK;
97 }
98
OnUserChange(uint32_t code,const std::string & user,const std::string & account)99 int32_t FeatureSystem::Feature::OnUserChange(uint32_t code, const std::string &user, const std::string &account)
100 {
101 return E_OK;
102 }
103
Online(const std::string & device)104 int32_t FeatureSystem::Feature::Online(const std::string &device)
105 {
106 return E_OK;
107 }
108
Offline(const std::string & device)109 int32_t FeatureSystem::Feature::Offline(const std::string &device)
110 {
111 return E_OK;
112 }
113
OnReady(const std::string & device)114 int32_t FeatureSystem::Feature::OnReady(const std::string &device)
115 {
116 return E_OK;
117 }
118
OnSessionReady(const std::string & device)119 int32_t FeatureSystem::Feature::OnSessionReady(const std::string &device)
120 {
121 return E_OK;
122 }
123
OnBind(const FeatureSystem::Feature::BindInfo & bindInfo)124 int32_t FeatureSystem::Feature::OnBind(const FeatureSystem::Feature::BindInfo &bindInfo)
125 {
126 return E_OK;
127 }
128
OnScreenUnlocked(int32_t user)129 int32_t FeatureSystem::Feature::OnScreenUnlocked(int32_t user)
130 {
131 return E_OK;
132 }
133 } // namespace DistributedData
134 } // namespace OHOS