• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 AV_SESSION_BUNDLE_STATUS_ADAPTER_H
17 #define AV_SESSION_BUNDLE_STATUS_ADAPTER_H
18 
19 #include <mutex>
20 
21 #include "bundle_mgr_proxy.h"
22 #include "bundle_status_callback_host.h"
23 #include "bundle_resource_proxy.h"
24 
25 namespace OHOS::AVSession {
26 class BundleStatusAdapter {
27 public:
28     static BundleStatusAdapter& GetInstance();
29 
30     ~BundleStatusAdapter();
31 
32     void Init();
33 
34     bool GetBundleIcon(const std::string bundleName, std::string& icon);
35 
36     bool SubscribeBundleStatusEvent(const std::string bundleName,
37         const std::function<void(const std::string, const int32_t userId)>& callback, int32_t userId = DEFAULT_USER_ID);
38 
39     bool IsAudioPlayback(const std::string& bundleName, const std::string& abilityName);
40 
41     std::string GetBundleNameFromUid(const int32_t uid);
42 
43     __attribute__((no_sanitize("cfi"))) bool IsSupportPlayIntent(const std::string& bundleName,
44         std::string& supportModule, std::string& profile);
45 
46 private:
47     BundleStatusAdapter();
48 
49     void NotifyBundleRemoved(const std::string bundleName, const int32_t userId);
50 
51     bool CheckBundleSupport(std::string& profile);
52 
53     sptr<AppExecFwk::BundleMgrProxy> bundleMgrProxy;
54     sptr<AppExecFwk::IBundleResource> bundleResourceProxy;
55 
56     std::map<std::pair<std::string, int32_t>, std::function<void(const std::string, const int32_t)>>
57         bundleStatusListeners_;
58 
59     const int32_t backgroundModeDemand = 2;
60 
61     const int32_t getBundleInfoWithHapModule = 0x00000002;
62 
63     const int32_t startUserId = 100;
64 
65     const std::string PLAY_MUSICLIST = "PlayMusicList";
66 
67     const std::string PLAY_AUDIO = "PlayAudio";
68 
69     std::recursive_mutex bundleMgrProxyLock_;
70 
71     static const int32_t DEFAULT_USER_ID = 100;
72 };
73 
74 class BundleStatusCallbackImpl : public AppExecFwk::BundleStatusCallbackHost {
75 public:
76     explicit BundleStatusCallbackImpl(const std::function<void(const std::string, const int32_t)>& callback,
77         int32_t userId);
78     ~BundleStatusCallbackImpl() override;
79     void OnBundleStateChanged(const uint8_t installType, const int32_t resultCode,
80         const std::string &resultMsg, const std::string &bundleName) override;
OnBundleAdded(const std::string & bundleName,const int userId)81     void OnBundleAdded(const std::string &bundleName, const int userId) override {};
OnBundleUpdated(const std::string & bundleName,const int userId)82     void OnBundleUpdated(const std::string &bundleName, const int userId) override {};
OnBundleRemoved(const std::string & bundleName,const int userId)83     void OnBundleRemoved(const std::string &bundleName, const int userId) override {};
84 private:
85     DISALLOW_COPY_AND_MOVE(BundleStatusCallbackImpl);
86     std::function<void(const std::string, const int32_t userId)> callback_;
87     int32_t userId_;
88 };
89 }
90 #endif // AV_SESSION_BUNDLE_STATUS_ADAPTER_H
91 
92