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 #ifndef MOCK_IPC_COMMON_H 17 #define MOCK_IPC_COMMON_H 18 19 #include <cinttypes> 20 #include <iremote_stub.h> 21 #include <optional> 22 #include <string> 23 #include <set> 24 25 #include "iam_common_defines.h" 26 #include "nocopyable.h" 27 28 namespace OHOS { 29 namespace UserIam { 30 namespace UserAuth { 31 enum Permission { 32 MANAGE_USER_IDM_PERMISSION, 33 USE_USER_IDM_PERMISSION, 34 ACCESS_USER_AUTH_INTERNAL_PERMISSION, 35 ACCESS_BIOMETRIC_PERMISSION, 36 ACCESS_AUTH_RESPOOL, 37 ENFORCE_USER_IDM, 38 SUPPORT_USER_AUTH, 39 IS_SYSTEM_APP, 40 CLEAR_REDUNDANCY_PERMISSION, 41 USE_USER_ACCESS_MANAGER, 42 USER_AUTH_FROM_BACKGROUND, 43 ENTERPRISE_DEVICE_MGR, 44 }; 45 46 class IpcCommon final : public NoCopyable { 47 public: 48 static int32_t GetCallingUserId(IPCObjectStub &stub, int32_t &userId); 49 static int32_t GetActiveUserId(std::optional<int32_t> &userId); 50 static int32_t GetAllUserId(std::vector<int32_t> &userIds); 51 static int32_t GetUserTypeByUserId(int32_t userId, int32_t &userType); 52 static bool CheckPermission(IPCObjectStub &stub, Permission permission); 53 static bool GetCallerName(IPCObjectStub &stub, std::string &callerName, int32_t &callerType); 54 static bool GetCallingAppID(IPCObjectStub &stub, std::string &callingAppID); 55 static uint32_t GetAccessTokenId(IPCObjectStub &stub); 56 static void SetAccessTokenId(uint32_t tokenId, bool isSetTokenId); 57 static void AddPermission(Permission perm); 58 static void DeleteAllPermission(); 59 static uint32_t GetTokenId(IPCObjectStub &stub); 60 static void SetSkipUserFlag(bool isSkip); 61 static bool CheckForegroundApplication(const std::string &bundleName); 62 static bool IsOsAccountVerified(int32_t userId); 63 static int32_t GetDirectCallerType(IPCObjectStub &stub); 64 65 private: 66 static std::set<Permission> permSet_; 67 static bool isSetTokenId_; 68 static uint32_t tokenId_; 69 static bool skipFlag_; 70 }; 71 } // namespace UserAuth 72 } // namespace UserIam 73 } // namespace OHOS 74 #endif // MOCK_IPC_COMMON_H