1 package com
.google
.android
.gms
.b
;
3 import android
.content
.Context
;
4 import android
.net
.ConnectivityManager
;
5 import android
.net
.NetworkInfo
;
6 import android
.os
.Build
;
7 import android
.text
.TextUtils
;
8 import java
.io
.IOException
;
9 import java
.io
.InputStream
;
10 import java
.io
.UnsupportedEncodingException
;
11 import java
.net
.MalformedURLException
;
13 import java
.util
.List
;
14 import java
.util
.Locale
;
15 import org
.apache
.http
.Header
;
16 import org
.apache
.http
.HttpEntity
;
17 import org
.apache
.http
.HttpEntityEnclosingRequest
;
18 import org
.apache
.http
.HttpHost
;
19 import org
.apache
.http
.HttpResponse
;
20 import org
.apache
.http
.client
.ClientProtocolException
;
21 import org
.apache
.http
.client
.HttpClient
;
22 import org
.apache
.http
.entity
.StringEntity
;
23 import org
.apache
.http
.message
.BasicHttpEntityEnclosingRequest
;
25 /* access modifiers changed from: package-private */
26 public class s
implements al
{
27 private final String a
;
28 private final HttpClient b
;
29 private final Context c
;
33 s(HttpClient httpClient
, Context context
) {
34 this(httpClient
, a
.a(context
), context
);
37 s(HttpClient httpClient
, a aVar
, Context context
) {
38 this.c
= context
.getApplicationContext();
39 this.a
= a("GoogleAnalytics", "3.0", Build
.VERSION
.RELEASE
, t
.a(Locale
.getDefault()), Build
.MODEL
, Build
.ID
);
44 private HttpEntityEnclosingRequest
a(String str
, String str2
) {
45 BasicHttpEntityEnclosingRequest basicHttpEntityEnclosingRequest
;
46 if (TextUtils
.isEmpty(str
)) {
47 j
.d("Empty hit, discarding.");
50 String str3
= str2
+ "?" + str
;
51 if (str3
.length() < 2036) {
52 basicHttpEntityEnclosingRequest
= new BasicHttpEntityEnclosingRequest("GET", str3
);
54 basicHttpEntityEnclosingRequest
= new BasicHttpEntityEnclosingRequest("POST", str2
);
56 basicHttpEntityEnclosingRequest
.setEntity(new StringEntity(str
));
57 } catch (UnsupportedEncodingException e2
) {
58 j
.d("Encoding error, discarding hit");
62 basicHttpEntityEnclosingRequest
.addHeader("User-Agent", this.a
);
63 return basicHttpEntityEnclosingRequest
;
66 private void a(k kVar
, URL url
, boolean z
) {
68 if (!TextUtils
.isEmpty(kVar
.a()) && b()) {
71 url2
= this.e
!= null ?
this.e
: new URL("https://ssl.google-analytics.com/collect");
72 } catch (MalformedURLException e2
) {
78 HttpHost httpHost
= new HttpHost(url2
.getHost(), url2
.getPort(), url2
.getProtocol());
80 HttpEntityEnclosingRequest a2
= a(kVar
.a(), url2
.getPath());
82 a2
.addHeader("Host", httpHost
.toHostString());
89 HttpResponse execute
= this.b
.execute(httpHost
, a2
);
90 int statusCode
= execute
.getStatusLine().getStatusCode();
91 HttpEntity entity
= execute
.getEntity();
93 entity
.consumeContent();
95 if (statusCode
!= 200) {
96 j
.d("Bad response: " + execute
.getStatusLine().getStatusCode());
99 } catch (ClientProtocolException e3
) {
100 j
.d("ClientProtocolException sending monitoring hit.");
101 } catch (IOException e4
) {
102 j
.d("Exception sending monitoring hit: " + e4
.getClass().getSimpleName());
103 j
.d(e4
.getMessage());
108 private void a(HttpEntityEnclosingRequest httpEntityEnclosingRequest
) {
110 StringBuffer stringBuffer
= new StringBuffer();
111 for (Header header
: httpEntityEnclosingRequest
.getAllHeaders()) {
112 stringBuffer
.append(header
.toString()).append("\n");
114 stringBuffer
.append(httpEntityEnclosingRequest
.getRequestLine().toString()).append("\n");
115 if (httpEntityEnclosingRequest
.getEntity() != null) {
117 InputStream content
= httpEntityEnclosingRequest
.getEntity().getContent();
118 if (content
!= null && (available
= content
.available()) > 0) {
119 byte[] bArr
= new byte[available
];
121 stringBuffer
.append("POST:\n");
122 stringBuffer
.append(new String(bArr
)).append("\n");
124 } catch (IOException e2
) {
125 j
.c("Error Writing hit to log...");
128 j
.c(stringBuffer
.toString());
131 @Override // com.google.android.gms.b.al
132 public int a(List list
, k kVar
, boolean z
) {
136 int min
= Math
.min(list
.size(), 40);
137 kVar
.a("_hr", list
.size());
143 bj bjVar
= (bj
) list
.get(i4
);
147 j
.d("No destination: discarding hit: " + bjVar
.a());
149 j
.d("No destination: discarding hit.");
155 HttpHost httpHost
= new HttpHost(a2
.getHost(), a2
.getPort(), a2
.getProtocol());
156 String path
= a2
.getPath();
157 String a3
= TextUtils
.isEmpty(bjVar
.a()) ?
"" : bk
.a(bjVar
, System
.currentTimeMillis());
158 HttpEntityEnclosingRequest a4
= a(a3
, path
);
164 a4
.addHeader("Host", httpHost
.toHostString());
168 if (a3
.length() > 8192) {
169 j
.d("Hit too long (> 8192 bytes)--not sent");
171 } else if (this.d
.b()) {
172 j
.b("Dry run enabled. Hit not actually sent.");
178 } catch (ClientProtocolException e2
) {
179 j
.d("ClientProtocolException sending hit; discarding hit...");
181 } catch (IOException e3
) {
182 j
.d("Exception sending hit: " + e3
.getClass().getSimpleName());
183 j
.d(e3
.getMessage());
191 HttpResponse execute
= this.b
.execute(httpHost
, a4
);
192 int statusCode
= execute
.getStatusLine().getStatusCode();
193 HttpEntity entity
= execute
.getEntity();
194 if (entity
!= null) {
195 entity
.consumeContent();
197 if (statusCode
!= 200) {
198 j
.d("Bad response: " + execute
.getStatusLine().getStatusCode());
201 kVar
.a("_td", a3
.getBytes().length
);
218 /* access modifiers changed from: package-private */
219 public String
a(String str
, String str2
, String str3
, String str4
, String str5
, String str6
) {
220 return String
.format("%s/%s (Linux; U; Android %s; %s; %s Build/%s)", str
, str2
, str3
, str4
, str5
, str6
);
223 /* access modifiers changed from: package-private */
224 public URL
a(bj bjVar
) {
225 if (this.e
!= null) {
229 return new URL("http:".equals(bjVar
.d()) ?
"http://www.google-analytics.com/collect" : "https://ssl.google-analytics.com/collect");
230 } catch (MalformedURLException e2
) {
231 j
.a("Error trying to parse the hardcoded host url. This really shouldn't happen.");
236 @Override // com.google.android.gms.b.al
237 public void a(String str
) {
239 this.e
= new URL(str
);
240 } catch (MalformedURLException e2
) {
245 @Override // com.google.android.gms.b.al
247 NetworkInfo activeNetworkInfo
= ((ConnectivityManager
) this.c
.getSystemService("connectivity")).getActiveNetworkInfo();
248 if (activeNetworkInfo
!= null && activeNetworkInfo
.isConnected()) {
251 j
.c("...no network connectivity");
255 /* access modifiers changed from: package-private */
257 return Math
.random() * 100.0d
<= 1.0d
;