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