Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 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 | |
Mike Ma | 3505666 | 2018-12-06 13:32:59 -0800 | [diff] [blame] | 21 | #include <log/log.h> |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 22 | |
| 23 | namespace android { |
| 24 | namespace os { |
| 25 | |
| 26 | IncidentReportArgs::IncidentReportArgs() |
| 27 | :mSections(), |
Yi Jin | 0f04716 | 2017-09-05 13:44:22 -0700 | [diff] [blame] | 28 | mAll(false), |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame^] | 29 | mPrivacyPolicy(-1) |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 30 | { |
| 31 | } |
| 32 | |
| 33 | IncidentReportArgs::IncidentReportArgs(const IncidentReportArgs& that) |
| 34 | :mSections(that.mSections), |
| 35 | mHeaders(that.mHeaders), |
Yi Jin | 0f04716 | 2017-09-05 13:44:22 -0700 | [diff] [blame] | 36 | mAll(that.mAll), |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame^] | 37 | mPrivacyPolicy(that.mPrivacyPolicy), |
| 38 | mReceiverPkg(that.mReceiverPkg), |
| 39 | mReceiverCls(that.mReceiverCls) |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 40 | { |
| 41 | } |
| 42 | |
| 43 | IncidentReportArgs::~IncidentReportArgs() |
| 44 | { |
| 45 | } |
| 46 | |
| 47 | status_t |
| 48 | 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 | |
Yi Jin | bdf5894 | 2017-11-14 17:58:19 -0800 | [diff] [blame] | 74 | for (vector<vector<uint8_t>>::const_iterator it = mHeaders.begin(); it != mHeaders.end(); it++) { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 75 | err = out->writeByteVector(*it); |
| 76 | if (err != NO_ERROR) { |
| 77 | return err; |
| 78 | } |
| 79 | } |
| 80 | |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame^] | 81 | err = out->writeInt32(mPrivacyPolicy); |
Yi Jin | 0f04716 | 2017-09-05 13:44:22 -0700 | [diff] [blame] | 82 | if (err != NO_ERROR) { |
| 83 | return err; |
| 84 | } |
| 85 | |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame^] | 86 | err = out->writeString16(String16(mReceiverPkg.c_str())); |
Yao Chen | a8e78b9 | 2019-03-04 17:23:38 -0800 | [diff] [blame] | 87 | if (err != NO_ERROR) { |
| 88 | return err; |
| 89 | } |
| 90 | |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame^] | 91 | err = out->writeString16(String16(mReceiverCls.c_str())); |
Yao Chen | a8e78b9 | 2019-03-04 17:23:38 -0800 | [diff] [blame] | 92 | if (err != NO_ERROR) { |
| 93 | return err; |
| 94 | } |
| 95 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 96 | return NO_ERROR; |
| 97 | } |
| 98 | |
| 99 | status_t |
| 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 | |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame^] | 142 | int32_t privacyPolicy; |
| 143 | err = in->readInt32(&privacyPolicy); |
Yi Jin | 0f04716 | 2017-09-05 13:44:22 -0700 | [diff] [blame] | 144 | if (err != NO_ERROR) { |
| 145 | return err; |
| 146 | } |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame^] | 147 | mPrivacyPolicy = privacyPolicy; |
Yi Jin | 0f04716 | 2017-09-05 13:44:22 -0700 | [diff] [blame] | 148 | |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame^] | 149 | mReceiverPkg = String8(in->readString16()).string(); |
| 150 | mReceiverCls = String8(in->readString16()).string(); |
Yao Chen | a8e78b9 | 2019-03-04 17:23:38 -0800 | [diff] [blame] | 151 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 152 | return OK; |
| 153 | } |
| 154 | |
| 155 | void |
| 156 | IncidentReportArgs::setAll(bool all) |
| 157 | { |
| 158 | mAll = all; |
| 159 | if (all) { |
| 160 | mSections.clear(); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | void |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame^] | 165 | IncidentReportArgs::setPrivacyPolicy(int privacyPolicy) |
Yi Jin | 0f04716 | 2017-09-05 13:44:22 -0700 | [diff] [blame] | 166 | { |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame^] | 167 | mPrivacyPolicy = privacyPolicy; |
Yi Jin | 0f04716 | 2017-09-05 13:44:22 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | void |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 171 | IncidentReportArgs::addSection(int section) |
| 172 | { |
| 173 | if (!mAll) { |
| 174 | mSections.insert(section); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | void |
Yao Chen | a8e78b9 | 2019-03-04 17:23:38 -0800 | [diff] [blame] | 179 | IncidentReportArgs::setReceiverPkg(const string& pkg) |
| 180 | { |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame^] | 181 | mReceiverPkg = pkg; |
Yao Chen | a8e78b9 | 2019-03-04 17:23:38 -0800 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | void |
| 185 | IncidentReportArgs::setReceiverCls(const string& cls) |
| 186 | { |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame^] | 187 | mReceiverCls = cls; |
Yao Chen | a8e78b9 | 2019-03-04 17:23:38 -0800 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | void |
Yao Chen | ec21648 | 2019-02-06 16:45:40 -0800 | [diff] [blame] | 191 | IncidentReportArgs::addHeader(const vector<uint8_t>& headerProto) |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 192 | { |
Yao Chen | ec21648 | 2019-02-06 16:45:40 -0800 | [diff] [blame] | 193 | mHeaders.push_back(headerProto); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | bool |
| 197 | IncidentReportArgs::containsSection(int section) const |
| 198 | { |
| 199 | return mAll || mSections.find(section) != mSections.end(); |
| 200 | } |
| 201 | |
| 202 | void |
| 203 | IncidentReportArgs::merge(const IncidentReportArgs& that) |
| 204 | { |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame^] | 205 | for (const vector<uint8_t>& header: that.mHeaders) { |
| 206 | mHeaders.push_back(header); |
| 207 | } |
| 208 | if (!mAll) { |
| 209 | if (that.mAll) { |
| 210 | mAll = true; |
| 211 | mSections.clear(); |
| 212 | } else { |
| 213 | for (set<int>::const_iterator it=that.mSections.begin(); |
| 214 | it!=that.mSections.end(); it++) { |
| 215 | mSections.insert(*it); |
| 216 | } |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | } |
| 222 | } |