blob: 46c8dcf967d7230b4055dceb5128c8145990831c [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
Yao Chena8e78b92019-03-04 17:23:38 -080084 err = out->writeString16(mReceiverPkg);
85 if (err != NO_ERROR) {
86 return err;
87 }
88
89 err = out->writeString16(mReceiverCls);
90 if (err != NO_ERROR) {
91 return err;
92 }
93
Joe Onorato1754d742016-11-21 17:51:35 -080094 return NO_ERROR;
95}
96
97status_t
98IncidentReportArgs::readFromParcel(const Parcel* in)
99{
100 status_t err;
101
102 int32_t all;
103 err = in->readInt32(&all);
104 if (err != NO_ERROR) {
105 return err;
106 }
107 if (all != 0) {
108 mAll = all;
109 }
110
111 mSections.clear();
112 int32_t sectionCount;
113 err = in->readInt32(&sectionCount);
114 if (err != NO_ERROR) {
115 return err;
116 }
117 for (int i=0; i<sectionCount; i++) {
118 int32_t section;
119 err = in->readInt32(&section);
120 if (err != NO_ERROR) {
121 return err;
122 }
123
124 mSections.insert(section);
125 }
126
127 int32_t headerCount;
128 err = in->readInt32(&headerCount);
129 if (err != NO_ERROR) {
130 return err;
131 }
132 mHeaders.resize(headerCount);
133 for (int i=0; i<headerCount; i++) {
134 err = in->readByteVector(&mHeaders[i]);
135 if (err != NO_ERROR) {
136 return err;
137 }
138 }
139
Yi Jin0f047162017-09-05 13:44:22 -0700140 int32_t dest;
141 err = in->readInt32(&dest);
142 if (err != NO_ERROR) {
143 return err;
144 }
145 mDest = dest;
146
Yao Chena8e78b92019-03-04 17:23:38 -0800147 mReceiverPkg = in->readString16();
148 mReceiverCls = in->readString16();
149
Joe Onorato1754d742016-11-21 17:51:35 -0800150 return OK;
151}
152
153void
154IncidentReportArgs::setAll(bool all)
155{
156 mAll = all;
157 if (all) {
158 mSections.clear();
159 }
160}
161
162void
Yi Jin0f047162017-09-05 13:44:22 -0700163IncidentReportArgs::setDest(int dest)
164{
165 mDest = dest;
166}
167
168void
Joe Onorato1754d742016-11-21 17:51:35 -0800169IncidentReportArgs::addSection(int section)
170{
171 if (!mAll) {
172 mSections.insert(section);
173 }
174}
175
176void
Yao Chena8e78b92019-03-04 17:23:38 -0800177IncidentReportArgs::setReceiverPkg(const string& pkg)
178{
179 mReceiverPkg = String16(pkg.c_str());
180}
181
182void
183IncidentReportArgs::setReceiverCls(const string& cls)
184{
185 mReceiverCls = String16(cls.c_str());
186}
187
188void
Yao Chenec216482019-02-06 16:45:40 -0800189IncidentReportArgs::addHeader(const vector<uint8_t>& headerProto)
Joe Onorato1754d742016-11-21 17:51:35 -0800190{
Yao Chenec216482019-02-06 16:45:40 -0800191 mHeaders.push_back(headerProto);
Joe Onorato1754d742016-11-21 17:51:35 -0800192}
193
194bool
195IncidentReportArgs::containsSection(int section) const
196{
197 return mAll || mSections.find(section) != mSections.end();
198}
199
200void
201IncidentReportArgs::merge(const IncidentReportArgs& that)
202{
203 if (mAll) {
204 return;
205 } else if (that.mAll) {
206 mAll = true;
207 mSections.clear();
208 } else {
209 for (set<int>::const_iterator it=that.mSections.begin();
210 it!=that.mSections.end(); it++) {
211 mSections.insert(*it);
212 }
213 }
214}
215
216}
217}