• 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 IAM_CONTEXT_CALLBACK_H
17 #define IAM_CONTEXT_CALLBACK_H
18 
19 #include <cstdint>
20 #include <chrono>
21 #include <functional>
22 #include <memory>
23 #include <optional>
24 #include <vector>
25 
26 #include "context.h"
27 #include "iam_defines.h"
28 #include "iam_callback_interface.h"
29 #include "user_auth_common_defines.h"
30 
31 namespace OHOS {
32 namespace UserIam {
33 namespace UserAuth {
34 class ContextCallbackNotifyListener {
35 public:
36     struct MetaData {
37         OperationType operationType;
38         int32_t operationResult = -1;
39         std::optional<int32_t> userId;
40         std::optional<int32_t> remainTime;
41         std::optional<int32_t> freezingTime;
42         std::optional<int32_t> sdkVersion;
43         std::optional<uint64_t> requestContextId;
44         std::optional<uint64_t> authContextId;
45         std::optional<AuthTrustLevel> atl;
46         std::optional<int32_t> authType;
47         std::optional<uint32_t> authWidgetType;
48         std::optional<std::string> callerName;
49         std::chrono::time_point<std::chrono::steady_clock> startTime;
50         std::chrono::time_point<std::chrono::steady_clock> endTime;
51     };
52     using Notify = std::function<void(const MetaData &metaData)>;
53     static ContextCallbackNotifyListener &GetInstance();
54     void AddNotifier(const Notify &notify);
55     void Process(const MetaData &metaData);
56 
57 private:
58     std::vector<Notify> notifierList_;
59 };
60 
61 class ContextCallback {
62 public:
63     static std::shared_ptr<ContextCallback> NewInstance(sptr<IamCallbackInterface> iamCallback,
64         OperationType operationType);
65     static std::shared_ptr<ContextCallback> NewDummyInstance(OperationType operationType);
66     virtual ~ContextCallback() = default;
67     virtual void OnResult(int32_t resultCode, const Attributes &finalResult) = 0;
68     virtual void OnAcquireInfo(ExecutorRole src, int32_t moduleType, const std::vector<uint8_t> &acquireMsg) const = 0;
69     virtual void SetTraceCallerName(const std::string &callerName) = 0;
70     virtual void SetTraceRequestContextId(uint64_t requestContextId) = 0;
71     virtual void SetTraceAuthContextId(uint64_t authContextId) = 0;
72     virtual void SetTraceUserId(int32_t userId) = 0;
73     virtual void SetTraceRemainTime(int32_t remainTime) = 0;
74     virtual void SetTraceFreezingTime(int32_t freezingTime) = 0;
75     virtual void SetTraceSdkVersion(int32_t version) = 0;
76     virtual void SetTraceAuthType(int32_t authType) = 0;
77     virtual void SetTraceAuthWidgetType(uint32_t authWidgetType) = 0;
78     virtual void SetTraceAuthTrustLevel(AuthTrustLevel atl) = 0;
79     virtual void SetCleaner(Context::ContextStopCallback callback) = 0;
80 };
81 } // namespace UserAuth
82 } // namespace UserIam
83 } // namespace OHOS
84 #endif // IAM_CONTEXT_CALLBACK_H