1 /* 2 * Copyright (c) 2022-2025 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 FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_CONTINUOUS_TASK_PARAMS_H 17 #define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_CONTINUOUS_TASK_PARAMS_H 18 19 #include <string> 20 21 #include "background_mode.h" 22 #include "iremote_object.h" 23 #include "parcel.h" 24 #include "refbase.h" 25 #include "want_agent.h" 26 27 namespace OHOS { 28 namespace BackgroundTaskMgr { 29 struct ContinuousTaskParam : public Parcelable { 30 bool isNewApi_ {false}; 31 uint32_t bgModeId_ {0}; 32 std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent_ {nullptr}; 33 std::string abilityName_ {""}; 34 sptr<IRemoteObject> abilityToken_ {nullptr}; 35 std::string appName_ {""}; 36 bool isBatchApi_ {false}; 37 std::vector<uint32_t> bgModeIds_ {}; 38 int32_t abilityId_ {-1}; 39 int32_t notificationId_ {-1}; // out 40 int32_t continuousTaskId_ {-1}; // out 41 42 ContinuousTaskParam() = default; 43 ContinuousTaskParam(bool isNewApi, uint32_t bgModeId, 44 const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent, const std::string abilityName, 45 const sptr<IRemoteObject> abilityToken, const std::string &appName, bool isBatchApi = false, 46 const std::vector<uint32_t> &bgModeIds = {}, int32_t abilityId = -1) isNewApi_ContinuousTaskParam47 : isNewApi_(isNewApi), bgModeId_(bgModeId), wantAgent_(wantAgent), abilityName_(abilityName), 48 abilityToken_(abilityToken), appName_(appName), isBatchApi_(isBatchApi), bgModeIds_(bgModeIds), 49 abilityId_(abilityId) { 50 if (isBatchApi_ && bgModeIds_.size() > 0) { 51 auto findNonDataTransfer = [](const auto &target) { 52 return target != BackgroundMode::DATA_TRANSFER; 53 }; 54 auto iter = std::find_if(bgModeIds_.begin(), bgModeIds_.end(), findNonDataTransfer); 55 if (iter != bgModeIds_.end()) { 56 bgModeId_ = *iter; 57 } else { 58 bgModeId_ = bgModeIds_[0]; 59 } 60 } else { 61 bgModeIds_.push_back(bgModeId); 62 } 63 } 64 bool ReadFromParcel(Parcel &parcel); 65 bool Marshalling(Parcel &parcel) const override; 66 static ContinuousTaskParam *Unmarshalling(Parcel &parcel); 67 }; 68 69 struct ContinuousTaskParamForInner : public Parcelable { 70 int32_t uid_ {0}; 71 uint32_t bgModeId_ {0}; 72 bool isStart_ {false}; 73 int32_t abilityId_ {-1}; 74 uint64_t tokenId_ {0}; 75 int32_t pid_ {0}; 76 77 ContinuousTaskParamForInner() = default; 78 ContinuousTaskParamForInner(int32_t uid, uint32_t bgModeId, bool isStart, int32_t abilityId = -1, 79 uint64_t tokenId = 0) uid_ContinuousTaskParamForInner80 : uid_(uid), bgModeId_(bgModeId), isStart_(isStart), abilityId_(abilityId), tokenId_(tokenId) {} 81 82 bool ReadFromParcel(Parcel &parcel); 83 bool Marshalling(Parcel &parcel) const override; 84 static ContinuousTaskParamForInner *Unmarshalling(Parcel &parcel); 85 void SetPid(const int32_t pid); 86 int32_t GetPid() const; 87 }; 88 } // namespace BackgroundTaskMgr 89 } // namespace OHOS 90 #endif // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_CONTINUOUS_TASK_PARAMS_H