1 /*
2  * Copyright (c) 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 SYSTEM_ABILITY_SERVICE_STATUS_LISTENER_H
17 #define SYSTEM_ABILITY_SERVICE_STATUS_LISTENER_H
18 
19 #include "system_ability_status_change_stub.h"
20 
21 #include "iam_logger.h"
22 #include "iam_check.h"
23 
24 #define LOG_TAG "USER_AUTH_SA"
25 namespace OHOS {
26 namespace UserIam {
27 namespace UserAuth {
28 class SystemAbilityListener : public OHOS::SystemAbilityStatusChangeStub, public NoCopyable {
29 public:
30     using AddFunc = std::function<void(void)>;
31     using RemoveFunc = std::function<void(void)>;
32     SystemAbilityListener(std::string name, int32_t systemAbilityId,
33          AddFunc addFunc, RemoveFunc removeFunc);
~SystemAbilityListener()34     ~SystemAbilityListener() override {};
35 
36     void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
37     void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
38     static sptr<SystemAbilityListener> Subscribe(std::string name, int32_t systemAbilityId,
39          AddFunc addFunc, RemoveFunc removeFunc);
40     static int32_t UnSubscribe(int32_t systemAbilityId, sptr<SystemAbilityListener> &listener);
41 
42 private:
43     std::string name_;
44     int32_t systemAbilityId_ = -1;
45     AddFunc addFunc_;
46     RemoveFunc removeFunc_;
47 };
48 } // namespace UserAuth
49 } // namespace UserIam
50 } // namespace OHOS
51 #endif // SYSTEM_ABILITY_SERVICE_STATUS_LISTENER_H