导航菜单

页面标题

页面副标题

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

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

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


package com.octopus.ad;

import android.annotation.SuppressLint;
import android.app.DownloadManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.text.TextUtils;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.core.content.FileProvider;
import com.octopus.ad.internal.utilities.DownloadFactory;
import com.octopus.ad.internal.utilities.DownloadFactory$Download;
import com.octopus.ad.internal.utilities.ReportEventUtil;
import com.octopus.ad.utils.b.d;
import com.octopus.ad.utils.b.g;
import com.octopus.ad.utils.c;
import java.io.File;
import java.util.HashMap;

public final class DownloadService extends Service {
    private static DownloadFactory$Download f;
    private long a;
    private String b;

    private DownloadManager f1701c;

    private a f1702d;
    private b e;
    private HashMap<String, com.octopus.ad.utils.b> g;
    private HashMap<String, Boolean> h;
    private HashMap<Long, String> i;

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

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

    @Override
    public void onCreate() {
        super.onCreate();
        g.a("DownloadService", "DownloadService onCreate()");
        this.f1701c = (DownloadManager) getSystemService("download");
        this.f1702d = new a(this, new Handler());
        this.e = new b(this, (AnonymousClass1) null);
        this.g = new HashMap<>();
        this.h = new HashMap<>();
        this.i = new HashMap<>();
        a();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        g.a("DownloadService", "DownloadService onDestroy()");
        b();
        d();
    }

    @Override
    public int onStartCommand(Intent intent, int i, int i5) {
        if (intent == null) {
            return 1;
        }
        g.a("DownloadService", "DownloadService onStartCommand()");
        c();
        return super.onStartCommand(intent, i, i5);
    }

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

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

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

    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;
    }

    private synchronized void a(com.octopus.ad.utils.b bVar) {
        Uri uriForFile;
        HashMap<String, Boolean> hashMap = this.h;
        if (hashMap != null && hashMap.get(bVar.c()) != null && Boolean.TRUE.equals(this.h.get(bVar.c()))) {
            g.a("DownloadService", "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("DownloadService", "uri......" + uriForFile);
                    intent.setDataAndType(uriForFile, "application/vnd.android.package-archive");
                    startActivity(intent);
                    c(bVar);
                }
            } catch (Exception e) {
                g.a("OctopusAd", "An Exception Caught", e);
            }
        }
        try {
            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.a = this.f1701c.enqueue(request);
            g.b("DownloadService", "mReqId:" + this.a);
            HashMap<Long, String> hashMap2 = this.i;
            if (hashMap2 != null) {
                hashMap2.put(Long.valueOf(this.a), bVar.c());
            }
            HashMap<String, Boolean> hashMap3 = this.h;
            if (hashMap3 != null) {
                hashMap3.put(bVar.c(), Boolean.TRUE);
            }
            Toast.makeText(getApplicationContext(), "已开始下载…", 0).show();
            g.a("DownloadService", "BEGIN_DOWNLOAD!");
            if (bVar.h() != null) {
                ReportEventUtil.report(bVar.h().a());
            }
        } catch (Exception e2) {
            g.a("OctopusAd", "An Exception Caught", e2);
            try {
                if (!TextUtils.isEmpty(bVar.a()) && bVar.a().contains("http")) {
                    HashMap<String, Boolean> hashMap4 = this.h;
                    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.a("OctopusAd", "An Exception Caught", e3);
            }
        }
    }

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

    public void b(final com.octopus.ad.utils.b bVar) {
        if (bVar == null) {
            return;
        }
        g.a("DownloadService", "--appUpdate downloadApk start--");
        DownloadFactory$Download create = DownloadFactory.create();
        f = create;
        create.register(new DownloadFactory.DownloadDelegate() {
            public boolean onCheck(File file) {
                return true;
            }

            public void onFail(int i) {
                g.a("DownloadService", "--appUpdate downloadApk onFail--");
                try {
                    String a = bVar.a();
                    if (TextUtils.isEmpty(a) || !a.contains("http")) {
                        return;
                    }
                    if (DownloadService.this.h != null) {
                        DownloadService.this.h.put(bVar.c(), Boolean.TRUE);
                    }
                    Intent intent = new Intent();
                    intent.setAction("android.intent.action.VIEW");
                    intent.setData(Uri.parse(a));
                    intent.setFlags(268435456);
                    DownloadService.this.startActivity(intent);
                } catch (Exception e) {
                    g.a("OctopusAd", "An Exception Caught", e);
                }
            }

            public void onProgress(long j, long j4) {
            }

            public void onSuccess(File file) {
                g.a("DownloadService", "--appUpdate downloadApk onSuccess--");
                if (DownloadService.this.h != null) {
                    DownloadService.this.h.put(bVar.c(), Boolean.FALSE);
                }
                DownloadService.this.a(DownloadService.this.getApplicationContext(), (Long) (-1L), bVar);
            }
        });
        f.start(new DownloadFactory.Request(bVar.a(), bVar.d(), bVar.b()));
    }

    public void a(Long l) {
        try {
            HashMap<Long, String> hashMap = this.i;
            if (hashMap != null) {
                String str = hashMap.get(l);
                if (!TextUtils.isEmpty(str)) {
                    HashMap<String, Boolean> hashMap2 = this.h;
                    if (hashMap2 != null) {
                        hashMap2.put(str, Boolean.FALSE);
                    }
                    HashMap<String, com.octopus.ad.utils.b> hashMap3 = this.g;
                    if (hashMap3 != null) {
                        hashMap3.remove(str);
                    }
                }
            }
            DownloadManager downloadManager = this.f1701c;
            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 j) {
        g.a("DownloadService", "onReceived...download finish...begin install!");
        HashMap<Long, String> hashMap = this.i;
        if (hashMap == null || this.g == null) {
            return;
        }
        String str = hashMap.get(Long.valueOf(j));
        HashMap<String, Boolean> hashMap2 = this.h;
        if (hashMap2 != null) {
            hashMap2.put(str, Boolean.FALSE);
        }
        com.octopus.ad.utils.b bVar = this.g.get(str);
        if (bVar != null) {
            if (bVar.h() != null) {
                ReportEventUtil.report(bVar.h().b());
            }
            a(context, Long.valueOf(j), bVar);
        }
    }

    public void a(Context context, Long l, com.octopus.ad.utils.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.f1701c.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.b, new File(bVar.d(), bVar.b()));
                intent.addFlags(3);
            }
            if (uriForFile != null) {
                g.a("DownloadService", "uri......" + uriForFile);
                intent.setDataAndType(uriForFile, "application/vnd.android.package-archive");
                context.startActivity(intent);
                c(bVar);
            }
        } catch (Exception e) {
            g.a("OctopusAd", "An Exception Caught", e);
        }
    }
}