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