1 /* 2 * Copyright (C) 2022-2023 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 "devicestatus_permission.h" 17 18 #include "ipc_skeleton.h" 19 #include "accesstoken_kit.h" 20 21 #include "fi_log.h" 22 23 #undef LOG_TAG 24 #define LOG_TAG "DeviceStatusPermission" 25 26 namespace OHOS { 27 namespace Msdp { 28 namespace DeviceStatus { 29 CheckCallingPermission(const std::string & permissionName)30bool DeviceStatusPermission::CheckCallingPermission(const std::string &permissionName) 31 { 32 Security::AccessToken::AccessTokenID callingToken = IPCSkeleton::GetCallingTokenID(); 33 int32_t auth = Security::AccessToken::AccessTokenKit::VerifyAccessToken(callingToken, permissionName); 34 if (auth != Security::AccessToken::TypePermissionState::PERMISSION_GRANTED) { 35 FI_HILOGD("Has no permission.permission name = %{public}s", permissionName.c_str()); 36 return ERR_NG; 37 } 38 return ERR_OK; 39 } 40 GetAppInfo()41std::string DeviceStatusPermission::GetAppInfo() 42 { 43 pid_t pid = IPCSkeleton::GetCallingPid(); 44 uid_t uid = IPCSkeleton::GetCallingUid(); 45 return Security::Permission::AppIdInfoHelper::CreateAppIdInfo(pid, uid); 46 } 47 } // namespace DeviceStatus 48 } // namespace Msdp 49 } // namespace OHOS 50