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