1 /*
2  * Copyright (C) 2020 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 "CarPowerPolicy.h"
18 
19 #include <binder/Parcel.h>
20 
21 namespace android {
22 namespace car {
23 namespace hardware {
24 namespace power {
25 
26 using android::Parcel;
27 using android::status_t;
28 
CarPowerPolicy(const std::string & policyId,const std::vector<int32_t> & enabledComponents,const std::vector<int32_t> & disabledComponents)29 CarPowerPolicy::CarPowerPolicy(const std::string& policyId,
30                                const std::vector<int32_t>& enabledComponents,
31                                const std::vector<int32_t>& disabledComponents) :
32       mPolicyId(policyId.c_str(), policyId.length()),
33       mEnabledComponents(enabledComponents),
34       mDisabledComponents(disabledComponents) {}
35 
writeToParcel(Parcel * parcel) const36 status_t CarPowerPolicy::writeToParcel(Parcel* parcel) const {
37     status_t status = parcel->writeString8(mPolicyId);
38     if (status != OK) {
39         return status;
40     }
41     status = parcel->writeInt32Vector(mEnabledComponents);
42     if (status != OK) {
43         return status;
44     }
45     return parcel->writeInt32Vector(mDisabledComponents);
46 }
47 
readFromParcel(const Parcel * parcel)48 status_t CarPowerPolicy::readFromParcel(const Parcel* parcel) {
49     status_t status = parcel->readString8(&mPolicyId);
50     if (status != OK) {
51         return status;
52     }
53     status = parcel->readInt32Vector(&mEnabledComponents);
54     if (status != OK) {
55         return status;
56     }
57     return parcel->readInt32Vector(&mDisabledComponents);
58 }
59 
60 }  // namespace power
61 }  // namespace hardware
62 }  // namespace car
63 }  // namespace android
64