• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025-2025 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 LOG_TAG
17 #define LOG_TAG "AppBundleManager"
18 #endif
19 
20 #include "app_bundle_manager.h"
21 
22 #include "system_ability_definition.h"
23 #include "bundle_mgr_interface.h"
24 #include "bundle_mgr_proxy.h"
25 #include "iservice_registry.h"
26 
27 #include "audio_common_log.h"
28 #include "audio_errors.h"
29 #include "audio_utils.h"
30 
31 namespace OHOS {
32 namespace AudioStandard {
33 static constexpr unsigned int GET_BUNDLE_TIME_OUT_SECONDS = 10;
34 constexpr int32_t BOOTUP_MUSIC_UID = 1003;
GetBundleNameFromUid(int32_t uid)35 std::string AppBundleManager::GetBundleNameFromUid(int32_t uid)
36 {
37     CHECK_AND_RETURN_RET_LOG(uid != BOOTUP_MUSIC_UID, "", "no need query from BMS.");
38     AudioXCollie audioXCollie("AudioServer::GetBundleNameFromUid",
39         GET_BUNDLE_TIME_OUT_SECONDS, nullptr, nullptr, AUDIO_XCOLLIE_FLAG_LOG | AUDIO_XCOLLIE_FLAG_RECOVERY);
40     std::string bundleName {""};
41     WatchTimeout guard("SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager():GetBundleNameFromUid");
42     auto systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
43     CHECK_AND_RETURN_RET_LOG(systemAbilityManager != nullptr, "", "systemAbilityManager is nullptr");
44     guard.CheckCurrTimeout();
45 
46     sptr<IRemoteObject> remoteObject = systemAbilityManager->CheckSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
47     CHECK_AND_RETURN_RET_LOG(remoteObject != nullptr, "", "remoteObject is nullptr");
48 
49     sptr<AppExecFwk::IBundleMgr> bundleMgrProxy = OHOS::iface_cast<AppExecFwk::IBundleMgr>(remoteObject);
50     CHECK_AND_RETURN_RET_LOG(bundleMgrProxy != nullptr, "", "bundleMgrProxy is nullptr");
51 
52     WatchTimeout reguard("bundleMgrProxy->GetNameForUid:GetBundleNameFromUid");
53     bundleMgrProxy->GetNameForUid(uid, bundleName);
54     reguard.CheckCurrTimeout();
55 
56     return bundleName;
57 }
58 } // namespace AudioStandard
59 } // namespace OHOS