1 /* 2 * Copyright (C) 2021 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.libraries.entitlement; 18 19 import android.os.Build; 20 import android.os.Build.VERSION; 21 22 import com.android.libraries.entitlement.utils.Ts43Constants; 23 24 import com.google.auto.value.AutoValue; 25 26 /** 27 * Service entitlement HTTP request parameters, as defined in GSMA spec TS.43 section 2.2. 28 */ 29 @AutoValue 30 public abstract class ServiceEntitlementRequest { 31 /** Accepts the content type in XML format. */ 32 public static final String ACCEPT_CONTENT_TYPE_XML = "text/vnd.wap.connectivity-xml"; 33 /** Accepts the content type in JSON format. */ 34 public static final String ACCEPT_CONTENT_TYPE_JSON = 35 "application/json"; 36 public static final String ACCEPT_CONTENT_TYPE_JSON_AND_XML = 37 "application/json, text/vnd.wap.connectivity-xml"; 38 /** Default value of configuration version. */ 39 public static final int DEFAULT_CONFIGURATION_VERSION = 0; 40 41 /** 42 * Returns the version of configuration currently stored on the client. Used by HTTP parameter 43 * "vers". 44 */ configurationVersion()45 public abstract int configurationVersion(); 46 47 /** 48 * Returns the version of the entitlement specification. Used by HTTP parameter 49 * "entitlement_version". 50 */ entitlementVersion()51 public abstract String entitlementVersion(); 52 53 /** 54 * Returns the authentication token. Used by HTTP parameter "token". 55 */ authenticationToken()56 public abstract String authenticationToken(); 57 58 /** 59 * Returns the temporary token. Used by HTTP parameter "temporary_token". 60 */ temporaryToken()61 public abstract String temporaryToken(); 62 63 /** 64 * Returns the unique identifier of the device like IMEI. Used by HTTP parameter "terminal_id". 65 */ terminalId()66 public abstract String terminalId(); 67 68 /** 69 * Returns the OEM of the device. Used by HTTP parameter "terminal_vendor". 70 */ terminalVendor()71 public abstract String terminalVendor(); 72 73 /** 74 * Returns the model of the device. Used by HTTP parameter "terminal_model". 75 */ terminalModel()76 public abstract String terminalModel(); 77 78 /** 79 * Returns the software version of the device. Used by HTTP parameter "terminal_sw_version". 80 */ terminalSoftwareVersion()81 public abstract String terminalSoftwareVersion(); 82 83 /** 84 * Returns the name of the device application making the request. Used by HTTP parameter 85 * "app_name". 86 */ appName()87 public abstract String appName(); 88 89 /** 90 * Returns the version of the device application making the request. Used by HTTP parameter 91 * "app_version". 92 */ appVersion()93 public abstract String appVersion(); 94 95 /** 96 * Returns the FCM registration token used to register for entitlement configuration request 97 * from network. Used by HTTP parameter "notif_token". 98 */ notificationToken()99 public abstract String notificationToken(); 100 101 /** 102 * Returns the action associated with the FCM registration token. Used by HTTP parameter 103 * "notif_action". 104 */ 105 @Ts43Constants.NotificationAction notificationAction()106 public abstract int notificationAction(); 107 108 /** 109 * Returns the accepted content type of http response. 110 * 111 * @see #ACCEPT_CONTENT_TYPE_XML 112 * @see #ACCEPT_CONTENT_TYPE_JSON 113 * @see #ACCEPT_CONTENT_TYPE_JSON_AND_XML 114 */ acceptContentType()115 public abstract String acceptContentType(); 116 117 /** 118 * Returns the boost type for premium network. Used for premium network slice entitlement. 119 */ boostType()120 public abstract String boostType(); 121 122 /** 123 * Returns the GID1 (Group ID level 1) of the SIM card. Used by HTTP parameter "gid1". 124 */ gid1()125 public abstract String gid1(); 126 127 /** 128 * Returns a new {@link Builder} object. 129 */ builder()130 public static Builder builder() { 131 return new AutoValue_ServiceEntitlementRequest.Builder() 132 .setConfigurationVersion(DEFAULT_CONFIGURATION_VERSION) 133 .setEntitlementVersion(Ts43Constants.DEFAULT_ENTITLEMENT_VERSION) 134 .setAuthenticationToken("") 135 .setTemporaryToken("") 136 .setTerminalId("") 137 .setTerminalVendor(Build.MANUFACTURER) 138 .setTerminalModel(Build.MODEL) 139 .setTerminalSoftwareVersion(VERSION.RELEASE) 140 .setAppName("") 141 .setAppVersion("") 142 .setNotificationToken("") 143 .setNotificationAction(Ts43Constants.NOTIFICATION_ACTION_ENABLE_FCM) 144 .setAcceptContentType(ACCEPT_CONTENT_TYPE_JSON_AND_XML) 145 .setBoostType("") 146 .setGid1(""); 147 } 148 149 /** 150 * Builder. 151 */ 152 @AutoValue.Builder 153 public abstract static class Builder { 154 /** 155 * Sets the version of configuration currently stored on the client. Used by HTTP parameter 156 * "vers". 157 * 158 * <p>If not set, default to {@link #DEFAULT_CONFIGURATION_VERSION} indicating no existing 159 * configuration. 160 */ setConfigurationVersion(int value)161 public abstract Builder setConfigurationVersion(int value); 162 163 /** 164 * Sets the current version of the entitlement specification. Used by HTTP parameter 165 * "entitlement_version". 166 * 167 * <p>If not set, default to {@link Ts43Constants#DEFAULT_ENTITLEMENT_VERSION} base on 168 * TS.43-v5.0. 169 */ setEntitlementVersion(String value)170 public abstract Builder setEntitlementVersion(String value); 171 172 /** 173 * Sets the authentication token. Used by HTTP parameter "token". 174 * 175 * <p>If not set, will trigger embedded EAP-AKA authentication as decribed in TS.43 section 176 * 2.6.1. 177 */ setAuthenticationToken(String value)178 public abstract Builder setAuthenticationToken(String value); 179 180 /** 181 * Sets the temporary token. Used by HTTP parameter "temporary_token". 182 * 183 * <p>Optional. 184 */ setTemporaryToken(String value)185 public abstract Builder setTemporaryToken(String value); 186 187 /** 188 * Sets the unique identifier of the device like IMEI. Used by HTTP parameter 189 * "terminal_id". 190 * 191 * <p>If not set, will use the device IMEI. 192 */ setTerminalId(String value)193 public abstract Builder setTerminalId(String value); 194 195 /** 196 * Sets the OEM of the device. Used by HTTP parameter "terminal_vendor". 197 * 198 * <p>If not set, will use {@link android.os.Build#MANUFACTURER}. 199 */ setTerminalVendor(String value)200 public abstract Builder setTerminalVendor(String value); 201 202 /** 203 * Sets the model of the device. Used by HTTP parameter "terminal_model". 204 * 205 * <p>If not set, will use {@link android.os.Build#MODEL}. 206 */ setTerminalModel(String value)207 public abstract Builder setTerminalModel(String value); 208 209 /** 210 * Sets the software version of the device. Used by HTTP parameter "terminal_sw_version". 211 * 212 * <p>If not set, will use {@link android.os.Build.VERSION#BASE_OS}. 213 */ setTerminalSoftwareVersion(String value)214 public abstract Builder setTerminalSoftwareVersion(String value); 215 216 /** 217 * Sets the name of the device application making the request. Used by HTTP parameter 218 * "app_name". 219 * 220 * <p>Optional. 221 */ setAppName(String value)222 public abstract Builder setAppName(String value); 223 224 /** 225 * Sets the version of the device application making the request. Used by HTTP parameter 226 * "app_version". 227 * 228 * <p>Optional. 229 */ setAppVersion(String value)230 public abstract Builder setAppVersion(String value); 231 232 /** 233 * Sets the FCM registration token used to register for entitlement configuration request 234 * from network. Used by HTTP parameter "notif_token". 235 * 236 * <p>Optional. 237 */ setNotificationToken(String value)238 public abstract Builder setNotificationToken(String value); 239 240 /** 241 * Sets the action associated with the FCM registration token. Used by HTTP parameter 242 * "notif_action". 243 * 244 * <p>Required if a token is set with {@link #setNotificationToken}, and default to 245 * {@link Ts43Constants#NOTIFICATION_ACTION_ENABLE_FCM}; otherwise ignored. 246 */ setNotificationAction(@s43Constants.NotificationAction int value)247 public abstract Builder setNotificationAction(@Ts43Constants.NotificationAction int value); 248 249 /** 250 * Sets the configuration document format the caller accepts, e.g. XML or JSON. Used by HTTP 251 * request header "Accept". 252 * 253 * <p>If not set, will use {@link #ACCEPT_CONTENT_TYPE_JSON_AND_XML}. 254 * 255 * @see #ACCEPT_CONTENT_TYPE_XML 256 * @see #ACCEPT_CONTENT_TYPE_JSON 257 * @see #ACCEPT_CONTENT_TYPE_JSON_AND_XML 258 */ setAcceptContentType(String contentType)259 public abstract Builder setAcceptContentType(String contentType); 260 261 /** 262 * Sets the boost type for premium network. Used by HTTP parameter 263 * "boost_type" in case of premium network slice entitlement. 264 * 265 * <p>Optional. 266 */ setBoostType(String value)267 public abstract Builder setBoostType(String value); 268 269 /** 270 * Sets the GID1 for the SIM Card. Used by HTTP parameter "gid1" for MVNO entitlement 271 * activation. 272 * 273 * <p>Required for TS.43 Versions beginning with v12.0. Will retrieve the value from 274 * {@link android.telephony.TelephonyManager} if not set. 275 */ setGid1(String value)276 public abstract Builder setGid1(String value); 277 build()278 public abstract ServiceEntitlementRequest build(); 279 } 280 } 281