1 /* 2 * Copyright (c) 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 #ifndef OHOS_ABILITY_RUNTIME_URI_PERMISSION_RDB_H 17 #define OHOS_ABILITY_RUNTIME_URI_PERMISSION_RDB_H 18 19 20 #include <string> 21 #include <vector> 22 23 #include "istorage_manager.h" 24 #include "rdb_data_manager.h" 25 26 27 namespace OHOS { 28 namespace AAFwk { 29 30 struct RdbGrantInfo { 31 std::string uri; 32 uint32_t flag; 33 const uint32_t fromTokenId; 34 const uint32_t targetTokenId; 35 }; 36 37 class UriPermissionRdb { 38 public: 39 UriPermissionRdb(); 40 int32_t AddGrantInfo(const std::string& uri, uint32_t flag, uint32_t fromTokenId, uint32_t targetTokenId); 41 int32_t RemoveGrantInfo(uint32_t tokenId, sptr<StorageManager::IStorageManager> storageManager); 42 int32_t RemoveGrantInfo(const std::string& uri, uint32_t tokenId, 43 sptr<StorageManager::IStorageManager> storageManager); 44 int32_t RemoveGrantInfo(const NativeRdb::AbsRdbPredicates& absRdbPredicates, 45 sptr<StorageManager::IStorageManager> storageManager); 46 bool CheckPersistableUriPermissionProxy(const std::string& uri, uint32_t flag, uint32_t tokenId); 47 void ShowAllGrantInfo(); 48 49 private: 50 bool QueryData(const NativeRdb::AbsRdbPredicates& absRdbPredicates, std::vector<RdbGrantInfo>& rdbGrantInfoList, 51 int& rowCount); 52 bool InsertData(const std::vector<RdbGrantInfo>& rdbGrantInfoList); 53 bool UpdateData(const NativeRdb::AbsRdbPredicates& absRdbPredicates, const NativeRdb::ValuesBucket& valuesBucket); 54 bool DeleteData(const NativeRdb::AbsRdbPredicates& absRdbPredicates); 55 bool GetGrantInfo(std::shared_ptr<NativeRdb::AbsSharedResultSet> absSharedResultSet, 56 std::vector<RdbGrantInfo> &rdbGrantInfoList); 57 58 private: 59 std::shared_ptr<RdbDataManager> rdbDataManager_ = nullptr; 60 }; 61 62 void PrintRdbGrantInfo(const RdbGrantInfo& info); 63 } 64 } 65 #endif