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