180922886Sopenharmony_ci/* 280922886Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 380922886Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 480922886Sopenharmony_ci * you may not use this file except in compliance with the License. 580922886Sopenharmony_ci * You may obtain a copy of the License at 680922886Sopenharmony_ci * 780922886Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 880922886Sopenharmony_ci * 980922886Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1080922886Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1180922886Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1280922886Sopenharmony_ci * See the License for the specific language governing permissions and 1380922886Sopenharmony_ci * limitations under the License. 1480922886Sopenharmony_ci */ 1580922886Sopenharmony_ci 1680922886Sopenharmony_ci#ifndef AV_SESSION_BUNDLE_STATUS_ADAPTER_H 1780922886Sopenharmony_ci#define AV_SESSION_BUNDLE_STATUS_ADAPTER_H 1880922886Sopenharmony_ci 1980922886Sopenharmony_ci#include <mutex> 2080922886Sopenharmony_ci 2180922886Sopenharmony_ci#include "bundle_mgr_proxy.h" 2280922886Sopenharmony_ci#include "bundle_status_callback_host.h" 2380922886Sopenharmony_ci 2480922886Sopenharmony_cinamespace OHOS::AVSession { 2580922886Sopenharmony_ciclass BundleStatusAdapter { 2680922886Sopenharmony_cipublic: 2780922886Sopenharmony_ci static BundleStatusAdapter& GetInstance(); 2880922886Sopenharmony_ci 2980922886Sopenharmony_ci ~BundleStatusAdapter(); 3080922886Sopenharmony_ci 3180922886Sopenharmony_ci void Init(); 3280922886Sopenharmony_ci 3380922886Sopenharmony_ci bool SubscribeBundleStatusEvent(const std::string bundleName, 3480922886Sopenharmony_ci const std::function<void(const std::string, const int32_t userId)>& callback, int32_t userId = DEFAULT_USER_ID); 3580922886Sopenharmony_ci 3680922886Sopenharmony_ci bool IsAudioPlayback(const std::string& bundleName, const std::string& abilityName); 3780922886Sopenharmony_ci 3880922886Sopenharmony_ci std::string GetBundleNameFromUid(const int32_t uid); 3980922886Sopenharmony_ci 4080922886Sopenharmony_ci __attribute__((no_sanitize("cfi"))) bool IsSupportPlayIntent(const std::string& bundleName, 4180922886Sopenharmony_ci std::string& supportModule, std::string& profile); 4280922886Sopenharmony_ci 4380922886Sopenharmony_ciprivate: 4480922886Sopenharmony_ci BundleStatusAdapter(); 4580922886Sopenharmony_ci 4680922886Sopenharmony_ci void NotifyBundleRemoved(const std::string bundleName, const int32_t userId); 4780922886Sopenharmony_ci 4880922886Sopenharmony_ci bool CheckBundleSupport(std::string& profile); 4980922886Sopenharmony_ci 5080922886Sopenharmony_ci sptr<AppExecFwk::BundleMgrProxy> bundleMgrProxy; 5180922886Sopenharmony_ci 5280922886Sopenharmony_ci std::map<std::pair<std::string, int32_t>, std::function<void(const std::string, const int32_t)>> 5380922886Sopenharmony_ci bundleStatusListeners_; 5480922886Sopenharmony_ci 5580922886Sopenharmony_ci const int32_t backgroundModeDemand = 2; 5680922886Sopenharmony_ci 5780922886Sopenharmony_ci const int32_t getBundleInfoWithHapModule = 0x00000002; 5880922886Sopenharmony_ci 5980922886Sopenharmony_ci const int32_t startUserId = 100; 6080922886Sopenharmony_ci 6180922886Sopenharmony_ci const std::string PLAY_MUSICLIST = "PlayMusicList"; 6280922886Sopenharmony_ci 6380922886Sopenharmony_ci const std::string PLAY_AUDIO = "PlayAudio"; 6480922886Sopenharmony_ci 6580922886Sopenharmony_ci std::recursive_mutex bundleMgrProxyLock_; 6680922886Sopenharmony_ci 6780922886Sopenharmony_ci static const int32_t DEFAULT_USER_ID = 100; 6880922886Sopenharmony_ci}; 6980922886Sopenharmony_ci 7080922886Sopenharmony_ciclass BundleStatusCallbackImpl : public AppExecFwk::BundleStatusCallbackHost { 7180922886Sopenharmony_cipublic: 7280922886Sopenharmony_ci explicit BundleStatusCallbackImpl(const std::function<void(const std::string, const int32_t)>& callback, 7380922886Sopenharmony_ci int32_t userId); 7480922886Sopenharmony_ci ~BundleStatusCallbackImpl() override; 7580922886Sopenharmony_ci void OnBundleStateChanged(const uint8_t installType, const int32_t resultCode, 7680922886Sopenharmony_ci const std::string &resultMsg, const std::string &bundleName) override; 7780922886Sopenharmony_ci void OnBundleAdded(const std::string &bundleName, const int userId) override {}; 7880922886Sopenharmony_ci void OnBundleUpdated(const std::string &bundleName, const int userId) override {}; 7980922886Sopenharmony_ci void OnBundleRemoved(const std::string &bundleName, const int userId) override {}; 8080922886Sopenharmony_ciprivate: 8180922886Sopenharmony_ci DISALLOW_COPY_AND_MOVE(BundleStatusCallbackImpl); 8280922886Sopenharmony_ci std::function<void(const std::string, const int32_t userId)> callback_; 8380922886Sopenharmony_ci int32_t userId_; 8480922886Sopenharmony_ci}; 8580922886Sopenharmony_ci} 8680922886Sopenharmony_ci#endif // AV_SESSION_BUNDLE_STATUS_ADAPTER_H 8780922886Sopenharmony_ci 88