1 /*
2 * Copyright (c) 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 #include "media_monitor_wrapper.h"
17 #include "system_ability.h"
18
19 namespace {
20 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_FOUNDATION, "HiStreamer"};
21 }
22
23 namespace OHOS {
24 namespace Media {
25 namespace MediaMonitor {
26 #if (defined(__aarch64__) || defined(__x86_64__))
27 const std::string WRAPPER_DL_PATH = "/system/lib64/libmedia_monitor_wrapper.z.so";
28 #else
29 const std::string WRAPPER_DL_PATH = "/system/lib/libmedia_monitor_wrapper.z.so";
30 #endif
31 const char *GET_BUNDLE_INFO_FROM_UID = "GetBundleInfoFromUid";
32
MediaMonitorWrapper()33 MediaMonitorWrapper::MediaMonitorWrapper()
34 {
35 soHandler_ = ::dlopen(WRAPPER_DL_PATH.c_str(), RTLD_NOW);
36 if (!soHandler_) {
37 MEDIA_LOG_E("dlopen failed due to " PUBLIC_LOG_S, ::dlerror());
38 return;
39 }
40 getBundleInfoFromUid_ =
41 reinterpret_cast<GetBundleInfoFromUid *>(::dlsym(soHandler_, "GetBundleInfoFromUid"));
42 if (!getBundleInfoFromUid_) {
43 MEDIA_LOG_E("dlsym failed.check so has this function." PUBLIC_LOG_S, ::dlerror());
44 }
45 }
46
~MediaMonitorWrapper()47 MediaMonitorWrapper::~MediaMonitorWrapper()
48 {
49 if (soHandler_) {
50 ::dlclose(soHandler_);
51 soHandler_ = nullptr;
52 }
53 }
54
GetBundleInfo(int32_t appUid,BundleInfo * bundleInfo)55 MediaMonitorErr MediaMonitorWrapper::GetBundleInfo(int32_t appUid, BundleInfo *bundleInfo)
56 {
57 if (!getBundleInfoFromUid_) {
58 MEDIA_LOG_E("getBundleInfoFromUid_ failed.");
59 return MediaMonitorErr::ERR_OPERATION_FAILED;
60 }
61 return getBundleInfoFromUid_(appUid, bundleInfo);
62 }
63
64 } // namespace MediaMonitor
65 } // namespace Media
66 } // namespace OHOS
67