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_INTERFACES_INNERKITS_INCLUDE_TRANSIENT_TASK_APP_INFO_H
17 #define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_TRANSIENT_TASK_APP_INFO_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <string>
22 
23 #include <message_parcel.h>
24 
25 namespace OHOS {
26 namespace BackgroundTaskMgr {
27 constexpr int32_t INVAILD_PID = -1;
28 constexpr int32_t INVAILD_UID = -1;
29 
30 class TransientTaskAppInfo final {
31 public:
32     TransientTaskAppInfo(std::string packageName, int32_t uid, int32_t pid = -1)
33         : packageName_(packageName), uid_(uid), pid_(pid) {}
34     TransientTaskAppInfo() = default;
35     ~TransientTaskAppInfo() = default;
36 
37     /**
38      * @brief Marshals a purpose into a parcel.
39      *
40      * @param parcel Indicates the parcel object for marshalling.
41      * @return True if success, else false.
42      */
43     bool Marshalling(MessageParcel& out) const;
44 
45     /**
46      * @brief Unmarshals a purpose from a Parcel.
47      *
48      * @param parcel Indicates the MessageParcel object for unmarshalling.
49      * @return App info of transient task.
50      */
51     static std::shared_ptr<TransientTaskAppInfo> Unmarshalling(MessageParcel& in);
52 
53     /**
54      * @brief Get the package name.
55      *
56      * @return Package name.
57      */
GetPackageName()58     inline std::string& GetPackageName()
59     {
60         return packageName_;
61     }
62 
63     /**
64      * @brief Get the uid.
65      *
66      * @return The uid of app.
67      */
GetUid()68     inline int32_t GetUid()
69     {
70         return uid_;
71     }
72 
73     /**
74      * @brief Get the uid.
75      *
76      * @return The pid of app.
77      */
GetPid()78     inline int32_t GetPid()
79     {
80         return pid_;
81     }
82 
83 private:
84     bool ReadFromParcel(MessageParcel& in);
85 
86     std::string packageName_;
87     int32_t uid_;
88     int32_t pid_;
89 };
90 }  // namespace BackgroundTaskMgr
91 }  // namespace OHOS
92 #endif  // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_TRANSIENT_TASK_APP_INFO_H