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[10];
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     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> GetWantAgent() const;
59     std::string ParseToJsonStr();
60     bool ParseFromJson(const nlohmann::json &value);
61     std::string ToString(std::vector<uint32_t> &bgmodes);
62     bool IsSystem() const;
63 
64 private:
65     std::vector<uint32_t> ToVector(std::string &str);
66     std::string bundleName_ {""};
67     std::string abilityName_ {""};
68     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent_ {nullptr};
69     int32_t userId_ {0};
70     int32_t uid_ {0};
71     pid_t pid_ {0};
72     uint32_t bgModeId_ {0};
73     bool isNewApi_ {false};
74     bool isFromWebview_ {false};
75     std::string notificationLabel_ {""};
76     int32_t notificationId_ {-1};
77     std::shared_ptr<WantAgentInfo> wantAgentInfo_ {nullptr};
78     std::string appName_ {""};
79     uint64_t fullTokenId_ {0};
80     bool isBatchApi_ {false};
81     std::vector<uint32_t> bgModeIds_ {};
82     int32_t abilityId_ {-1};
83     int32_t reason_ {0};
84     bool isSystem_ {false};
85 
86     friend class BgContinuousTaskMgr;
87     friend class NotificationTools;
88 };
89 }  // namespace BackgroundTaskMgr
90 }  // namespace OHOS
91 #endif  // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_SERVICES_CONTINUOUS_TASK_INCLUDE_CONTINUOUS_TASK_INFO_H