1 /* 2 * Copyright (c) 2022 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_SERVICES_CONTINUOUS_TASK_INCLUDE_CONTINUOUS_TASK_INFO_H 17 #define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_SERVICES_CONTINUOUS_TASK_INCLUDE_CONTINUOUS_TASK_INFO_H 18 19 #include "iremote_object.h" 20 #include "nlohmann/json.hpp" 21 #include "parcel.h" 22 #include "want_agent.h" 23 24 namespace OHOS { 25 namespace BackgroundTaskMgr { 26 extern const char *g_continuousTaskModeName[11]; 27 28 // stop task reason 29 enum : int32_t { 30 USER_CANCEL, 31 REMOVE_NOTIFICATION_CANCEL, 32 FREEZE_CANCEL, 33 SYSTEM_CANCEL, 34 }; 35 36 struct WantAgentInfo { 37 std::string bundleName_ {""}; 38 std::string abilityName_ {""}; 39 }; 40 41 class ContinuousTaskRecord { 42 public: 43 ContinuousTaskRecord() = default; 44 ContinuousTaskRecord(const std::string &bundleName, const std::string &abilityName, 45 int32_t uid, int32_t pid, uint32_t bgModeId, bool isBatchApi = false, 46 const std::vector<uint32_t> &bgModeIds = {}, int32_t abilityId = -1); 47 std::string GetBundleName() const; 48 std::string GetAbilityName() const; 49 bool IsNewApi() const; 50 bool IsFromWebview() const; 51 uint32_t GetBgModeId() const; 52 int32_t GetUserId() const; 53 int32_t GetUid() const; 54 pid_t GetPid() const; 55 int32_t GetAbilityId() const; 56 std::string GetNotificationLabel() const; 57 int32_t GetNotificationId() const; 58 int32_t GetContinuousTaskId() const; 59 std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> GetWantAgent() const; 60 std::string ParseToJsonStr(); 61 bool ParseFromJson(const nlohmann::json &value); 62 std::string ToString(std::vector<uint32_t> &bgmodes); 63 bool IsSystem() const; 64 65 private: 66 std::vector<uint32_t> ToVector(std::string &str); 67 void SetRecordValue(const nlohmann::json &value); 68 69 std::string bundleName_ {""}; 70 std::string abilityName_ {""}; 71 std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent_ {nullptr}; 72 int32_t userId_ {0}; 73 int32_t uid_ {0}; 74 pid_t pid_ {0}; 75 uint32_t bgModeId_ {0}; 76 bool isNewApi_ {false}; 77 bool isFromWebview_ {false}; 78 std::string notificationLabel_ {""}; 79 int32_t notificationId_ {-1}; 80 std::shared_ptr<WantAgentInfo> wantAgentInfo_ {nullptr}; 81 std::string appName_ {""}; 82 uint64_t fullTokenId_ {0}; 83 bool isBatchApi_ {false}; 84 std::vector<uint32_t> bgModeIds_ {}; 85 std::vector<uint32_t> bgSubModeIds_ {}; 86 int32_t abilityId_ {-1}; 87 int32_t reason_ {0}; 88 bool isSystem_ {false}; 89 int32_t continuousTaskId_ {-1}; 90 bool suspendState_ {false}; 91 int32_t suspendReason_ {0}; 92 93 friend class BgContinuousTaskMgr; 94 friend class NotificationTools; 95 }; 96 } // namespace BackgroundTaskMgr 97 } // namespace OHOS 98 #endif // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_SERVICES_CONTINUOUS_TASK_INCLUDE_CONTINUOUS_TASK_INFO_H