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 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 84 | return NO_ERROR; |
| 85 | } |
| 86 | |
| 87 | status_t |
| 88 | IncidentReportArgs::readFromParcel(const Parcel* in) |
| 89 | { |
| 90 | status_t err; |
| 91 | |
| 92 | int32_t all; |
| 93 | err = in->readInt32(&all); |
| 94 | if (err != NO_ERROR) { |
| 95 | return err; |
| 96 | } |
| 97 | if (all != 0) { |
| 98 | mAll = all; |
| 99 | } |
| 100 | |
| 101 | mSections.clear(); |
| 102 | int32_t sectionCount; |
| 103 | err = in->readInt32(§ionCount); |
| 104 | if (err != NO_ERROR) { |
| 105 | return err; |
| 106 | } |
| 107 | for (int i=0; i<sectionCount; i++) { |
| 108 | int32_t section; |
| 109 | err = in->readInt32(§ion); |
| 110 | if (err != NO_ERROR) { |
| 111 | return err; |
| 112 | } |
| 113 | |
| 114 | mSections.insert(section); |
| 115 | } |
| 116 | |
| 117 | int32_t headerCount; |
| 118 | err = in->readInt32(&headerCount); |
| 119 | if (err != NO_ERROR) { |
| 120 | return err; |
| 121 | } |
| 122 | mHeaders.resize(headerCount); |
| 123 | for (int i=0; i<headerCount; i++) { |
| 124 | err = in->readByteVector(&mHeaders[i]); |
| 125 | if (err != NO_ERROR) { |
| 126 | return err; |
| 127 | } |
| 128 | } |
| 129 | |
Yi Jin | 0f04716 | 2017-09-05 13:44:22 -0700 | [diff] [blame] | 130 | int32_t dest; |
| 131 | err = in->readInt32(&dest); |
| 132 | if (err != NO_ERROR) { |
| 133 | return err; |
| 134 | } |
| 135 | mDest = dest; |
| 136 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 137 | return OK; |
| 138 | } |
| 139 | |
| 140 | void |
| 141 | IncidentReportArgs::setAll(bool all) |
| 142 | { |
| 143 | mAll = all; |
| 144 | if (all) { |
| 145 | mSections.clear(); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | void |
Yi Jin | 0f04716 | 2017-09-05 13:44:22 -0700 | [diff] [blame] | 150 | IncidentReportArgs::setDest(int dest) |
| 151 | { |
| 152 | mDest = dest; |
| 153 | } |
| 154 | |
| 155 | void |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 156 | IncidentReportArgs::addSection(int section) |
| 157 | { |
| 158 | if (!mAll) { |
| 159 | mSections.insert(section); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | void |
Yao Chen | ec21648 | 2019-02-06 16:45:40 -0800 | [diff] [blame] | 164 | IncidentReportArgs::addHeader(const vector<uint8_t>& headerProto) |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 165 | { |
Yao Chen | ec21648 | 2019-02-06 16:45:40 -0800 | [diff] [blame] | 166 | mHeaders.push_back(headerProto); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | bool |
| 170 | IncidentReportArgs::containsSection(int section) const |
| 171 | { |
| 172 | return mAll || mSections.find(section) != mSections.end(); |
| 173 | } |
| 174 | |
| 175 | void |
| 176 | IncidentReportArgs::merge(const IncidentReportArgs& that) |
| 177 | { |
| 178 | if (mAll) { |
| 179 | return; |
| 180 | } else if (that.mAll) { |
| 181 | mAll = true; |
| 182 | mSections.clear(); |
| 183 | } else { |
| 184 | for (set<int>::const_iterator it=that.mSections.begin(); |
| 185 | it!=that.mSections.end(); it++) { |
| 186 | mSections.insert(*it); |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | } |
| 192 | } |