1 package com
.google
.android
.gms
.d
;
3 import android
.content
.Context
;
4 import android
.content
.res
.Resources
;
5 import com
.google
.android
.gms
.internal
.df
;
6 import com
.google
.android
.gms
.internal
.dz
;
7 import com
.google
.android
.gms
.internal
.ea
;
8 import com
.google
.android
.gms
.internal
.n
;
9 import java
.io
.ByteArrayOutputStream
;
11 import java
.io
.FileInputStream
;
12 import java
.io
.FileNotFoundException
;
13 import java
.io
.FileOutputStream
;
14 import java
.io
.IOException
;
15 import java
.io
.InputStream
;
16 import java
.io
.UnsupportedEncodingException
;
17 import java
.util
.concurrent
.ExecutorService
;
18 import java
.util
.concurrent
.Executors
;
19 import org
.json
.JSONException
;
21 /* access modifiers changed from: package-private */
22 public class db
implements ft
{
23 private final Context a
;
24 private final String b
;
25 private final ExecutorService c
= Executors
.newSingleThreadExecutor();
28 db(Context context
, String str
) {
33 private di
a(ByteArrayOutputStream byteArrayOutputStream
) {
35 return bb
.a(byteArrayOutputStream
.toString("UTF-8"));
36 } catch (UnsupportedEncodingException e
) {
37 bk
.d("Tried to convert binary resource to string for JSON parsing; not UTF-8 format");
39 } catch (JSONException e2
) {
40 bk
.b("Resource is a UTF-8 encoded string but doesn't contain a JSON container");
45 private di
a(byte[] bArr
) {
47 return de
.a(n
.a(bArr
));
49 bk
.b("Resource doesn't contain a binary container");
52 bk
.b("Resource doesn't contain a binary container");
57 @Override // com.google.android.gms.d.ft
59 bk
.e("Atttempting to load container from resource ID " + i
);
61 InputStream openRawResource
= this.a
.getResources().openRawResource(i
);
62 ByteArrayOutputStream byteArrayOutputStream
= new ByteArrayOutputStream();
63 de
.a(openRawResource
, byteArrayOutputStream
);
64 di a2
= a(byteArrayOutputStream
);
65 return a2
!= null ? a2
: a(byteArrayOutputStream
.toByteArray());
66 } catch (IOException e
) {
67 bk
.b("Error reading default container resource with ID " + i
);
69 } catch (Resources
.NotFoundException e2
) {
70 bk
.b("No default container resource found.");
75 @Override // com.google.android.gms.common.api.d
76 public synchronized void a() {
80 @Override // com.google.android.gms.d.ft
81 public void a(bi biVar
) {
85 @Override // com.google.android.gms.d.ft
86 public void a(df dfVar
) {
87 this.c
.execute(new dd(this, dfVar
));
90 @Override // com.google.android.gms.d.ft
92 this.c
.execute(new dc(this));
95 /* access modifiers changed from: package-private */
96 public boolean b(df dfVar
) {
100 FileOutputStream fileOutputStream
= new FileOutputStream(d2
);
102 fileOutputStream
.write(ea
.a(dfVar
));
105 fileOutputStream
.close();
106 } catch (IOException e
) {
107 bk
.b("error closing stream for writing resource to disk");
109 } catch (IOException e2
) {
110 bk
.b("Error writing resource to disk. Removing resource from disk.");
113 fileOutputStream
.close();
114 } catch (IOException e3
) {
115 bk
.b("error closing stream for writing resource to disk");
117 } catch (Throwable th
) {
119 fileOutputStream
.close();
120 } catch (IOException e4
) {
121 bk
.b("error closing stream for writing resource to disk");
125 } catch (FileNotFoundException e5
) {
126 bk
.a("Error opening resource file for writing");
131 /* access modifiers changed from: package-private */
133 if (this.d
== null) {
134 throw new IllegalStateException("callback must be set before execute");
137 bk
.e("Start loading resource from disk ...");
138 if ((ck
.a().b() == cl
.CONTAINER
|| ck
.a().b() == cl
.CONTAINER_DEBUG
) && this.b
.equals(ck
.a().d())) {
139 this.d
.a(bj
.NOT_AVAILABLE
);
143 FileInputStream fileInputStream
= new FileInputStream(d());
145 ByteArrayOutputStream byteArrayOutputStream
= new ByteArrayOutputStream();
146 de
.a(fileInputStream
, byteArrayOutputStream
);
147 this.d
.a(df
.a(byteArrayOutputStream
.toByteArray()));
149 fileInputStream
.close();
150 } catch (IOException e
) {
151 bk
.b("error closing stream for reading resource from disk");
153 } catch (IOException e2
) {
154 bk
.b("error reading resource from disk");
155 this.d
.a(bj
.IO_ERROR
);
157 fileInputStream
.close();
158 } catch (IOException e3
) {
159 bk
.b("error closing stream for reading resource from disk");
161 } catch (Throwable th
) {
163 fileInputStream
.close();
164 } catch (IOException e4
) {
165 bk
.b("error closing stream for reading resource from disk");
169 bk
.e("Load resource from disk finished.");
170 } catch (FileNotFoundException e5
) {
171 bk
.d("resource not on disk");
172 this.d
.a(bj
.NOT_AVAILABLE
);
176 /* access modifiers changed from: package-private */
178 return new File(this.a
.getDir("google_tagmanager", 0), "resource_" + this.b
);