@@ -58,8 +58,6 @@ public class HttpAccess {
58
58
59
59
private String userAgent ;
60
60
private OkHttpClient okHttpClient ;
61
- private OkHttpClient .Builder okHttpBuilder ;
62
- private OkHttpClient .Builder unauthenticatedOkHttpBuilder ;
63
61
64
62
// Connection manager.
65
63
private final ConnectivityManager conMgr ;
@@ -100,26 +98,41 @@ public HttpAccess(Context app, String userAgent) {
100
98
*
101
99
* @return okHttpClient.Builder with appropriate connection spec
102
100
* and user agent interceptor for an authenticated client.
101
+ *
102
+ * @deprecated To be removed in 14.0. Please use {@link #createNewClientBuilder()} instead.
103
103
*/
104
+ @ Deprecated
104
105
public OkHttpClient .Builder getOkHttpClientBuilder () {
105
- if (okHttpBuilder == null ) {
106
- okHttpBuilder = createNewClientBuilder ();
107
- }
108
-
109
- return okHttpBuilder ;
106
+ return createNewClientBuilder ();
110
107
}
111
108
112
109
/**
113
110
*
114
111
* @return okHttpClient.Builder with appropriate connection spec
115
112
* and user agent interceptor for an unauthenticated client.
113
+ *
114
+ * @deprecated To be removed in 14.0. Please use {@link #createNewClientBuilder()} instead.
116
115
*/
116
+ @ Deprecated
117
117
public OkHttpClient .Builder getUnauthenticatedOkHttpBuilder () {
118
- if (unauthenticatedOkHttpBuilder == null ) {
119
- unauthenticatedOkHttpBuilder = createNewClientBuilder ();
120
- }
118
+ return createNewClientBuilder ();
119
+ }
121
120
122
- return unauthenticatedOkHttpBuilder ;
121
+ /**
122
+ * Creates a new OkHttp Client Builder with appropriate connection spec
123
+ * and user agent interceptor.
124
+ *
125
+ * @return the okHttpClient.Builder
126
+ */
127
+ public OkHttpClient .Builder createNewClientBuilder () {
128
+ ConnectionSpec connectionSpec = new ConnectionSpec .Builder (ConnectionSpec .MODERN_TLS )
129
+ .tlsVersions (TlsVersion .TLS_1_1 , TlsVersion .TLS_1_2 )
130
+ .build ();
131
+ return new OkHttpClient .Builder ()
132
+ .connectionSpecs (Collections .singletonList (connectionSpec ))
133
+ .connectTimeout (CONNECT_TIMEOUT , TimeUnit .SECONDS )
134
+ .readTimeout (READ_TIMEOUT , TimeUnit .SECONDS )
135
+ .addNetworkInterceptor (new UserAgentInterceptor ());
123
136
}
124
137
125
138
/**
@@ -128,7 +141,7 @@ public OkHttpClient.Builder getUnauthenticatedOkHttpBuilder() {
128
141
*/
129
142
public synchronized OkHttpClient getOkHttpClient () {
130
143
if (okHttpClient == null ) {
131
- okHttpClient = getOkHttpClientBuilder ().build ();
144
+ okHttpClient = createNewClientBuilder ().build ();
132
145
}
133
146
return okHttpClient ;
134
147
}
@@ -158,17 +171,6 @@ public String getUserAgent() {
158
171
return userAgent ;
159
172
}
160
173
161
- private OkHttpClient .Builder createNewClientBuilder () {
162
- ConnectionSpec connectionSpec = new ConnectionSpec .Builder (ConnectionSpec .MODERN_TLS )
163
- .tlsVersions (TlsVersion .TLS_1_1 , TlsVersion .TLS_1_2 )
164
- .build ();
165
- return new OkHttpClient .Builder ()
166
- .connectionSpecs (Collections .singletonList (connectionSpec ))
167
- .connectTimeout (CONNECT_TIMEOUT , TimeUnit .SECONDS )
168
- .readTimeout (READ_TIMEOUT , TimeUnit .SECONDS )
169
- .addNetworkInterceptor (new UserAgentInterceptor ());
170
- }
171
-
172
174
/**
173
175
* Exception thrown if the device is offline, during an attempted HTTP call.
174
176
*/
0 commit comments