uid_info.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (C) 2017 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. #include <binder/Parcel.h>
  17. #include "uid_info.h"
  18. using namespace android;
  19. using namespace android::os::storaged;
  20. status_t UidInfo::writeToParcel(Parcel* parcel) const {
  21. parcel->writeInt32(uid);
  22. parcel->writeCString(name.c_str());
  23. parcel->write(&io, sizeof(io));
  24. parcel->writeInt32(tasks.size());
  25. for (const auto& task_it : tasks) {
  26. parcel->writeInt32(task_it.first);
  27. parcel->writeCString(task_it.second.comm.c_str());
  28. parcel->write(&task_it.second.io, sizeof(task_it.second.io));
  29. }
  30. return OK;
  31. }
  32. status_t UidInfo::readFromParcel(const Parcel* parcel) {
  33. uid = parcel->readInt32();
  34. name = parcel->readCString();
  35. parcel->read(&io, sizeof(io));
  36. uint32_t tasks_size = parcel->readInt32();
  37. for (uint32_t i = 0; i < tasks_size; i++) {
  38. task_info task;
  39. task.pid = parcel->readInt32();
  40. task.comm = parcel->readCString();
  41. parcel->read(&task.io, sizeof(task.io));
  42. tasks[task.pid] = task;
  43. }
  44. return OK;
  45. }