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 OPEN_DLP_FILE_CALLBACK_MANAGER_H 17 #define OPEN_DLP_FILE_CALLBACK_MANAGER_H 18 19 #include <mutex> 20 #include <map> 21 #include <vector> 22 #include <string_view> 23 24 #include "dlp_sandbox_info.h" 25 #include "iremote_broker.h" 26 27 namespace OHOS { 28 namespace Security { 29 namespace DlpPermission { 30 struct OpenDlpFileCallbackRecord { OpenDlpFileCallbackRecordOpenDlpFileCallbackRecord31 OpenDlpFileCallbackRecord() : callbackObject(nullptr) {} OpenDlpFileCallbackRecordOpenDlpFileCallbackRecord32 explicit OpenDlpFileCallbackRecord(sptr<IRemoteObject> callback) : callbackObject(callback) {} 33 34 sptr<IRemoteObject> callbackObject; 35 int32_t userId = 0; 36 std::string bundleName = ""; 37 }; 38 39 class OpenDlpFileCallbackManager { 40 public: 41 virtual ~OpenDlpFileCallbackManager(); 42 OpenDlpFileCallbackManager(); 43 static OpenDlpFileCallbackManager &GetInstance(); 44 45 int32_t AddCallback( 46 int32_t pid, int32_t userId, const std::string& bundleName, const sptr<IRemoteObject>& callback); 47 int32_t RemoveCallback(const sptr<IRemoteObject>& callback); 48 int32_t RemoveCallback(int32_t pid, const sptr<IRemoteObject> &callback); 49 void ExecuteCallbackAsync(const DlpSandboxInfo &dlpSandboxInfo); 50 bool IsCallbackEmpty(); 51 52 private: 53 bool OnOpenDlpFile(const sptr<IRemoteObject> &subscribeRecordPtr, const DlpSandboxInfo &dlpSandboxInfo); 54 std::mutex mutex_; 55 std::map<int32_t, std::vector<OpenDlpFileCallbackRecord>> openDlpFileCallbackMap_; 56 sptr<IRemoteObject::DeathRecipient> callbackDeathRecipient_; 57 }; 58 } // namespace DlpPermission 59 } // namespace Security 60 } // namespace OHOS 61 #endif // OPEN_DLP_FILE_CALLBACK_MANAGER_H 62