1 /* 2 * Copyright (C) 2023 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 com.android.car.internal; 18 19 import android.annotation.Nullable; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 23 /** 24 * Wrapper for a parcelable object <V> 25 * 26 * @param <V> refer to a Parcelable object. 27 * @hide 28 */ 29 public final class ResultWrapper<V> implements Parcelable { 30 31 @Nullable 32 private final V mResult; 33 ResultWrapper(V result)34 public ResultWrapper(V result) { 35 mResult = result; 36 } 37 ResultWrapper(Parcel in)38 ResultWrapper(Parcel in) { 39 @SuppressWarnings("unchecked") 40 V safeCast = (V) in.readValue(getClass().getClassLoader()); 41 mResult = safeCast; 42 } 43 getResult()44 public V getResult() { 45 return mResult; 46 } 47 48 @Override describeContents()49 public int describeContents() { 50 return 0; 51 } 52 53 @Override writeToParcel(Parcel dest, int flags)54 public void writeToParcel(Parcel dest, int flags) { 55 dest.writeValue(mResult); 56 } 57 58 public static final Parcelable.Creator<ResultWrapper> CREATOR = 59 new Parcelable.Creator<ResultWrapper>() { 60 public ResultWrapper createFromParcel(Parcel in) { 61 return new ResultWrapper(in); 62 } 63 64 public ResultWrapper[] newArray(int size) { 65 return new ResultWrapper[size]; 66 } 67 }; 68 69 } 70