导航菜单

页面标题

页面副标题

Spermatid Pro v6.4.3 - DownloadDialogActivity.java 源代码

正在查看: Spermatid Pro v6.4.3 应用的 DownloadDialogActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.octopus.ad.internal.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DownloadManager;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.core.content.FileProvider;
import com.octopus.ad.R;
import com.octopus.ad.internal.utilities.DownloadFactory;
import com.octopus.ad.internal.utilities.DownloadFactory$Download;
import com.octopus.ad.internal.utilities.ImageManager;
import com.octopus.ad.internal.utilities.ReportEventUtil;
import com.octopus.ad.model.ComplianceInfo;
import com.octopus.ad.utils.b;
import com.octopus.ad.utils.b.d;
import com.octopus.ad.utils.b.g;
import com.octopus.ad.utils.c;
import com.octopus.ad.widget.FlickerProgressBar;
import java.io.File;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.HashMap;

public class DownloadDialogActivity extends Activity {
    private static final String a = "DownloadDialogActivity";
    private static DownloadFactory$Download h;
    private long b;

    private String f1713c;

    private DownloadManager f1714d;
    private a e;
    private b f;
    private FlickerProgressBar g;
    private HashMap<String, b> i;
    private HashMap<String, Boolean> j;
    private HashMap<Long, String> k;
    private c l;

    private ComplianceInfo f1715m;

    private boolean f1716n;

    public class a extends ContentObserver {
        public a(Handler handler) {
            super(handler);
        }

        @Override
        public void onChange(boolean z) {
            super.onChange(z);
            int[] iArr = {0, 0, 0};
            Cursor cursor = null;
            try {
                try {
                    cursor = DownloadDialogActivity.this.f1714d.query(new DownloadManager.Query().setFilterById(DownloadDialogActivity.this.b));
                    if (cursor != null && cursor.moveToFirst()) {
                        iArr[0] = cursor.getInt(cursor.getColumnIndexOrThrow("bytes_so_far"));
                        iArr[1] = cursor.getInt(cursor.getColumnIndexOrThrow("total_size"));
                        iArr[2] = cursor.getInt(cursor.getColumnIndex("status"));
                        g.a(DownloadDialogActivity.a, "progress:" + iArr[0] + "/" + iArr[1]);
                        if (iArr[1] > 0) {
                            DecimalFormat decimalFormat = new DecimalFormat("#.#");
                            decimalFormat.setRoundingMode(RoundingMode.DOWN);
                            DownloadDialogActivity.this.g.setProgress(Float.parseFloat(decimalFormat.format((iArr[0] * 100.0f) / iArr[1])));
                        }
                        int i = cursor.getInt(cursor.getColumnIndex("status"));
                        g.a(DownloadDialogActivity.a, "onChange status:" + i);
                        DownloadDialogActivity.this.g.setStatus(i);
                        if (1 == i) {
                            DownloadDialogActivity.this.c(c.a(DownloadDialogActivity.this).a());
                        }
                    }
                    if (cursor == null) {
                        return;
                    }
                } catch (Exception e) {
                    g.a("OctopusAd", "An Exception Caught", e);
                    if (cursor == null) {
                        return;
                    }
                }
                cursor.close();
            } catch (Throwable th) {
                if (cursor != null) {
                    cursor.close();
                }
                throw th;
            }
        }
    }

    private void g() {
        if (this.e != null) {
            getContentResolver().unregisterContentObserver(this.e);
            this.e = null;
            g.a(a, "unregisterContentObserver()");
        }
        b bVar = this.f;
        if (bVar != null) {
            unregisterReceiver(bVar);
            this.f = null;
            g.a(a, "unregisterReceiver()");
        }
    }

    private void h() {
        DownloadFactory$Download downloadFactory$Download = h;
        if (downloadFactory$Download != null) {
            downloadFactory$Download.destroy();
        }
        if (this.j != null) {
            this.j = null;
        }
        if (this.i != null) {
            this.i = null;
        }
        if (this.k != null) {
            this.k = null;
        }
        c.a(this).f();
        g.a(a, "releaseResources()");
    }

    @Override
    public void onCreate(@Nullable Bundle bundle) {
        super.onCreate(bundle);
        c a2 = c.a(this);
        this.l = a2;
        this.f1715m = a2.b();
        b();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        g.a(a, "DownloadService onDestroy()");
        c cVar = this.l;
        if (cVar != null) {
            cVar.d();
        }
        try {
            g();
            h();
        } catch (Throwable th) {
            g.a("OctopusAd", "A Throwable Caught", th);
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        f();
    }

    private void b() {
        try {
            if (this.l != null && this.f1715m != null) {
                AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.OctopusAlertDialogStyle);
                View inflate = LayoutInflater.from(this).inflate(R.layout.oct_dialog_download, (ViewGroup) null);
                builder.setView(inflate);
                AlertDialog create = builder.create();
                create.setCancelable(false);
                create.setCanceledOnTouchOutside(false);
                ImageView imageView = (ImageView) inflate.findViewById(R.id.iv_app_icon);
                TextView textView = (TextView) inflate.findViewById(R.id.tv_app_name);
                TextView textView2 = (TextView) inflate.findViewById(R.id.tv_app_version);
                TextView textView3 = (TextView) inflate.findViewById(R.id.tv_app_developer);
                TextView textView4 = (TextView) inflate.findViewById(R.id.tv_app_permission);
                TextView textView5 = (TextView) inflate.findViewById(R.id.tv_app_privacy);
                TextView textView6 = (TextView) inflate.findViewById(R.id.tv_app_function);
                this.g = inflate.findViewById(R.id.btn_download);
                ImageView imageView2 = (ImageView) inflate.findViewById(R.id.iv_close);
                ImageManager.with((Context) null).load(this.f1715m.getAppIconURL()).into(imageView);
                textView.setText(this.f1715m.getAppName());
                textView2.setText(String.format("版本号:%s", this.f1715m.getAppVersion()));
                textView3.setText(String.format("开发者:%s", this.f1715m.getDeveloperName()));
                b a2 = c.a(this).a();
                if (a2 != null && new File(a2.d(), a2.b()).exists()) {
                    this.g.setProgress(100.0f);
                    this.g.setStatus(8);
                }
                textView4.setPaintFlags(textView4.getPaintFlags() | 8);
                textView5.setPaintFlags(textView5.getPaintFlags() | 8);
                textView6.setPaintFlags(textView6.getPaintFlags() | 8);
                textView4.setOnClickListener(new 1(this));
                textView5.setOnClickListener(new 2(this));
                textView6.setOnClickListener(new 3(this));
                this.g.setOnClickListener(new 4(this));
                imageView2.setOnClickListener(new 5(this, create));
                create.show();
            }
        } catch (Exception e) {
            g.a("OctopusAd", "An Exception Caught", e);
        }
    }

    public void c() {
        Log.e(a, "startDownload");
        this.f1714d = (DownloadManager) getSystemService("download");
        this.e = new a(new Handler());
        this.f = new b(this, (1) null);
        this.i = new HashMap<>();
        this.j = new HashMap<>();
        this.k = new HashMap<>();
        d();
        e();
    }

    @SuppressLint({"WrongConstant", "UnspecifiedRegisterReceiverFlag"})
    private void d() {
        try {
            getContentResolver().registerContentObserver(Uri.parse("content://downloads/my_downloads"), true, this.e);
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction("android.intent.action.DOWNLOAD_COMPLETE");
            if (Build.VERSION.SDK_INT >= 26) {
                registerReceiver(this.f, intentFilter, 2);
            } else {
                registerReceiver(this.f, intentFilter);
            }
        } catch (Exception e) {
            g.a("OctopusAd", "An Exception Caught", e);
        }
    }

    private void e() {
        b a2 = c.a(this).a();
        if (a2 == null) {
            return;
        }
        HashMap<String, b> hashMap = this.i;
        if (hashMap != null) {
            hashMap.put(a2.c(), a2);
        }
        HashMap<String, Boolean> hashMap2 = this.j;
        if (hashMap2 != null && hashMap2.get(a2.c()) == null) {
            g.a(a, "not have package status...");
            this.j.put(a2.c(), Boolean.FALSE);
        }
        if (TextUtils.isEmpty(a2.g())) {
            this.f1713c = getPackageName() + ".octopus.provider";
        } else {
            this.f1713c = a2.g();
        }
        d.a(a2.d());
        a(a2);
    }

    private void f() {
        try {
            HashMap<Long, String> hashMap = this.k;
            if (hashMap == null || this.i == null) {
                return;
            }
            String str = hashMap.get(Long.valueOf(this.b));
            if (d.a(this, str)) {
                b bVar = this.i.get(str);
                if (bVar != null) {
                    File file = new File(bVar.d(), bVar.b());
                    if (file.exists() && file.delete()) {
                        g.a(a, "apkFile delete success");
                    }
                    c.a(this).b(true);
                    if (bVar.h() != null) {
                        ReportEventUtil.report(bVar.h().d());
                    }
                    this.i.remove(str);
                }
                HashMap<String, b> hashMap2 = this.i;
                if (hashMap2 == null || !hashMap2.isEmpty()) {
                    return;
                }
                finish();
            }
        } catch (Exception e) {
            g.a("OctopusAd", "An Exception Caught", e);
        }
    }

    private synchronized void a(b bVar) {
        Uri uriForFile;
        HashMap<String, Boolean> hashMap = this.j;
        if (hashMap != null && hashMap.get(bVar.c()) != null && Boolean.TRUE.equals(this.j.get(bVar.c()))) {
            g.a(a, "downloading..." + bVar.c() + "...please not repeat click");
            Toast.makeText(getApplicationContext(), "正在下载…请勿重复点击", 0).show();
            return;
        }
        File file = new File(bVar.d(), bVar.b());
        if (file.exists()) {
            try {
                c.a(this).b(false);
                Intent intent = new Intent("android.intent.action.VIEW");
                intent.addFlags(268435456);
                intent.setAction("android.intent.action.VIEW");
                if (Build.VERSION.SDK_INT < 24) {
                    uriForFile = Uri.fromFile(file);
                } else {
                    uriForFile = FileProvider.getUriForFile(this, bVar.g(), file);
                    intent.addFlags(3);
                }
                if (uriForFile != null) {
                    g.a(a, "uri......" + uriForFile);
                    intent.setDataAndType(uriForFile, "application/vnd.android.package-archive");
                    startActivity(intent);
                    b(bVar);
                }
            } catch (Exception e) {
                g.c(a, "apkFile.exists():" + e);
            }
        }
        try {
            if (this.f1716n) {
                a(Long.valueOf(this.b));
                this.g.b();
                this.f1716n = false;
                Toast.makeText(getApplicationContext(), "已取消下载", 0).show();
            } else {
                this.f1716n = true;
                DownloadManager.Request request = new DownloadManager.Request(Uri.parse(bVar.a()));
                request.setTitle(bVar.e());
                request.setDescription(bVar.f());
                request.setNotificationVisibility(1);
                request.setDestinationUri(Uri.fromFile(file));
                request.setMimeType("application/vnd.android.package-archive");
                this.b = this.f1714d.enqueue(request);
                String str = a;
                g.b(str, "mReqId:" + this.b);
                HashMap<Long, String> hashMap2 = this.k;
                if (hashMap2 != null) {
                    hashMap2.put(Long.valueOf(this.b), bVar.c());
                }
                HashMap<String, Boolean> hashMap3 = this.j;
                if (hashMap3 != null) {
                    hashMap3.put(bVar.c(), Boolean.TRUE);
                }
                Toast.makeText(getApplicationContext(), "已开始下载…", 0).show();
                g.a(str, "BEGIN_DOWNLOAD!");
                if (bVar.h() != null) {
                    ReportEventUtil.report(bVar.h().a());
                }
            }
        } catch (Exception e2) {
            g.a(a, "DownloadManager download fail:" + e2);
            try {
                if (!TextUtils.isEmpty(bVar.a()) && bVar.a().contains("http")) {
                    HashMap<String, Boolean> hashMap4 = this.j;
                    if (hashMap4 != null) {
                        hashMap4.put(bVar.c(), Boolean.TRUE);
                    }
                    Intent intent2 = new Intent();
                    intent2.setAction("android.intent.action.VIEW");
                    intent2.setData(Uri.parse(bVar.a()));
                    intent2.setFlags(268435456);
                    startActivity(intent2);
                }
            } catch (Exception e3) {
                g.c(a, "skip browser fail:" + e3);
            }
        }
    }

    public void c(b bVar) {
        if (bVar == null) {
            return;
        }
        g.a(a, "--appUpdate downloadApk start--");
        DownloadFactory$Download create = DownloadFactory.create();
        h = create;
        create.register(new 6(this, bVar));
        h.start(new DownloadFactory.Request(bVar.a(), bVar.d(), bVar.b()));
    }

    private void b(b bVar) {
        g.a(a, "BEGIN_INSTALL!");
        if (bVar.h() != null) {
            ReportEventUtil.report(bVar.h().c());
        }
    }

    private static File b(Context context, long j) {
        Cursor query;
        String path;
        DownloadManager downloadManager = (DownloadManager) context.getSystemService("download");
        File file = null;
        if (j != -1) {
            DownloadManager.Query query2 = new DownloadManager.Query();
            query2.setFilterById(j);
            query2.setFilterByStatus(8);
            if (downloadManager != null && (query = downloadManager.query(query2)) != null) {
                if (query.moveToFirst()) {
                    String string = query.getString(query.getColumnIndex("local_uri"));
                    if (!TextUtils.isEmpty(string) && (path = Uri.parse(string).getPath()) != null) {
                        file = new File(path);
                    }
                }
                query.close();
            }
        }
        return file;
    }

    public void a(Context context, long j) {
        g.a(a, "onReceived...download finish...begin install!");
        HashMap<Long, String> hashMap = this.k;
        if (hashMap == null || this.i == null) {
            return;
        }
        String str = hashMap.get(Long.valueOf(j));
        HashMap<String, Boolean> hashMap2 = this.j;
        if (hashMap2 != null) {
            hashMap2.put(str, Boolean.FALSE);
        }
        b bVar = this.i.get(str);
        if (bVar != null) {
            if (bVar.h() != null) {
                ReportEventUtil.report(bVar.h().b());
            }
            a(context, Long.valueOf(j), bVar);
        }
    }

    public void a(Long l) {
        try {
            HashMap<Long, String> hashMap = this.k;
            if (hashMap != null) {
                String str = hashMap.get(l);
                if (!TextUtils.isEmpty(str)) {
                    HashMap<String, Boolean> hashMap2 = this.j;
                    if (hashMap2 != null) {
                        hashMap2.put(str, Boolean.FALSE);
                    }
                    HashMap<String, b> hashMap3 = this.i;
                    if (hashMap3 != null) {
                        hashMap3.remove(str);
                    }
                }
            }
            DownloadManager downloadManager = this.f1714d;
            if (downloadManager == null || l == null) {
                return;
            }
            downloadManager.remove(l.longValue());
        } catch (Exception e) {
            g.a("OctopusAd", "An Exception Caught", e);
        }
    }

    public void a(Context context, Long l, b bVar) {
        Uri uriForFile;
        try {
            c.a(context).b(false);
            Intent intent = new Intent();
            intent.addFlags(268435456);
            intent.setAction("android.intent.action.VIEW");
            int i = Build.VERSION.SDK_INT;
            if (i < 23) {
                uriForFile = this.f1714d.getUriForDownloadedFile(l.longValue());
            } else if (i < 24) {
                File b = b(context, l.longValue());
                uriForFile = b != null ? Uri.fromFile(b) : null;
            } else {
                uriForFile = FileProvider.getUriForFile(context, this.f1713c, new File(bVar.d(), bVar.b()));
                intent.addFlags(3);
            }
            if (uriForFile != null) {
                g.a(a, "uri......" + uriForFile);
                intent.setDataAndType(uriForFile, "application/vnd.android.package-archive");
                context.startActivity(intent);
                b(bVar);
            }
        } catch (Exception e) {
            g.a("OctopusAd", "An Exception Caught", e);
        }
    }
}