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 #include "screenlock_appinfo.h" 16 17 #include "accesstoken_kit.h" 18 #include "sclock_log.h" 19 20 namespace OHOS { 21 namespace ScreenLock { 22 using namespace Security::AccessToken; GetAppInfoByToken(std::uint32_t tokenId,AppInfo & appInfo)23bool ScreenLockAppInfo::GetAppInfoByToken(std::uint32_t tokenId, AppInfo &appInfo) 24 { 25 int32_t tokenType = AccessTokenKit::GetTokenTypeFlag(tokenId); 26 switch (tokenType) { 27 case ATokenTypeEnum::TOKEN_HAP: { 28 HapTokenInfo hapInfo; 29 if (AccessTokenKit::GetHapTokenInfo(tokenId, hapInfo) != 0) { 30 SCLOCK_HILOGE("get hap token info fail"); 31 return false; 32 } 33 appInfo.bundleName = hapInfo.bundleName; 34 appInfo.appId = hapInfo.appID; 35 return true; 36 } 37 case ATokenTypeEnum::TOKEN_NATIVE: 38 case ATokenTypeEnum::TOKEN_SHELL: { 39 NativeTokenInfo tokenInfo; 40 if (AccessTokenKit::GetNativeTokenInfo(tokenId, tokenInfo) != 0) { 41 SCLOCK_HILOGE("get native token info fail"); 42 return false; 43 } 44 appInfo.bundleName = tokenInfo.processName; 45 appInfo.appId = tokenInfo.processName; 46 return true; 47 } 48 default: { 49 SCLOCK_HILOGI("token type not match"); 50 break; 51 } 52 } 53 return false; 54 } 55 } // namespace ScreenLock 56 } // namespace OHOS 57