1 /* 2 * Copyright (C) 2015 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.security.keymaster; 18 19 import android.compat.annotation.UnsupportedAppUsage; 20 import android.os.Build; 21 import android.os.IBinder; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 25 /** 26 * Class for handling the parceling of return values from keymaster crypto operations 27 * (begin/update/finish). 28 * @hide 29 */ 30 public class OperationResult implements Parcelable { 31 public final int resultCode; 32 public final IBinder token; 33 public final long operationHandle; 34 public final int inputConsumed; 35 public final byte[] output; 36 public final KeymasterArguments outParams; 37 38 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 39 public static final @android.annotation.NonNull Parcelable.Creator<OperationResult> CREATOR = new 40 Parcelable.Creator<OperationResult>() { 41 @Override 42 public OperationResult createFromParcel(Parcel in) { 43 return new OperationResult(in); 44 } 45 46 @Override 47 public OperationResult[] newArray(int length) { 48 return new OperationResult[length]; 49 } 50 }; 51 OperationResult( int resultCode, IBinder token, long operationHandle, int inputConsumed, byte[] output, KeymasterArguments outParams)52 public OperationResult( 53 int resultCode, IBinder token, long operationHandle, int inputConsumed, byte[] output, 54 KeymasterArguments outParams) { 55 this.resultCode = resultCode; 56 this.token = token; 57 this.operationHandle = operationHandle; 58 this.inputConsumed = inputConsumed; 59 this.output = output; 60 this.outParams = outParams; 61 } 62 OperationResult(int resultCode)63 public OperationResult(int resultCode) { 64 this(resultCode, null, 0, 0, null, null); 65 } 66 OperationResult(Parcel in)67 protected OperationResult(Parcel in) { 68 resultCode = in.readInt(); 69 token = in.readStrongBinder(); 70 operationHandle = in.readLong(); 71 inputConsumed = in.readInt(); 72 output = in.createByteArray(); 73 outParams = KeymasterArguments.CREATOR.createFromParcel(in); 74 } 75 76 @Override describeContents()77 public int describeContents() { 78 return 0; 79 } 80 81 @Override writeToParcel(Parcel out, int flags)82 public void writeToParcel(Parcel out, int flags) { 83 out.writeInt(resultCode); 84 out.writeStrongBinder(token); 85 out.writeLong(operationHandle); 86 out.writeInt(inputConsumed); 87 out.writeByteArray(output); 88 outParams.writeToParcel(out, flags); 89 } 90 } 91