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.telecom.cts.apps; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 import androidx.annotation.NonNull; 23 24 public class BooleanTransaction extends BaseTransaction implements Parcelable { 25 getBoolResult()26 public boolean getBoolResult() { 27 return mBoolResult; 28 } 29 30 boolean mBoolResult; 31 BooleanTransaction(TestAppTransaction result, boolean boolResult)32 public BooleanTransaction(TestAppTransaction result, boolean boolResult) { 33 mResult = result; 34 mBoolResult = boolResult; 35 } 36 BooleanTransaction(TestAppTransaction result, TestAppException exception)37 public BooleanTransaction(TestAppTransaction result, TestAppException exception) { 38 mResult = result; 39 mException = exception; 40 } 41 42 @Override describeContents()43 public int describeContents() { 44 return 0; 45 } 46 47 @Override writeToParcel(@onNull Parcel dest, int flags)48 public void writeToParcel(@NonNull Parcel dest, int flags) { 49 dest.writeParcelable(mResult, flags); 50 if (isTransactionSuccessful()) { 51 dest.writeBoolean(mBoolResult); 52 } else { 53 dest.writeParcelable(mException, flags); 54 } 55 } 56 57 public static final Creator<BooleanTransaction> CREATOR = new Creator<>() { 58 @Override 59 public BooleanTransaction createFromParcel(Parcel source) { 60 TestAppTransaction transactionResult = 61 source.readParcelable(getClass().getClassLoader(), 62 TestAppTransaction.class); 63 64 if (transactionResult != null 65 && transactionResult.equals(TestAppTransaction.Success)) { 66 return new BooleanTransaction( 67 transactionResult, 68 source.readBoolean()); 69 } else { 70 return new BooleanTransaction( 71 transactionResult, 72 source.readParcelable(getClass().getClassLoader(), 73 TestAppException.class)); 74 } 75 } 76 77 @Override 78 public BooleanTransaction[] newArray(int size) { 79 return new BooleanTransaction[size]; 80 } 81 }; 82 83 84 } 85