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 {
31 }
32
IncidentReportArgs(const IncidentReportArgs & that)33 IncidentReportArgs::IncidentReportArgs(const IncidentReportArgs& that)
34 :mSections(that.mSections),
35 mHeaders(that.mHeaders),
36 mAll(that.mAll),
37 mPrivacyPolicy(that.mPrivacyPolicy),
38 mReceiverPkg(that.mReceiverPkg),
39 mReceiverCls(that.mReceiverCls)
40 {
41 }
42
~IncidentReportArgs()43 IncidentReportArgs::~IncidentReportArgs()
44 {
45 }
46
47 status_t
writeToParcel(Parcel * out) const48 IncidentReportArgs::writeToParcel(Parcel* out) const
49 {
50 status_t err;
51
52 err = out->writeInt32(mAll);
53 if (err != NO_ERROR) {
54 return err;
55 }
56
57 err = out->writeInt32(mSections.size());
58 if (err != NO_ERROR) {
59 return err;
60 }
61
62 for (set<int>::const_iterator it=mSections.begin(); it!=mSections.end(); it++) {
63 err = out->writeInt32(*it);
64 if (err != NO_ERROR) {
65 return err;
66 }
67 }
68
69 err = out->writeInt32(mHeaders.size());
70 if (err != NO_ERROR) {
71 return err;
72 }
73
74 for (vector<vector<uint8_t>>::const_iterator it = mHeaders.begin(); it != mHeaders.end(); it++) {
75 err = out->writeByteVector(*it);
76 if (err != NO_ERROR) {
77 return err;
78 }
79 }
80
81 err = out->writeInt32(mPrivacyPolicy);
82 if (err != NO_ERROR) {
83 return err;
84 }
85
86 err = out->writeString16(String16(mReceiverPkg.c_str()));
87 if (err != NO_ERROR) {
88 return err;
89 }
90
91 err = out->writeString16(String16(mReceiverCls.c_str()));
92 if (err != NO_ERROR) {
93 return err;
94 }
95
96 return NO_ERROR;
97 }
98
99 status_t
readFromParcel(const Parcel * in)100 IncidentReportArgs::readFromParcel(const Parcel* in)
101 {
102 status_t err;
103
104 int32_t all;
105 err = in->readInt32(&all);
106 if (err != NO_ERROR) {
107 return err;
108 }
109 if (all != 0) {
110 mAll = all;
111 }
112
113 mSections.clear();
114 int32_t sectionCount;
115 err = in->readInt32(§ionCount);
116 if (err != NO_ERROR) {
117 return err;
118 }
119 for (int i=0; i<sectionCount; i++) {
120 int32_t section;
121 err = in->readInt32(§ion);
122 if (err != NO_ERROR) {
123 return err;
124 }
125
126 mSections.insert(section);
127 }
128
129 int32_t headerCount;
130 err = in->readInt32(&headerCount);
131 if (err != NO_ERROR) {
132 return err;
133 }
134 mHeaders.resize(headerCount);
135 for (int i=0; i<headerCount; i++) {
136 err = in->readByteVector(&mHeaders[i]);
137 if (err != NO_ERROR) {
138 return err;
139 }
140 }
141
142 int32_t privacyPolicy;
143 err = in->readInt32(&privacyPolicy);
144 if (err != NO_ERROR) {
145 return err;
146 }
147 mPrivacyPolicy = privacyPolicy;
148
149 mReceiverPkg = String8(in->readString16()).string();
150 mReceiverCls = String8(in->readString16()).string();
151
152 return OK;
153 }
154
155 void
setAll(bool all)156 IncidentReportArgs::setAll(bool all)
157 {
158 mAll = all;
159 if (all) {
160 mSections.clear();
161 }
162 }
163
164 void
setPrivacyPolicy(int privacyPolicy)165 IncidentReportArgs::setPrivacyPolicy(int privacyPolicy)
166 {
167 mPrivacyPolicy = privacyPolicy;
168 }
169
170 void
addSection(int section)171 IncidentReportArgs::addSection(int section)
172 {
173 if (!mAll) {
174 mSections.insert(section);
175 }
176 }
177
178 void
setReceiverPkg(const string & pkg)179 IncidentReportArgs::setReceiverPkg(const string& pkg)
180 {
181 mReceiverPkg = pkg;
182 }
183
184 void
setReceiverCls(const string & cls)185 IncidentReportArgs::setReceiverCls(const string& cls)
186 {
187 mReceiverCls = cls;
188 }
189
190 void
addHeader(const vector<uint8_t> & headerProto)191 IncidentReportArgs::addHeader(const vector<uint8_t>& headerProto)
192 {
193 mHeaders.push_back(headerProto);
194 }
195
196 bool
containsSection(int section,bool specific) const197 IncidentReportArgs::containsSection(int section, bool specific) const
198 {
199 if (specific) {
200 return mSections.find(section) != mSections.end();
201 } else {
202 return mAll || mSections.find(section) != mSections.end();
203 }
204 }
205
206 void
merge(const IncidentReportArgs & that)207 IncidentReportArgs::merge(const IncidentReportArgs& that)
208 {
209 for (const vector<uint8_t>& header: that.mHeaders) {
210 mHeaders.push_back(header);
211 }
212 if (!mAll) {
213 if (that.mAll) {
214 mAll = true;
215 mSections.clear();
216 } else {
217 for (set<int>::const_iterator it=that.mSections.begin();
218 it!=that.mSections.end(); it++) {
219 mSections.insert(*it);
220 }
221 }
222 }
223 }
224
225 }
226 }
227