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.net.Network; 20 21 import androidx.annotation.Nullable; 22 23 import com.google.auto.value.AutoValue; 24 25 /** 26 * Carrier specific customization to be used in the service entitlement queries and operations. 27 * 28 * @see #ServiceEntitlement 29 */ 30 @AutoValue 31 public abstract class CarrierConfig { 32 /** Default value of {@link #timeoutInSec} if not set. */ 33 public static final int DEFAULT_TIMEOUT_IN_SEC = 30; 34 35 public static final String CLIENT_TS_43_IMS_ENTITLEMENT = "IMS-Entitlement"; 36 public static final String CLIENT_TS_43_COMPANION_ODSA = "Companion-ODSA"; 37 public static final String CLIENT_TS_43_PRIMARY_ODSA = "Primary-ODSA"; 38 public static final String CLIENT_TS_43_SERVER_ODSA = "Server-ODSA"; 39 40 /** The carrier's entitlement server URL. See {@link Builder#setServerUrl}. */ serverUrl()41 public abstract String serverUrl(); 42 43 /** 44 * Client-ts43 attribute. Used to set the User-Agent header in HTTP requests as defined in TS.43 45 * section 2.2. 46 */ clientTs43()47 public abstract String clientTs43(); 48 49 /** Returns {@code true} if HTTP POST, instead of GET, should be used for TS.43 requests. */ useHttpPost()50 public abstract boolean useHttpPost(); 51 52 /** Client side timeout for HTTP connection. See {@link Builder#setTimeoutInSec}. */ timeoutInSec()53 public abstract int timeoutInSec(); 54 55 /** The {@link Network} used for HTTP connection. See {@link Builder#setNetwork}. */ 56 @Nullable network()57 public abstract Network network(); 58 59 /** Returns a new {@link Builder} object. */ builder()60 public static Builder builder() { 61 return new AutoValue_CarrierConfig.Builder() 62 .setServerUrl("") 63 .setClientTs43("") 64 .setUseHttpPost(false) 65 .setTimeoutInSec(DEFAULT_TIMEOUT_IN_SEC); 66 } 67 68 /** Builder. */ 69 @AutoValue.Builder 70 public abstract static class Builder { build()71 public abstract CarrierConfig build(); 72 73 /** 74 * Sets the carrier's entitlement server URL. If not set, will use {@code 75 * https://aes.mnc<MNC>.mcc<MCC>.pub.3gppnetwork.org} as defined in GSMA TS.43 section 2.1. 76 */ setServerUrl(String url)77 public abstract Builder setServerUrl(String url); 78 79 /** Sets the Client-ts43 attribute. Used to set the User-Agent header in HTTP requests. */ setClientTs43(String clientTs43)80 public abstract Builder setClientTs43(String clientTs43); 81 82 /** Set to {@code true} to use HTTP POST instead of GET for TS.43 requests. */ setUseHttpPost(boolean useHttpPost)83 public abstract Builder setUseHttpPost(boolean useHttpPost); 84 85 /** 86 * Sets the client side timeout for HTTP connection. Default to 87 * {@link DEFAULT_TIMEOUT_IN_SEC}. 88 * 89 * <p>This timeout is used by both {@link java.net.URLConnection#setConnectTimeout} and 90 * {@link java.net.URLConnection#setReadTimeout}. 91 */ setTimeoutInSec(int timeoutInSec)92 public abstract Builder setTimeoutInSec(int timeoutInSec); 93 94 /** 95 * Sets the {@link Network} used for HTTP connection. If not set, the device default network 96 * is used. 97 */ setNetwork(Network network)98 public abstract Builder setNetwork(Network network); 99 } 100 } 101