iKredit v1.2.0.3版本的 MD5 值为:2c00c5c79eecbd6be4c3c546c28d778d

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


package com.ikreditgp.dialog;

import android.R;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.os.Process;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SeekBar;
import android.widget.TextView;
import androidx.core.content.FileProvider;
import androidx.exifinterface.media.ExifInterface;
import com.appsflyer.share.Constants;
import com.ikreditgp.UpdateContentAdapter;
import com.ikreditgp.Utils.AndroidUtils;
import com.ikreditgp.Utils.ButtonUtils;
import com.ikreditgp.Utils.FileUtil;
import com.ikreditgp.Utils.LogMgr;
import com.ikreditgp.Utils.StoreUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;

public class UpdateDg extends BaseDialog {
    private static final int DOWN_OVER = 2;
    private static final int DOWN_TOAST = 3;
    private static final String DOWN_TOAST_CONTENT = "toast_content";
    private static final int DOWN_UPDATE = 1;
    private UpdateContentAdapter adapter;
    private File apkFile;
    private int apkSize;
    private String downloadUrl;
    private boolean interceptFlag;
    private String isNeedMust;
    private ListView lv_dg_update;
    private Context mContext;
    private Handler mHandler;
    private String newestVersion;
    private int progress;
    private SeekBar seekbar_find;
    private SeekBar seekbar_find_;
    private TextView tv_dg_update_close;
    private TextView tv_dg_update_update;
    private TextView tv_dg_update_version;

    public UpdateDg(Context context, String str, ArrayList<CharSequence> arrayList, String str2, String str3, int i, int i2) {
        super(context, i2);
        this.interceptFlag = false;
        this.mHandler = new Handler() {
            @Override
            public void handleMessage(Message message) {
                int i3 = message.what;
                if (i3 == 1) {
                    if (UpdateDg.this.progress > 100) {
                        UpdateDg.this.progress = 100;
                    }
                    UpdateDg.this.seekbar_find.setProgress(UpdateDg.this.progress);
                } else if (i3 == 2) {
                    UpdateDg updateDg = UpdateDg.this;
                    updateDg.finishCustomNotify(updateDg.apkFile);
                } else {
                    if (i3 != 3) {
                        return;
                    }
                    Bundle data = message.getData();
                    if (data != null && data.containsKey(UpdateDg.DOWN_TOAST_CONTENT)) {
                        UpdateDg.this.showToast(data.getString(UpdateDg.DOWN_TOAST_CONTENT));
                    }
                    UpdateDg.this.cancel();
                }
            }
        };
        this.mContext = context;
        this.isNeedMust = str3;
        this.downloadUrl = str2;
        this.newestVersion = str;
        this.apkSize = i;
        initView(context, arrayList);
    }

    private void initView(final Context context, ArrayList<CharSequence> arrayList) {
        if (getWindow() != null) {
            getWindow().setBackgroundDrawableResource(R.color.transparent);
            setCancelable(false);
            View inflate = LayoutInflater.from(context).inflate(com.ikreditgp.R.layout.dg_update, (ViewGroup) null);
            this.tv_dg_update_version = (TextView) inflate.findViewById(com.ikreditgp.R.id.tv_dg_update_version);
            SeekBar seekBar = (SeekBar) inflate.findViewById(com.ikreditgp.R.id.seekbar_find);
            this.seekbar_find = seekBar;
            seekBar.setEnabled(false);
            this.tv_dg_update_update = (TextView) inflate.findViewById(com.ikreditgp.R.id.tv_dg_update_update);
            this.tv_dg_update_close = (TextView) inflate.findViewById(com.ikreditgp.R.id.tv_dg_update_close);
            this.seekbar_find_ = (SeekBar) inflate.findViewById(com.ikreditgp.R.id.seekbar_find_);
            this.lv_dg_update = (ListView) inflate.findViewById(com.ikreditgp.R.id.lv_dg_update);
            this.tv_dg_update_version.setText(ExifInterface.GPS_MEASUREMENT_INTERRUPTED + this.newestVersion);
            UpdateContentAdapter updateContentAdapter = new UpdateContentAdapter(context, arrayList);
            this.adapter = updateContentAdapter;
            this.lv_dg_update.setAdapter((ListAdapter) updateContentAdapter);
            AndroidUtils.setListViewHeightBasedOnChildren(this.lv_dg_update);
            if ("1".equals(this.isNeedMust)) {
                this.tv_dg_update_close.setVisibility(8);
                this.seekbar_find_.setVisibility(8);
            }
            this.tv_dg_update_close.setOnClickListener(new View.OnClickListener() {
                @Override
                public final void onClick(View view) {
                    UpdateDg.this.lambda$initView$0$UpdateDg(context, view);
                }
            });
            this.tv_dg_update_update.setOnClickListener(new View.OnClickListener() {
                @Override
                public final void onClick(View view) {
                    UpdateDg.this.lambda$initView$1$UpdateDg(context, view);
                }
            });
            setContentView(inflate);
        }
    }

    public void lambda$initView$0$UpdateDg(Context context, View view) {
        this.interceptFlag = true;
        if ("1".equals(this.isNeedMust)) {
            exitApp();
        } else {
            cancel();
            ((Activity) context).finish();
        }
    }

    public void lambda$initView$1$UpdateDg(Context context, View view) {
        if (ButtonUtils.isFastDoubleClick()) {
            return;
        }
        String packageName = this.mContext.getPackageName();
        if (StoreUtils.isHasGoogleStore(this.mContext)) {
            StoreUtils.launchAppDetail(this.mContext, packageName, StoreUtils.GooglePlayStorePackageName);
        } else {
            this.mContext.startActivity(new Intent("android.intent.action.VIEW", Uri.parse("https://play.google.com/store/apps/details?id=" + packageName)));
        }
        if ("1".equals(this.isNeedMust)) {
            return;
        }
        cancel();
        ((Activity) context).finish();
    }

    public void exitApp() {
        if (Build.VERSION.SDK_INT <= 7) {
            System.out.println("   version  < 7");
            ((ActivityManager) this.mContext.getSystemService("activity")).restartPackage(this.mContext.getPackageName());
        } else {
            ((ActivityManager) this.mContext.getSystemService("activity")).killBackgroundProcesses(this.mContext.getPackageName());
        }
        Process.killProcess(Process.myPid());
    }

    class UpgradeTask extends AsyncTask<String, Integer, String> {
        private String apkFileName;

        @Override
        public void onPostExecute(String str) {
        }

        UpgradeTask() {
        }

        public String getRedirectUrl(String str) {
            URL url;
            HttpURLConnection httpURLConnection = null;
            try {
                url = new URL(str);
            } catch (MalformedURLException e) {
                e.printStackTrace();
                url = null;
            }
            try {
                httpURLConnection = (HttpURLConnection) url.openConnection();
            } catch (IOException e2) {
                e2.printStackTrace();
            }
            try {
                if (httpURLConnection.getResponseCode() != 302 && httpURLConnection.getResponseCode() != 301) {
                    return str;
                }
                return httpURLConnection.getHeaderField("location");
            } catch (IOException e3) {
                e3.printStackTrace();
                return "";
            }
        }

        @Override
        public String doInBackground(String... strArr) {
            FileOutputStream fileOutputStream;
            InputStream inputStream;
            InputStream inputStream2 = null;
            try {
                HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(getRedirectUrl(strArr[0])).openConnection();
                int contentLength = httpURLConnection.getContentLength();
                if (httpURLConnection.getResponseCode() != 200) {
                    LogMgr.showErrorLog("location=" + httpURLConnection.getHeaderField("location"));
                    LogMgr.showErrorLog("普通版更新apk,异步操作UpgradeTask网络连接异常!  urlConn.getResponseCode()==" + httpURLConnection.getResponseCode());
                    UpdateDg.this.showToast("network error!");
                    return null;
                }
                if (!"mounted".equals(Environment.getExternalStorageState())) {
                    UpdateDg.this.showToast("SDcard wrong!");
                    return null;
                }
                if (FileUtil.getAbsolutePath().getFreeSpace() < contentLength) {
                    UpdateDg.this.showToast("SDcard's room is over!");
                    return null;
                }
                this.apkFileName = FileUtil.getAbsolutePath() + Constants.URL_PATH_DELIMITER + UpdateDg.this.mContext.getString(com.ikreditgp.R.string.app_name) + ".apk";
                UpdateDg.this.apkFile = new File(this.apkFileName);
                fileOutputStream = new FileOutputStream(UpdateDg.this.apkFile);
                try {
                    if (!UpdateDg.this.apkFile.getParentFile().exists()) {
                        UpdateDg.this.apkFile.getParentFile().mkdirs();
                    }
                    InputStream inputStream3 = httpURLConnection.getInputStream();
                    try {
                        byte[] bArr = new byte[1024];
                        int i = 0;
                        while (true) {
                            int read = inputStream3.read(bArr);
                            i += read;
                            UpdateDg updateDg = UpdateDg.this;
                            double d = i;
                            Double.isNaN(d);
                            double d2 = contentLength;
                            Double.isNaN(d2);
                            updateDg.progress = (int) (((d * 1.0d) / d2) * 100.0d);
                            UpdateDg.this.mHandler.sendEmptyMessage(1);
                            if (read <= 0) {
                                UpdateDg.this.mHandler.sendEmptyMessage(2);
                                break;
                            }
                            fileOutputStream.write(bArr, 0, read);
                            if (UpdateDg.this.interceptFlag) {
                                break;
                            }
                        }
                        fileOutputStream.close();
                        inputStream3.close();
                        if (inputStream3 != null) {
                            try {
                                inputStream3.close();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                        try {
                            fileOutputStream.close();
                        } catch (IOException e2) {
                            e2.printStackTrace();
                        }
                        return null;
                    } catch (IOException e3) {
                        inputStream = inputStream3;
                        e = e3;
                        try {
                            e.printStackTrace();
                            if (inputStream != null) {
                                try {
                                    inputStream.close();
                                } catch (IOException e4) {
                                    e4.printStackTrace();
                                }
                            }
                            if (fileOutputStream != null) {
                                try {
                                    fileOutputStream.close();
                                } catch (IOException e5) {
                                    e5.printStackTrace();
                                }
                            }
                            return null;
                        } catch (Throwable th) {
                            th = th;
                            inputStream2 = inputStream;
                            if (inputStream2 != null) {
                                try {
                                    inputStream2.close();
                                } catch (IOException e6) {
                                    e6.printStackTrace();
                                }
                            }
                            if (fileOutputStream != null) {
                                throw th;
                            }
                            try {
                                fileOutputStream.close();
                                throw th;
                            } catch (IOException e7) {
                                e7.printStackTrace();
                                throw th;
                            }
                        }
                    } catch (Throwable th2) {
                        inputStream2 = inputStream3;
                        th = th2;
                        if (inputStream2 != null) {
                        }
                        if (fileOutputStream != null) {
                        }
                    }
                } catch (IOException e8) {
                    e = e8;
                    inputStream = null;
                } catch (Throwable th3) {
                    th = th3;
                }
            } catch (IOException e9) {
                e = e9;
                inputStream = null;
                fileOutputStream = null;
            } catch (Throwable th4) {
                th = th4;
                fileOutputStream = null;
            }
        }
    }

    public void showToast(String str) {
        if (this.mHandler == null) {
            return;
        }
        Message obtain = Message.obtain();
        obtain.what = 3;
        Bundle bundle = new Bundle();
        bundle.putString(DOWN_TOAST_CONTENT, str);
        obtain.setData(bundle);
        this.mHandler.sendMessage(obtain);
    }

    public void finishCustomNotify(File file) {
        if (!"1".equals(this.isNeedMust)) {
            cancel();
        }
        Intent intent = new Intent("android.intent.action.VIEW");
        if (Build.VERSION.SDK_INT >= 24) {
            intent.setFlags(268435456);
            intent.addFlags(1);
            intent.setDataAndType(FileProvider.getUriForFile(this.mContext, "com.ikreditgp.provider", file), "application/vnd.android.package-archive");
        } else {
            intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
            intent.setFlags(268435456);
        }
        this.mContext.startActivity(intent);
    }

    @Override
    public void goShow() {
        show();
    }
}