1 /* 2 * Copyright (C) 2020 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.telephony.gba; 18 19 import android.annotation.NonNull; 20 import android.net.Uri; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 import android.telephony.IBootstrapAuthenticationCallback; 24 25 import com.android.internal.telephony.uicc.IccUtils; 26 27 import java.util.concurrent.atomic.AtomicInteger; 28 29 /** 30 * GBA authentication request 31 * {@hide} 32 */ 33 public final class GbaAuthRequest implements Parcelable { 34 private int mToken; 35 private int mSubId; 36 private int mAppType; 37 private Uri mNafUrl; 38 private byte[] mSecurityProtocol; 39 private boolean mForceBootStrapping; 40 private IBootstrapAuthenticationCallback mCallback; 41 42 private static AtomicInteger sUniqueToken = new AtomicInteger(0); 43 GbaAuthRequest(int subId, int appType, Uri nafUrl, byte[] securityProtocol, boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)44 public GbaAuthRequest(int subId, int appType, Uri nafUrl, byte[] securityProtocol, 45 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { 46 this(nextUniqueToken(), subId, appType, nafUrl, 47 securityProtocol, forceBootStrapping, callback); 48 } 49 GbaAuthRequest(GbaAuthRequest request)50 public GbaAuthRequest(GbaAuthRequest request) { 51 this(request.mToken, request.mSubId, request.mAppType, request.mNafUrl, 52 request.mSecurityProtocol, request.mForceBootStrapping, request.mCallback); 53 } 54 GbaAuthRequest(int token, int subId, int appType, Uri nafUrl, byte[] securityProtocol, boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)55 public GbaAuthRequest(int token, int subId, int appType, Uri nafUrl, byte[] securityProtocol, 56 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { 57 mToken = token; 58 mSubId = subId; 59 mAppType = appType; 60 mNafUrl = nafUrl; 61 mSecurityProtocol = securityProtocol; 62 mCallback = callback; 63 mForceBootStrapping = forceBootStrapping; 64 } 65 getToken()66 public int getToken() { 67 return mToken; 68 } 69 getSubId()70 public int getSubId() { 71 return mSubId; 72 } 73 getAppType()74 public int getAppType() { 75 return mAppType; 76 } 77 getNafUrl()78 public Uri getNafUrl() { 79 return mNafUrl; 80 } 81 getSecurityProtocol()82 public byte[] getSecurityProtocol() { 83 return mSecurityProtocol; 84 } 85 isForceBootStrapping()86 public boolean isForceBootStrapping() { 87 return mForceBootStrapping; 88 } 89 setCallback(IBootstrapAuthenticationCallback cb)90 public void setCallback(IBootstrapAuthenticationCallback cb) { 91 mCallback = cb; 92 } 93 getCallback()94 public IBootstrapAuthenticationCallback getCallback() { 95 return mCallback; 96 } 97 98 /** 99 * {@link Parcelable#writeToParcel} 100 */ writeToParcel(@onNull Parcel out, int flags)101 public void writeToParcel(@NonNull Parcel out, int flags) { 102 out.writeInt(mToken); 103 out.writeInt(mSubId); 104 out.writeInt(mAppType); 105 out.writeParcelable(mNafUrl, 0); 106 out.writeInt(mSecurityProtocol.length); 107 out.writeByteArray(mSecurityProtocol); 108 out.writeBoolean(mForceBootStrapping); 109 out.writeStrongInterface(mCallback); 110 } 111 112 /** 113 * {@link Parcelable.Creator} 114 * 115 */ 116 public static final @android.annotation.NonNull Parcelable.Creator< 117 GbaAuthRequest> CREATOR = new Creator<GbaAuthRequest>() { 118 @Override 119 public GbaAuthRequest createFromParcel(Parcel in) { 120 int token = in.readInt(); 121 int subId = in.readInt(); 122 int appType = in.readInt(); 123 Uri nafUrl = in.readParcelable(GbaAuthRequest.class.getClassLoader(), android.net.Uri.class); 124 int len = in.readInt(); 125 byte[] protocol = new byte[len]; 126 in.readByteArray(protocol); 127 boolean forceBootStrapping = in.readBoolean(); 128 IBootstrapAuthenticationCallback callback = 129 IBootstrapAuthenticationCallback.Stub 130 .asInterface(in.readStrongBinder()); 131 return new GbaAuthRequest(token, subId, appType, nafUrl, protocol, 132 forceBootStrapping, callback); 133 } 134 135 @Override 136 public GbaAuthRequest[] newArray(int size) { 137 return new GbaAuthRequest[size]; 138 } 139 }; 140 141 /** 142 * {@link Parcelable#describeContents} 143 */ describeContents()144 public int describeContents() { 145 return 0; 146 } 147 nextUniqueToken()148 private static int nextUniqueToken() { 149 return sUniqueToken.getAndIncrement() << 16 | (0xFFFF & (int) System.currentTimeMillis()); 150 } 151 152 @Override toString()153 public String toString() { 154 String str = "Token: " + mToken + "SubId:" + mSubId + ", AppType:" 155 + mAppType + ", NafUrl:" + mNafUrl + ", SecurityProtocol:" 156 + IccUtils.bytesToHexString(mSecurityProtocol) 157 + ", ForceBootStrapping:" + mForceBootStrapping 158 + ", CallBack:" + mCallback; 159 return str; 160 } 161 } 162