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