1 /*
2  * Copyright (c) 2024-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 OHOS_CAMERA_BMS_ADAPTER_H
17 #define OHOS_CAMERA_BMS_ADAPTER_H
18 
19 #include <refbase.h>
20 #include "camera_util.h"
21 #include "system_ability_status_change_stub.h"
22 #include "iservice_registry.h"
23 #include "bundle_mgr_interface.h"
24 #include "system_ability_definition.h"
25 #include "lru_map.h"
26 
27 namespace OHOS {
28 namespace CameraStandard {
29 
30 class BmsSaListener : public SystemAbilityStatusChangeStub {
31 public:
32     using RemoveCallback = std::function<void()>;
BmsSaListener(RemoveCallback callback)33     explicit BmsSaListener(RemoveCallback callback) : callback_(std::move(callback)) {
34     }
35     void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
36     void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
37 private:
38     RemoveCallback callback_;
39 };
40 
41 class BmsAdapter : public RefBase {
42 public:
43     ~BmsAdapter();
44     static sptr<BmsAdapter> GetInstance();
45     std::string GetBundleName(int uid);
46     sptr<OHOS::AppExecFwk::IBundleMgr> GetBms();
47     void SetBms(sptr<OHOS::AppExecFwk::IBundleMgr> bms);
48 
49 private:
50     BmsAdapter();
51     bool RegisterListener();
52     bool UnRegisterListener();
53     static sptr<BmsAdapter> bmsAdapter_;
54     static std::mutex instanceMutex_;
55     std::mutex bmslock_;
56     sptr<OHOS::AppExecFwk::IBundleMgr> bms_ = nullptr;
57     sptr<BmsSaListener> bmsSaListener_ = nullptr;
58     LruMap<int, std::string> cacheMap;
59 };
60 } // namespace CameraStandard
61 } // namespace OHOS
62 #endif // OHOS_CAMERA_BMS_ADAPTER_H