first commit
[bylock.git] / sources / com / google / android / gms / b / s.java
blob7402d9e35991d59f2ab029b92d512a2960ff76de
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;
12 import java.net.URL;
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;
30 private a d;
31 private URL e;
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);
40 this.b = httpClient;
41 this.d = aVar;
44 private HttpEntityEnclosingRequest a(String str, String str2) {
45 BasicHttpEntityEnclosingRequest basicHttpEntityEnclosingRequest;
46 if (TextUtils.isEmpty(str)) {
47 j.d("Empty hit, discarding.");
48 return null;
50 String str3 = str2 + "?" + str;
51 if (str3.length() < 2036) {
52 basicHttpEntityEnclosingRequest = new BasicHttpEntityEnclosingRequest("GET", str3);
53 } else {
54 basicHttpEntityEnclosingRequest = new BasicHttpEntityEnclosingRequest("POST", str2);
55 try {
56 basicHttpEntityEnclosingRequest.setEntity(new StringEntity(str));
57 } catch (UnsupportedEncodingException e2) {
58 j.d("Encoding error, discarding hit");
59 return null;
62 basicHttpEntityEnclosingRequest.addHeader("User-Agent", this.a);
63 return basicHttpEntityEnclosingRequest;
66 private void a(k kVar, URL url, boolean z) {
67 URL url2;
68 if (!TextUtils.isEmpty(kVar.a()) && b()) {
69 if (url == null) {
70 try {
71 url2 = this.e != null ? this.e : new URL("https://ssl.google-analytics.com/collect");
72 } catch (MalformedURLException e2) {
73 return;
75 } else {
76 url2 = url;
78 HttpHost httpHost = new HttpHost(url2.getHost(), url2.getPort(), url2.getProtocol());
79 try {
80 HttpEntityEnclosingRequest a2 = a(kVar.a(), url2.getPath());
81 if (a2 != null) {
82 a2.addHeader("Host", httpHost.toHostString());
83 if (j.a()) {
84 a(a2);
86 if (z) {
87 an.b(this.c);
89 HttpResponse execute = this.b.execute(httpHost, a2);
90 int statusCode = execute.getStatusLine().getStatusCode();
91 HttpEntity entity = execute.getEntity();
92 if (entity != null) {
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) {
109 int available;
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) {
116 try {
117 InputStream content = httpEntityEnclosingRequest.getEntity().getContent();
118 if (content != null && (available = content.available()) > 0) {
119 byte[] bArr = new byte[available];
120 content.read(bArr);
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) {
133 int i;
134 URL url;
135 int i2 = 0;
136 int min = Math.min(list.size(), 40);
137 kVar.a("_hr", list.size());
138 int i3 = 0;
139 URL url2 = null;
140 boolean z2 = true;
141 int i4 = 0;
142 while (i4 < min) {
143 bj bjVar = (bj) list.get(i4);
144 URL a2 = a(bjVar);
145 if (a2 == null) {
146 if (j.a()) {
147 j.d("No destination: discarding hit: " + bjVar.a());
148 } else {
149 j.d("No destination: discarding hit.");
151 i3++;
152 i = i2 + 1;
153 url = url2;
154 } else {
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);
159 if (a4 == null) {
160 i3++;
161 i = i2 + 1;
162 url = a2;
163 } else {
164 a4.addHeader("Host", httpHost.toHostString());
165 if (j.a()) {
166 a(a4);
168 if (a3.length() > 8192) {
169 j.d("Hit too long (> 8192 bytes)--not sent");
170 i3++;
171 } else if (this.d.b()) {
172 j.b("Dry run enabled. Hit not actually sent.");
173 } else {
174 if (z2) {
175 try {
176 an.b(this.c);
177 z2 = false;
178 } catch (ClientProtocolException e2) {
179 j.d("ClientProtocolException sending hit; discarding hit...");
180 kVar.a("_hd", i3);
181 } catch (IOException e3) {
182 j.d("Exception sending hit: " + e3.getClass().getSimpleName());
183 j.d(e3.getMessage());
184 kVar.a("_de", 1);
185 kVar.a("_hd", i3);
186 kVar.a("_hs", i2);
187 a(kVar, a2, z2);
188 return i2;
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);
202 i = i2 + 1;
203 url = a2;
206 i4++;
207 i2 = i;
208 url2 = url;
210 kVar.a("_hd", i3);
211 kVar.a("_hs", i2);
212 if (z) {
213 a(kVar, url2, z2);
215 return i2;
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) {
226 return this.e;
228 try {
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.");
232 return null;
236 @Override // com.google.android.gms.b.al
237 public void a(String str) {
238 try {
239 this.e = new URL(str);
240 } catch (MalformedURLException e2) {
241 this.e = null;
245 @Override // com.google.android.gms.b.al
246 public boolean a() {
247 NetworkInfo activeNetworkInfo = ((ConnectivityManager) this.c.getSystemService("connectivity")).getActiveNetworkInfo();
248 if (activeNetworkInfo != null && activeNetworkInfo.isConnected()) {
249 return true;
251 j.c("...no network connectivity");
252 return false;
255 /* access modifiers changed from: package-private */
256 public boolean b() {
257 return Math.random() * 100.0d <= 1.0d;