blob: 9d8a98338ef0929076949fd0f5806147ab2574ff [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),
Joe Onorato99598ee2019-02-11 15:55:13 +000029 mPrivacyPolicy(-1)
Joe Onorato1754d742016-11-21 17:51:35 -080030{
31}
32
33IncidentReportArgs::IncidentReportArgs(const IncidentReportArgs& that)
34 :mSections(that.mSections),
35 mHeaders(that.mHeaders),
Yi Jin0f047162017-09-05 13:44:22 -070036 mAll(that.mAll),
Joe Onorato99598ee2019-02-11 15:55:13 +000037 mPrivacyPolicy(that.mPrivacyPolicy),
38 mReceiverPkg(that.mReceiverPkg),
39 mReceiverCls(that.mReceiverCls)
Joe Onorato1754d742016-11-21 17:51:35 -080040{
41}
42
43IncidentReportArgs::~IncidentReportArgs()
44{
45}
46
47status_t
48IncidentReportArgs::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
Yi Jinbdf58942017-11-14 17:58:19 -080074 for (vector<vector<uint8_t>>::const_iterator it = mHeaders.begin(); it != mHeaders.end(); it++) {
Joe Onorato1754d742016-11-21 17:51:35 -080075 err = out->writeByteVector(*it);
76 if (err != NO_ERROR) {
77 return err;
78 }
79 }
80
Joe Onorato99598ee2019-02-11 15:55:13 +000081 err = out->writeInt32(mPrivacyPolicy);
Yi Jin0f047162017-09-05 13:44:22 -070082 if (err != NO_ERROR) {
83 return err;
84 }
85
Joe Onorato99598ee2019-02-11 15:55:13 +000086 err = out->writeString16(String16(mReceiverPkg.c_str()));
Yao Chena8e78b92019-03-04 17:23:38 -080087 if (err != NO_ERROR) {
88 return err;
89 }
90
Joe Onorato99598ee2019-02-11 15:55:13 +000091 err = out->writeString16(String16(mReceiverCls.c_str()));
Yao Chena8e78b92019-03-04 17:23:38 -080092 if (err != NO_ERROR) {
93 return err;
94 }
95
Joe Onorato1754d742016-11-21 17:51:35 -080096 return NO_ERROR;
97}
98
99status_t
100IncidentReportArgs::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(&sectionCount);
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(&section);
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
Joe Onorato99598ee2019-02-11 15:55:13 +0000142 int32_t privacyPolicy;
143 err = in->readInt32(&privacyPolicy);
Yi Jin0f047162017-09-05 13:44:22 -0700144 if (err != NO_ERROR) {
145 return err;
146 }
Joe Onorato99598ee2019-02-11 15:55:13 +0000147 mPrivacyPolicy = privacyPolicy;
Yi Jin0f047162017-09-05 13:44:22 -0700148
Joe Onorato99598ee2019-02-11 15:55:13 +0000149 mReceiverPkg = String8(in->readString16()).string();
150 mReceiverCls = String8(in->readString16()).string();
Yao Chena8e78b92019-03-04 17:23:38 -0800151
Joe Onorato1754d742016-11-21 17:51:35 -0800152 return OK;
153}
154
155void
156IncidentReportArgs::setAll(bool all)
157{
158 mAll = all;
159 if (all) {
160 mSections.clear();
161 }
162}
163
164void
Joe Onorato99598ee2019-02-11 15:55:13 +0000165IncidentReportArgs::setPrivacyPolicy(int privacyPolicy)
Yi Jin0f047162017-09-05 13:44:22 -0700166{
Joe Onorato99598ee2019-02-11 15:55:13 +0000167 mPrivacyPolicy = privacyPolicy;
Yi Jin0f047162017-09-05 13:44:22 -0700168}
169
170void
Joe Onorato1754d742016-11-21 17:51:35 -0800171IncidentReportArgs::addSection(int section)
172{
173 if (!mAll) {
174 mSections.insert(section);
175 }
176}
177
178void
Yao Chena8e78b92019-03-04 17:23:38 -0800179IncidentReportArgs::setReceiverPkg(const string& pkg)
180{
Joe Onorato99598ee2019-02-11 15:55:13 +0000181 mReceiverPkg = pkg;
Yao Chena8e78b92019-03-04 17:23:38 -0800182}
183
184void
185IncidentReportArgs::setReceiverCls(const string& cls)
186{
Joe Onorato99598ee2019-02-11 15:55:13 +0000187 mReceiverCls = cls;
Yao Chena8e78b92019-03-04 17:23:38 -0800188}
189
190void
Yao Chenec216482019-02-06 16:45:40 -0800191IncidentReportArgs::addHeader(const vector<uint8_t>& headerProto)
Joe Onorato1754d742016-11-21 17:51:35 -0800192{
Yao Chenec216482019-02-06 16:45:40 -0800193 mHeaders.push_back(headerProto);
Joe Onorato1754d742016-11-21 17:51:35 -0800194}
195
196bool
Joe Onorato7a406b42019-04-12 18:11:30 -0700197IncidentReportArgs::containsSection(int section, bool specific) const
Joe Onorato1754d742016-11-21 17:51:35 -0800198{
Joe Onorato7a406b42019-04-12 18:11:30 -0700199 if (specific) {
200 return mSections.find(section) != mSections.end();
201 } else {
202 return mAll || mSections.find(section) != mSections.end();
203 }
Joe Onorato1754d742016-11-21 17:51:35 -0800204}
205
206void
207IncidentReportArgs::merge(const IncidentReportArgs& that)
208{
Joe Onorato99598ee2019-02-11 15:55:13 +0000209 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 }
Joe Onorato1754d742016-11-21 17:51:35 -0800221 }
222 }
223}
224
225}
226}