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_KIT_H 17 #define EL5_FILEKEY_MANAGER_KIT_H 18 19 #include <string> 20 21 #include "data_lock_type.h" 22 #include "el5_filekey_callback_interface.h" 23 24 namespace OHOS { 25 namespace Security { 26 namespace AccessToken { 27 class El5FilekeyManagerKit { 28 public: 29 /** 30 * @brief Acquire access of data. 31 * If acquiring MEDIA_DATA, you need to apply for ohos.permission.ACCESS_SCREEN_LOCK_MEDIA_DATA permission, 32 * if acquiring ALL_DATA, you need to apply for ohos.permission.ACCESS_SCREEN_LOCK_ALL_DATA permission. 33 * @permission ohos.permission.ACCESS_SCREEN_LOCK_MEDIA_DATA or ohos.permission.ACCESS_SCREEN_LOCK_ALL_DATA 34 * @param type Type of data accessed 35 * @return error code, see el5_filekey_manager_error.h 36 */ 37 static int32_t AcquireAccess(DataLockType type); 38 /** 39 * @brief Release access of data. 40 * If releasing MEDIA_DATA, you need to apply for ohos.permission.ACCESS_SCREEN_LOCK_MEDIA_DATA permission, 41 * if releasing ALL_DATA, you need to apply for ohos.permission.ACCESS_SCREEN_LOCK_ALL_DATA permission. 42 * @permission ohos.permission.ACCESS_SCREEN_LOCK_MEDIA_DATA or ohos.permission.ACCESS_SCREEN_LOCK_ALL_DATA 43 * @param type Type of data accessed 44 * @return error code, see el5_filekey_manager_error.h 45 */ 46 static int32_t ReleaseAccess(DataLockType type); 47 /** 48 * @brief Generate app key of the installed application. 49 * @param uid The uid 50 * @param bundleName bundle name 51 * @param keyId Return keyId of the installed application 52 * @return error code, see el5_filekey_manager_error.h 53 */ 54 static int32_t GenerateAppKey(uint32_t uid, const std::string& bundleName, std::string& keyId); 55 /** 56 * @brief Delete app key of the uninstalled application. 57 * @param bundleName bundle name 58 * @param userId The user id 59 * @return error code, see el5_filekey_manager_error.h 60 */ 61 static int32_t DeleteAppKey(const std::string& bundleName, int32_t userId); 62 /** 63 * @brief Get key infos of the specified user, the state is unloaded. 64 * @param userId The user id 65 * @param keyInfos Key infos of the specified user id, as query result 66 * @return error code, see el5_filekey_manager_error.h 67 */ 68 static int32_t GetUserAppKey(int32_t userId, std::vector<std::pair<int32_t, std::string>> &keyInfos); 69 /** 70 * @brief Set app key load infos of the specified user. 71 * @param userId The user id 72 * @param loadInfos Key load infos of the specified user id 73 * @return error code, see el5_filekey_manager_error.h 74 */ 75 static int32_t ChangeUserAppkeysLoadInfo(int32_t userId, std::vector<std::pair<std::string, bool>> &loadInfos); 76 /** 77 * @brief Set file path policy. 78 * @return error code, see el5_filekey_manager_error.h 79 */ 80 static int32_t SetFilePathPolicy(); 81 /** 82 * @brief Register app key generation callback. 83 * @param callback smart point of class El5FilekeyCallbackInterface quote 84 * @return error code, see el5_filekey_manager_error.h 85 */ 86 static int32_t RegisterCallback(const sptr<El5FilekeyCallbackInterface> &callback); 87 /** 88 * @brief Get all key infos of the specified user 89 * @param userId The user id 90 * @param keyInfos Key infos of the specified user id, as query result 91 * @return error code, see el5_filekey_manager_error.h 92 */ 93 static int32_t GetUserAllAppKey(int32_t userId, std::vector<std::pair<int32_t, std::string>> &keyInfos); 94 }; 95 } // namespace AccessToken 96 } // namespace Security 97 } // namespace OHOS 98 #endif // EL5_FILEKEY_MANAGER_KIT_H 99