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


package com.mbridge.msdk.mbdownload;

import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Debug;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.SparseArray;
import android.widget.Toast;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import com.mbridge.msdk.MBridgeConstans;
import com.mbridge.msdk.foundation.tools.MBFileProvider;
import com.mbridge.msdk.foundation.tools.s;
import com.mbridge.msdk.foundation.tools.w;
import com.mbridge.msdk.mbdownload.b;
import com.mbridge.msdk.mbdownload.e;
import com.ss.android.downloadad.api.constant.AdBaseConstants;
import com.tencent.smtt.sdk.TbsVideoCacheTask;
import java.io.File;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/* compiled from: DownloadProvider */
public class c {
    public static final String a = "c";
    public static boolean b = false;
    protected static Map<b.a, Messenger> c = new HashMap();
    protected static SparseArray<e.b> d = new SparseArray<>();
    final Messenger e = new Messenger(new b());
    SparseArray<Long> f = new SparseArray<>();
    private NotificationManagerCompat g;
    private e h;
    private i i;
    private Handler j;
    private boolean k = true;
    private Service l;

    public final IBinder a(Intent intent) {
        w.a(a, "onBind ");
        return this.e.getBinder();
    }

    public final int a(Intent intent, int i2, int i3) {
        if (!(intent == null || intent.getExtras() == null)) {
            this.h.a(this, intent);
        }
        if (Build.VERSION.SDK_INT >= 19 && (this.i.b() || this.k)) {
            try {
                Intent intent2 = new Intent(this.l.getApplicationContext(), getClass());
                intent2.setPackage(this.l.getPackageName());
                ((AlarmManager) this.l.getApplicationContext().getSystemService(NotificationCompat.CATEGORY_ALARM)).set(3, SystemClock.elapsedRealtime() + 5000, PendingIntent.getService(this.l.getApplicationContext(), 1, intent2, 1073741824));
            } catch (Exception unused) {
            }
        }
        if (this.k) {
            d();
            this.k = false;
        }
        return 1;
    }

    public final void a() {
        if (b) {
            Debug.waitForDebugger();
        }
        this.g = NotificationManagerCompat.from(this.l.getApplicationContext());
        j.a();
        this.i = new i(this.l);
        this.h = new e(d, c, this.i);
        this.j = new a();
    }

    public final void b() {
        try {
            d.a(this.l.getApplicationContext()).a(259200);
            d.a(this.l.getApplicationContext()).finalize();
        } catch (Exception e2) {
            w.d(a, e2.getMessage());
        }
    }

    private void d() {
        for (Integer num : this.i.a()) {
            this.g.cancel(num.intValue());
        }
    }

    public final void a(int i2) {
        NotificationChannel notificationChannel;
        if (d.indexOfKey(i2) >= 0) {
            e.b bVar = d.get(i2);
            long[] jArr = bVar.f;
            int i3 = 0;
            if (jArr != null && jArr[1] > 0 && (i3 = (int) ((((float) jArr[0]) / ((float) jArr[1])) * 100.0f)) > 100) {
                i3 = 99;
            }
            if (!bVar.e.r) {
                this.f.put(i2, -1L);
                e.a a2 = this.h.a(this.l, bVar.e, i2, i3);
                bVar.b = a2;
                try {
                    this.g.notify(i2, a2.d());
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
                try {
                    String str = this.g.areNotificationsEnabled() ? "true" : "false";
                    String str2 = "";
                    NotificationManager notificationManager = (NotificationManager) this.l.getSystemService("notification");
                    if (Build.VERSION.SDK_INT >= 26 && (notificationChannel = notificationManager.getNotificationChannel("download")) != null) {
                        str2 = String.valueOf(notificationChannel.getImportance());
                    }
                    com.mbridge.msdk.foundation.same.report.e.a(this.l, str, String.valueOf(this.g.getImportance()), str2);
                } catch (Throwable th) {
                    th.printStackTrace();
                }
            }
        }
    }

    public final void a(int i2, int i3) {
        if (d.indexOfKey(i2) >= 0) {
            e.b bVar = d.get(i2);
            b.a aVar = bVar.e;
            long currentTimeMillis = System.currentTimeMillis();
            if (!aVar.r && currentTimeMillis - this.f.get(i2).longValue() > 500) {
                this.f.put(i2, Long.valueOf(currentTimeMillis));
                e.a aVar2 = bVar.b;
                e.a a2 = aVar2.a(100, i3, false);
                a2.a((CharSequence) (String.valueOf(i3) + "%"));
                if (bVar.e.i) {
                    aVar2.a();
                }
                try {
                    this.g.notify(i2, aVar2.d());
                } catch (Exception unused) {
                    a(bVar, i2);
                    e.a aVar3 = bVar.b;
                    e.a a3 = aVar3.a(100, i3, false);
                    a3.a((CharSequence) (String.valueOf(i3) + "%"));
                    if (bVar.e.i) {
                        aVar3.a();
                    }
                    try {
                        this.g.notify(i2, aVar3.d());
                    } catch (Exception e2) {
                        e2.printStackTrace();
                    }
                }
            }
        }
    }

    public final void b(int i2, int i3) {
        if (i3 == 1) {
            e.b bVar = d.get(i2);
            e.a aVar = bVar.b;
            aVar.a(100, 100, false).a(bVar.e.j).b(g.a(this.l.getBaseContext())).a((CharSequence) g.c(this.l.getBaseContext())).b().a(bVar.e.h);
            try {
                this.g.notify(i2, aVar.d());
            } catch (Exception unused) {
                a(bVar, i2);
                e.a aVar2 = bVar.b;
                aVar2.a(100, 100, false).a(bVar.e.j).b(g.a(this.l.getBaseContext())).a((CharSequence) g.c(this.l.getBaseContext())).b().a(bVar.e.h);
                try {
                    this.g.notify(i2, aVar2.d());
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
            }
        } else if (i3 == 9) {
            e.b bVar2 = d.get(i2);
            e.a aVar3 = bVar2.b;
            aVar3.a(100, 100, false).a(bVar2.e.j).b(g.b(this.l.getBaseContext())).a((CharSequence) g.d(this.l.getBaseContext())).b().a(false);
            try {
                this.g.notify(i2, aVar3.d());
            } catch (Exception unused2) {
                a(bVar2, i2);
                e.a aVar4 = bVar2.b;
                aVar4.a(100, 100, false).a(bVar2.e.j).b(g.b(this.l.getBaseContext())).a((CharSequence) g.d(this.l.getBaseContext())).b().a(false);
                try {
                    this.g.notify(i2, aVar4.d());
                } catch (Exception e3) {
                    e3.printStackTrace();
                }
            }
        }
    }

    public final void a(int i2, String str) {
        e.b bVar;
        if (d.indexOfKey(i2) >= 0 && (bVar = d.get(i2)) != null) {
            b.a aVar = bVar.e;
            e.a aVar2 = bVar.b;
            aVar2.a(100, 100, false).a(aVar.j).b(g.a(this.l.getBaseContext())).a((CharSequence) g.c(this.l.getBaseContext())).b().a(aVar.h).a(17301634);
            try {
                this.g.notify(i2, aVar2.d());
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            d.a(this.l).a(aVar.b, aVar.d, 100);
            Bundle bundle = new Bundle();
            bundle.putString(TbsVideoCacheTask.KEY_VIDEO_CACHE_PARAM_FILENAME, str);
            if (aVar.b.equalsIgnoreCase("delta_update")) {
                Message obtain = Message.obtain();
                obtain.what = 6;
                obtain.arg1 = 1;
                obtain.obj = aVar;
                obtain.arg2 = i2;
                obtain.setData(bundle);
                this.j.sendMessage(obtain);
                return;
            }
            Message obtain2 = Message.obtain();
            obtain2.what = 5;
            obtain2.arg1 = 1;
            obtain2.obj = aVar;
            obtain2.arg2 = i2;
            obtain2.setData(bundle);
            this.j.sendMessage(obtain2);
            Message obtain3 = Message.obtain();
            obtain3.what = 5;
            obtain3.arg1 = 1;
            obtain3.arg2 = i2;
            obtain3.setData(bundle);
            try {
                if (c.get(aVar) != null) {
                    c.get(aVar).send(obtain3);
                }
            } catch (RemoteException unused) {
                this.h.a(this.l, i2);
            }
        }
    }

    public final void a(int i2, Exception exc) {
        if (d.indexOfKey(i2) >= 0) {
            this.h.a(this.l, i2);
        }
    }

    private void a(e.b bVar, int i2) {
        bVar.b = this.h.a(this.l, bVar.e, i2, 0);
    }

    /* compiled from: DownloadProvider */
    class b extends Handler {
        b() {
        }

        public final void handleMessage(Message message) {
            try {
                String str = c.a;
                w.a(str, "IncomingHandler(msg.what:" + message.what + " msg.arg1:" + message.arg1 + " msg.arg2:" + message.arg2 + " msg.replyTo:" + message.replyTo);
                if (message.what != 4) {
                    super.handleMessage(message);
                    return;
                }
                Bundle data = message.getData();
                String str2 = c.a;
                w.a(str2, "IncomingHandler(msg.getData():" + data);
                b.a aVar = new b.a(data.getString("mComponentName"), data.getString("mTitle"), data.getString("mUrl"), data.getString("uniqueKey"), data.getBoolean("mOnGoingStatus"));
                aVar.e = data.getString("mMd5");
                aVar.f = data.getString("mTargetMd5");
                aVar.a = data.getString("mReqClz");
                aVar.k = data.getStringArray("succUrls");
                aVar.m = data.getStringArray("faiUrls");
                aVar.n = data.getStringArray("startUrls");
                aVar.o = data.getStringArray("pauseUrls");
                aVar.p = data.getStringArray("cancelUrls");
                aVar.l = data.getStringArray("carryonUrls");
                aVar.q = data.getBoolean("rich_notification");
                aVar.r = data.getBoolean("mSilent");
                aVar.s = data.getBoolean("mWifiOnly");
                aVar.i = data.getBoolean("mCanPause");
                aVar.j = data.getString("mTargetAppIconUrl");
                if (c.this.h.a(aVar, c.b, message.replyTo)) {
                    String str3 = c.a;
                    w.b(str3, aVar.c + " is already in downloading list. ");
                    int a2 = c.this.h.a(aVar);
                    if (a2 == -1 || c.d.get(a2).a != null) {
                        if (!(c.this.l == null || c.this.l.getBaseContext() == null)) {
                            Toast.makeText(c.this.l, g.h(c.this.l.getBaseContext()), 0).show();
                        }
                        Message obtain = Message.obtain();
                        obtain.what = 2;
                        obtain.arg1 = 2;
                        obtain.arg2 = 0;
                        try {
                            message.replyTo.send(obtain);
                        } catch (RemoteException e) {
                            e.printStackTrace();
                        }
                    } else {
                        String a3 = j.a(a2, "continue");
                        Intent intent = new Intent(c.this.l, c.class);
                        intent.putExtra("com.mbridge.msdk.broadcast.download.msg", a3);
                        c.this.h.a(c.this, intent);
                    }
                } else if (e.b(c.this.l)) {
                    c.c.put(aVar, message.replyTo);
                    Message obtain2 = Message.obtain();
                    obtain2.what = 1;
                    obtain2.arg1 = 1;
                    obtain2.arg2 = 0;
                    try {
                        message.replyTo.send(obtain2);
                    } catch (RemoteException e2) {
                        e2.printStackTrace();
                    }
                    c.a(c.this, aVar);
                } else {
                    Toast.makeText(c.this.l, g.e(c.this.l.getBaseContext()), 0).show();
                    Message obtain3 = Message.obtain();
                    obtain3.what = 2;
                    obtain3.arg1 = 4;
                    obtain3.arg2 = 0;
                    try {
                        message.replyTo.send(obtain3);
                    } catch (RemoteException e3) {
                        e3.printStackTrace();
                    }
                }
            } catch (Exception e4) {
                e4.printStackTrace();
            }
        }
    }

    /* compiled from: DownloadProvider */
    class a extends Handler {
        a() {
        }

        /* JADX WARNING: Code restructure failed: missing block: B:27:0x0148, code lost:
            r0 = move-exception;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:28:0x0149, code lost:
            r0.printStackTrace();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:42:0x01c1, code lost:
            r0 = move-exception;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:43:0x01c2, code lost:
            r0.printStackTrace();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:51:0x021f, code lost:
            r0 = move-exception;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:52:0x0220, code lost:
            r2 = com.mbridge.msdk.mbdownload.c.a;
            com.mbridge.msdk.foundation.tools.w.d(r2, "can not install. " + r0.getMessage());
            r18.a.g.cancel(r4 + 1);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:54:?, code lost:
            return;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:55:?, code lost:
            return;
         */
        /* JADX WARNING: Failed to process nested try/catch */
        /* JADX WARNING: Removed duplicated region for block: B:36:0x017e  */
        /* JADX WARNING: Removed duplicated region for block: B:37:0x0197  */
        /* JADX WARNING: Removed duplicated region for block: B:39:0x01b1  */
        /* JADX WARNING: Removed duplicated region for block: B:53:? A[ExcHandler: all (unused java.lang.Throwable), SYNTHETIC, Splitter:B:12:0x00a5] */
        public final void handleMessage(Message message) {
            String string;
            Intent intent;
            Notification notification;
            Uri uri;
            int i = message.what;
            if (i == 5) {
                b.a aVar = (b.a) message.obj;
                int i2 = message.arg2;
                try {
                    string = message.getData().getString(TbsVideoCacheTask.KEY_VIDEO_CACHE_PARAM_FILENAME);
                    w.a(c.a, "Cancel old notification....");
                    intent = new Intent("android.intent.action.VIEW");
                    intent.addFlags(268435456);
                    Context applicationContext = c.this.l.getApplicationContext();
                    if (s.w(applicationContext) < 24 || Build.VERSION.SDK_INT < 24) {
                        intent.setDataAndType(Uri.fromFile(new File(string)), AdBaseConstants.MIME_APK);
                        PendingIntent activity = PendingIntent.getActivity(c.this.l, 0, intent, 134217728);
                        if (!aVar.r) {
                            notification = e.a(c.this.l, g.j(c.this.l.getBaseContext()), activity);
                        } else {
                            notification = e.a(c.this.l, g.i(c.this.l.getBaseContext()), activity);
                        }
                        if (notification != null) {
                            notification.flags = 16;
                            c.this.g.notify(i2 + 1, notification);
                            w.a(c.a, "Show new  notification....");
                        }
                        boolean a2 = c.this.h.a(c.this.l);
                        w.a(c.a, String.format("isAppOnForeground = %1$B", Boolean.valueOf(a2)));
                        if (a2 && !aVar.r) {
                            c.this.g.cancel(i2 + 1);
                            com.mbridge.msdk.click.c.c(c.this.l, aVar.g);
                        }
                        w.b(c.a, String.format("%1$10s downloaded. Saved to: %2$s", aVar.c, string));
                    }
                    Uri uri2 = null;
                    if (!TextUtils.isEmpty(MBridgeConstans.FILE_PROVIDE_CUSTOM_PATH)) {
                        Method method = Class.forName(MBridgeConstans.FILE_PROVIDE_CUSTOM_PATH).getMethod("getUriForFile", Context.class, String.class, File.class);
                        uri = (Uri) method.invoke(null, applicationContext, applicationContext.getApplicationContext().getPackageName() + ".mbFileProvider", new File(string));
                    } else {
                        uri = MBFileProvider.getUriForFile(applicationContext, applicationContext.getApplicationContext().getPackageName() + ".mbFileProvider", new File(string));
                    }
                    uri2 = uri;
                    if (uri2 != null) {
                        intent.setDataAndType(uri2, AdBaseConstants.MIME_APK);
                        intent.addFlags(1);
                    }
                    PendingIntent activity2 = PendingIntent.getActivity(c.this.l, 0, intent, 134217728);
                    if (!aVar.r) {
                    }
                    if (notification != null) {
                    }
                    boolean a22 = c.this.h.a(c.this.l);
                    w.a(c.a, String.format("isAppOnForeground = %1$B", Boolean.valueOf(a22)));
                    c.this.g.cancel(i2 + 1);
                    com.mbridge.msdk.click.c.c(c.this.l, aVar.g);
                    w.b(c.a, String.format("%1$10s downloaded. Saved to: %2$s", aVar.c, string));
                } catch (Exception unused) {
                    intent.setDataAndType(Uri.fromFile(new File(string)), AdBaseConstants.MIME_APK);
                } catch (Throwable unused2) {
                }
            } else if (i == 6) {
                b.a aVar2 = (b.a) message.obj;
                int i3 = message.arg2;
                String string2 = message.getData().getString(TbsVideoCacheTask.KEY_VIDEO_CACHE_PARAM_FILENAME);
                c.this.g.cancel(i3);
                Notification a3 = e.a(c.this.l, g.k(c.this.l.getBaseContext()), PendingIntent.getActivity(c.this.l, 0, new Intent(), 134217728));
                if (a3 != null) {
                    try {
                        c.this.g.notify(i3 + 1, a3);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                String replace = string2.replace(".patch", ".apk");
                String a4 = a.a(c.this.l);
                e eVar = c.this.h;
                Objects.requireNonNull(eVar);
                new e.c(c.this.l, i3, aVar2, replace).execute(a4, replace, string2);
            }
        }
    }

    public final void a(Service service) {
        this.l = service;
    }

    public final Service c() {
        return this.l;
    }

    static /* synthetic */ void a(c cVar, b.a aVar) {
        String str = a;
        w.a(str, "startDownload([mComponentName:" + aVar.b + " mTitle:" + aVar.c + " mUrl:" + aVar.d + "])");
        e eVar = cVar.h;
        int abs = Math.abs((int) (((long) ((aVar.c.hashCode() >> 2) + (aVar.d.hashCode() >> 3))) + System.currentTimeMillis()));
        k kVar = new k(cVar, aVar, abs, 0);
        e.b bVar = new e.b(aVar, abs);
        cVar.i.a(abs);
        d.put(bVar.c, bVar);
        bVar.a = kVar;
        kVar.start();
        if (b) {
            int size = c.size();
            int size2 = d.size();
            w.b(str, "Client size =" + size + "   cacheSize = " + size2);
            if (size != size2) {
                throw new RuntimeException("Client size =" + size + "   cacheSize = " + size2);
            }
        }
        if (b) {
            for (int i2 = 0; i2 < d.size(); i2++) {
                String str2 = a;
                w.a(str2, "Running task " + d.valueAt(i2).e.c);
            }
        }
    }
}