最右.apk(点击下载) / b.java


package com.tencent.klevin.config.b;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Base64;
import cn.xiaochuankeji.hermes.klevin.BuildConfig;
import com.tencent.klevin.KlevinConfig;
import com.tencent.klevin.e.e.b0;
import com.tencent.klevin.e.e.c0;
import com.tencent.klevin.e.e.e;
import com.tencent.klevin.e.e.f;
import com.tencent.klevin.e.e.w;
import com.tencent.klevin.e.e.z;
import com.tencent.klevin.utils.g;
import com.tencent.klevin.utils.k;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.json.JSONException;
import org.json.JSONObject;

public class b {

    public class a implements f {
        public a() {
        }

        @Override // com.tencent.klevin.e.e.f
        public void onFailure(e eVar, IOException iOException) {
            iOException.printStackTrace();
        }

        /* JADX WARNING: Removed duplicated region for block: B:13:0x0030 A[Catch:{ JSONException -> 0x0016, IOException -> 0x0013 }] */
        /* JADX WARNING: Removed duplicated region for block: B:27:? A[RETURN, SYNTHETIC] */
        @Override // com.tencent.klevin.e.e.f
        public void onResponse(e eVar, c0 c0Var) {
            String str;
            if (c0Var != null) {
                try {
                    if (c0Var.l() != null) {
                        str = c0Var.l().q();
                        com.tencent.klevin.base.log.a.e("KLEVINSDK_config", "config: " + str);
                        if (str == null) {
                            JSONObject jSONObject = new JSONObject(str);
                            int optInt = jSONObject.optInt("code", -1);
                            if (optInt == 0) {
                                JSONObject optJSONObject = jSONObject.optJSONObject("data");
                                if (optJSONObject != null) {
                                    optJSONObject.getString("match_rule");
                                    optJSONObject.getString("confName");
                                    String string = optJSONObject.getString("conf");
                                    if (!TextUtils.isEmpty(string)) {
                                        string = b.this.a((b) string);
                                    }
                                    g.a(string.getBytes("UTF-8"), new File(com.tencent.klevin.b.m().f(), ".AdConfigCloud"), false);
                                    if (a.b().e(string)) {
                                        b.this.a();
                                        return;
                                    }
                                    return;
                                }
                                return;
                            }
                            com.tencent.klevin.base.log.a.b("KLEVINSDK_config", "code=" + optInt + ", msg=" + jSONObject.optString("msg"));
                            return;
                        }
                        return;
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    return;
                } catch (IOException e2) {
                    e2.printStackTrace();
                    return;
                }
            }
            str = null;
            com.tencent.klevin.base.log.a.e("KLEVINSDK_config", "config: " + str);
            if (str == null) {
            }
        }
    }

    public void a(Context context) {
        if (a(new File(com.tencent.klevin.b.m().f(), ".AdConfigCloud"))) {
            a();
            return;
        }
        File file = new File(com.tencent.klevin.b.m().f(), "AdConfig");
        if (!file.exists()) {
            a(context, file);
        }
        if (a(file)) {
            a();
        }
    }

    private boolean a(File file) {
        String e = g.e(file);
        if (TextUtils.isEmpty(e)) {
            return false;
        }
        return a.b().e(e);
    }

    /* JADX WARNING: Removed duplicated region for block: B:29:0x0046 A[SYNTHETIC, Splitter:B:29:0x0046] */
    /* JADX WARNING: Removed duplicated region for block: B:33:0x004d A[SYNTHETIC, Splitter:B:33:0x004d] */
    /* JADX WARNING: Removed duplicated region for block: B:40:0x0054 A[SYNTHETIC, Splitter:B:40:0x0054] */
    /* JADX WARNING: Removed duplicated region for block: B:51:? A[RETURN, SYNTHETIC] */
    private void a(Context context, File file) {
        InputStream inputStream;
        Throwable th;
        FileOutputStream fileOutputStream = null;
        try {
            inputStream = context.getResources().getAssets().open("klevin/AdConfig");
            try {
                if (g.a(file)) {
                    FileOutputStream fileOutputStream2 = new FileOutputStream(file);
                    try {
                        byte[] bArr = new byte[1024];
                        while (true) {
                            int read = inputStream.read(bArr);
                            if (read <= 0) {
                                break;
                            }
                            fileOutputStream2.write(bArr, 0, read);
                        }
                        fileOutputStream2.flush();
                        fileOutputStream = fileOutputStream2;
                    } catch (IOException unused) {
                        fileOutputStream = fileOutputStream2;
                        if (inputStream != null) {
                        }
                        if (fileOutputStream == null) {
                        }
                        fileOutputStream.close();
                    } catch (Throwable th2) {
                        th = th2;
                        fileOutputStream = fileOutputStream2;
                        if (inputStream != null) {
                        }
                        if (fileOutputStream != null) {
                        }
                        throw th;
                    }
                }
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (IOException unused2) {
                    }
                }
                if (fileOutputStream == null) {
                    return;
                }
            } catch (IOException unused3) {
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (IOException unused4) {
                    }
                }
                if (fileOutputStream == null) {
                    return;
                }
                fileOutputStream.close();
            } catch (Throwable th3) {
                th = th3;
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (IOException unused5) {
                    }
                }
                if (fileOutputStream != null) {
                    try {
                        fileOutputStream.close();
                    } catch (IOException unused6) {
                    }
                }
                throw th;
            }
        } catch (IOException unused7) {
            inputStream = null;
            if (inputStream != null) {
            }
            if (fileOutputStream == null) {
            }
            fileOutputStream.close();
        } catch (Throwable th4) {
            th = th4;
            inputStream = null;
            if (inputStream != null) {
            }
            if (fileOutputStream != null) {
            }
            throw th;
        }
        try {
            fileOutputStream.close();
        } catch (IOException unused8) {
        }
    }

    public void a(KlevinConfig klevinConfig) {
        String str = klevinConfig.isTestEnv() ? "https://test.api.yky.qq.com/" : "https://api.yky.qq.com/";
        z a2 = new z.a().b(str + "api/ad_conf/read?os=android&sdk_ver=" + BuildConfig.YOUKYYING_AD_VERSION + "&media_app_id=" + klevinConfig.getAppId()).b().a();
        b0.a(a2, -5);
        w.a(a2).a(new a());
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private String a(String str) {
        try {
            return new String(Base64.decode(str.getBytes(), 0));
        } catch (IllegalArgumentException unused) {
            return str;
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void a() {
        k.a(com.tencent.klevin.b.m().c()).a(new Intent("com.tencent.klevin.config.ACTION_CONFIG_UPDATE"));
    }
}