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 a new {@link Builder} object. 124 */ builder()125 public static Builder builder() { 126 return new AutoValue_ServiceEntitlementRequest.Builder() 127 .setConfigurationVersion(DEFAULT_CONFIGURATION_VERSION) 128 .setEntitlementVersion(Ts43Constants.DEFAULT_ENTITLEMENT_VERSION) 129 .setAuthenticationToken("") 130 .setTemporaryToken("") 131 .setTerminalId("") 132 .setTerminalVendor(Build.MANUFACTURER) 133 .setTerminalModel(Build.MODEL) 134 .setTerminalSoftwareVersion(VERSION.RELEASE) 135 .setAppName("") 136 .setAppVersion("") 137 .setNotificationToken("") 138 .setNotificationAction(Ts43Constants.NOTIFICATION_ACTION_ENABLE_FCM) 139 .setAcceptContentType(ACCEPT_CONTENT_TYPE_JSON_AND_XML) 140 .setBoostType(""); 141 } 142 143 /** 144 * Builder. 145 */ 146 @AutoValue.Builder 147 public abstract static class Builder { 148 /** 149 * Sets the version of configuration currently stored on the client. Used by HTTP parameter 150 * "vers". 151 * 152 * <p>If not set, default to {@link #DEFAULT_CONFIGURATION_VERSION} indicating no existing 153 * configuration. 154 */ setConfigurationVersion(int value)155 public abstract Builder setConfigurationVersion(int value); 156 157 /** 158 * Sets the current version of the entitlement specification. Used by HTTP parameter 159 * "entitlement_version". 160 * 161 * <p>If not set, default to {@link Ts43Constants#DEFAULT_ENTITLEMENT_VERSION} base on 162 * TS.43-v5.0. 163 */ setEntitlementVersion(String value)164 public abstract Builder setEntitlementVersion(String value); 165 166 /** 167 * Sets the authentication token. Used by HTTP parameter "token". 168 * 169 * <p>If not set, will trigger embedded EAP-AKA authentication as decribed in TS.43 section 170 * 2.6.1. 171 */ setAuthenticationToken(String value)172 public abstract Builder setAuthenticationToken(String value); 173 174 /** 175 * Sets the temporary token. Used by HTTP parameter "temporary_token". 176 * 177 * <p>Optional. 178 */ setTemporaryToken(String value)179 public abstract Builder setTemporaryToken(String value); 180 181 /** 182 * Sets the unique identifier of the device like IMEI. Used by HTTP parameter 183 * "terminal_id". 184 * 185 * <p>If not set, will use the device IMEI. 186 */ setTerminalId(String value)187 public abstract Builder setTerminalId(String value); 188 189 /** 190 * Sets the OEM of the device. Used by HTTP parameter "terminal_vendor". 191 * 192 * <p>If not set, will use {@link android.os.Build#MANUFACTURER}. 193 */ setTerminalVendor(String value)194 public abstract Builder setTerminalVendor(String value); 195 196 /** 197 * Sets the model of the device. Used by HTTP parameter "terminal_model". 198 * 199 * <p>If not set, will use {@link android.os.Build#MODEL}. 200 */ setTerminalModel(String value)201 public abstract Builder setTerminalModel(String value); 202 203 /** 204 * Sets the software version of the device. Used by HTTP parameter "terminal_sw_version". 205 * 206 * <p>If not set, will use {@link android.os.Build.VERSION#BASE_OS}. 207 */ setTerminalSoftwareVersion(String value)208 public abstract Builder setTerminalSoftwareVersion(String value); 209 210 /** 211 * Sets the name of the device application making the request. Used by HTTP parameter 212 * "app_name". 213 * 214 * <p>Optional. 215 */ setAppName(String value)216 public abstract Builder setAppName(String value); 217 218 /** 219 * Sets the version of the device application making the request. Used by HTTP parameter 220 * "app_version". 221 * 222 * <p>Optional. 223 */ setAppVersion(String value)224 public abstract Builder setAppVersion(String value); 225 226 /** 227 * Sets the FCM registration token used to register for entitlement configuration request 228 * from network. Used by HTTP parameter "notif_token". 229 * 230 * <p>Optional. 231 */ setNotificationToken(String value)232 public abstract Builder setNotificationToken(String value); 233 234 /** 235 * Sets the action associated with the FCM registration token. Used by HTTP parameter 236 * "notif_action". 237 * 238 * <p>Required if a token is set with {@link #setNotificationToken}, and default to 239 * {@link Ts43Constants#NOTIFICATION_ACTION_ENABLE_FCM}; otherwise ignored. 240 */ setNotificationAction(@s43Constants.NotificationAction int value)241 public abstract Builder setNotificationAction(@Ts43Constants.NotificationAction int value); 242 243 /** 244 * Sets the configuration document format the caller accepts, e.g. XML or JSON. Used by HTTP 245 * request header "Accept". 246 * 247 * <p>If not set, will use {@link #ACCEPT_CONTENT_TYPE_JSON_AND_XML}. 248 * 249 * @see #ACCEPT_CONTENT_TYPE_XML 250 * @see #ACCEPT_CONTENT_TYPE_JSON 251 * @see #ACCEPT_CONTENT_TYPE_JSON_AND_XML 252 */ setAcceptContentType(String contentType)253 public abstract Builder setAcceptContentType(String contentType); 254 255 /** 256 * Sets the boost type for premium network. Used by HTTP parameter 257 * "boost_type" in case of premium network slice entitlement. 258 * 259 * <p>Optional. 260 */ setBoostType(String value)261 public abstract Builder setBoostType(String value); 262 build()263 public abstract ServiceEntitlementRequest build(); 264 } 265 } 266