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