1 /* 2 * Copyright (C) 2021 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 package android.car.builtin.os; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.SystemApi; 22 import android.os.Parcel; 23 import android.util.ArraySet; 24 25 /** 26 * Helper for {@link Parcel}. 27 * 28 * @hide 29 */ 30 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) 31 public final class ParcelHelper { ParcelHelper()32 private ParcelHelper() { 33 throw new UnsupportedOperationException(); 34 } 35 36 /** Reads array of string from the passed parcel */ 37 @Nullable readStringArray(@onNull Parcel parcel)38 public static String[] readStringArray(@NonNull Parcel parcel) { 39 return parcel.readStringArray(); 40 } 41 42 /** Reads a Blob */ 43 @Nullable readBlob(@onNull Parcel parcel)44 public static byte[] readBlob(@NonNull Parcel parcel) { 45 return parcel.readBlob(); 46 } 47 48 /** Writes the byte array to the Parcel */ writeBlob(@onNull Parcel parcel, @Nullable byte[] b)49 public static void writeBlob(@NonNull Parcel parcel, @Nullable byte[] b) { 50 parcel.writeBlob(b); 51 } 52 53 /** Reads ArraySet */ 54 @Nullable readArraySet(@onNull Parcel parcel, @Nullable ClassLoader loader)55 public static ArraySet<? extends Object> readArraySet(@NonNull Parcel parcel, 56 @Nullable ClassLoader loader) { 57 return parcel.readArraySet(loader); 58 } 59 60 /** Writes ArraySet */ writeArraySet(@onNull Parcel parcel, @Nullable ArraySet<? extends Object> val)61 public static void writeArraySet(@NonNull Parcel parcel, 62 @Nullable ArraySet<? extends Object> val) { 63 parcel.writeArraySet(val); 64 } 65 } 66