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 #include "bundle_active_log.h"
17 #include "app_group_callback_info.h"
18
19 namespace OHOS {
20 namespace DeviceUsageStats {
AppGroupCallbackInfo(int32_t userId,int32_t oldGroup,int32_t newGroup,uint32_t changeReason,std::string bundleName)21 AppGroupCallbackInfo::AppGroupCallbackInfo(int32_t userId, int32_t oldGroup, int32_t newGroup,
22 uint32_t changeReason, std::string bundleName)
23 {
24 userId_ = userId;
25 oldGroup_ = oldGroup;
26 newGroup_ = newGroup;
27 changeReason_ = changeReason;
28 bundleName_ = bundleName;
29 }
30
GetUserId() const31 int32_t AppGroupCallbackInfo::GetUserId() const
32 {
33 return userId_;
34 }
35
GetOldGroup() const36 int32_t AppGroupCallbackInfo::GetOldGroup() const
37 {
38 return oldGroup_;
39 }
40
GetNewGroup() const41 int32_t AppGroupCallbackInfo::GetNewGroup() const
42 {
43 return newGroup_;
44 }
45
GetChangeReason() const46 uint32_t AppGroupCallbackInfo::GetChangeReason() const
47 {
48 return changeReason_;
49 }
50
GetBundleName() const51 std::string AppGroupCallbackInfo::GetBundleName() const
52 {
53 return bundleName_;
54 }
55
Marshalling(Parcel & parcel) const56 bool AppGroupCallbackInfo::Marshalling(Parcel &parcel) const
57 {
58 if (!parcel.WriteInt32(userId_)) {
59 BUNDLE_ACTIVE_LOGE("Failed to write userId_");
60 return false;
61 }
62
63 if (!parcel.WriteInt32(oldGroup_)) {
64 BUNDLE_ACTIVE_LOGE("Failed to write creator oldGroup_");
65 return false;
66 }
67
68 if (!parcel.WriteInt32(newGroup_)) {
69 BUNDLE_ACTIVE_LOGE("Failed to write creator newGroup_");
70 return false;
71 }
72
73 if (!parcel.WriteUint32(changeReason_)) {
74 BUNDLE_ACTIVE_LOGE("Failed to write creator changeReason_");
75 return false;
76 }
77
78 if (!parcel.WriteString(bundleName_)) {
79 BUNDLE_ACTIVE_LOGE("Failed to write bundleName_");
80 return false;
81 }
82 return true;
83 }
84
Unmarshalling(Parcel & parcel)85 AppGroupCallbackInfo* AppGroupCallbackInfo::Unmarshalling(Parcel &parcel)
86 {
87 AppGroupCallbackInfo* result = new (std::nothrow) AppGroupCallbackInfo();
88 if (!result) {
89 BUNDLE_ACTIVE_LOGE("new AppGroupCallbackInfo failed!");
90 return result;
91 }
92 result->userId_ = parcel.ReadInt32();
93 result->oldGroup_ = parcel.ReadInt32();
94 result->newGroup_ = parcel.ReadInt32();
95 result->changeReason_ = parcel.ReadUint32();
96 result->bundleName_ = parcel.ReadString();
97 return result;
98 }
99 }
100 }
101
102