blob: 858813ff4276fb75e95d1557b67beae71faa3929 [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
Pawan Wagh3c3e3682023-05-18 20:23:44 +0000136 err = in->resizeOutVector<vector<uint8_t>>(&mHeaders);
Joe Onorato1754d742016-11-21 17:51:35 -0800137 if (err != NO_ERROR) {
138 return err;
139 }
Pawan Wagh3c3e3682023-05-18 20:23:44 +0000140
141 for (int i=0; i<mHeaders.size(); i++) {
Joe Onorato1754d742016-11-21 17:51:35 -0800142 err = in->readByteVector(&mHeaders[i]);
143 if (err != NO_ERROR) {
144 return err;
145 }
146 }
147
Joe Onorato99598ee2019-02-11 15:55:13 +0000148 int32_t privacyPolicy;
149 err = in->readInt32(&privacyPolicy);
Yi Jin0f047162017-09-05 13:44:22 -0700150 if (err != NO_ERROR) {
151 return err;
152 }
Joe Onorato99598ee2019-02-11 15:55:13 +0000153 mPrivacyPolicy = privacyPolicy;
Yi Jin0f047162017-09-05 13:44:22 -0700154
Tomasz Wasilczyk3815d342023-08-10 23:54:44 +0000155 mReceiverPkg = String8(in->readString16()).c_str();
156 mReceiverCls = String8(in->readString16()).c_str();
Yao Chena8e78b92019-03-04 17:23:38 -0800157
Mike Mab6f7c472020-03-03 17:58:35 -0800158 int32_t gzip;
159 err = in->readInt32(&gzip);
160 if (err != NO_ERROR) {
161 return err;
162 }
163 if (gzip != 0) {
164 mGzip = gzip;
165 }
166
Joe Onorato1754d742016-11-21 17:51:35 -0800167 return OK;
168}
169
170void
171IncidentReportArgs::setAll(bool all)
172{
173 mAll = all;
174 if (all) {
175 mSections.clear();
176 }
177}
178
179void
Joe Onorato99598ee2019-02-11 15:55:13 +0000180IncidentReportArgs::setPrivacyPolicy(int privacyPolicy)
Yi Jin0f047162017-09-05 13:44:22 -0700181{
Joe Onorato99598ee2019-02-11 15:55:13 +0000182 mPrivacyPolicy = privacyPolicy;
Yi Jin0f047162017-09-05 13:44:22 -0700183}
184
185void
Joe Onorato1754d742016-11-21 17:51:35 -0800186IncidentReportArgs::addSection(int section)
187{
188 if (!mAll) {
189 mSections.insert(section);
190 }
191}
192
193void
Yao Chena8e78b92019-03-04 17:23:38 -0800194IncidentReportArgs::setReceiverPkg(const string& pkg)
195{
Joe Onorato99598ee2019-02-11 15:55:13 +0000196 mReceiverPkg = pkg;
Yao Chena8e78b92019-03-04 17:23:38 -0800197}
198
199void
200IncidentReportArgs::setReceiverCls(const string& cls)
201{
Joe Onorato99598ee2019-02-11 15:55:13 +0000202 mReceiverCls = cls;
Yao Chena8e78b92019-03-04 17:23:38 -0800203}
204
205void
Yao Chenec216482019-02-06 16:45:40 -0800206IncidentReportArgs::addHeader(const vector<uint8_t>& headerProto)
Joe Onorato1754d742016-11-21 17:51:35 -0800207{
Yao Chenec216482019-02-06 16:45:40 -0800208 mHeaders.push_back(headerProto);
Joe Onorato1754d742016-11-21 17:51:35 -0800209}
210
Mike Mab6f7c472020-03-03 17:58:35 -0800211void
212IncidentReportArgs::setGzip(bool gzip)
213{
214 mGzip = gzip;
215}
216
Joe Onorato1754d742016-11-21 17:51:35 -0800217bool
Joe Onorato7a406b42019-04-12 18:11:30 -0700218IncidentReportArgs::containsSection(int section, bool specific) const
Joe Onorato1754d742016-11-21 17:51:35 -0800219{
Joe Onorato7a406b42019-04-12 18:11:30 -0700220 if (specific) {
221 return mSections.find(section) != mSections.end();
222 } else {
223 return mAll || mSections.find(section) != mSections.end();
224 }
Joe Onorato1754d742016-11-21 17:51:35 -0800225}
226
227void
228IncidentReportArgs::merge(const IncidentReportArgs& that)
229{
Joe Onorato99598ee2019-02-11 15:55:13 +0000230 for (const vector<uint8_t>& header: that.mHeaders) {
231 mHeaders.push_back(header);
232 }
233 if (!mAll) {
234 if (that.mAll) {
235 mAll = true;
236 mSections.clear();
237 } else {
238 for (set<int>::const_iterator it=that.mSections.begin();
239 it!=that.mSections.end(); it++) {
240 mSections.insert(*it);
241 }
Joe Onorato1754d742016-11-21 17:51:35 -0800242 }
243 }
244}
245
246}
247}