blob: 06b7a5b682b123f3b00e2dde2b833f2d33879296 [file] [log] [blame]
Joe Onorato1754d742016-11-21 17:51:35 -08001/**
2 * Copyright (c) 2016, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "dumpstate"
18
19#include <android/os/IncidentReportArgs.h>
20
Mike Ma35056662018-12-06 13:32:59 -080021#include <log/log.h>
Joe Onorato1754d742016-11-21 17:51:35 -080022
23namespace android {
24namespace os {
25
26IncidentReportArgs::IncidentReportArgs()
27 :mSections(),
Yi Jin0f047162017-09-05 13:44:22 -070028 mAll(false),
29 mDest(-1)
Joe Onorato1754d742016-11-21 17:51:35 -080030{
31}
32
33IncidentReportArgs::IncidentReportArgs(const IncidentReportArgs& that)
34 :mSections(that.mSections),
35 mHeaders(that.mHeaders),
Yi Jin0f047162017-09-05 13:44:22 -070036 mAll(that.mAll),
37 mDest(that.mDest)
Joe Onorato1754d742016-11-21 17:51:35 -080038{
39}
40
41IncidentReportArgs::~IncidentReportArgs()
42{
43}
44
45status_t
46IncidentReportArgs::writeToParcel(Parcel* out) const
47{
48 status_t err;
49
50 err = out->writeInt32(mAll);
51 if (err != NO_ERROR) {
52 return err;
53 }
54
55 err = out->writeInt32(mSections.size());
56 if (err != NO_ERROR) {
57 return err;
58 }
59
60 for (set<int>::const_iterator it=mSections.begin(); it!=mSections.end(); it++) {
61 err = out->writeInt32(*it);
62 if (err != NO_ERROR) {
63 return err;
64 }
65 }
66
67 err = out->writeInt32(mHeaders.size());
68 if (err != NO_ERROR) {
69 return err;
70 }
71
Yi Jinbdf58942017-11-14 17:58:19 -080072 for (vector<vector<uint8_t>>::const_iterator it = mHeaders.begin(); it != mHeaders.end(); it++) {
Joe Onorato1754d742016-11-21 17:51:35 -080073 err = out->writeByteVector(*it);
74 if (err != NO_ERROR) {
75 return err;
76 }
77 }
78
Yi Jin0f047162017-09-05 13:44:22 -070079 err = out->writeInt32(mDest);
80 if (err != NO_ERROR) {
81 return err;
82 }
83
Joe Onorato1754d742016-11-21 17:51:35 -080084 return NO_ERROR;
85}
86
87status_t
88IncidentReportArgs::readFromParcel(const Parcel* in)
89{
90 status_t err;
91
92 int32_t all;
93 err = in->readInt32(&all);
94 if (err != NO_ERROR) {
95 return err;
96 }
97 if (all != 0) {
98 mAll = all;
99 }
100
101 mSections.clear();
102 int32_t sectionCount;
103 err = in->readInt32(&sectionCount);
104 if (err != NO_ERROR) {
105 return err;
106 }
107 for (int i=0; i<sectionCount; i++) {
108 int32_t section;
109 err = in->readInt32(&section);
110 if (err != NO_ERROR) {
111 return err;
112 }
113
114 mSections.insert(section);
115 }
116
117 int32_t headerCount;
118 err = in->readInt32(&headerCount);
119 if (err != NO_ERROR) {
120 return err;
121 }
122 mHeaders.resize(headerCount);
123 for (int i=0; i<headerCount; i++) {
124 err = in->readByteVector(&mHeaders[i]);
125 if (err != NO_ERROR) {
126 return err;
127 }
128 }
129
Yi Jin0f047162017-09-05 13:44:22 -0700130 int32_t dest;
131 err = in->readInt32(&dest);
132 if (err != NO_ERROR) {
133 return err;
134 }
135 mDest = dest;
136
Joe Onorato1754d742016-11-21 17:51:35 -0800137 return OK;
138}
139
140void
141IncidentReportArgs::setAll(bool all)
142{
143 mAll = all;
144 if (all) {
145 mSections.clear();
146 }
147}
148
149void
Yi Jin0f047162017-09-05 13:44:22 -0700150IncidentReportArgs::setDest(int dest)
151{
152 mDest = dest;
153}
154
155void
Joe Onorato1754d742016-11-21 17:51:35 -0800156IncidentReportArgs::addSection(int section)
157{
158 if (!mAll) {
159 mSections.insert(section);
160 }
161}
162
163void
Yao Chenec216482019-02-06 16:45:40 -0800164IncidentReportArgs::addHeader(const vector<uint8_t>& headerProto)
Joe Onorato1754d742016-11-21 17:51:35 -0800165{
Yao Chenec216482019-02-06 16:45:40 -0800166 mHeaders.push_back(headerProto);
Joe Onorato1754d742016-11-21 17:51:35 -0800167}
168
169bool
170IncidentReportArgs::containsSection(int section) const
171{
172 return mAll || mSections.find(section) != mSections.end();
173}
174
175void
176IncidentReportArgs::merge(const IncidentReportArgs& that)
177{
178 if (mAll) {
179 return;
180 } else if (that.mAll) {
181 mAll = true;
182 mSections.clear();
183 } else {
184 for (set<int>::const_iterator it=that.mSections.begin();
185 it!=that.mSections.end(); it++) {
186 mSections.insert(*it);
187 }
188 }
189}
190
191}
192}