11754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato/**
21754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato * Copyright (c) 2016, The Android Open Source Project
31754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato *
41754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato * Licensed under the Apache License, Version 2.0 (the "License");
51754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato * you may not use this file except in compliance with the License.
61754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato * You may obtain a copy of the License at
71754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato *
81754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato *     http://www.apache.org/licenses/LICENSE-2.0
91754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato *
101754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato * Unless required by applicable law or agreed to in writing, software
111754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato * distributed under the License is distributed on an "AS IS" BASIS,
121754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato * See the License for the specific language governing permissions and
141754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato * limitations under the License.
151754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato */
161754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato
171754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato#define LOG_TAG "dumpstate"
181754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato
191754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato#include <android/os/IncidentReportArgs.h>
201754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato
211754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato#include <cutils/log.h>
221754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato
231754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onoratonamespace android {
241754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onoratonamespace os {
251754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato
261754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe OnoratoIncidentReportArgs::IncidentReportArgs()
271754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    :mSections(),
281754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato     mAll(false)
291754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato{
301754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato}
311754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato
321754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe OnoratoIncidentReportArgs::IncidentReportArgs(const IncidentReportArgs& that)
331754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    :mSections(that.mSections),
341754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato     mHeaders(that.mHeaders),
351754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato     mAll(that.mAll)
361754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato{
371754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato}
381754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato
391754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe OnoratoIncidentReportArgs::~IncidentReportArgs()
401754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato{
411754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato}
421754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato
431754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onoratostatus_t
441754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe OnoratoIncidentReportArgs::writeToParcel(Parcel* out) const
451754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato{
461754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    status_t err;
471754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato
481754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    err = out->writeInt32(mAll);
491754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    if (err != NO_ERROR) {
501754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato        return err;
511754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    }
521754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato
531754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    err = out->writeInt32(mSections.size());
541754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    if (err != NO_ERROR) {
551754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato        return err;
561754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    }
571754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato
581754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    for (set<int>::const_iterator it=mSections.begin(); it!=mSections.end(); it++) {
591754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato        err = out->writeInt32(*it);
601754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato        if (err != NO_ERROR) {
611754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato            return err;
621754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato        }
631754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    }
641754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato
651754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    err = out->writeInt32(mHeaders.size());
661754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    if (err != NO_ERROR) {
671754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato        return err;
681754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    }
691754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato
701754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    for (vector<vector<int8_t>>::const_iterator it = mHeaders.begin(); it != mHeaders.end(); it++) {
711754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato        err = out->writeByteVector(*it);
721754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato        if (err != NO_ERROR) {
731754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato            return err;
741754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato        }
751754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    }
761754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato
771754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    return NO_ERROR;
781754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato}
791754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato
801754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onoratostatus_t
811754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe OnoratoIncidentReportArgs::readFromParcel(const Parcel* in)
821754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato{
831754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    status_t err;
841754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato
851754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    int32_t all;
861754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    err = in->readInt32(&all);
871754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    if (err != NO_ERROR) {
881754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato        return err;
891754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    }
901754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    if (all != 0) {
911754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato        mAll = all;
921754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    }
931754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato
941754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    mSections.clear();
951754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    int32_t sectionCount;
961754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    err = in->readInt32(&sectionCount);
971754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    if (err != NO_ERROR) {
981754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato        return err;
991754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    }
1001754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    for (int i=0; i<sectionCount; i++) {
1011754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato        int32_t section;
1021754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato        err = in->readInt32(&section);
1031754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato        if (err != NO_ERROR) {
1041754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato            return err;
1051754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato        }
1061754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato
1071754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato        mSections.insert(section);
1081754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    }
1091754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato
1101754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    int32_t headerCount;
1111754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    err = in->readInt32(&headerCount);
1121754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    if (err != NO_ERROR) {
1131754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato        return err;
1141754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    }
1151754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    mHeaders.resize(headerCount);
1161754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    for (int i=0; i<headerCount; i++) {
1171754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato        err = in->readByteVector(&mHeaders[i]);
1181754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato        if (err != NO_ERROR) {
1191754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato            return err;
1201754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato        }
1211754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    }
1221754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato
1231754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    return OK;
1241754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato}
1251754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato
1261754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onoratovoid
1271754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe OnoratoIncidentReportArgs::setAll(bool all)
1281754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato{
1291754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    mAll = all;
1301754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    if (all) {
1311754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato        mSections.clear();
1321754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato    }
1331754d744a7a34731ffc07af1bc3dbfcb06864ab0Joe Onorato}
134