/* * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef IAM_CONTEXT_CALLBACK_H #define IAM_CONTEXT_CALLBACK_H #include #include #include #include #include #include #include "context.h" #include "iam_defines.h" #include "iam_callback_interface.h" #include "user_auth_common_defines.h" namespace OHOS { namespace UserIam { namespace UserAuth { class ContextCallbackNotifyListener { public: struct MetaData { OperationType operationType; int32_t operationResult = -1; std::optional userId; std::optional remainTime; std::optional freezingTime; std::optional sdkVersion; std::optional requestContextId; std::optional authContextId; std::optional atl; std::optional authType; std::optional authWidgetType; std::optional callerName; std::optional callerType; std::chrono::time_point startTime; std::chrono::time_point endTime; std::optional reuseUnlockResultMode; std::optional reuseUnlockResultDuration; std::optional isBackgroundApplication; }; using Notify = std::function; static ContextCallbackNotifyListener &GetInstance(); void AddNotifier(const Notify ¬ify); void Process(const MetaData &metaData, TraceFlag flag); private: std::vector notifierList_; }; class ContextCallback { public: static std::shared_ptr NewInstance(sptr iamCallback, OperationType operationType); static std::shared_ptr NewDummyInstance(OperationType operationType); virtual ~ContextCallback() = default; virtual void OnResult(int32_t resultCode, const Attributes &finalResult) = 0; virtual void OnAcquireInfo(ExecutorRole src, int32_t moduleType, const std::vector &acquireMsg) = 0; virtual void SetTraceCallerName(const std::string &callerName) = 0; virtual void SetTraceRequestContextId(uint64_t requestContextId) = 0; virtual void SetTraceAuthContextId(uint64_t authContextId) = 0; virtual void SetTraceUserId(int32_t userId) = 0; virtual void SetTraceRemainTime(int32_t remainTime) = 0; virtual void SetTraceFreezingTime(int32_t freezingTime) = 0; virtual void SetTraceSdkVersion(int32_t version) = 0; virtual void SetTraceAuthType(int32_t authType) = 0; virtual void SetTraceAuthWidgetType(uint32_t authWidgetType) = 0; virtual void SetTraceAuthTrustLevel(AuthTrustLevel atl) = 0; virtual void SetTraceReuseUnlockResultMode(uint32_t reuseUnlockResultMode) = 0; virtual void SetTraceReuseUnlockResultDuration(uint64_t reuseUnlockResultDuration) = 0; virtual void SetCleaner(Context::ContextStopCallback callback) = 0; virtual void SetTraceCallerType(int32_t callerType) = 0; virtual void SetTraceIsBackgroundApplication(bool isBackgroundApplication) = 0; virtual void ProcessAuthResult(int32_t tip, const std::vector &extraInfo) = 0; virtual sptr GetIamCallback() = 0; virtual std::string GetCallerName() = 0; }; } // namespace UserAuth } // namespace UserIam } // namespace OHOS #endif // IAM_CONTEXT_CALLBACK_H