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