blob: db495cfbf7e1bed57c165a23ae19ce7249ece841 [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),
Mike Mab6f7c472020-03-03 17:58:35 -080029 mPrivacyPolicy(-1),
30 mGzip(false)
Joe Onorato1754d742016-11-21 17:51:35 -080031{
32}
33
34IncidentReportArgs::IncidentReportArgs(const IncidentReportArgs& that)
35 :mSections(that.mSections),
36 mHeaders(that.mHeaders),
Yi Jin0f047162017-09-05 13:44:22 -070037 mAll(that.mAll),
Joe Onorato99598ee2019-02-11 15:55:13 +000038 mPrivacyPolicy(that.mPrivacyPolicy),
39 mReceiverPkg(that.mReceiverPkg),
Mike Mab6f7c472020-03-03 17:58:35 -080040 mReceiverCls(that.mReceiverCls),
41 mGzip(that.mGzip)
Joe Onorato1754d742016-11-21 17:51:35 -080042{
43}
44
45IncidentReportArgs::~IncidentReportArgs()
46{
47}
48
49status_t
50IncidentReportArgs::writeToParcel(Parcel* out) const
51{
52 status_t err;
53
54 err = out->writeInt32(mAll);
55 if (err != NO_ERROR) {
56 return err;
57 }
58
59 err = out->writeInt32(mSections.size());
60 if (err != NO_ERROR) {
61 return err;
62 }
63
64 for (set<int>::const_iterator it=mSections.begin(); it!=mSections.end(); it++) {
65 err = out->writeInt32(*it);
66 if (err != NO_ERROR) {
67 return err;
68 }
69 }
70
71 err = out->writeInt32(mHeaders.size());
72 if (err != NO_ERROR) {
73 return err;
74 }
75
Yi Jinbdf58942017-11-14 17:58:19 -080076 for (vector<vector<uint8_t>>::const_iterator it = mHeaders.begin(); it != mHeaders.end(); it++) {
Joe Onorato1754d742016-11-21 17:51:35 -080077 err = out->writeByteVector(*it);
78 if (err != NO_ERROR) {
79 return err;
80 }
81 }
82
Joe Onorato99598ee2019-02-11 15:55:13 +000083 err = out->writeInt32(mPrivacyPolicy);
Yi Jin0f047162017-09-05 13:44:22 -070084 if (err != NO_ERROR) {
85 return err;
86 }
87
Joe Onorato99598ee2019-02-11 15:55:13 +000088 err = out->writeString16(String16(mReceiverPkg.c_str()));
Yao Chena8e78b92019-03-04 17:23:38 -080089 if (err != NO_ERROR) {
90 return err;
91 }
92
Joe Onorato99598ee2019-02-11 15:55:13 +000093 err = out->writeString16(String16(mReceiverCls.c_str()));
Yao Chena8e78b92019-03-04 17:23:38 -080094 if (err != NO_ERROR) {
95 return err;
96 }
97
Mike Mab6f7c472020-03-03 17:58:35 -080098 err = out->writeInt32(mGzip);
99 if (err != NO_ERROR) {
100 return err;
101 }
102
Joe Onorato1754d742016-11-21 17:51:35 -0800103 return NO_ERROR;
104}
105
106status_t
107IncidentReportArgs::readFromParcel(const Parcel* in)
108{
109 status_t err;
110
111 int32_t all;
112 err = in->readInt32(&all);
113 if (err != NO_ERROR) {
114 return err;
115 }
116 if (all != 0) {
117 mAll = all;
118 }
119
120 mSections.clear();
121 int32_t sectionCount;
122 err = in->readInt32(&sectionCount);
123 if (err != NO_ERROR) {
124 return err;
125 }
126 for (int i=0; i<sectionCount; i++) {
127 int32_t section;
128 err = in->readInt32(&section);
129 if (err != NO_ERROR) {
130 return err;
131 }
132
133 mSections.insert(section);
134 }
135
136 int32_t headerCount;
137 err = in->readInt32(&headerCount);
138 if (err != NO_ERROR) {
139 return err;
140 }
141 mHeaders.resize(headerCount);
142 for (int i=0; i<headerCount; i++) {
143 err = in->readByteVector(&mHeaders[i]);
144 if (err != NO_ERROR) {
145 return err;
146 }
147 }
148
Joe Onorato99598ee2019-02-11 15:55:13 +0000149 int32_t privacyPolicy;
150 err = in->readInt32(&privacyPolicy);
Yi Jin0f047162017-09-05 13:44:22 -0700151 if (err != NO_ERROR) {
152 return err;
153 }
Joe Onorato99598ee2019-02-11 15:55:13 +0000154 mPrivacyPolicy = privacyPolicy;
Yi Jin0f047162017-09-05 13:44:22 -0700155
Joe Onorato99598ee2019-02-11 15:55:13 +0000156 mReceiverPkg = String8(in->readString16()).string();
157 mReceiverCls = String8(in->readString16()).string();
Yao Chena8e78b92019-03-04 17:23:38 -0800158
Mike Mab6f7c472020-03-03 17:58:35 -0800159 int32_t gzip;
160 err = in->readInt32(&gzip);
161 if (err != NO_ERROR) {
162 return err;
163 }
164 if (gzip != 0) {
165 mGzip = gzip;
166 }
167
Joe Onorato1754d742016-11-21 17:51:35 -0800168 return OK;
169}
170
171void
172IncidentReportArgs::setAll(bool all)
173{
174 mAll = all;
175 if (all) {
176 mSections.clear();
177 }
178}
179
180void
Joe Onorato99598ee2019-02-11 15:55:13 +0000181IncidentReportArgs::setPrivacyPolicy(int privacyPolicy)
Yi Jin0f047162017-09-05 13:44:22 -0700182{
Joe Onorato99598ee2019-02-11 15:55:13 +0000183 mPrivacyPolicy = privacyPolicy;
Yi Jin0f047162017-09-05 13:44:22 -0700184}
185
186void
Joe Onorato1754d742016-11-21 17:51:35 -0800187IncidentReportArgs::addSection(int section)
188{
189 if (!mAll) {
190 mSections.insert(section);
191 }
192}
193
194void
Yao Chena8e78b92019-03-04 17:23:38 -0800195IncidentReportArgs::setReceiverPkg(const string& pkg)
196{
Joe Onorato99598ee2019-02-11 15:55:13 +0000197 mReceiverPkg = pkg;
Yao Chena8e78b92019-03-04 17:23:38 -0800198}
199
200void
201IncidentReportArgs::setReceiverCls(const string& cls)
202{
Joe Onorato99598ee2019-02-11 15:55:13 +0000203 mReceiverCls = cls;
Yao Chena8e78b92019-03-04 17:23:38 -0800204}
205
206void
Yao Chenec216482019-02-06 16:45:40 -0800207IncidentReportArgs::addHeader(const vector<uint8_t>& headerProto)
Joe Onorato1754d742016-11-21 17:51:35 -0800208{
Yao Chenec216482019-02-06 16:45:40 -0800209 mHeaders.push_back(headerProto);
Joe Onorato1754d742016-11-21 17:51:35 -0800210}
211
Mike Mab6f7c472020-03-03 17:58:35 -0800212void
213IncidentReportArgs::setGzip(bool gzip)
214{
215 mGzip = gzip;
216}
217
Joe Onorato1754d742016-11-21 17:51:35 -0800218bool
Joe Onorato7a406b42019-04-12 18:11:30 -0700219IncidentReportArgs::containsSection(int section, bool specific) const
Joe Onorato1754d742016-11-21 17:51:35 -0800220{
Joe Onorato7a406b42019-04-12 18:11:30 -0700221 if (specific) {
222 return mSections.find(section) != mSections.end();
223 } else {
224 return mAll || mSections.find(section) != mSections.end();
225 }
Joe Onorato1754d742016-11-21 17:51:35 -0800226}
227
228void
229IncidentReportArgs::merge(const IncidentReportArgs& that)
230{
Joe Onorato99598ee2019-02-11 15:55:13 +0000231 for (const vector<uint8_t>& header: that.mHeaders) {
232 mHeaders.push_back(header);
233 }
234 if (!mAll) {
235 if (that.mAll) {
236 mAll = true;
237 mSections.clear();
238 } else {
239 for (set<int>::const_iterator it=that.mSections.begin();
240 it!=that.mSections.end(); it++) {
241 mSections.insert(*it);
242 }
Joe Onorato1754d742016-11-21 17:51:35 -0800243 }
244 }
245}
246
247}
248}