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 EL5_FILEKEY_MANAGER_CLIENT_H 17 #define EL5_FILEKEY_MANAGER_CLIENT_H 18 19 #include "el5_filekey_manager_interface.h" 20 21 #include <condition_variable> 22 23 namespace OHOS { 24 namespace Security { 25 namespace AccessToken { 26 constexpr int32_t DEFAULT_SA_REQUEST_RETRY_TIMES = 1; 27 class El5FilekeyManagerClient { 28 public: 29 static El5FilekeyManagerClient &GetInstance(); 30 ~El5FilekeyManagerClient(); 31 32 int32_t AcquireAccess(DataLockType type); 33 int32_t ReleaseAccess(DataLockType type); 34 int32_t GenerateAppKey(uint32_t uid, const std::string &bundleName, std::string &keyId); 35 int32_t DeleteAppKey(const std::string &bundleName, int32_t userId); 36 int32_t GetUserAppKey(int32_t userId, bool getAllFlag, std::vector<std::pair<int32_t, std::string>> &keyInfos); 37 int32_t ChangeUserAppkeysLoadInfo(int32_t userId, std::vector<std::pair<std::string, bool>> &loadInfos); 38 int32_t SetFilePathPolicy(); 39 int32_t RegisterCallback(const sptr<El5FilekeyCallbackInterface> &callback); 40 int32_t GenerateGroupIDKey(uint32_t uid, const std::string &groupID, std::string &keyId); 41 int32_t DeleteGroupIDKey(uint32_t uid, const std::string &groupID); 42 int32_t QueryAppKeyState(DataLockType type); 43 int32_t CallProxyWithRetry(const std::function<int32_t(sptr<El5FilekeyManagerInterface> &)> &func, 44 const char *funcName, int32_t retryTimes = DEFAULT_SA_REQUEST_RETRY_TIMES); 45 bool IsRequestNeedRetry(int32_t ret); 46 47 private: 48 El5FilekeyManagerClient(); 49 DISALLOW_COPY_AND_MOVE(El5FilekeyManagerClient); 50 std::mutex proxyMutex_; 51 sptr<El5FilekeyManagerInterface> GetProxy(); 52 }; 53 } // namespace AccessToken 54 } // namespace Security 55 } // namespace OHOS 56 #endif // EL5_FILEKEY_MANAGER_CLIENT_H 57