1 /* 2 * Copyright (c) 2022-2024 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_H 17 #define IAM_CONTEXT_H 18 19 #include <cstdint> 20 #include <memory> 21 #include <string> 22 #include <vector> 23 24 #include "nocopyable.h" 25 26 #include "schedule_node.h" 27 28 namespace OHOS { 29 namespace UserIam { 30 namespace UserAuth { 31 constexpr uint64_t REUSE_AUTH_RESULT_CONTEXT_ID = 1; 32 33 enum ContextState { 34 STATE_INIT, 35 STATE_RUNNING, 36 STATE_END, 37 }; 38 39 enum ContextType { 40 CONTEXT_SIMPLE_AUTH, 41 CONTEXT_ENROLL, 42 CONTEXT_IDENTIFY, 43 WIDGET_AUTH_CONTEXT, 44 REMOTE_AUTH_CONTEXT, 45 REMOTE_AUTH_INVOKER_CONTEXT, 46 SCHEDULE_HOLDER_CONTEXT, 47 }; 48 49 class Context { 50 public: 51 using ContextStopCallback = std::function<void()>; 52 virtual ~Context() = default; 53 virtual bool Start() = 0; 54 virtual bool Stop() = 0; 55 virtual uint64_t GetContextId() const = 0; 56 virtual ContextType GetContextType() const = 0; 57 virtual std::shared_ptr<ScheduleNode> GetScheduleNode(uint64_t scheduleId) const = 0; 58 virtual uint32_t GetTokenId() const = 0; 59 virtual int32_t GetLatestError() const = 0; 60 virtual int32_t GetUserId() const = 0; 61 virtual int32_t GetAuthType() const = 0; 62 virtual std::string GetCallerName() const = 0; 63 64 protected: 65 virtual void SetLatestError(int32_t error) = 0; 66 }; 67 } // namespace UserAuth 68 } // namespace UserIam 69 } // namespace OHOS 70 #endif // IAM_CONTEXT_H