1 /* 2 * Copyright (c) 2022-2023 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 /** 17 * @addtogroup Privacy 18 * @{ 19 * 20 * @brief Provides sensitive permissions access management. 21 * 22 * @since 8.0 23 * @version 8.0 24 */ 25 26 /** 27 * @file privacy_kit.h 28 * 29 * @brief Declares PrivacyKit interfaces. 30 * 31 * @since 8.0 32 * @version 8.0 33 */ 34 35 #ifndef INTERFACES_INNER_KITS_PRIVACY_KIT_H 36 #define INTERFACES_INNER_KITS_PRIVACY_KIT_H 37 38 #include <string> 39 40 #include "access_token.h" 41 #include "add_perm_param_info.h" 42 #include "on_permission_used_record_callback.h" 43 #include "permission_used_request.h" 44 #include "permission_used_result.h" 45 #include "permission_used_type_info.h" 46 #include "perm_active_status_customized_cbk.h" 47 #include "privacy_param.h" 48 #include "state_customized_cbk.h" 49 50 namespace OHOS { 51 namespace Security { 52 namespace AccessToken { 53 /** 54 * @brief Declares PrivacyKit class 55 */ 56 class PrivacyKit { 57 public: 58 /** 59 * @brief Add input tokenID access input permission record. 60 * @param tokenID token id 61 * @param permissionName permission nanme 62 * @param successCount access success count 63 * @param failCount fail success count 64 * @return error code, see privacy_error.h 65 */ 66 static int32_t AddPermissionUsedRecord(AccessTokenID tokenID, const std::string& permissionName, 67 int32_t successCount, int32_t failCount, bool asyncMode = false); 68 /** 69 * @brief Add input tokenID access input permission record. 70 * @param info struct AddPermParamInfo, see add_perm_param_info.h 71 * @param asyncMode ipc wait type, true means sync waiting, false means async waiting 72 * @return error code, see privacy_error.h 73 */ 74 static int32_t AddPermissionUsedRecord(const AddPermParamInfo& info, bool asyncMode = false); 75 /** 76 * @brief Set permission used record toggle status. 77 * @param userID the userID 78 * @param status permission used record toggle status, true means record, false means not record 79 * @return error code, see privacy_error.h 80 */ 81 static int32_t SetPermissionUsedRecordToggleStatus(int32_t userID, bool status); 82 /** 83 * @brief Get permission used record toggle status. 84 * @param userID the userID 85 * @param status permission used record toggle status, true means record, false means not record 86 * @return error code, see privacy_error.h 87 */ 88 static int32_t GetPermissionUsedRecordToggleStatus(int32_t userID, bool& status); 89 /** 90 * @brief Input tokenID start using input permission. 91 * @param tokenID token id 92 * @param permissionName permission nanme 93 * @return error code, see privacy_error.h 94 */ 95 static int32_t StartUsingPermission(AccessTokenID tokenID, const std::string& permissionName, int32_t pid = -1, 96 PermissionUsedType type = PermissionUsedType::NORMAL_TYPE); 97 /** 98 * @brief Input tokenID start using input permission and return by callback, 99 * only those services which has float window such as camera or 100 * microphone can use this interface. 101 * @param tokenID token id 102 * @param permissionName permission nanme 103 * @param callback StateCustomizedCbk nanme 104 * @return error code, see privacy_error.h 105 */ 106 static int32_t StartUsingPermission(AccessTokenID tokenID, const std::string& permissionName, 107 const std::shared_ptr<StateCustomizedCbk>& callback, int32_t pid = -1, 108 PermissionUsedType type = PermissionUsedType::NORMAL_TYPE); 109 /** 110 * @brief Input tokenID stop using input permission. 111 * @param tokenID token id 112 * @param permissionName permission nanme 113 * @return error code, see privacy_error.h 114 */ 115 static int32_t StopUsingPermission(AccessTokenID tokenID, const std::string& permissionName, int32_t pid = -1); 116 /** 117 * @brief Remove input tokenID sensitive permission used records. 118 * @param tokenID token id 119 * @return error code, see privacy_error.h 120 */ 121 static int32_t RemovePermissionUsedRecords(AccessTokenID tokenID); 122 /** 123 * @brief Get sensitive permission used records. 124 * @param request PermissionUsedRequest quote 125 * @param result PermissionUsedResult quote, as query result 126 * @return error code, see privacy_error.h 127 */ 128 static int32_t GetPermissionUsedRecords(const PermissionUsedRequest& request, PermissionUsedResult& result); 129 /** 130 * @brief Get sensitive permission used records. 131 * @param request PermissionUsedRequest quote 132 * @param callback OnPermissionUsedRecordCallback smart pointer quote 133 * @return error code, see privacy_error.h 134 */ 135 static int32_t GetPermissionUsedRecords( 136 const PermissionUsedRequest& request, const sptr<OnPermissionUsedRecordCallback>& callback); 137 /** 138 * @brief Register sensitive permission active status change callback. 139 * @param callback PermActiveStatusCustomizedCbk smark pointer quote 140 * @return error code, see privacy_error.h 141 */ 142 static int32_t RegisterPermActiveStatusCallback(const std::shared_ptr<PermActiveStatusCustomizedCbk>& callback); 143 /** 144 * @brief Unregister sensitive permission active status change callback. 145 * @param callback PermActiveStatusCustomizedCbk smark pointer quote 146 * @return error code, see privacy_error.h 147 */ 148 static int32_t UnRegisterPermActiveStatusCallback(const std::shared_ptr<PermActiveStatusCustomizedCbk>& callback); 149 /** 150 * @brief Judge whether the input tokenID can use the input permission or not. 151 * @param tokenID token id 152 * @param permissionName permission nanme 153 * @return true means allow to user the permission, false means not allow 154 */ 155 static bool IsAllowedUsingPermission(AccessTokenID tokenID, const std::string& permissionName, int32_t pid = -1); 156 157 /** 158 * @brief query permission used type. 159 * @param tokenId token id, if 0 return all tokenIds 160 * @param permissionName permission name, if null return all permissions 161 * @param results query result as PermissionUsedTypeInfo array 162 * @return error code, see privacy_error.h 163 */ 164 static int32_t GetPermissionUsedTypeInfos(const AccessTokenID tokenId, const std::string& permissionName, 165 std::vector<PermissionUsedTypeInfo>& results); 166 167 /** 168 * @brief try set mute policy. 169 * @param policyType policy type, see privacy_param.h 170 * @param caller caller type, see privacy_param.h 171 * @param isMute mute or unmute 172 * @param tokenID when policyType is EDM, this param should be first caller token id, 173 * when policyType is not EDM, this param will be ignore. 174 * @return error code, see privacy_error.h 175 */ 176 static int32_t SetMutePolicy(uint32_t policyType, uint32_t callerType, bool isMute, AccessTokenID tokenID); 177 178 /** 179 * @brief try set background visit policy. 180 * @param tokenId token id 181 * @param isAllowed allow or disallow 182 * @return error code, see privacy_error.h 183 */ 184 static int32_t SetHapWithFGReminder(uint32_t tokenId, bool isAllowed); 185 }; 186 } // namespace AccessToken 187 } // namespace Security 188 } // namespace OHOS 189 #endif 190