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 import android.os.Parcelable.Creator; 21 22 import com.android.car.vehiclenetwork.VehicleNetworkProto.VehiclePropValues; 23 import com.google.protobuf.InvalidProtocolBufferException; 24 25 /** 26 * Have separate Parcelable for {@link VehiclePropValues} to use only one Blob. 27 * Handling this as array of single entry can lead into having multiple Blob, 28 * which can increase binder transfer size a lot (as each data can be below blob start size), 29 * or can add lots of Blob, which brings lots of performance issue. 30 */ 31 public class VehiclePropValuesParcelable implements Parcelable { 32 33 public final VehiclePropValues values; 34 35 public VehiclePropValuesParcelable(VehiclePropValues values) { 36 this.values = values; 37 } 38 39 public VehiclePropValuesParcelable(Parcel in) { 40 byte[] blob = in.readBlob(); 41 try { 42 values = VehiclePropValues.parseFrom(blob); 43 } catch (InvalidProtocolBufferException e) { 44 throw new IllegalArgumentException(e); 45 } 46 } 47 48 @Override 49 public int describeContents() { 50 return 0; 51 } 52 53 @Override 54 public void writeToParcel(Parcel dest, int flags) { 55 // this is never used for java side as service is implemented in native side. 56 dest.writeBlob(values.toByteArray()); 57 } 58 59 public static final Creator<VehiclePropValuesParcelable> CREATOR = 60 new Creator<VehiclePropValuesParcelable>() { 61 @Override 62 public VehiclePropValuesParcelable createFromParcel(Parcel in) { 63 return new VehiclePropValuesParcelable(in); 64 } 65 66 @Override 67 public VehiclePropValuesParcelable[] newArray(int size) { 68 return new VehiclePropValuesParcelable[size]; 69 } 70 }; 71 } 72