LINE.apk(点击下载) / b.java


package com.linecorp.channel.activity.navigationbar;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.text.TextUtils;
import b.d;
import com.google.android.exoplayer.DefaultLoadControl;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import java.util.Objects;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.net.ssl.HttpsURLConnection;
import ln.r0;
import un3.e;

public class b extends AsyncTask<c, Void, Boolean> {

    /* renamed from: a  reason: collision with root package name */
    public c f32338a;

    /* renamed from: b  reason: collision with root package name */
    public a f32339b;

    /* renamed from: c  reason: collision with root package name */
    public em.b f32340c;

    public interface a {
    }

    public b(a aVar, em.b bVar) {
        this.f32339b = aVar;
        this.f32340c = bVar;
    }

    public final void a() throws Exception {
        if (isCancelled()) {
            throw new Exception();
        }
    }

    public final void b(InputStream inputStream, OutputStream outputStream) throws Exception {
        byte[] bArr = new byte[10240];
        while (true) {
            int read = inputStream.read(bArr, 0, 10240);
            if (read != -1) {
                a();
                outputStream.write(bArr, 0, read);
            } else {
                return;
            }
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r2v0, types: [java.net.HttpURLConnection] */
    /* JADX WARN: Type inference failed for: r2v1 */
    /* JADX WARN: Type inference failed for: r2v3 */
    /* JADX WARNING: Removed duplicated region for block: B:52:0x00ea A[Catch:{ all -> 0x00ee }] */
    /* JADX WARNING: Removed duplicated region for block: B:58:0x00f5 A[SYNTHETIC, Splitter:B:58:0x00f5] */
    /* JADX WARNING: Unknown variable types count: 1 */
    public final void c() throws Exception {
        Throwable th4;
        BufferedOutputStream bufferedOutputStream;
        Throwable th5;
        Exception e14;
        a();
        File d14 = this.f32338a.d();
        if (d14 != null) {
            ?? r24 = 0;
            try {
                StringBuilder sb4 = new StringBuilder();
                sb4.append(this.f32340c.h() ? "http://dl.appresource.line.beta.naver.jp/products/" : "https://scdn.line-apps.com/titlebar/");
                sb4.append(this.f32338a.f32342b);
                sb4.append("/");
                sb4.append(this.f32338a.f32343c);
                sb4.append("/");
                sb4.append("android.zip");
                String sb5 = sb4.toString();
                if (d14.exists()) {
                    if (!d14.delete()) {
                        throw new IOException("failed delete file. path=" + d14.getAbsolutePath());
                    }
                }
                bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(d14));
                try {
                    a();
                    HttpURLConnection d15 = d(sb5, 20000, 60000, this.f32340c.m(), null);
                    d15.connect();
                    int responseCode = d15.getResponseCode();
                    if (responseCode == 200) {
                        BufferedInputStream bufferedInputStream = new BufferedInputStream(d15.getInputStream());
                        try {
                            b(bufferedInputStream, bufferedOutputStream);
                        } finally {
                            bufferedInputStream.close();
                        }
                        try {
                            d15.disconnect();
                            bufferedOutputStream.flush();
                            try {
                                bufferedOutputStream.close();
                            } catch (IOException unused) {
                            }
                        } catch (Exception e15) {
                            e14 = e15;
                            try {
                                if (d14.exists()) {
                                }
                                throw e14;
                            } catch (Throwable th6) {
                                r24 = bufferedOutputStream;
                                th5 = th6;
                                th4 = th5;
                                bufferedOutputStream = r24;
                                if (bufferedOutputStream != null) {
                                }
                                throw th4;
                            }
                        } catch (Throwable th7) {
                            th4 = th7;
                            if (bufferedOutputStream != null) {
                            }
                            throw th4;
                        }
                    } else {
                        throw new IOException("ResponseCode is not OK. responseCode=" + responseCode);
                    }
                } catch (Exception e16) {
                    if (d14.exists()) {
                        d14.delete();
                    }
                    throw e16;
                } catch (Throwable th8) {
                    if (0 != 0) {
                        r24.disconnect();
                    }
                    throw th8;
                }
            } catch (Exception e17) {
                e14 = e17;
                bufferedOutputStream = null;
                if (d14.exists()) {
                    d14.delete();
                }
                throw e14;
            } catch (Throwable th9) {
                th5 = th9;
                th4 = th5;
                bufferedOutputStream = r24;
                if (bufferedOutputStream != null) {
                    try {
                        bufferedOutputStream.close();
                    } catch (IOException unused2) {
                    }
                }
                throw th4;
            }
        }
    }

    public final HttpURLConnection d(String str, int i14, int i15, String str2, Map<String, String> map) throws IOException {
        HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
        httpURLConnection.setConnectTimeout(i14);
        httpURLConnection.setReadTimeout(i15);
        httpURLConnection.setRequestProperty("User-Agent", str2);
        httpURLConnection.setRequestProperty("Accept-Encoding", "identity");
        if (httpURLConnection instanceof HttpsURLConnection) {
            try {
                ((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(fl.a.a(DefaultLoadControl.DEFAULT_HIGH_WATERMARK_MS));
            } catch (Exception unused) {
                throw new IOException("failed getSSLSocketFactory");
            }
        }
        httpURLConnection.setRequestMethod("GET");
        return httpURLConnection;
    }

    /* Return type fixed from 'java.lang.Object' to match base method */
    /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object[]] */
    @Override // android.os.AsyncTask
    public Boolean doInBackground(c[] cVarArr) {
        c cVar = cVarArr[0];
        this.f32338a = cVar;
        try {
            try {
                e.b(cVar.c(true));
            } catch (IOException | IllegalArgumentException unused) {
            }
            c();
            e();
            String str = null;
            this.f32338a.f(null, false);
            if (!TextUtils.isEmpty(this.f32338a.f32341a)) {
                c cVar2 = this.f32338a;
                String str2 = cVar2.f32341a;
                int i14 = cVar2.f32343c;
                File c14 = cVar2.c(false);
                if (c14 != null) {
                    File[] listFiles = c14.listFiles();
                    StringBuilder sb4 = new StringBuilder();
                    for (File file : listFiles) {
                        if (sb4.length() > 0) {
                            sb4.append(",");
                        }
                        sb4.append(file.getName());
                    }
                    str = sb4.toString();
                }
                SQLiteDatabase writableDatabase = lm.b.f107386b.f107387a.getWritableDatabase();
                ContentValues contentValues = new ContentValues();
                contentValues.put("header_version", Integer.valueOf(i14));
                contentValues.put("header_files", str);
                writableDatabase.update("channel", contentValues, "id=?", new String[]{str2});
            }
            return Boolean.TRUE;
        } catch (Exception unused2) {
            return Boolean.FALSE;
        }
    }

    /* JADX WARNING: Can't wrap try/catch for region: R(3:11|12|(3:14|(2:16|48)(4:17|18|19|49)|47)(4:20|21|22|23)) */
    /* JADX WARNING: Code restructure failed: missing block: B:27:0x0061, code lost:
        r1 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:28:0x0062, code lost:
        r2 = r1;
        r1 = r2;
     */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Missing exception handler attribute for start block: B:11:0x0031 */
    /* JADX WARNING: Removed duplicated region for block: B:11:0x0031 A[LOOP:0: B:11:0x0031->B:47:0x0031, LOOP_START, SYNTHETIC, Splitter:B:11:0x0031] */
    public final void e() throws Exception {
        a();
        File d14 = this.f32338a.d();
        if (d14 == null || !d14.exists()) {
            throw new IOException(r0.a(d.a("not exists file.(path="), d14 != null ? d14.getAbsolutePath() : "null", ")"));
        } else if (!d14.isFile()) {
            StringBuilder a14 = d.a("not available file.(path=");
            a14.append(d14.getAbsolutePath());
            a14.append(")");
            throw new IOException(a14.toString());
        } else if (d14.canRead()) {
            hl.a aVar = null;
            try {
                hl.a aVar2 = new hl.a(new BufferedInputStream(new FileInputStream(d14)));
                while (true) {
                    ZipEntry nextEntry = aVar2.getNextEntry();
                    if (nextEntry != null) {
                        a();
                        if (!nextEntry.isDirectory()) {
                            f(new File(this.f32338a.c(true), nextEntry.getName()), aVar2);
                        }
                    } else {
                        try {
                            aVar2.close();
                            return;
                        } finally {
                            d14.delete();
                        }
                    }
                }
            } catch (Throwable th4) {
                Throwable th5 = th4;
                try {
                    aVar.close();
                    throw th5;
                } finally {
                    d14.delete();
                }
            }
        } else {
            StringBuilder a15 = d.a("cannot read file.(path=");
            a15.append(d14.getAbsolutePath());
            a15.append(")");
            throw new IOException(a15.toString());
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:23:0x0048  */
    public final void f(File file, ZipInputStream zipInputStream) throws Exception {
        Throwable th4;
        FileOutputStream fileOutputStream;
        IOException e14;
        if (!file.exists() || file.delete()) {
            FileOutputStream fileOutputStream2 = null;
            try {
                fileOutputStream = new FileOutputStream(file);
                try {
                    b(zipInputStream, fileOutputStream);
                    fileOutputStream.flush();
                    fileOutputStream.close();
                    zipInputStream.closeEntry();
                } catch (IOException e15) {
                    e14 = e15;
                    try {
                        file.delete();
                        throw e14;
                    } catch (Throwable th5) {
                        th4 = th5;
                        fileOutputStream2 = fileOutputStream;
                        if (fileOutputStream2 != null) {
                            fileOutputStream2.close();
                        }
                        zipInputStream.closeEntry();
                        throw th4;
                    }
                }
            } catch (IOException e16) {
                fileOutputStream = null;
                e14 = e16;
                file.delete();
                throw e14;
            } catch (Throwable th6) {
                th4 = th6;
                if (fileOutputStream2 != null) {
                }
                zipInputStream.closeEntry();
                throw th4;
            }
        } else {
            StringBuilder a14 = d.a("failed delete file. path=");
            a14.append(file.getAbsolutePath());
            throw new IOException(a14.toString());
        }
    }

    public void onCancelled() {
        Objects.requireNonNull(this.f32339b);
    }

    /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
    @Override // android.os.AsyncTask
    public void onPostExecute(Boolean bool) {
        a aVar = this.f32339b;
        boolean booleanValue = bool.booleanValue();
        a aVar2 = (a) aVar;
        Objects.requireNonNull(aVar2);
        if (booleanValue) {
            aVar2.e(booleanValue);
        }
    }
}