万能钥匙.apk(点击下载) / l.java


package com.lantern.conn.sdk.manager;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.text.TextUtils;
import com.lantern.conn.sdk.WkApplication;
import com.lantern.conn.sdk.config.d;
import com.lantern.conn.sdk.core.common.BLLog;
import com.lantern.conn.sdk.core.common.g;
import com.lantern.dmn.task.b;
import java.io.File;
import java.io.FileInputStream;
import java.security.MessageDigest;
import org.json.JSONObject;

/* compiled from: WkSdkApkDownloadUtil */
public class l {

    /* renamed from: a  reason: collision with root package name */
    private static a f5527a = null;

    /* renamed from: b  reason: collision with root package name */
    private static long f5528b = -1;

    public static long a() {
        return f5528b;
    }

    public static String b() {
        a d = d(WkApplication.getAppContext());
        return (d == null || TextUtils.isEmpty(d.f5529a)) ? "com.snda.lantern.wifilocating" : d.f5529a;
    }

    static boolean a(Context context, boolean z, boolean z2) {
        a d = d(context);
        f5527a = d;
        if (d == null) {
            return true;
        }
        c(f5527a.d);
        a(f5527a.f5529a);
        a(context, f5527a.f5530b, z, z2);
        return true;
    }

    static boolean c() {
        long j = f5528b;
        return j != -1 && b(j);
    }

    static boolean a(long j) {
        Cursor a2 = c(WkApplication.getAppContext()).a(new b.C0200b().a(j));
        if (a2.moveToFirst()) {
            String string = a2.getString(a2.getColumnIndex("title"));
            if (a2.getInt(a2.getColumnIndex("status")) == 8) {
                File file = new File(Environment.getExternalStoragePublicDirectory(l()), string);
                if (file.exists()) {
                    String absolutePath = file.getAbsolutePath();
                    boolean b2 = b(absolutePath, f5527a.c);
                    n.a(WkApplication.getAppContext(), absolutePath, b2);
                    return b2;
                }
            }
        }
        return false;
    }

    public static boolean d() {
        try {
            WkApplication.getAppContext().getPackageManager().getApplicationInfo(b(), 0);
            return true;
        } catch (PackageManager.NameNotFoundException unused) {
            return false;
        }
    }

    public static Intent a(Context context, String str) {
        if (context == null) {
            return null;
        }
        Intent intent = new Intent("android.intent.action.VIEW");
        int i = context.getApplicationInfo().targetSdkVersion;
        BLLog.i("sdk_target version is ".concat(String.valueOf(i)));
        if (Build.VERSION.SDK_INT < 24 || i < 24) {
            intent.setDataAndType(Uri.parse("file://".concat(String.valueOf(str))), "application/vnd.android.package-archive");
            intent.setFlags(268435456);
        } else {
            intent.setDataAndType(WKConnSdkFileProvider.getUriForFile(context, "com.lantern.conn.sdk.lsbrowsernew.downloadsn.provider", new File(str)), "application/vnd.android.package-archive");
            intent.setFlags(268435457);
        }
        return intent;
    }

    static boolean e() {
        a d = d(WkApplication.getAppContext());
        return (d == null || TextUtils.isEmpty(d.f5529a)) ? h() != null && j() >= 0 : h() != null && d.f5529a.equals(i()) && j() >= d.d;
    }

    public static boolean f() {
        return !d() && h() != null;
    }

    private static b c(Context context) {
        return new b(context);
    }

    private static long a(Context context, Uri uri, String str, boolean z, boolean z2) {
        if (z) {
            n.a(1);
        } else {
            n.a(2);
        }
        b c = c(context);
        b.c cVar = new b.c(uri);
        if (z2) {
            cVar.a(2);
        }
        cVar.b(false);
        cVar.a(l(), str);
        cVar.a(true);
        cVar.c(true);
        long a2 = c.a(cVar);
        f5528b = a2;
        return a2;
    }

    private static boolean a(File file, String str) {
        if (file == null || TextUtils.isEmpty(str)) {
            BLLog.d("aaa empty md5", new Object[0]);
            return false;
        }
        String a2 = a(file);
        if (str.equalsIgnoreCase(a2)) {
            return true;
        }
        BLLog.d("aaa fileMd5:".concat(String.valueOf(a2)), new Object[0]);
        BLLog.d("aaa md5:".concat(String.valueOf(str)), new Object[0]);
        return false;
    }

    /* JADX WARNING: Removed duplicated region for block: B:21:0x0036 A[SYNTHETIC, Splitter:B:21:0x0036] */
    /* JADX WARNING: Removed duplicated region for block: B:30:0x0042 A[SYNTHETIC, Splitter:B:30:0x0042] */
    private static String a(File file) {
        FileInputStream fileInputStream;
        Throwable th;
        try {
            fileInputStream = new FileInputStream(file);
            try {
                byte[] bArr = new byte[1024];
                MessageDigest instance = MessageDigest.getInstance("MD5");
                int i = 0;
                while (i != -1) {
                    i = fileInputStream.read(bArr);
                    if (i > 0) {
                        instance.update(bArr, 0, i);
                    }
                }
                String a2 = a(instance.digest());
                try {
                    fileInputStream.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return a2;
            } catch (Exception unused) {
                if (fileInputStream != null) {
                    try {
                        fileInputStream.close();
                    } catch (Exception e2) {
                        e2.printStackTrace();
                    }
                }
                return null;
            } catch (Throwable th2) {
                th = th2;
                if (fileInputStream != null) {
                    try {
                        fileInputStream.close();
                    } catch (Exception e3) {
                        e3.printStackTrace();
                    }
                }
                throw th;
            }
        } catch (Exception unused2) {
            fileInputStream = null;
            if (fileInputStream != null) {
            }
            return null;
        } catch (Throwable th3) {
            th = th3;
            fileInputStream = null;
            if (fileInputStream != null) {
            }
            throw th;
        }
    }

    private static String a(byte[] bArr) {
        String str = "";
        for (byte b2 : bArr) {
            str = str + Integer.toString((b2 & 255) + 256, 16).substring(1);
        }
        return str.toUpperCase();
    }

    private static boolean a(String str, String str2) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        BLLog.d("aaa return path ".concat(String.valueOf(str)), new Object[0]);
        File file = new File(str);
        if (!a(file, str2)) {
            BLLog.d("aaa md5 incorrect", new Object[0]);
            if (!file.delete()) {
                BLLog.d("file deleted failed!", new Object[0]);
            }
            return false;
        } else if (c(WkApplication.getAppContext(), str)) {
            return true;
        } else {
            BLLog.d("aaa invalid apk", new Object[0]);
            if (!file.delete()) {
                BLLog.d("file deleted failed!", new Object[0]);
            }
            return false;
        }
    }

    private static boolean b(String str, String str2) {
        if (a(str, str2)) {
            b(str);
            return true;
        }
        BLLog.d("aaa downloaded file is not valid", new Object[0]);
        return false;
    }

    private static boolean b(long j) {
        boolean z = false;
        Cursor a2 = c(WkApplication.getAppContext()).a(new b.C0200b().a(j));
        if (a2 != null) {
            if (a2.moveToFirst() && a2.getInt(a2.getColumnIndex("status")) == 2) {
                z = true;
            }
            a2.close();
        }
        return z;
    }

    /* access modifiers changed from: package-private */
    /* compiled from: WkSdkApkDownloadUtil */
    public static class a {

        /* renamed from: a  reason: collision with root package name */
        String f5529a;

        /* renamed from: b  reason: collision with root package name */
        String f5530b;
        String c;
        long d;

        a(String str, String str2, String str3, long j) {
            this.f5529a = str;
            this.f5530b = str2;
            this.c = str3;
            this.d = j;
        }
    }

    private static a g() {
        if ("com.snda.lantern.wifilocating".equals("com.snda.wifilocating")) {
            return new a("com.snda.lantern.wifilocating", "http://dl.lianwifi.com/download/android/WifiKey-181219-liantong-modify-lxdl.apk", "cf20f8e3b35e7d5e80c2a89a0f33e1d0", 181219);
        }
        return new a("com.snda.lantern.wifilocating", "http://dl.lianwifi.com/download/android/WifiKey-lxdl.apk", "bf1ad923783b8cafc11a25e0d61e07f3", 181219);
    }

    private static a d(Context context) {
        try {
            JSONObject a2 = d.a(WkApplication.getAppContext()).a("wksdk_sdk_download_apk20");
            if (a2 != null) {
                String string = a2.getString("apk_url");
                String string2 = a2.getString("apk_md5");
                String string3 = a2.getString("apk_pkg_name");
                long optLong = a2.optLong("apk_ver", 0);
                if (!TextUtils.isEmpty(string)) {
                    if (!TextUtils.isEmpty(string2)) {
                        return new a(string3, string, string2, optLong);
                    }
                }
                return g();
            }
        } catch (Exception e) {
            BLLog.e(e);
        }
        return g();
    }

    static void a(Context context) {
        b(context, k());
    }

    private static void b(Context context, String str) {
        Intent a2 = a(context, str);
        if (a2 != null) {
            context.startActivity(a2);
        }
    }

    private static String h() {
        String k = k();
        if (TextUtils.isEmpty(k) || !new File(k()).exists()) {
            return null;
        }
        return k;
    }

    private static boolean c(Context context, String str) {
        try {
            PackageInfo packageArchiveInfo = context.getPackageManager().getPackageArchiveInfo(str, 64);
            if (packageArchiveInfo == null) {
                return false;
            }
            Signature[] signatureArr = packageArchiveInfo.signatures;
            for (Signature signature : signatureArr) {
                String a2 = g.a(signature.toByteArray());
                BLLog.i("aaa Signature md5ByteArray : ".concat(String.valueOf(a2)));
                BLLog.i("aaa Signature md5FromStr : ".concat(String.valueOf(g.a(signature.toCharsString()))));
                BLLog.i("aaa Signature hashcode : " + signature.hashCode());
                if ("E25B9A4E4ED5A7810BE03B42CFAA9F39".compareToIgnoreCase(a2) == 0) {
                    return true;
                }
            }
            return true;
        } catch (Exception unused) {
            return false;
        }
    }

    private static void a(Context context, String str, boolean z, boolean z2) {
        b("");
        a(context, Uri.parse(str), "wifikey.apk", z, z2);
    }

    private static void a(String str) {
        WkApplication.getAppContext().getSharedPreferences("wifi_key", 0).edit().putString("wifi_key_last_download_apk_pkg_name", str).apply();
    }

    private static String i() {
        return WkApplication.getAppContext().getSharedPreferences("wifi_key", 0).getString("wifi_key_last_download_apk_pkg_name", "");
    }

    private static void c(long j) {
        WkApplication.getAppContext().getSharedPreferences("wifi_key", 0).edit().putLong("wifi_key_last_download_apk_ver", j).apply();
    }

    private static long j() {
        return WkApplication.getAppContext().getSharedPreferences("wifi_key", 0).getLong("wifi_key_last_download_apk_ver", 0);
    }

    private static void b(String str) {
        WkApplication.getAppContext().getSharedPreferences("wifi_key", 0).edit().putString("wifi_key_last_download_apk", str).apply();
    }

    private static String k() {
        return WkApplication.getAppContext().getSharedPreferences("wifi_key", 0).getString("wifi_key_last_download_apk", null);
    }

    private static String l() {
        File externalStoragePublicDirectory = Environment.getExternalStoragePublicDirectory("/temp/wifikey/");
        if (externalStoragePublicDirectory.exists()) {
            return "/temp/wifikey/";
        }
        externalStoragePublicDirectory.mkdirs();
        return "/temp/wifikey/";
    }

    static void b(Context context) {
        b c = c(WkApplication.getAppContext());
        Cursor a2 = c.a(new b.C0200b().a(7));
        if (a2 != null) {
            while (a2.moveToNext()) {
                long j = a2.getLong(a2.getColumnIndex("_id"));
                BLLog.d("aaa cancelSilentDownload id ".concat(String.valueOf(j)), new Object[0]);
                BLLog.d("aaa cancelSilentDownload removed  ".concat(String.valueOf(c.a(j))), new Object[0]);
            }
        }
    }
}