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 22 namespace OHOS::AVSession { 23 class BundleStatusAdapter { 24 public: 25 static BundleStatusAdapter& GetInstance(); 26 27 ~BundleStatusAdapter(); 28 29 void Init(); 30 31 bool SubscribeBundleStatusEvent(const std::string bundleName, 32 const std::function<void(const std::string)>& callback); 33 34 bool IsAudioPlayback(const std::string& bundleName, const std::string& abilityName); 35 36 std::string GetBundleNameFromUid(const int32_t uid); 37 38 private: 39 BundleStatusAdapter(); 40 41 void NotifyBundleRemoved(const std::string bundleName); 42 43 sptr<AppExecFwk::BundleMgrProxy> bundleMgrProxy; 44 45 std::map<std::string, std::function<void(const std::string)>> bundleStatusListeners_; 46 47 const int32_t BACKGROUND_MODE_DEMAND = 2; 48 }; 49 50 class BundleStatusCallbackImpl : public AppExecFwk::BundleStatusCallbackHost { 51 public: 52 explicit BundleStatusCallbackImpl(const std::function<void(const std::string)>& callback); 53 ~BundleStatusCallbackImpl() override; 54 void OnBundleStateChanged(const uint8_t installType, const int32_t resultCode, 55 const std::string &resultMsg, const std::string &bundleName) override; OnBundleAdded(const std::string & bundleName,const int userId)56 void OnBundleAdded(const std::string &bundleName, const int userId) override {}; OnBundleUpdated(const std::string & bundleName,const int userId)57 void OnBundleUpdated(const std::string &bundleName, const int userId) override {}; OnBundleRemoved(const std::string & bundleName,const int userId)58 void OnBundleRemoved(const std::string &bundleName, const int userId) override {}; 59 private: 60 DISALLOW_COPY_AND_MOVE(BundleStatusCallbackImpl); 61 std::function<void(std::string)> callback_; 62 }; 63 } 64 #endif // AV_SESSION_BUNDLE_STATUS_ADAPTER_H 65 66