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 #include "driver_manager_status_listener.h"
17
18 #include "driver_manager.h"
19 #include "iam_logger.h"
20 #include "system_ability_definition.h"
21
22 #define LOG_TAG "USER_AUTH_EXECUTOR"
23
24 namespace OHOS {
25 namespace UserIam {
26 namespace UserAuth {
GetInstance()27 sptr<DriverManagerStatusListener> DriverManagerStatusListener::GetInstance()
28 {
29 static sptr<DriverManagerStatusListener> instance(new (std::nothrow) DriverManagerStatusListener());
30 if (instance == nullptr) {
31 IAM_LOGE("instance is nullptr");
32 }
33 return instance;
34 }
35
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)36 void DriverManagerStatusListener::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId)
37 {
38 if (systemAbilityId != DEVICE_SERVICE_MANAGER_SA_ID) {
39 return;
40 }
41
42 IAM_LOGI("device service manager SA added");
43 Singleton<DriverManager>::GetInstance().SubscribeHdiDriverStatus();
44 }
45
OnRemoveSystemAbility(int32_t systemAbilityId,const std::string & deviceId)46 void DriverManagerStatusListener::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId)
47 {
48 if (systemAbilityId != DEVICE_SERVICE_MANAGER_SA_ID) {
49 return;
50 }
51
52 IAM_LOGI("device service manager SA removed");
53 // when hdi device manager die, hdi driver status is not reliable, disconnect all
54 Singleton<DriverManager>::GetInstance().OnAllHdiDisconnect();
55 }
56 } // namespace UserAuth
57 } // namespace UserIam
58 } // namespace OHOS
59