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_START_ABILITY_SANDBOX_SAVEFILE_H 17 #define OHOS_ABILITY_RUNTIME_START_ABILITY_SANDBOX_SAVEFILE_H 18 19 #include <memory> 20 #include <mutex> 21 #include <unordered_map> 22 #include "start_ability_handler.h" 23 24 namespace OHOS { 25 namespace AAFwk { 26 struct SaveFileRecord { 27 int32_t originReqCode = 0; 28 std::weak_ptr<AbilityRecord> caller; 29 }; 30 31 class StartAbilitySandboxSavefile : public StartAbilityHandler, 32 public std::enable_shared_from_this<StartAbilitySandboxSavefile> { 33 public: 34 static const std::string handlerName_; 35 bool MatchStartRequest(StartAbilityParams ¶ms) override; 36 int HandleStartRequest(StartAbilityParams ¶ms) override; 37 std::string GetHandlerName() override; 38 39 void HandleResult(const Want &want, int resultCode, int requestCode); 40 protected: 41 int PushRecord(int reqCode, const std::shared_ptr<AbilityRecord> &caller); 42 bool ContainRecord(int reqCode); 43 44 int StartAbility(StartAbilityParams ¶ms, int requestCode); 45 private: 46 std::mutex recordsMutex_; 47 std::unordered_map<int, SaveFileRecord> fileSavingRecords_; 48 int requestCode_ = 0; 49 }; 50 } // namespace AAFwk 51 } // namespace OHOS 52 #endif // OHOS_ABILITY_RUNTIME_START_ABILITY_SANDBOX_SAVEFILE_H