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 }; 42 43 class IpcCommon final : public NoCopyable { 44 public: 45 static int32_t GetCallingUserId(IPCObjectStub &stub, int32_t &userId); 46 static int32_t GetActiveUserId(std::optional<int32_t> &userId); 47 static int32_t GetAllUserId(std::vector<int32_t> &userIds); 48 static int32_t GetUserTypeByUserId(int32_t userId, int32_t &userType); 49 static bool CheckPermission(IPCObjectStub &stub, Permission permission); 50 static bool GetCallerName(IPCObjectStub &stub, std::string &callerName, int32_t &callerType); 51 static bool GetCallingAppID(IPCObjectStub &stub, std::string &callingAppID); 52 static uint32_t GetAccessTokenId(IPCObjectStub &stub); 53 static void SetAccessTokenId(uint32_t tokenId, bool isSetTokenId); 54 static void AddPermission(Permission perm); 55 static void DeleteAllPermission(); 56 static uint32_t GetTokenId(IPCObjectStub &stub); 57 static void SetSkipUserFlag(bool isSkip); 58 static bool CheckForegroundApplication(const std::string &bundleName); 59 static bool IsOsAccountVerified(int32_t userId); 60 61 private: 62 static std::set<Permission> permSet_; 63 static bool isSetTokenId_; 64 static uint32_t tokenId_; 65 static bool skipFlag_; 66 }; 67 } // namespace UserAuth 68 } // namespace UserIam 69 } // namespace OHOS 70 #endif // MOCK_IPC_COMMON_H