• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CHECKER_CHECKER_MANAGER_H
17 #define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CHECKER_CHECKER_MANAGER_H
18 #include <vector>
19 #include "visibility.h"
20 #include "concurrent_map.h"
21 namespace OHOS {
22 namespace DistributedData {
23 class CheckerManager {
24 public:
25     static constexpr pid_t INVALID_UID = -1;
26     static constexpr const char* SYSTEM_CHECKER = "SystemChecker";
27     struct Trust {
28         std::string bundleName;
29         std::string appId;
30         std::string packageName;
31         std::string base64Key;
32         std::string checker;
33     };
34     class Checker {
35     public:
36         virtual void Initialize() = 0;
37         virtual bool SetTrustInfo(const Trust &trust) = 0;
38         virtual std::string GetAppId(pid_t uid, const std::string &bundleName) = 0;
39         virtual bool IsValid(pid_t uid, const std::string &bundleName) = 0;
40     protected:
41         API_EXPORT ~Checker() = default;
42     };
43     API_EXPORT static CheckerManager &GetInstance();
44     API_EXPORT void RegisterPlugin(const std::string &checker, std::function<Checker *()> getter);
45     API_EXPORT std::string GetAppId(const std::string &bundleName, pid_t uid);
46     API_EXPORT bool IsValid(const std::string &bundleName, pid_t uid);
47     API_EXPORT void LoadCheckers(std::vector<std::string> &checkers);
48     API_EXPORT Checker *GetChecker(const std::string &checker);
49 private:
50     std::map<std::string, Checker *> checkers_;
51     ConcurrentMap<std::string, std::function<Checker *()>> getters_;
52 };
53 }
54 }
55 #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CHECKER_CHECKER_MANAGER_H
56