• 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 "bundle_mgr_proxy.h"
20 #include "bundle_status_callback_host.h"
21 #include "insight_intent_execute_param.h"
22 
23 namespace OHOS::AVSession {
24 class BundleStatusAdapter {
25 public:
26     static BundleStatusAdapter& GetInstance();
27 
28     ~BundleStatusAdapter();
29 
30     void Init();
31 
32     bool SubscribeBundleStatusEvent(const std::string bundleName,
33         const std::function<void(const std::string)>& callback);
34 
35     bool IsAudioPlayback(const std::string& bundleName, const std::string& abilityName);
36 
37     std::string GetBundleNameFromUid(const int32_t uid);
38 
39     bool IsSupportPlayIntent(const std::string& bundleName, std::string& supportModule, std::string& profile);
40 
41     bool GetPlayIntentParam(const std::string& bundleName, const std::string& assetId,
42                             AppExecFwk::InsightIntentExecuteParam &executeParam);
43 
44 private:
45     BundleStatusAdapter();
46 
47     void NotifyBundleRemoved(const std::string bundleName);
48 
49     sptr<AppExecFwk::BundleMgrProxy> bundleMgrProxy;
50 
51     std::map<std::string, std::function<void(const std::string)>> bundleStatusListeners_;
52 
53     const int32_t backgroundModeDemand = 2;
54 
55     const int32_t getBundleInfoWithHapModule = 0x00000002;
56 
57     const int32_t startUserId = 100;
58 
59     const std::string PLAY_MUSICLIST = "PlayMusicList";
60 
61     const std::string PLAY_MUSIC = "PlayMusic";
62 };
63 
64 class BundleStatusCallbackImpl : public AppExecFwk::BundleStatusCallbackHost {
65 public:
66     explicit BundleStatusCallbackImpl(const std::function<void(const std::string)>& callback);
67     ~BundleStatusCallbackImpl() override;
68     void OnBundleStateChanged(const uint8_t installType, const int32_t resultCode,
69         const std::string &resultMsg, const std::string &bundleName) override;
OnBundleAdded(const std::string & bundleName,const int userId)70     void OnBundleAdded(const std::string &bundleName, const int userId) override {};
OnBundleUpdated(const std::string & bundleName,const int userId)71     void OnBundleUpdated(const std::string &bundleName, const int userId) override {};
OnBundleRemoved(const std::string & bundleName,const int userId)72     void OnBundleRemoved(const std::string &bundleName, const int userId) override {};
73 private:
74     DISALLOW_COPY_AND_MOVE(BundleStatusCallbackImpl);
75     std::function<void(std::string)> callback_;
76 };
77 }
78 #endif // AV_SESSION_BUNDLE_STATUS_ADAPTER_H
79 
80