1 /**
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
21 #include <log/log.h>
22
23 namespace android {
24 namespace os {
25
IncidentReportArgs()26 IncidentReportArgs::IncidentReportArgs()
27 :mSections(),
28 mAll(false),
29 mPrivacyPolicy(-1),
30 mGzip(false)
31 {
32 }
33
IncidentReportArgs(const IncidentReportArgs & that)34 IncidentReportArgs::IncidentReportArgs(const IncidentReportArgs& that)
35 :mSections(that.mSections),
36 mHeaders(that.mHeaders),
37 mAll(that.mAll),
38 mPrivacyPolicy(that.mPrivacyPolicy),
39 mReceiverPkg(that.mReceiverPkg),
40 mReceiverCls(that.mReceiverCls),
41 mGzip(that.mGzip)
42 {
43 }
44
~IncidentReportArgs()45 IncidentReportArgs::~IncidentReportArgs()
46 {
47 }
48
49 status_t
writeToParcel(Parcel * out) const50 IncidentReportArgs::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
76 for (vector<vector<uint8_t>>::const_iterator it = mHeaders.begin(); it != mHeaders.end(); it++) {
77 err = out->writeByteVector(*it);
78 if (err != NO_ERROR) {
79 return err;
80 }
81 }
82
83 err = out->writeInt32(mPrivacyPolicy);
84 if (err != NO_ERROR) {
85 return err;
86 }
87
88 err = out->writeString16(String16(mReceiverPkg.c_str()));
89 if (err != NO_ERROR) {
90 return err;
91 }
92
93 err = out->writeString16(String16(mReceiverCls.c_str()));
94 if (err != NO_ERROR) {
95 return err;
96 }
97
98 err = out->writeInt32(mGzip);
99 if (err != NO_ERROR) {
100 return err;
101 }
102
103 return NO_ERROR;
104 }
105
106 status_t
readFromParcel(const Parcel * in)107 IncidentReportArgs::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(§ionCount);
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(§ion);
129 if (err != NO_ERROR) {
130 return err;
131 }
132
133 mSections.insert(section);
134 }
135
136 err = in->resizeOutVector<vector<uint8_t>>(&mHeaders);
137 if (err != NO_ERROR) {
138 return err;
139 }
140
141 for (int i=0; i<mHeaders.size(); i++) {
142 err = in->readByteVector(&mHeaders[i]);
143 if (err != NO_ERROR) {
144 return err;
145 }
146 }
147
148 int32_t privacyPolicy;
149 err = in->readInt32(&privacyPolicy);
150 if (err != NO_ERROR) {
151 return err;
152 }
153 mPrivacyPolicy = privacyPolicy;
154
155 mReceiverPkg = String8(in->readString16()).c_str();
156 mReceiverCls = String8(in->readString16()).c_str();
157
158 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
167 return OK;
168 }
169
170 void
setAll(bool all)171 IncidentReportArgs::setAll(bool all)
172 {
173 mAll = all;
174 if (all) {
175 mSections.clear();
176 }
177 }
178
179 void
setPrivacyPolicy(int privacyPolicy)180 IncidentReportArgs::setPrivacyPolicy(int privacyPolicy)
181 {
182 mPrivacyPolicy = privacyPolicy;
183 }
184
185 void
addSection(int section)186 IncidentReportArgs::addSection(int section)
187 {
188 if (!mAll) {
189 mSections.insert(section);
190 }
191 }
192
193 void
setReceiverPkg(const string & pkg)194 IncidentReportArgs::setReceiverPkg(const string& pkg)
195 {
196 mReceiverPkg = pkg;
197 }
198
199 void
setReceiverCls(const string & cls)200 IncidentReportArgs::setReceiverCls(const string& cls)
201 {
202 mReceiverCls = cls;
203 }
204
205 void
addHeader(const vector<uint8_t> & headerProto)206 IncidentReportArgs::addHeader(const vector<uint8_t>& headerProto)
207 {
208 mHeaders.push_back(headerProto);
209 }
210
211 void
setGzip(bool gzip)212 IncidentReportArgs::setGzip(bool gzip)
213 {
214 mGzip = gzip;
215 }
216
217 bool
containsSection(int section,bool specific) const218 IncidentReportArgs::containsSection(int section, bool specific) const
219 {
220 if (specific) {
221 return mSections.find(section) != mSections.end();
222 } else {
223 return mAll || mSections.find(section) != mSections.end();
224 }
225 }
226
227 void
merge(const IncidentReportArgs & that)228 IncidentReportArgs::merge(const IncidentReportArgs& that)
229 {
230 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 }
242 }
243 }
244 }
245
246 }
247 }
248