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