鸠摩搜书官方正版 v1.7版本的 MD5 值为:01c9a20d2c415de3233d7f691829edf5

以下内容为反编译后的 bs.java 源代码,内容仅作参考


package net.youmi.android;

import android.R;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

final class bs extends AsyncTask implements dj {
    private static Notification c;

    PendingIntent f531a;
    Context b;
    private String d;
    private String e;
    private long f = 0;
    private long g = 0;
    private bw h;

    public bs(Context context, bw bwVar) {
        this.b = context;
        this.h = bwVar;
        this.f531a = PendingIntent.getActivity(this.b, 99998, new Intent(), 268435456);
        Notification notification = new Notification();
        c = notification;
        notification.icon = R.drawable.stat_sys_download;
        c.setLatestEventInfo(this.b.getApplicationContext(), "下载更新", "开始下载", this.f531a);
    }

    @Override
    public File doInBackground(String... strArr) {
        InputStream inputStream;
        DefaultHttpClient defaultHttpClient;
        InputStream inputStream2;
        DefaultHttpClient defaultHttpClient2;
        Throwable th;
        HttpEntity entity;
        int i = 0;
        if (this.b == null) {
            publishProgress(-3);
            return null;
        }
        if (strArr == null) {
            publishProgress(-3);
            return null;
        }
        if (this.h == null) {
            publishProgress(-3);
            return null;
        }
        if (!aw.a(this.b)) {
            publishProgress(-3);
            return null;
        }
        if (!ba.a(this.b)) {
            publishProgress(-1);
            return null;
        }
        if (!aw.a(this.b, "android.permission.INTERNET")) {
            publishProgress(-3);
            return null;
        }
        if (!aq.b(this.b)) {
            publishProgress(-2);
            return null;
        }
        if (strArr.length <= 0) {
            return null;
        }
        this.d = strArr[0];
        this.e = this.d;
        try {
            try {
                publishProgress(-4);
                File file = new File(aj.e().a(l.b(this.h.c)));
                try {
                    if (file.exists()) {
                        file.delete();
                    }
                } catch (Exception e) {
                }
                defaultHttpClient2 = aq.a(this.b, this);
                try {
                    HttpGet httpGet = new HttpGet(this.d);
                    httpGet.setHeader("Referer", "http://sdk.youmi.net/?p=3&app=" + f.a(this.b) + "&chn=" + f.e(this.b));
                    HttpResponse execute = defaultHttpClient2.execute(httpGet);
                    if (execute.getStatusLine().getStatusCode() != 200 || (entity = execute.getEntity()) == null) {
                        if (defaultHttpClient2 == null) {
                            return null;
                        }
                        try {
                            defaultHttpClient2.getConnectionManager().shutdown();
                            return null;
                        } catch (Exception e2) {
                            return null;
                        }
                    }
                    this.f = entity.getContentLength();
                    FileOutputStream fileOutputStream = new FileOutputStream(file);
                    inputStream2 = entity.getContent();
                    try {
                        try {
                            byte[] bArr = new byte[1024];
                            while (true) {
                                int read = inputStream2.read(bArr);
                                if (read <= 0) {
                                    try {
                                        break;
                                    } catch (Exception e3) {
                                    }
                                } else {
                                    fileOutputStream.write(bArr, 0, read);
                                    i++;
                                    this.g += read;
                                    try {
                                        if (i % 30 == 0) {
                                            if (this.f <= 0) {
                                                publishProgress(80);
                                            } else if (this.g < this.f) {
                                                publishProgress(Integer.valueOf((int) ((this.g * 100) / this.f)));
                                            } else {
                                                publishProgress(99);
                                            }
                                        }
                                    } catch (Exception e4) {
                                    }
                                }
                            }
                            fileOutputStream.close();
                            if (defaultHttpClient2 != null) {
                                try {
                                    defaultHttpClient2.getConnectionManager().shutdown();
                                } catch (Exception e5) {
                                }
                            }
                            if (inputStream2 != null) {
                                try {
                                    inputStream2.close();
                                } catch (Exception e6) {
                                }
                            }
                            return file;
                        } catch (Throwable th2) {
                            th = th2;
                            if (defaultHttpClient2 != null) {
                                try {
                                    defaultHttpClient2.getConnectionManager().shutdown();
                                } catch (Exception e7) {
                                }
                            }
                            if (inputStream2 == null) {
                                throw th;
                            }
                            try {
                                inputStream2.close();
                                throw th;
                            } catch (Exception e8) {
                                throw th;
                            }
                        }
                    } catch (Exception e9) {
                        inputStream = inputStream2;
                        defaultHttpClient = defaultHttpClient2;
                        if (defaultHttpClient != null) {
                            try {
                                defaultHttpClient.getConnectionManager().shutdown();
                            } catch (Exception e10) {
                            }
                        }
                        if (inputStream == null) {
                            return null;
                        }
                        try {
                            inputStream.close();
                            return null;
                        } catch (Exception e11) {
                            return null;
                        }
                    }
                } catch (Exception e12) {
                    inputStream = null;
                    defaultHttpClient = defaultHttpClient2;
                } catch (Throwable th3) {
                    inputStream2 = null;
                    th = th3;
                }
            } catch (Throwable th4) {
                inputStream2 = null;
                defaultHttpClient2 = null;
                th = th4;
            }
        } catch (Exception e13) {
            inputStream = null;
            defaultHttpClient = null;
        }
    }

    private void a() {
        try {
            ((NotificationManager) this.b.getSystemService("notification")).notify(99998, c);
        } catch (Exception e) {
        }
    }

    private void a(int i) {
        try {
            c.tickerText = "下载进度:" + i + "%";
            c.flags = 2;
            c.setLatestEventInfo(this.b.getApplicationContext(), "下载更新", "下载进度:" + i + "%", this.f531a);
            a();
        } catch (Exception e) {
        }
    }

    private void b(String str) {
        try {
            c.tickerText = "下载更新失败";
            c.icon = R.drawable.stat_sys_download_done;
            c.flags = 16;
            c.setLatestEventInfo(this.b.getApplicationContext(), "下载更新", str, this.f531a);
            a();
        } catch (Exception e) {
        }
        be.a(this.b, "更新失败,请稍候重试!", 1);
    }

    @Override
    public final void a(String str) {
        this.e = str;
    }

    @Override
    protected final void onPostExecute(Object obj) {
        File file = (File) obj;
        super.onPostExecute(file);
        if (file == null || !file.exists()) {
            b("更新失败,请稍候重试");
            return;
        }
        if (file != null) {
            try {
                if (file.exists()) {
                    try {
                        ((NotificationManager) this.b.getSystemService("notification")).cancel(99998);
                    } catch (Exception e) {
                    }
                    try {
                        be.a(this.b, "下载成功,正在安装...", 0);
                    } catch (Exception e2) {
                    }
                    Context context = this.b;
                    bw bwVar = this.h;
                    ad.a(context, file);
                }
            } catch (Exception e3) {
            }
        }
    }

    @Override
    protected final void onProgressUpdate(Object... objArr) {
        Integer[] numArr = (Integer[]) objArr;
        super.onProgressUpdate(numArr);
        if (numArr != null) {
            try {
                if (numArr.length > 0) {
                    int intValue = numArr[0].intValue();
                    if (intValue == -1) {
                        b("存储卡不可用,无法更新下载,请检查存储卡设置!");
                    } else if (intValue == -2) {
                        b("网络错误,无法更新下载");
                    } else if (intValue == -3) {
                        b("下载过程遇到错误,取消本次下载");
                    } else if (intValue == -4) {
                        a(0);
                    } else if (intValue >= 0 && intValue <= 100) {
                        a(intValue);
                    }
                }
            } catch (Exception e) {
            }
        }
    }
}