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 android.health.connect.aidl; 18 19 import android.annotation.NonNull; 20 import android.health.connect.HealthConnectException; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 import java.io.PrintWriter; 25 import java.io.StringWriter; 26 27 /** @hide */ 28 public final class HealthConnectExceptionParcel implements Parcelable { 29 30 @NonNull 31 public static final Creator<HealthConnectExceptionParcel> CREATOR = 32 new Creator<HealthConnectExceptionParcel>() { 33 @Override 34 public HealthConnectExceptionParcel createFromParcel(Parcel in) { 35 return new HealthConnectExceptionParcel( 36 new HealthConnectException(in.readInt(), in.readString())); 37 } 38 39 @Override 40 public HealthConnectExceptionParcel[] newArray(int size) { 41 return new HealthConnectExceptionParcel[size]; 42 } 43 }; 44 45 private final HealthConnectException mHealthConnectException; 46 HealthConnectExceptionParcel(HealthConnectException healthConnectException)47 public HealthConnectExceptionParcel(HealthConnectException healthConnectException) { 48 mHealthConnectException = healthConnectException; 49 } 50 getHealthConnectException()51 public HealthConnectException getHealthConnectException() { 52 return mHealthConnectException; 53 } 54 55 @Override describeContents()56 public int describeContents() { 57 return 0; 58 } 59 60 @Override writeToParcel(@onNull Parcel dest, int flags)61 public void writeToParcel(@NonNull Parcel dest, int flags) { 62 dest.writeInt(mHealthConnectException.getErrorCode()); 63 dest.writeString(mHealthConnectException.getMessage()); 64 } 65 66 @Override toString()67 public String toString() { 68 StringWriter sw = new StringWriter(); 69 if (mHealthConnectException != null) { 70 PrintWriter pw = new PrintWriter(sw); 71 mHealthConnectException.printStackTrace(pw); 72 } 73 return "HealthConnectExceptionParcel: " + mHealthConnectException + "\n" + sw; 74 } 75 } 76