• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 DRIVER_STATE_MANAGER_H
17 #define DRIVER_STATE_MANAGER_H
18 
19 #include <mutex>
20 #include <optional>
21 
22 #include "iservstat_listener_hdi.h"
23 #include "system_ability_listener.h"
24 
25 namespace OHOS {
26 namespace UserIam {
27 namespace UserAuth {
28 using ServStatListenerStub = HDI::ServiceManager::V1_0::ServStatListenerStub;
29 class DriverStateManager {
30 public:
31     static DriverStateManager &GetInstance();
32     using DriverUpdateCallback = std::function<void()>;
33 
34     void OnDriverManagerAdd();
35     void OnDriverManagerRemove();
36     void OnDriverStart();
37     void OnDriverStop();
38     void RegisterDriverStartCallback(const DriverUpdateCallback &callback);
39     void RegisterDriverStopCallback(const DriverUpdateCallback &callback);
40     void StartSubscribe();
41 
42 private:
43     DriverStateManager() = default;
44     ~DriverStateManager() = default;
45 
46     bool isSubscribed_ = false;
47     std::recursive_mutex mutex_;
48     sptr<SystemAbilityListener> driverManagerStatusListener_ = nullptr;
49     sptr<ServStatListenerStub> driverStatusListener_ = nullptr;
50     std::optional<bool> isDriverRunning_ {std::nullopt};
51     std::vector<DriverUpdateCallback> startCallbacks_;
52     std::vector<DriverUpdateCallback> stopCallbacks_;
53 };
54 } // namespace UserAuth
55 } // namespace UserIam
56 } // namespace OHOS
57 #endif // DRIVER_STATE_MANAGER_H