• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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 #include "running_process_info.h"
17 
18 #include "nlohmann/json.hpp"
19 #include "string_ex.h"
20 
21 #include "hilog_tag_wrapper.h"
22 #include "parcel_macro_base.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
26 namespace {
27 const std::string JSON_KEY_PROCESSNAME = "processName";
28 const std::string JSON_KEY_PID = "pid";
29 const std::string JSON_KEY_STATE = "state";
30 }  // namespace
31 
ReadFromParcel(Parcel & parcel)32 bool RunningProcessInfo::ReadFromParcel(Parcel &parcel)
33 {
34     processName_ = Str16ToStr8(parcel.ReadString16());
35     int32_t typeData;
36     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, typeData);
37     pid_ = static_cast<int32_t>(typeData);
38     int32_t uidData;
39     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, uidData);
40     uid_ = static_cast<int32_t>(uidData);
41     int32_t stateData;
42     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, stateData);
43     state_ = static_cast<AppProcessState>(stateData);
44     isContinuousTask = parcel.ReadBool();
45     isKeepAlive = parcel.ReadBool();
46     isFocused = parcel.ReadBool();
47     isTestProcess = parcel.ReadBool();
48     isAbilityForegrounding = parcel.ReadBool();
49     isTestMode = parcel.ReadBool();
50     isDebugApp = parcel.ReadBool();
51     isExiting = parcel.ReadBool();
52     isPreForeground = parcel.ReadBool();
53     int32_t bundleTypeData;
54     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, bundleTypeData);
55     bundleType = static_cast<int32_t>(bundleTypeData);
56     if (!parcel.ReadStringVector(&bundleNames)) {
57         TAG_LOGE(AAFwkTag::APPMGR, "read bundleNames failed.");
58         return false;
59     }
60     int32_t processType;
61     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, processType);
62     processType_ = static_cast<ProcessType>(processType);
63     int32_t extensionType;
64     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, extensionType);
65     extensionType_ = static_cast<ExtensionAbilityType>(extensionType);
66     appCloneIndex = parcel.ReadInt32();
67     instanceKey = Str16ToStr8(parcel.ReadString16());
68     int32_t appModeType;
69     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, appModeType);
70     appMode = static_cast<AppExecFwk::MultiAppModeType>(appModeType);
71     int32_t rssData;
72     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, rssData);
73     rssValue = static_cast<int32_t>(rssData);
74     int32_t pssData;
75     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, pssData);
76     pssValue = static_cast<int32_t>(pssData);
77     isCached = parcel.ReadBool();
78     return true;
79 }
80 
Unmarshalling(Parcel & parcel)81 RunningProcessInfo *RunningProcessInfo::Unmarshalling(Parcel &parcel)
82 {
83     RunningProcessInfo *info = new (std::nothrow) RunningProcessInfo();
84     if (info && !info->ReadFromParcel(parcel)) {
85         TAG_LOGW(AAFwkTag::APPMGR, "read from parcel failed");
86         delete info;
87         info = nullptr;
88     }
89     return info;
90 }
91 
Marshalling(Parcel & parcel) const92 bool RunningProcessInfo::Marshalling(Parcel &parcel) const
93 {
94     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(processName_));
95     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(pid_));
96     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(uid_));
97     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(state_));
98     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isContinuousTask);
99     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isKeepAlive);
100     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isFocused);
101     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isTestProcess);
102     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isAbilityForegrounding);
103     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isTestMode);
104     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isDebugApp);
105     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isExiting);
106     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isPreForeground);
107     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(bundleType));
108     if (!parcel.WriteStringVector(bundleNames)) {
109         TAG_LOGE(AAFwkTag::APPMGR, "write bundleNames failed.");
110         return false;
111     }
112     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(processType_));
113     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(extensionType_));
114     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, appCloneIndex);
115     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(instanceKey));
116     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(appMode));
117     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(rssValue));
118     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(pssValue));
119     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isCached);
120     return true;
121 }
122 }  // namespace AppExecFwk
123 }  // namespace OHOS
124