1 /* 2 * Copyright (c) 2021 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 IPROCESS_SYSTEM_API_ADAPTER_H 17 #define IPROCESS_SYSTEM_API_ADAPTER_H 18 19 #include <functional> 20 #include <string> 21 22 #include "store_types.h" 23 24 namespace DistributedDB { 25 using OnAccessControlledEvent = std::function<void(bool isAccessControlled)>; 26 27 // For all functions with returnType DBStatus: 28 // return DBStatus::OK if successful, otherwise DBStatus::DB_ERROR if anything wrong. 29 // Additional information of reason why failed can be present in the log by the implementation. 30 // For "Get" or "Is" functions, implementation should notice that concurrent call is possible. 31 // The distributeddb in one process can only use one ProcessSystemApiAdapter at the same time 32 class IProcessSystemApiAdapter { 33 public: 34 // Function used to register a AccessControlled listener, like screen locked. 35 // There will only be one callback at the same time for each function 36 // If register again, the latter callback replace the former callback. 37 // Register nullptr as callback to do unregister semantic. 38 // For concurrency security of implementation, there should be lock between register_operation and callback_event. 39 virtual DBStatus RegOnAccessControlledEvent(const OnAccessControlledEvent &callback) = 0; 40 41 // Check is the access of this device in locked state 42 virtual bool IsAccessControlled() const = 0; 43 44 // Set the SecurityOption to the targe filepath. 45 // If the filePath is a directory, All the files and directories in the filePath should be effective. 46 virtual DBStatus SetSecurityOption(const std::string &filePath, const SecurityOption &option) = 0; 47 48 // Get the SecurityOption of the targe filepath. 49 virtual DBStatus GetSecurityOption(const std::string &filePath, SecurityOption &option) const = 0; 50 51 // Check if the target device can save the data at the give sensitive class. 52 virtual bool CheckDeviceSecurityAbility(const std::string &devId, const SecurityOption &option) const = 0; 53 ~IProcessSystemApiAdapter()54 virtual ~IProcessSystemApiAdapter() {}; 55 }; 56 } // namespace DistributedDB 57 #endif // IPROCESS_SYSTEM_API_ADAPTER_H 58