• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.android.libraries.entitlement.utils.UrlConnectionFactory;
24 import com.google.auto.value.AutoValue;
25 
26 /**
27  * Carrier specific customization to be used in the service entitlement queries and operations.
28  *
29  * @see #ServiceEntitlement
30  */
31 @AutoValue
32 public abstract class CarrierConfig {
33     /** Default value of {@link #timeoutInSec} if not set. */
34     public static final int DEFAULT_TIMEOUT_IN_SEC = 30;
35 
36     public static final String CLIENT_TS_43_IMS_ENTITLEMENT = "client-IMS-Entitlement";
37     public static final String CLIENT_TS_43_COMPANION_ODSA = "client-Companion-ODSA";
38     public static final String CLIENT_TS_43_PRIMARY_ODSA = "client-Primary-ODSA";
39     public static final String CLIENT_TS_43_SERVER_ODSA = "client-Server-ODSA";
40 
41     /** The carrier's entitlement server URL. See {@link Builder#setServerUrl}. */
serverUrl()42     public abstract String serverUrl();
43 
44     /**
45      * Client-ts43 attribute. Used to set the User-Agent header in HTTP requests as defined in TS.43
46      * section 2.2.
47      */
clientTs43()48     public abstract String clientTs43();
49 
50     /** Returns {@code true} if HTTP POST, instead of GET, should be used for TS.43 requests. */
useHttpPost()51     public abstract boolean useHttpPost();
52 
53     /** Client side timeout for HTTP connection. See {@link Builder#setTimeoutInSec}. */
timeoutInSec()54     public abstract int timeoutInSec();
55 
56     /** The {@link Network} used for HTTP connection. See {@link Builder#setNetwork}. */
57     @Nullable
network()58     public abstract Network network();
59 
60     /** The factory to create connections. See {@link Builder#setUrlConnectionFactory}. */
61     @Nullable
urlConnectionFactory()62     public abstract UrlConnectionFactory urlConnectionFactory();
63 
64     /** The EAP-AKA realm. See {@link Builder#setEapAkaRealm}. */
eapAkaRealm()65     public abstract String eapAkaRealm();
66 
67     /** Returns a new {@link Builder} object. */
builder()68     public static Builder builder() {
69         return new AutoValue_CarrierConfig.Builder()
70                 .setServerUrl("")
71                 .setClientTs43("")
72                 .setUseHttpPost(false)
73                 .setTimeoutInSec(DEFAULT_TIMEOUT_IN_SEC)
74                 .setEapAkaRealm("nai.epc");
75     }
76 
77     /** Builder. */
78     @AutoValue.Builder
79     public abstract static class Builder {
build()80         public abstract CarrierConfig build();
81 
82         /**
83          * Sets the carrier's entitlement server URL. If not set, will use {@code
84          * https://aes.mnc<MNC>.mcc<MCC>.pub.3gppnetwork.org} as defined in GSMA TS.43 section 2.1.
85          */
setServerUrl(String url)86         public abstract Builder setServerUrl(String url);
87 
88         /** Sets the Client-ts43 attribute. Used to set the User-Agent header in HTTP requests. */
setClientTs43(String clientTs43)89         public abstract Builder setClientTs43(String clientTs43);
90 
91         /** Set to {@code true} to use HTTP POST instead of GET for TS.43 requests. */
setUseHttpPost(boolean useHttpPost)92         public abstract Builder setUseHttpPost(boolean useHttpPost);
93 
94         /**
95          * Sets the client side timeout for HTTP connection. Default to
96          * {@link DEFAULT_TIMEOUT_IN_SEC}.
97          *
98          * <p>This timeout is used by both {@link java.net.URLConnection#setConnectTimeout} and
99          * {@link java.net.URLConnection#setReadTimeout}.
100          */
setTimeoutInSec(int timeoutInSec)101         public abstract Builder setTimeoutInSec(int timeoutInSec);
102 
103         /**
104          * Sets the {@link Network} used for HTTP connection. If not set, the device default network
105          * is used.
106          */
setNetwork(Network network)107         public abstract Builder setNetwork(Network network);
108 
109         /**
110          * If unset, the default Android API {@link java.net.URL#openConnection}
111          * would be used. This allows callers of the lib to choose the HTTP stack.
112          */
setUrlConnectionFactory(UrlConnectionFactory urlConnectionFactory)113         public abstract Builder setUrlConnectionFactory(UrlConnectionFactory urlConnectionFactory);
114 
115         /**
116          * Sets the realm for EAP-AKA. If unset, uses the standard "nai.epc" defined in 3GPP TS
117          * 23.003 clause 19.3.2.
118          */
setEapAkaRealm(String eapAkaRealm)119         public abstract Builder setEapAkaRealm(String eapAkaRealm);
120     }
121 }
122