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 PIN_AUTH_SERVICE_H 17 #define PIN_AUTH_SERVICE_H 18 19 #include <list> 20 #include <mutex> 21 #include <string> 22 #include "ipc_skeleton.h" 23 #include "nocopyable.h" 24 #include "singleton.h" 25 #include "system_ability.h" 26 #include "system_ability_definition.h" 27 #include "i_inputer_data_stub.h" 28 #include "iremote_inputer.h" 29 #include "pinauth_controller.h" 30 #include "pinauth_stub.h" 31 #include "auth_attributes.h" 32 #include "auth_executor_registry.h" 33 #include "executor_callback.h" 34 #include "useridm_client.h" 35 #include "pin_auth.h" 36 37 namespace OHOS { 38 namespace UserIAM { 39 namespace PinAuth { 40 using AuthAttributes = AuthResPool::AuthAttributes; 41 using IExecutorMessenger = AuthResPool::IExecutorMessenger; 42 enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING }; 43 44 class PinAuthService : public SystemAbility, public PinAuthStub { 45 public: 46 DECLEAR_SYSTEM_ABILITY(PinAuthService); 47 DISALLOW_COPY_AND_MOVE(PinAuthService); 48 PinAuthService(); 49 ~PinAuthService() override; 50 51 public: 52 bool RegisterInputer(sptr<IRemoteInputer> inputer) override; 53 void UnRegisterInputer() override; 54 void OnStart() override; 55 void OnStop() override; 56 void ActuatorInfoQuery(); 57 58 private: 59 void OnResult(uint32_t resultCode); 60 bool CheckPermission(const std::string &permission); 61 class MngIQCallback : public AuthResPool::QueryCallback { 62 public: 63 DISALLOW_COPY_AND_MOVE(MngIQCallback); MngIQCallback(PinAuthService * service)64 explicit MngIQCallback(PinAuthService *service) : service_(service) 65 { 66 } 67 virtual ~MngIQCallback() = default; OnResult(uint32_t resultCode)68 void OnResult(uint32_t resultCode) override 69 { 70 service_->OnResult(resultCode); 71 } 72 73 private: 74 std::shared_ptr<PinAuthService> service_; 75 }; 76 77 int32_t OnBeginExecute(uint64_t scheduleId, std::vector<uint8_t> &publicKey, 78 std::shared_ptr<AuthResPool::AuthAttributes> commandAttrs); 79 int32_t OnEndExecute(uint64_t scheduleId, std::shared_ptr<AuthAttributes> consumerAttr); 80 int32_t OnSetProperty(std::shared_ptr<AuthResPool::AuthAttributes> properties); 81 int32_t OnGetProperty(std::shared_ptr<AuthResPool::AuthAttributes> conditions, 82 std::shared_ptr<AuthAttributes> values); 83 void OnMessengerReady(const sptr<IExecutorMessenger> &messenger); 84 85 class MngExCallback : public AuthResPool::ExecutorCallback { 86 public: 87 DISALLOW_COPY_AND_MOVE(MngExCallback); MngExCallback(PinAuthService * service)88 explicit MngExCallback(PinAuthService *service) : service_(service) 89 { 90 } 91 virtual ~MngExCallback() = default; 92 OnBeginExecute(uint64_t scheduleId,std::vector<uint8_t> & publicKey,std::shared_ptr<AuthAttributes> commandAttrs)93 int32_t OnBeginExecute(uint64_t scheduleId, std::vector<uint8_t> &publicKey, 94 std::shared_ptr<AuthAttributes> commandAttrs) override 95 { 96 return service_->OnBeginExecute(scheduleId, publicKey, commandAttrs); 97 } 98 OnSetProperty(std::shared_ptr<AuthResPool::AuthAttributes> properties)99 int32_t OnSetProperty(std::shared_ptr<AuthResPool::AuthAttributes> properties) override 100 { 101 return service_->OnSetProperty(properties); 102 } 103 OnGetProperty(std::shared_ptr<AuthResPool::AuthAttributes> conditions,std::shared_ptr<AuthResPool::AuthAttributes> values)104 int32_t OnGetProperty(std::shared_ptr<AuthResPool::AuthAttributes> conditions, 105 std::shared_ptr<AuthResPool::AuthAttributes> values) override 106 { 107 return service_->OnGetProperty(conditions, values); 108 } 109 OnMessengerReady(const sptr<IExecutorMessenger> & messenger)110 void OnMessengerReady(const sptr<IExecutorMessenger> &messenger) override 111 { 112 service_->OnMessengerReady(messenger); 113 } 114 OnEndExecute(uint64_t sessionId,std::shared_ptr<AuthAttributes> consumerAttr)115 int32_t OnEndExecute(uint64_t sessionId, std::shared_ptr<AuthAttributes> consumerAttr) override 116 { 117 return service_->OnEndExecute(sessionId, consumerAttr); 118 } 119 120 private: 121 std::shared_ptr<PinAuthService> service_; 122 }; 123 124 ServiceRunningState serviceRunningState_ = ServiceRunningState::STATE_NOT_START; 125 std::shared_ptr<AuthResPool::AuthExecutor> executor_; 126 std::shared_ptr<MngIQCallback> mngIQ_; 127 std::shared_ptr<MngExCallback> mngEx_; 128 std::shared_ptr<PinAuth> pin_; 129 uint64_t executorID_ = 0; 130 std::mutex mutex_; 131 sptr<IExecutorMessenger> messenger_; 132 133 class ReconciliationCallback : public UserIDM::GetInfoCallback { 134 public: 135 DISALLOW_COPY_AND_MOVE(ReconciliationCallback); 136 ReconciliationCallback() = default; 137 virtual ~ReconciliationCallback() = default; 138 139 void OnGetInfo(std::vector<UserIDM::CredentialInfo> &info) override; 140 }; 141 }; 142 } // namespace PinAuth 143 } // namespace UserIAM 144 } // namespace OHOS 145 146 #endif // PIN_AUTH_SERVICE_H 147