• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 CO_AUTH_SERVICE_H
17 #define CO_AUTH_SERVICE_H
18 
19 #include "co_auth_stub.h"
20 #include "co_auth_interface.h"
21 
22 #include <optional>
23 
24 #include "resource_node_pool.h"
25 #include <system_ability.h>
26 #include <system_ability_definition.h>
27 #include "system_ability_listener.h"
28 
29 namespace OHOS {
30 namespace UserIam {
31 namespace UserAuth {
32 using ExecutorRegisterInfo = CoAuthInterface::ExecutorRegisterInfo;
33 class CoAuthService : public SystemAbility, public CoAuthStub {
34 public:
35     static constexpr uint32_t DEFER_TIME = 100;
36     DECLARE_SYSTEM_ABILITY(CoAuthService);
37     static std::shared_ptr<CoAuthService> GetInstance();
38 
39     CoAuthService();
40     ~CoAuthService() override = default;
41     int Dump(int fd, const std::vector<std::u16string> &args) override;
42     int32_t ExecutorRegister(const IpcExecutorRegisterInfo &ipcExecutorRegisterInfo,
43         const sptr<IExecutorCallback> &executorCallback, uint64_t &executorIndex) override;
44     int32_t ExecutorUnregister(uint64_t executorIndex) override;
45     void SetIsReady(bool isReady);
46     void SetAccessTokenReady(bool isReady);
47     void OnDriverStart();
48     void OnDriverStop();
49     ResultCode RegisterAccessTokenListener();
50     ResultCode UnRegisterAccessTokenListener();
51     int32_t CallbackEnter([[maybe_unused]] uint32_t code) override;
52     int32_t CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) override;
53 
54 protected:
55     void OnStart() override;
56     void OnStop() override;
57 
58 private:
59     static void AddExecutorDeathRecipient(uint64_t executorIndex, AuthType authType, ExecutorRole role,
60         std::shared_ptr<IExecutorCallback> callback);
61     void AuthServiceInit();
62     void NotifyFwkReady();
63     bool IsFwkReady();
64     int32_t ProcExecutorRegisterSuccess(std::shared_ptr<ResourceNode> &resourceNode,
65         const std::shared_ptr<IExecutorCallback> &callback, std::vector<uint64_t> &templateIdList,
66         std::vector<uint8_t> &fwkPublicKey);
67     void InitExecutorRegisterInfo(const IpcExecutorRegisterInfo &ipcExecutorRegisterInfo,
68         ExecutorRegisterInfo &executorRegisterInfo);
69 
70     static std::shared_ptr<CoAuthService> instance_;
71     std::recursive_mutex mutex_;
72     bool isReady_{false};
73     bool accessTokenReady_{false};
74     sptr<SystemAbilityListener> accessTokenListener_ {nullptr};
75 };
76 } // namespace UserAuth
77 } // namespace UserIam
78 } // namespace OHOS
79 #endif // CO_AUTH_SERVICE_H
80