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


package com.linksure.browser.update.a;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Environment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import b.a.a;
import com.bluefay.a.c;
import com.bluefay.a.d;
import com.lantern.core.WkSettings;
import com.lantern.core.utils.AppUtil;
import com.linksure.browser.BrowserApp;
import com.linksure.browser.analytics.b;
import com.linksure.browser.base.BaseActivity;
import com.linksure.browser.update.e;
import com.linksure.browser.utils.o;
import com.linksure.framework.a.l;
import com.wifi.link.wfys.R;
import com.xiaomi.mipush.sdk.Constants;
import java.io.File;
import org.json.JSONException;
import org.json.JSONObject;

/* compiled from: UpdateManager */
public final class a {

    /* renamed from: a  reason: collision with root package name */
    Context f7329a;

    /* renamed from: b  reason: collision with root package name */
    b f7330b;
    com.bluefay.b.a c;
    AlertDialog d;
    boolean e;
    private e f = null;
    private com.bluefay.b.a g = new com.bluefay.b.a() {
        /* class com.linksure.browser.update.a.a.AnonymousClass1 */

        @Override // com.bluefay.b.a
        public final void run(int i, String str, Object obj) {
            com.linksure.browser.update.bean.a aVar = (com.linksure.browser.update.bean.a) obj;
            if (a.this.c != null) {
                a.this.c.run(i, str, obj);
            }
            if (i == 1 && aVar != null) {
                if (!a.a(a.this.f7329a, aVar.h) || aVar.h.equals(a.this.f7329a.getPackageName())) {
                    a aVar2 = a.this;
                    JSONObject jSONObject = new JSONObject();
                    String str2 = null;
                    if (aVar2.e) {
                        str2 = "cli";
                    } else if (TextUtils.equals("1", aVar.e)) {
                        str2 = "sergentle";
                    } else if (TextUtils.equals("2", aVar.e)) {
                        str2 = "serforce";
                    }
                    if (str2 != null) {
                        try {
                            jSONObject.put("source", str2);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        b.a("update_dialog", jSONObject.toString());
                    }
                    if (a.this.e || aVar.e.equals("1")) {
                        a aVar3 = a.this;
                        aVar3.f7329a.getString(R.string.upgrade_forced_for_now);
                        aVar3.f7329a.getString(R.string.upgrade_forced_for_default);
                        aVar3.a(aVar, true, true, false);
                    } else if (aVar.e.equals("2")) {
                        a aVar4 = a.this;
                        if (aVar4.a(aVar) != null) {
                            aVar4.f7329a.getString(R.string.upgrade_forced_for_now);
                            aVar4.a(aVar, false, false, true);
                        } else if (com.bluefay.a.a.b(aVar4.f7329a)) {
                            aVar4.f7329a.getString(R.string.upgrade_forced_for_now);
                            aVar4.f7329a.getString(R.string.upgrade_forced_for_wifi);
                            aVar4.a(aVar, false, true, true);
                        } else {
                            NetworkInfo activeNetworkInfo = ((ConnectivityManager) aVar4.f7329a.getSystemService("connectivity")).getActiveNetworkInfo();
                            if (activeNetworkInfo != null && activeNetworkInfo.getType() == 1) {
                                aVar4.f7329a.getString(R.string.upgrade_forced_for_now);
                                aVar4.a(aVar, false, false, true);
                            }
                        }
                    }
                    WkSettings.setUpgradeTimeStamp(a.this.f7329a);
                    WkSettings.setUpgradeVersionCode(a.this.f7329a, aVar.g);
                    WkSettings.setUpgradeVersionChannel(a.this.f7329a, BrowserApp.j().getChannelID());
                    StringBuilder sb = new StringBuilder();
                    sb.append(WkSettings.getUpgradeVersionCode(a.this.f7329a));
                    if (!d.getBooleanValue(sb.toString(), false)) {
                        WkSettings.setUpgrade(BrowserApp.f(), true);
                    }
                }
            }
        }
    };

    public a(Context context) {
        this.f7329a = context;
        this.f7330b = new b(this.f7329a);
    }

    public final void a(boolean z, com.bluefay.b.a aVar) {
        this.c = aVar;
        this.e = z;
        a(this.g);
    }

    private void a(com.bluefay.b.a aVar) {
        boolean c2 = com.bluefay.a.a.c(com.bluefay.c.a.a());
        int a2 = com.bluefay.a.a.a(com.bluefay.c.a.a());
        com.bluefay.b.e.b("isNetworkConnected:%s network_type:%s", Boolean.valueOf(c2), Integer.valueOf(a2));
        if (!c2 || a2 == -1) {
            aVar.run(11, null, null);
            return;
        }
        String a3 = a(com.bluefay.c.a.a());
        com.bluefay.b.e.a("version_info:".concat(String.valueOf(a3)));
        if (a3 == null) {
            com.bluefay.b.e.c("device_info id is null, can't update");
            aVar.run(0, null, null);
            return;
        }
        this.f = new e(aVar);
        this.f.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new String[0]);
    }

    /* access modifiers changed from: package-private */
    public final void a(final com.linksure.browser.update.bean.a aVar, boolean z, final boolean z2, final boolean z3) {
        String str;
        int i = 0;
        com.bluefay.b.e.b("isCanceled:%s isShowCancel:%s isForced:%s", Boolean.valueOf(z), Boolean.valueOf(z2), Boolean.valueOf(z3));
        if (((BaseActivity) this.f7329a).isActivityDestroyed()) {
            com.bluefay.b.e.c("Activity is not running");
            return;
        }
        String str2 = aVar.f7359b;
        AlertDialog.Builder builder = new AlertDialog.Builder(this.f7329a, R.style.UpdateDialogStyle);
        View inflate = LayoutInflater.from(this.f7329a).inflate(R.layout.dialog_update, (ViewGroup) null, false);
        builder.setView(inflate);
        TextView textView = (TextView) inflate.findViewById(R.id.update_title);
        if (aVar.f7358a.startsWith("v")) {
            str = aVar.f7358a;
        } else {
            str = "v" + aVar.f7358a;
        }
        textView.setText(this.f7329a.getString(R.string.upgrade_dialog_title, str));
        TextView textView2 = (TextView) inflate.findViewById(R.id.update_msg);
        if (str2 != null && str2.length() > 0) {
            textView2.setText(str2);
        }
        ImageView imageView = (ImageView) inflate.findViewById(R.id.update_close);
        com.linksure.framework.a.d.a(imageView);
        if (!z2) {
            i = 4;
        }
        imageView.setVisibility(i);
        if (z2) {
            imageView.setOnClickListener(new View.OnClickListener() {
                /* class com.linksure.browser.update.a.a.AnonymousClass2 */

                public final void onClick(View view) {
                    if (a.this.d != null) {
                        a.this.d.dismiss();
                    }
                    if (z3) {
                        a aVar = a.this;
                        a.a(aVar, aVar.f7329a, aVar, z3);
                        return;
                    }
                    com.linksure.browser.preference.a.a().a("key_upgrade_ignore_time", System.currentTimeMillis());
                }
            });
        }
        ((Button) inflate.findViewById(R.id.btn_update)).setOnClickListener(new View.OnClickListener() {
            /* class com.linksure.browser.update.a.a.AnonymousClass3 */

            public final void onClick(View view) {
                if (a.this.d != null) {
                    a.this.d.dismiss();
                }
                b.a("lsbr_newversion_confirm");
                a aVar = a.this;
                a.a(aVar, aVar.f7329a, aVar, z3);
            }
        });
        builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
            /* class com.linksure.browser.update.a.a.AnonymousClass4 */

            public final void onCancel(DialogInterface dialogInterface) {
                if (!z2) {
                    ((BaseActivity) a.this.f7329a).finish();
                }
                a.a(a.this, "update_diacan", z3);
            }
        });
        this.d = builder.create();
        this.d.setCanceledOnTouchOutside(z);
        this.d.show();
        b.a("lsbr_newversion_pop");
    }

    /* access modifiers changed from: package-private */
    public final String a(com.linksure.browser.update.bean.a aVar) {
        File externalStoragePublicDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
        if (!externalStoragePublicDirectory.exists()) {
            externalStoragePublicDirectory.mkdirs();
        }
        if (!externalStoragePublicDirectory.exists()) {
            com.bluefay.a.e.a((int) R.string.upgrade_phone_card_not_exist);
        }
        if (!externalStoragePublicDirectory.exists()) {
            return null;
        }
        File file = new File(externalStoragePublicDirectory, String.format("%s-%s.apk", TextUtils.isEmpty(aVar.h) ? this.f7329a.getPackageName() : aVar.h, aVar.f7358a));
        if (!file.exists()) {
            return null;
        }
        com.bluefay.b.e.a("exists");
        if (com.linksure.browser.update.utils.a.a(this.f7329a, file.getAbsolutePath()) || com.linksure.browser.update.utils.a.a(this.f7329a, file.getAbsolutePath(), aVar.i)) {
            return file.getAbsolutePath();
        }
        return null;
    }

    static boolean a(Context context, String str) {
        try {
            context.getPackageManager().getPackageInfo(str, 1);
            return true;
        } catch (Exception unused) {
            return false;
        }
    }

    private static String a(Context context) {
        int c2 = com.bluefay.c.a.c();
        String channelName = AppUtil.getChannelName(context);
        try {
            JSONObject jSONObject = new JSONObject();
            if (channelName != null && channelName.length() > 0) {
                jSONObject.put("channel_name", channelName);
            }
            jSONObject.put("version_code", c2);
            jSONObject.put("package", context.getPackageName());
            jSONObject.put("locale", c.getDefaultLocale());
            return jSONObject.toString();
        } catch (Exception e2) {
            com.bluefay.b.e.a(e2);
            return null;
        }
    }

    private void a(Context context, final com.linksure.browser.update.bean.a aVar, final boolean z) {
        if (context != null) {
            o.c((Activity) this.f7329a, new String[]{"android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.READ_EXTERNAL_STORAGE"}, new o.a() {
                /* class com.linksure.browser.update.a.a.AnonymousClass5 */

                @Override // com.linksure.browser.utils.o.a
                public final void onDenied() {
                }

                /* JADX WARNING: Removed duplicated region for block: B:18:0x0076  */
                /* JADX WARNING: Removed duplicated region for block: B:37:0x0163  */
                /* JADX WARNING: Removed duplicated region for block: B:38:0x0166  */
                @Override // com.linksure.browser.utils.o.a
                public final void onGranted() {
                    String str;
                    String a2;
                    a aVar = a.this;
                    com.linksure.browser.update.bean.a aVar2 = aVar;
                    boolean z = z;
                    if (!(aVar2 == null || aVar2.d == null)) {
                        if (aVar2.d.startsWith("market://")) {
                            if (com.bluefay.a.b.a(aVar.f7329a, "com.android.vending")) {
                                Intent intent = new Intent("android.intent.action.VIEW", Uri.parse("market://details?id=" + aVar.f7329a.getPackageName()));
                                intent.setPackage("com.android.vending");
                                intent.setFlags(268435456);
                                com.bluefay.a.e.a(aVar.f7329a, intent);
                            } else {
                                str = "http://get.geakmobi.com/redirect/get_geakos/";
                                a2 = aVar.a(aVar2);
                                if (!com.linksure.browser.update.utils.a.a(aVar.f7329a, a2) || com.linksure.browser.update.utils.a.a(aVar.f7329a, a2, aVar2.i)) {
                                    com.bluefay.b.e.a("install apk");
                                    com.linksure.browser.update.utils.a.a(a2, z, aVar.f7329a);
                                    com.linksure.browser.update.d a3 = com.linksure.browser.update.d.a();
                                    a3.f7360a = aVar.e;
                                    a3.f7361b = z ? "2" : "1";
                                    l.a(new Runnable() {
                                        /* class com.linksure.browser.update.d.AnonymousClass1 */

                                        public final void run() {
                                            d.this.f7360a = false;
                                            d.this.f7361b = null;
                                        }
                                    }, Constants.ASSEMBLE_PUSH_NETWORK_INTERVAL);
                                } else if (!(str == null || aVar.f7330b == null)) {
                                    String format = String.format("%s-%s.apk", TextUtils.isEmpty(aVar2.h) ? aVar.f7329a.getPackageName() : aVar2.h, aVar2.f7358a);
                                    b bVar = aVar.f7330b;
                                    Uri parse = Uri.parse(str);
                                    bVar.d = aVar2.i;
                                    if (bVar.c == 0) {
                                        a.c cVar = new a.c(parse);
                                        cVar.h = false;
                                        File externalStoragePublicDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
                                        if (format != null) {
                                            cVar.f2216b = Uri.withAppendedPath(Uri.fromFile(externalStoragePublicDirectory), format);
                                            cVar.f = true;
                                            cVar.j = false;
                                            long a4 = bVar.f7343b.a(cVar);
                                            com.bluefay.b.e.b("Start download uri:%s id:%s", parse, Long.valueOf(bVar.c));
                                            bVar.c = a4;
                                            bVar.a(bVar.c);
                                        } else {
                                            throw new NullPointerException("subPath cannot be null");
                                        }
                                    } else {
                                        b.a.a aVar3 = bVar.f7343b;
                                        long[] jArr = {bVar.c};
                                        com.bluefay.b.e.a("resumeDownload");
                                        ContentValues contentValues = new ContentValues();
                                        contentValues.put("numfailed", "0");
                                        contentValues.put("control", (Integer) 0);
                                        contentValues.put("status", (Integer) 190);
                                        ContentResolver contentResolver = aVar3.f2210a;
                                        Uri uri = aVar3.f2211b;
                                        contentResolver.update(uri, contentValues, " status != '192' AND " + b.a.a.b(jArr), b.a.a.c(jArr));
                                    }
                                }
                                a.a(a.this, "update_diasure", z);
                            }
                        } else if (aVar2.d.startsWith("http://") || aVar2.d.startsWith("https://")) {
                            str = aVar2.d;
                            a2 = aVar.a(aVar2);
                            if (!com.linksure.browser.update.utils.a.a(aVar.f7329a, a2)) {
                            }
                            com.bluefay.b.e.a("install apk");
                            com.linksure.browser.update.utils.a.a(a2, z, aVar.f7329a);
                            com.linksure.browser.update.d a32 = com.linksure.browser.update.d.a();
                            a32.f7360a = aVar.e;
                            a32.f7361b = z ? "2" : "1";
                            l.a(new Runnable() {
                                /* class com.linksure.browser.update.d.AnonymousClass1 */

                                public final void run() {
                                    d.this.f7360a = false;
                                    d.this.f7361b = null;
                                }
                            }, Constants.ASSEMBLE_PUSH_NETWORK_INTERVAL);
                            a.a(a.this, "update_diasure", z);
                        }
                    }
                    str = null;
                    a2 = aVar.a(aVar2);
                    if (!com.linksure.browser.update.utils.a.a(aVar.f7329a, a2)) {
                    }
                    com.bluefay.b.e.a("install apk");
                    com.linksure.browser.update.utils.a.a(a2, z, aVar.f7329a);
                    com.linksure.browser.update.d a322 = com.linksure.browser.update.d.a();
                    a322.f7360a = aVar.e;
                    a322.f7361b = z ? "2" : "1";
                    l.a(new Runnable() {
                        /* class com.linksure.browser.update.d.AnonymousClass1 */

                        public final void run() {
                            d.this.f7360a = false;
                            d.this.f7361b = null;
                        }
                    }, Constants.ASSEMBLE_PUSH_NETWORK_INTERVAL);
                    a.a(a.this, "update_diasure", z);
                }
            });
        }
    }

    public final void a() {
        e eVar = this.f;
        if (eVar != null) {
            eVar.a();
        }
    }

    static /* synthetic */ void a(a aVar, Context context, com.linksure.browser.update.bean.a aVar2, boolean z) {
        String channelID = BrowserApp.j().getChannelID();
        if (TextUtils.isEmpty(channelID)) {
            aVar.a(context, aVar2, z);
        }
        if (!channelID.startsWith("gp")) {
            aVar.a(context, aVar2, z);
        } else if (context != null) {
            Intent intent = new Intent("android.intent.action.VIEW");
            intent.setData(Uri.parse("market://details?id=" + context.getPackageName()));
            intent.setPackage("com.android.vending");
            if (intent.resolveActivity(context.getPackageManager()) != null) {
                context.startActivity(intent);
                return;
            }
            Intent intent2 = new Intent();
            intent2.setComponent(new ComponentName(context.getPackageName(), "com.linksure.browser.activity.BrowserActivity"));
            intent2.setData(Uri.parse("https://play.google.com/store/apps/details?id=" + context.getPackageName()));
            context.startActivity(intent2);
        }
    }

    static /* synthetic */ void a(a aVar, String str, boolean z) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("source", aVar.e ? "cli" : !z ? "sergentle" : "serforce");
        } catch (JSONException e2) {
            e2.printStackTrace();
        }
        b.a(str, jSONObject.toString());
    }
}