parcelable_update_engine_status.cc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. #include "update_engine/parcelable_update_engine_status.h"
  17. #include "update_engine/update_status_utils.h"
  18. #include <binder/Parcel.h>
  19. using update_engine::UpdateEngineStatus;
  20. namespace android {
  21. namespace brillo {
  22. ParcelableUpdateEngineStatus::ParcelableUpdateEngineStatus(
  23. const UpdateEngineStatus& status)
  24. : last_checked_time_(status.last_checked_time),
  25. current_operation_(
  26. chromeos_update_engine::UpdateStatusToString(status.status)),
  27. progress_(status.progress),
  28. current_version_(String16{status.current_version.c_str()}),
  29. current_system_version_(String16{status.current_system_version.c_str()}),
  30. new_size_(status.new_size_bytes),
  31. new_version_(String16{status.new_version.c_str()}),
  32. new_system_version_(String16{status.new_system_version.c_str()}) {}
  33. status_t ParcelableUpdateEngineStatus::writeToParcel(Parcel* parcel) const {
  34. status_t status;
  35. status = parcel->writeInt64(last_checked_time_);
  36. if (status != OK) {
  37. return status;
  38. }
  39. status = parcel->writeString16(current_operation_);
  40. if (status != OK) {
  41. return status;
  42. }
  43. status = parcel->writeDouble(progress_);
  44. if (status != OK) {
  45. return status;
  46. }
  47. status = parcel->writeString16(current_version_);
  48. if (status != OK) {
  49. return status;
  50. }
  51. status = parcel->writeString16(current_system_version_);
  52. if (status != OK) {
  53. return status;
  54. }
  55. status = parcel->writeInt64(new_size_);
  56. if (status != OK) {
  57. return status;
  58. }
  59. status = parcel->writeString16(new_version_);
  60. if (status != OK) {
  61. return status;
  62. }
  63. return parcel->writeString16(new_system_version_);
  64. }
  65. status_t ParcelableUpdateEngineStatus::readFromParcel(const Parcel* parcel) {
  66. status_t status;
  67. status = parcel->readInt64(&last_checked_time_);
  68. if (status != OK) {
  69. return status;
  70. }
  71. status = parcel->readString16(&current_operation_);
  72. if (status != OK) {
  73. return status;
  74. }
  75. status = parcel->readDouble(&progress_);
  76. if (status != OK) {
  77. return status;
  78. }
  79. status = parcel->readString16(&current_version_);
  80. if (status != OK) {
  81. return status;
  82. }
  83. status = parcel->readString16(&current_system_version_);
  84. if (status != OK) {
  85. return status;
  86. }
  87. status = parcel->readInt64(&new_size_);
  88. if (status != OK) {
  89. return status;
  90. }
  91. status = parcel->readString16(&new_version_);
  92. if (status != OK) {
  93. return status;
  94. }
  95. return parcel->readString16(&new_system_version_);
  96. }
  97. } // namespace brillo
  98. } // namespace android