1 /* 2 * Copyright (C) 2015 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 package com.android.car.vehiclenetwork; 17 18 import android.os.Parcel; 19 import android.os.Parcelable; 20 21 import com.android.car.vehiclenetwork.VehicleNetworkProto.VehiclePropConfigs; 22 import com.google.protobuf.InvalidProtocolBufferException; 23 24 public class VehiclePropConfigsParcelable implements Parcelable { 25 26 public final VehiclePropConfigs configs; 27 28 public VehiclePropConfigsParcelable(VehiclePropConfigs configs) { 29 this.configs = configs; 30 } 31 32 public VehiclePropConfigsParcelable(Parcel in) { 33 byte[] blob = in.readBlob(); 34 try { 35 configs = VehiclePropConfigs.parseFrom(blob); 36 } catch (InvalidProtocolBufferException e) { 37 throw new IllegalArgumentException(e); 38 } 39 } 40 41 @Override 42 public int describeContents() { 43 return 0; 44 } 45 46 @Override 47 public void writeToParcel(Parcel dest, int flags) { 48 // this is never used for java side as service is implemented in native side. 49 dest.writeBlob(configs.toByteArray()); 50 } 51 52 public static final Creator<VehiclePropConfigsParcelable> CREATOR = 53 new Creator<VehiclePropConfigsParcelable>() { 54 @Override 55 public VehiclePropConfigsParcelable createFromParcel(Parcel in) { 56 return new VehiclePropConfigsParcelable(in); 57 } 58 59 @Override 60 public VehiclePropConfigsParcelable[] newArray(int size) { 61 return new VehiclePropConfigsParcelable[size]; 62 } 63 }; 64 } 65