1 /* 2 * Copyright (c) 2022-2023 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 CO_AUTH_SERVICE_H 17 #define CO_AUTH_SERVICE_H 18 19 #include "co_auth_stub.h" 20 21 #include <optional> 22 23 #include <system_ability.h> 24 #include <system_ability_definition.h> 25 #include "system_ability_listener.h" 26 27 namespace OHOS { 28 namespace UserIam { 29 namespace UserAuth { 30 class CoAuthService : public SystemAbility, public CoAuthStub { 31 public: 32 static constexpr uint32_t DEFER_TIME = 100; 33 DECLARE_SYSTEM_ABILITY(CoAuthService); 34 static std::shared_ptr<CoAuthService> GetInstance(); 35 36 CoAuthService(); 37 ~CoAuthService() override = default; 38 int Dump(int fd, const std::vector<std::u16string> &args) override; 39 uint64_t ExecutorRegister(const ExecutorRegisterInfo &info, sptr<ExecutorCallbackInterface> &callback) override; 40 void ExecutorUnregister(uint64_t executorIndex) override; 41 void SetIsReady(bool isReady); 42 void SetAccessTokenReady(bool isReady); 43 void OnDriverStart(); 44 void OnDriverStop(); 45 ResultCode RegisterAccessTokenListener(); 46 ResultCode UnRegisterAccessTokenListener(); 47 48 protected: 49 void OnStart() override; 50 void OnStop() override; 51 52 private: 53 static void AddExecutorDeathRecipient(uint64_t executorIndex, AuthType authType, ExecutorRole role, 54 std::shared_ptr<ExecutorCallbackInterface> callback); 55 void AuthServiceInit(); 56 void NotifyFwkReady(); 57 bool IsFwkReady(); 58 59 static std::shared_ptr<CoAuthService> instance_; 60 std::recursive_mutex mutex_; 61 bool isReady_{false}; 62 bool accessTokenReady_{false}; 63 sptr<SystemAbilityListener> accessTokenListener_ {nullptr}; 64 }; 65 } // namespace UserAuth 66 } // namespace UserIam 67 } // namespace OHOS 68 #endif // CO_AUTH_SERVICE_H 69