• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(&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 
149     int32_t privacyPolicy;
150     err = in->readInt32(&privacyPolicy);
151     if (err != NO_ERROR) {
152         return err;
153     }
154     mPrivacyPolicy = privacyPolicy;
155 
156     mReceiverPkg = String8(in->readString16()).string();
157     mReceiverCls = String8(in->readString16()).string();
158 
159     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 
168     return OK;
169 }
170 
171 void
setAll(bool all)172 IncidentReportArgs::setAll(bool all)
173 {
174     mAll = all;
175     if (all) {
176         mSections.clear();
177     }
178 }
179 
180 void
setPrivacyPolicy(int privacyPolicy)181 IncidentReportArgs::setPrivacyPolicy(int privacyPolicy)
182 {
183     mPrivacyPolicy = privacyPolicy;
184 }
185 
186 void
addSection(int section)187 IncidentReportArgs::addSection(int section)
188 {
189     if (!mAll) {
190         mSections.insert(section);
191     }
192 }
193 
194 void
setReceiverPkg(const string & pkg)195 IncidentReportArgs::setReceiverPkg(const string& pkg)
196 {
197     mReceiverPkg = pkg;
198 }
199 
200 void
setReceiverCls(const string & cls)201 IncidentReportArgs::setReceiverCls(const string& cls)
202 {
203     mReceiverCls = cls;
204 }
205 
206 void
addHeader(const vector<uint8_t> & headerProto)207 IncidentReportArgs::addHeader(const vector<uint8_t>& headerProto)
208 {
209     mHeaders.push_back(headerProto);
210 }
211 
212 void
setGzip(bool gzip)213 IncidentReportArgs::setGzip(bool gzip)
214 {
215     mGzip = gzip;
216 }
217 
218 bool
containsSection(int section,bool specific) const219 IncidentReportArgs::containsSection(int section, bool specific) const
220 {
221     if (specific) {
222         return mSections.find(section) != mSections.end();
223     } else {
224         return mAll || mSections.find(section) != mSections.end();
225     }
226 }
227 
228 void
merge(const IncidentReportArgs & that)229 IncidentReportArgs::merge(const IncidentReportArgs& that)
230 {
231     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             }
243         }
244     }
245 }
246 
247 }
248 }
249