1 /* 2 * Copyright (C) 2022 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 "ipc_skeleton.h" 17 18 #include "if_system_ability_manager.h" 19 #include "iservice_registry.h" 20 #include "system_ability_definition.h" 21 #include "bundle_mgr_interface.h" 22 23 namespace OHOS { 24 #ifdef CONFIG_IPC_SINGLE 25 using namespace IPC_SINGLE; 26 #endif 27 namespace { 28 constexpr int32_t DEFAULT_UID = 100; 29 } DebugGetUidByBundleName(const std::string & bundleName,const int32_t userId)30int32_t DebugGetUidByBundleName(const std::string &bundleName, const int32_t userId) 31 { 32 sptr<ISystemAbilityManager> systemMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 33 if (systemMgr == nullptr) { 34 return -1; 35 } 36 37 sptr<IRemoteObject> remoteObject = systemMgr->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); 38 if (remoteObject == nullptr) { 39 return -1; 40 } 41 42 sptr<OHOS::AppExecFwk::IBundleMgr> bundleMgrProxy = iface_cast<OHOS::AppExecFwk::IBundleMgr>(remoteObject); 43 if (bundleMgrProxy == nullptr) { 44 return -1; 45 } 46 47 return bundleMgrProxy->GetUidByBundleName(bundleName, userId); 48 } 49 GetCallingPid()50pid_t IPCSkeleton::GetCallingPid() 51 { 52 return 1; 53 } 54 GetCallingUid()55pid_t IPCSkeleton::GetCallingUid() 56 { 57 return DebugGetUidByBundleName("com.ohos.launcher", DEFAULT_UID); 58 } 59 ResetCallingIdentity()60std::string IPCSkeleton::ResetCallingIdentity() 61 { 62 return ""; 63 } 64 SetCallingIdentity(std::string & identity)65bool IPCSkeleton::SetCallingIdentity(std::string &identity) 66 { 67 return true; 68 } 69 } // namespace OHOS 70