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 <cutils/log.h> 22 23 namespace android { 24 namespace os { 25 IncidentReportArgs()26IncidentReportArgs::IncidentReportArgs() 27 :mSections(), 28 mAll(false) 29 { 30 } 31 IncidentReportArgs(const IncidentReportArgs & that)32IncidentReportArgs::IncidentReportArgs(const IncidentReportArgs& that) 33 :mSections(that.mSections), 34 mHeaders(that.mHeaders), 35 mAll(that.mAll) 36 { 37 } 38 ~IncidentReportArgs()39IncidentReportArgs::~IncidentReportArgs() 40 { 41 } 42 43 status_t writeToParcel(Parcel * out) const44IncidentReportArgs::writeToParcel(Parcel* out) const 45 { 46 status_t err; 47 48 err = out->writeInt32(mAll); 49 if (err != NO_ERROR) { 50 return err; 51 } 52 53 err = out->writeInt32(mSections.size()); 54 if (err != NO_ERROR) { 55 return err; 56 } 57 58 for (set<int>::const_iterator it=mSections.begin(); it!=mSections.end(); it++) { 59 err = out->writeInt32(*it); 60 if (err != NO_ERROR) { 61 return err; 62 } 63 } 64 65 err = out->writeInt32(mHeaders.size()); 66 if (err != NO_ERROR) { 67 return err; 68 } 69 70 for (vector<vector<int8_t>>::const_iterator it = mHeaders.begin(); it != mHeaders.end(); it++) { 71 err = out->writeByteVector(*it); 72 if (err != NO_ERROR) { 73 return err; 74 } 75 } 76 77 return NO_ERROR; 78 } 79 80 status_t readFromParcel(const Parcel * in)81IncidentReportArgs::readFromParcel(const Parcel* in) 82 { 83 status_t err; 84 85 int32_t all; 86 err = in->readInt32(&all); 87 if (err != NO_ERROR) { 88 return err; 89 } 90 if (all != 0) { 91 mAll = all; 92 } 93 94 mSections.clear(); 95 int32_t sectionCount; 96 err = in->readInt32(§ionCount); 97 if (err != NO_ERROR) { 98 return err; 99 } 100 for (int i=0; i<sectionCount; i++) { 101 int32_t section; 102 err = in->readInt32(§ion); 103 if (err != NO_ERROR) { 104 return err; 105 } 106 107 mSections.insert(section); 108 } 109 110 int32_t headerCount; 111 err = in->readInt32(&headerCount); 112 if (err != NO_ERROR) { 113 return err; 114 } 115 mHeaders.resize(headerCount); 116 for (int i=0; i<headerCount; i++) { 117 err = in->readByteVector(&mHeaders[i]); 118 if (err != NO_ERROR) { 119 return err; 120 } 121 } 122 123 return OK; 124 } 125 126 void setAll(bool all)127IncidentReportArgs::setAll(bool all) 128 { 129 mAll = all; 130 if (all) { 131 mSections.clear(); 132 } 133 } 134 135 void addSection(int section)136IncidentReportArgs::addSection(int section) 137 { 138 if (!mAll) { 139 mSections.insert(section); 140 } 141 } 142 143 void addHeader(const vector<int8_t> & header)144IncidentReportArgs::addHeader(const vector<int8_t>& header) 145 { 146 mHeaders.push_back(header); 147 } 148 149 bool containsSection(int section) const150IncidentReportArgs::containsSection(int section) const 151 { 152 return mAll || mSections.find(section) != mSections.end(); 153 } 154 155 void merge(const IncidentReportArgs & that)156IncidentReportArgs::merge(const IncidentReportArgs& that) 157 { 158 if (mAll) { 159 return; 160 } else if (that.mAll) { 161 mAll = true; 162 mSections.clear(); 163 } else { 164 for (set<int>::const_iterator it=that.mSections.begin(); 165 it!=that.mSections.end(); it++) { 166 mSections.insert(*it); 167 } 168 } 169 } 170 171 } 172 } 173