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 "bundle_mgr_interface.h"
17 #include "bundle_mgr_proxy.h"
18 #include "iservice_registry.h"
19 #include "media_monitor_wrapper.h"
20 #include "system_ability_definition.h"
21
22 using namespace OHOS::Media::MediaMonitor;
23
24 namespace {
25 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_FOUNDATION, "HiStreamer"};
26 }
27
GetBundleInfoFromUid(int32_t appUid,BundleInfo * bundleInfoRes)28 extern "C" MediaMonitorErr GetBundleInfoFromUid(int32_t appUid, BundleInfo *bundleInfoRes)
29 {
30 std::string bundleName {""};
31 OHOS::AppExecFwk::BundleInfo bundleInfo;
32 auto systemAbilityManager = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
33 FALSE_RETURN_V_MSG_E(
34 systemAbilityManager != nullptr, MediaMonitorErr::ERR_INVALID_OPERATION, "systemAbilityManager is nullptr");
35
36 OHOS::sptr<OHOS::IRemoteObject> remoteObject
37 = systemAbilityManager->GetSystemAbility(OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
38 FALSE_RETURN_V_MSG_E(
39 remoteObject != nullptr, MediaMonitorErr::ERR_INVALID_OPERATION, "remoteObject is nullptr");
40
41 OHOS::sptr<OHOS::AppExecFwk::IBundleMgr> bundleMgrProxy
42 = OHOS::iface_cast<OHOS::AppExecFwk::IBundleMgr>(remoteObject);
43 FALSE_RETURN_V_MSG_E(
44 bundleMgrProxy != nullptr, MediaMonitorErr::ERR_INVALID_OPERATION, "bundleMgrProxy is nullptr");
45
46 bundleMgrProxy->GetNameForUid(appUid, bundleName);
47
48 bundleMgrProxy->GetBundleInfoV9(bundleName, OHOS::AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT |
49 OHOS::AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES |
50 OHOS::AppExecFwk::BundleFlag::GET_BUNDLE_WITH_REQUESTED_PERMISSION |
51 OHOS::AppExecFwk::BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO |
52 OHOS::AppExecFwk::BundleFlag::GET_BUNDLE_WITH_HASH_VALUE,
53 bundleInfo,
54 OHOS::AppExecFwk::Constants::ALL_USERID);
55 bundleInfoRes->appName = bundleInfo.name;
56 bundleInfoRes->versionCode = static_cast<int32_t> (bundleInfo.versionCode);
57
58 return MediaMonitorErr::SUCCESS;
59 }
60