翰林优商.apk(点击下载) / DownloadService.java


package com.iBookStar.activityComm;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.widget.Toast;
import androidx.core.app.NotificationCompat;
import androidx.core.content.FileProvider;
import com.iBookStar.utils.s;
import com.mbridge.msdk.foundation.entity.CampaignEx;
import com.ss.android.downloadad.api.constant.AdBaseConstants;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class DownloadService extends Service {
    private static int d = 0;
    private static String e = ".ibnchannel";
    private NotificationManager a;
    private int b = 0;
    private Handler c = new a();

    class a extends Handler {
        a() {
        }

        public void handleMessage(Message message) {
            b bVar = (b) message.obj;
            int i = message.what;
            if (i == 0) {
                DownloadService.this.a.cancel(bVar.g);
                if (bVar.b.toLowerCase().endsWith(".ttf")) {
                    Toast.makeText(DownloadService.this, "字体下载完成,阅读时自动加载", 0).show();
                } else {
                    if (s.a(bVar.d)) {
                        try {
                            PackageInfo packageArchiveInfo = DownloadService.this.getPackageManager().getPackageArchiveInfo(bVar.b, 1);
                            if (packageArchiveInfo != null) {
                                String str = packageArchiveInfo.applicationInfo.packageName;
                                bVar.d = str;
                                com.iBookStar.c.b.a(bVar.q, str);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    try {
                        Intent intent = new Intent("android.intent.action.VIEW");
                        intent.setFlags(268435456);
                        if (Build.VERSION.SDK_INT < 24 || DownloadService.this.getApplicationInfo().targetSdkVersion < 24) {
                            intent.setDataAndType(Uri.fromFile(new File(bVar.b)), AdBaseConstants.MIME_APK);
                        } else {
                            DownloadService downloadService = DownloadService.this;
                            Uri uriForFile = FileProvider.getUriForFile(downloadService, DownloadService.this.getPackageName() + ".ymfileprovider", new File(bVar.b));
                            intent.addFlags(1);
                            intent.setDataAndType(uriForFile, AdBaseConstants.MIME_APK);
                        }
                        DownloadService.this.startActivity(intent);
                    } catch (Throwable th) {
                        th.printStackTrace();
                    }
                }
                com.iBookStar.c.b.a(bVar.q);
                DownloadService.this.a(bVar.d, bVar.i, bVar.k, bVar.m);
            } else if (i == 1) {
                Notification a2 = DownloadService.this.a((DownloadService) bVar.c, "下载失败");
                a2.flags = 16;
                DownloadService.this.a.notify(bVar.g, a2);
                com.iBookStar.c.b.b(bVar.q);
            }
            DownloadService.c(DownloadService.this);
            if (DownloadService.this.b <= 0) {
                DownloadService.this.stopSelf(bVar.n);
            }
        }
    }

    public static class b {
        public String a;
        public String b;
        public String c;
        public String d;
        public String e;
        public String f;
        public int g;
        public boolean h;
        public long i;
        public String j;
        public String k;
        public String l;
        public String m;
        public int n;
        public long o;
        public int p;
        public long q;
    }

    /* access modifiers changed from: package-private */
    public class c implements Runnable {
        b a;
        Message b;

        public c(b bVar) {
            this.b = DownloadService.this.c.obtainMessage();
            this.a = bVar;
        }

        /* JADX WARNING: Code restructure failed: missing block: B:100:0x0216, code lost:
            if (r5 <= 0) goto L_0x02c1;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:101:0x0218, code lost:
            r8.write(r9, 0, r5);
            r12 = r12 + ((long) r5);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:102:0x021e, code lost:
            if (r4 == 0) goto L_0x0229;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:104:0x0227, code lost:
            if (r12 <= ((long) ((r4 * 200) * 1024))) goto L_0x0212;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:105:0x0229, code lost:
            r4 = r4 + 1;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:106:0x0232, code lost:
            if (r12 <= 1048576) goto L_0x024c;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:107:0x0234, code lost:
            r14 = new java.lang.StringBuilder();
            r17 = r11;
            r14.append(r6.format((double) ((((float) r12) / 1024.0f) / 1024.0f)));
            r5 = "MB";
         */
        /* JADX WARNING: Code restructure failed: missing block: B:108:0x0248, code lost:
            r14.append(r5);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:109:0x024c, code lost:
            r17 = r11;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:110:0x0252, code lost:
            if (r12 <= 1024) goto L_0x0266;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:111:0x0254, code lost:
            r14 = new java.lang.StringBuilder();
            r14.append(r6.format((double) (((float) r12) / 1024.0f)));
            r5 = "KB";
         */
        /* JADX WARNING: Code restructure failed: missing block: B:112:0x0266, code lost:
            r14 = new java.lang.StringBuilder();
            r14.append(r12);
            r5 = "B";
         */
        /* JADX WARNING: Code restructure failed: missing block: B:113:0x0271, code lost:
            r5 = r14.toString();
            r22.c.a.notify(r22.a.g, r22.c.a((com.iBookStar.activityComm.DownloadService) r22.a.c, r20 + r5));
            java.lang.System.out.println("+++++++++++++++++++, str=" + r5);
            r20 = r20;
            r4 = r4;
            r11 = r17;
            r6 = r6;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:114:0x02c1, code lost:
            java.lang.System.out.println(r11);
            r4 = new java.io.File(r22.a.b);
            r4.delete();
            r0.renameTo(r4);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:115:0x02d9, code lost:
            java.lang.System.out.println("+++++++++++++++++++, close");
         */
        /* JADX WARNING: Code restructure failed: missing block: B:116:0x02de, code lost:
            if (r3 == null) goto L_0x02e3;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:117:0x02e0, code lost:
            r3.disconnect();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:118:0x02e3, code lost:
            if (r7 == null) goto L_0x02e8;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:119:0x02e5, code lost:
            r7.close();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:120:0x02e8, code lost:
            r8.close();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:121:0x02ec, code lost:
            return true;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:122:0x02ed, code lost:
            r0 = th;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:123:0x02ee, code lost:
            r16 = r8;
            r8 = r7;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:124:0x02f2, code lost:
            r0 = th;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:125:0x02f3, code lost:
            r8 = r7;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:30:0x00c2, code lost:
            if (r11 == 200) goto L_0x00cf;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:32:0x00c6, code lost:
            if (r11 != 206) goto L_0x00c9;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:34:0x00ce, code lost:
            throw new java.lang.Exception("fail!");
         */
        /* JADX WARNING: Code restructure failed: missing block: B:35:0x00cf, code lost:
            r8 = "正在下载: ";
            r11 = "+++++++++++++++++++, download finish!!";
            r15 = 0;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:36:0x00d8, code lost:
            if (r12 <= 0) goto L_0x01d7;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:37:0x00da, code lost:
            r18 = 0 + r6;
            r12 = r12 + r6;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:38:0x00e1, code lost:
            if (com.iBookStar.utils.s.c(r14) == false) goto L_0x00f7;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:40:0x00eb, code lost:
            if (r14.toLowerCase().contains("gzip") == false) goto L_0x00f7;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:41:0x00ed, code lost:
            r6 = new java.util.zip.GZIPInputStream(r3.getInputStream());
         */
        /* JADX WARNING: Code restructure failed: missing block: B:42:0x00f7, code lost:
            r6 = r3.getInputStream();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:45:0x00fd, code lost:
            if (r10 <= 0) goto L_0x0101;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:46:0x00ff, code lost:
            r9 = true;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:47:0x0101, code lost:
            r9 = false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:48:0x0102, code lost:
            r7 = new java.io.FileOutputStream(r0, r9);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:51:?, code lost:
            r9 = new byte[4096];
            r10 = 0;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:52:0x010a, code lost:
            r14 = r6.read(r9);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:53:0x010e, code lost:
            if (r14 <= 0) goto L_0x0182;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:54:0x0110, code lost:
            r7.write(r9, r15, r14);
            r4 = r18 + ((long) r14);
            r14 = (int) ((((float) r4) * 100.0f) / ((float) r12));
         */
        /* JADX WARNING: Code restructure failed: missing block: B:55:0x011e, code lost:
            if (r10 == 0) goto L_0x012b;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:57:0x0122, code lost:
            if ((r14 - 5) <= r10) goto L_0x0125;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:59:0x0125, code lost:
            r18 = r4;
            r4 = 0;
            r15 = 0;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:60:0x012b, code lost:
            r22.c.a.notify(r22.a.g, r22.c.a((com.iBookStar.activityComm.DownloadService) r22.a.c, r8 + r14 + "%"));
            java.lang.System.out.println("+++++++++++++++++++, percent=" + r14);
            r9 = r9;
            r10 = r10 + 5;
            r8 = r8;
            r4 = 0;
            r15 = 0;
            r18 = r4;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:62:0x0184, code lost:
            if (r12 <= r4) goto L_0x01b2;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:64:0x0188, code lost:
            if (r18 < r12) goto L_0x01b2;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:65:0x018a, code lost:
            java.lang.System.out.println(r11);
            r4 = new java.io.File(r22.a.b);
            r4.delete();
            r0.renameTo(r4);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:66:0x019e, code lost:
            java.lang.System.out.println("+++++++++++++++++++, close");
         */
        /* JADX WARNING: Code restructure failed: missing block: B:67:0x01a3, code lost:
            if (r3 == null) goto L_0x01a8;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:68:0x01a5, code lost:
            r3.disconnect();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:69:0x01a8, code lost:
            if (r6 == null) goto L_0x01ad;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:70:0x01aa, code lost:
            r6.close();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:71:0x01ad, code lost:
            r7.close();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:72:0x01b1, code lost:
            return true;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:73:0x01b2, code lost:
            java.lang.System.out.println("+++++++++++++++++++, download fail!!");
            java.lang.System.out.println("+++++++++++++++++++, close");
         */
        /* JADX WARNING: Code restructure failed: missing block: B:74:0x01be, code lost:
            if (r3 == null) goto L_0x01c3;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:75:0x01c0, code lost:
            r3.disconnect();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:76:0x01c3, code lost:
            if (r6 == null) goto L_0x01c8;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:77:0x01c5, code lost:
            r6.close();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:78:0x01c8, code lost:
            r7.close();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:79:0x01cc, code lost:
            return false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:80:0x01cd, code lost:
            r0 = th;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:81:0x01ce, code lost:
            r8 = r6;
            r16 = r7;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:82:0x01d3, code lost:
            r0 = th;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:83:0x01d4, code lost:
            r8 = r6;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:84:0x01d7, code lost:
            r20 = r8;
            r6 = java.text.NumberFormat.getInstance();
            r6.setMaximumFractionDigits(2);
            r6.setMinimumFractionDigits(2);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:85:0x01e8, code lost:
            if (com.iBookStar.utils.s.c(r14) == false) goto L_0x01fe;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:87:0x01f2, code lost:
            if (r14.toLowerCase().contains("gzip") == false) goto L_0x01fe;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:88:0x01f4, code lost:
            r7 = new java.util.zip.GZIPInputStream(r3.getInputStream());
         */
        /* JADX WARNING: Code restructure failed: missing block: B:89:0x01fe, code lost:
            r7 = r3.getInputStream();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:92:0x0204, code lost:
            if (r10 <= 0) goto L_0x0208;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:93:0x0206, code lost:
            r9 = true;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:94:0x0208, code lost:
            r9 = false;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:95:0x0209, code lost:
            r8 = new java.io.FileOutputStream(r0, r9);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:98:?, code lost:
            r9 = new byte[4096];
            r12 = 0;
            r4 = 0;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:99:0x0212, code lost:
            r5 = r7.read(r9);
         */
        /* JADX WARNING: Removed duplicated region for block: B:128:0x0301 A[LOOP:0: B:10:0x0046->B:128:0x0301, LOOP_END] */
        /* JADX WARNING: Removed duplicated region for block: B:138:0x031d  */
        /* JADX WARNING: Removed duplicated region for block: B:140:0x0322  */
        /* JADX WARNING: Removed duplicated region for block: B:142:0x0327  */
        /* JADX WARNING: Removed duplicated region for block: B:146:0x0308 A[SYNTHETIC] */
        /* JADX WARNING: Removed duplicated region for block: B:17:0x0060  */
        public boolean a() {
            long j;
            String str;
            HttpURLConnection httpURLConnection;
            FileOutputStream fileOutputStream;
            InputStream inputStream;
            HttpURLConnection httpURLConnection2;
            Throwable th;
            int i;
            int responseCode;
            String headerField;
            File file = new File(this.a.b + ".tmp");
            long j2 = 0;
            if (!file.exists()) {
                file.getParentFile().mkdirs();
            } else if (this.a.h) {
                j = file.length();
                str = this.a.a;
                httpURLConnection = null;
                while (true) {
                    try {
                        httpURLConnection2 = (HttpURLConnection) new URL(str).openConnection();
                        try {
                            httpURLConnection2.setInstanceFollowRedirects(true);
                            httpURLConnection2.setRequestProperty("Accept-Encoding", "gzip, deflate");
                            i = (j > 0 ? 1 : (j == 0 ? 0 : -1));
                            if (i > 0) {
                                httpURLConnection2.setRequestProperty("RANGE", "bytes=" + j + "-");
                            }
                            httpURLConnection2.setConnectTimeout(10000);
                            httpURLConnection2.setReadTimeout(20000);
                            responseCode = httpURLConnection2.getResponseCode();
                            long contentLength = (long) httpURLConnection2.getContentLength();
                            String headerField2 = httpURLConnection2.getHeaderField("Content-Encoding");
                            if (responseCode == 416 || i <= 0) {
                                if (responseCode == 302 && responseCode != 301) {
                                    break;
                                }
                                headerField = httpURLConnection2.getHeaderField("Location");
                                if (s.a(headerField)) {
                                    httpURLConnection = httpURLConnection2;
                                    str = headerField;
                                } else {
                                    throw new Exception("fail!");
                                }
                            } else {
                                File file2 = new File(this.a.b);
                                file2.delete();
                                file.renameTo(file2);
                                System.out.println("+++++++++++++++++++, close");
                                if (httpURLConnection2 != null) {
                                    httpURLConnection2.disconnect();
                                }
                                return true;
                            }
                        } catch (Throwable th2) {
                            th = th2;
                            httpURLConnection = httpURLConnection2;
                            httpURLConnection2 = httpURLConnection;
                            inputStream = null;
                            fileOutputStream = null;
                            System.out.println("+++++++++++++++++++, close");
                            if (httpURLConnection2 != null) {
                            }
                            if (inputStream != null) {
                            }
                            if (fileOutputStream != null) {
                            }
                            throw th;
                        }
                    } catch (Throwable th3) {
                        th = th3;
                        httpURLConnection2 = httpURLConnection;
                        inputStream = null;
                        fileOutputStream = null;
                        System.out.println("+++++++++++++++++++, close");
                        if (httpURLConnection2 != null) {
                            httpURLConnection2.disconnect();
                        }
                        if (inputStream != null) {
                            inputStream.close();
                        }
                        if (fileOutputStream != null) {
                            fileOutputStream.close();
                        }
                        throw th;
                    }
                }
            } else {
                file.delete();
            }
            file.createNewFile();
            j = 0;
            str = this.a.a;
            httpURLConnection = null;
            while (true) {
                httpURLConnection2 = (HttpURLConnection) new URL(str).openConnection();
                httpURLConnection2.setInstanceFollowRedirects(true);
                httpURLConnection2.setRequestProperty("Accept-Encoding", "gzip, deflate");
                i = (j > 0 ? 1 : (j == 0 ? 0 : -1));
                if (i > 0) {
                }
                httpURLConnection2.setConnectTimeout(10000);
                httpURLConnection2.setReadTimeout(20000);
                responseCode = httpURLConnection2.getResponseCode();
                long contentLength2 = (long) httpURLConnection2.getContentLength();
                String headerField22 = httpURLConnection2.getHeaderField("Content-Encoding");
                if (responseCode == 416) {
                }
                if (responseCode == 302) {
                }
                headerField = httpURLConnection2.getHeaderField("Location");
                if (s.a(headerField)) {
                }
                httpURLConnection = httpURLConnection2;
                str = headerField;
            }
        }

        public void run() {
            Handler handler;
            try {
                if (a()) {
                    this.b.what = 0;
                    this.b.obj = this.a;
                    handler = DownloadService.this.c;
                } else {
                    this.b.what = 1;
                    this.b.obj = this.a;
                    handler = DownloadService.this.c;
                }
                handler.sendMessage(this.b);
            } catch (Exception e) {
                e.printStackTrace();
                Message message = this.b;
                message.what = 1;
                message.obj = this.a;
                DownloadService.this.c.sendMessage(this.b);
            }
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private Notification a(String str, String str2) {
        NotificationCompat.Builder builder;
        if (Build.VERSION.SDK_INT >= 26) {
            builder = new NotificationCompat.Builder(this, getPackageName() + e).setSmallIcon(17301633).setWhen(System.currentTimeMillis()).setContentTitle(str).setContentText(str2).setDefaults(-1).setOnlyAlertOnce(true);
        } else {
            builder = new NotificationCompat.Builder(this).setSmallIcon(17301633).setContentTitle(str).setContentText(str2).setDefaults(-1).setOnlyAlertOnce(true).setWhen(System.currentTimeMillis());
            if (Build.VERSION.SDK_INT >= 24) {
                builder.setPriority(4);
            } else {
                builder.setPriority(1);
            }
        }
        return builder.build();
    }

    private void a() {
        com.iBookStar.c.b.a();
        this.a = (NotificationManager) getSystemService("notification");
        if (Build.VERSION.SDK_INT >= 26) {
            try {
                this.a.createNotificationChannel(new NotificationChannel(getPackageName() + e, "下载通知", 4));
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }
    }

    private void a(long j, String str, String str2) {
        Intent intent = new Intent(getPackageName() + ".pre.download");
        intent.setComponent(new ComponentName(this, AppInstallReceiver.class));
        intent.putExtra("id", j);
        if (s.c(str)) {
            intent.putExtra("cppd_report_urls", str);
        }
        if (s.c(str2)) {
            intent.putExtra("click_id", str2);
        }
        intent.setData(Uri.parse("package://www.ibookstar.com"));
        sendBroadcast(intent);
    }

    private void a(Intent intent, int i) {
        String str;
        boolean booleanExtra = intent.getBooleanExtra("continuedown", false);
        String stringExtra = intent.getStringExtra(CampaignEx.JSON_KEY_TITLE);
        if (s.a(stringExtra)) {
            stringExtra = "未知.apk";
        }
        String stringExtra2 = intent.getStringExtra("downurl");
        String b2 = b(intent.getStringExtra("path"), stringExtra);
        String stringExtra3 = intent.getStringExtra("app_package");
        String stringExtra4 = intent.getStringExtra("app_class");
        String stringExtra5 = intent.getStringExtra("app_action");
        long longExtra = intent.getLongExtra("reportid", 0);
        String stringExtra6 = intent.getStringExtra("cppd_report_urls");
        String stringExtra7 = intent.getStringExtra("cpd_report_urls");
        String stringExtra8 = intent.getStringExtra("cpa_report_urls");
        String stringExtra9 = intent.getStringExtra("click_id");
        if (com.iBookStar.c.b.a(stringExtra2)) {
            str = "正在后台下载,完成后主动通知";
        } else {
            b bVar = new b();
            bVar.h = booleanExtra;
            bVar.a = stringExtra2;
            int i2 = d;
            d = i2 + 1;
            bVar.g = i2;
            bVar.b = b2;
            bVar.c = stringExtra;
            bVar.i = longExtra;
            bVar.d = stringExtra3;
            bVar.e = stringExtra4;
            bVar.f = stringExtra5;
            bVar.n = i;
            bVar.j = stringExtra6;
            bVar.k = stringExtra7;
            bVar.l = stringExtra8;
            bVar.m = stringExtra9;
            long a2 = com.iBookStar.c.b.a(bVar);
            bVar.q = a2;
            if (a2 > 0) {
                this.b++;
                File file = new File(b2);
                if (!booleanExtra || !file.exists()) {
                    file.delete();
                    new Thread(new c(bVar)).start();
                    this.a.notify(bVar.g, a(stringExtra, "正在下载: 0"));
                } else {
                    Message obtainMessage = this.c.obtainMessage();
                    obtainMessage.what = 0;
                    obtainMessage.obj = bVar;
                    this.c.sendMessage(obtainMessage);
                }
                a(bVar.i, bVar.j, bVar.m);
                str = "开始后台下载,完成后主动通知";
            } else {
                return;
            }
        }
        Toast.makeText(this, str, 0).show();
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void a(String str, long j, String str2, String str3) {
        Intent intent = new Intent(getPackageName() + ".download.complete");
        intent.setComponent(new ComponentName(this, AppInstallReceiver.class));
        intent.putExtra("id", j);
        if (s.c(str)) {
            intent.putExtra("package", str);
        }
        if (s.c(str2)) {
            intent.putExtra("cpd_report_urls", str2);
        }
        if (s.c(str3)) {
            intent.putExtra("click_id", str3);
        }
        intent.setData(Uri.parse("package://www.ibookstar.com"));
        sendBroadcast(intent);
    }

    public static String b(String str, String str2) {
        StringBuilder sb;
        if (!str2.toLowerCase().endsWith(".apk")) {
            sb = new StringBuilder();
            sb.append(str);
            sb.append(File.separator);
            sb.append(str2);
            sb.append(".apk");
        } else {
            sb = new StringBuilder();
            sb.append(str);
            sb.append(File.separator);
            sb.append(str2);
        }
        return sb.toString();
    }

    static /* synthetic */ int c(DownloadService downloadService) {
        int i = downloadService.b;
        downloadService.b = i - 1;
        return i;
    }

    public IBinder onBind(Intent intent) {
        return null;
    }

    public void onCreate() {
        super.onCreate();
        a();
    }

    public void onDestroy() {
        super.onDestroy();
    }

    public void onStart(Intent intent, int i) {
        a(intent, i);
        super.onStart(intent, i);
    }

    public int onStartCommand(Intent intent, int i, int i2) {
        a(intent, i2);
        return 2;
    }
}