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


package com.ss.android.downloadlib.g;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;
import com.kuaishou.weapon.p0.u;
import com.ss.android.download.api.config.q;
import com.ss.android.download.api.constant.BaseConstants;
import com.ss.android.downloadlib.a.a.b;
import com.ss.android.downloadlib.activity.JumpKllkActivity;
import com.ss.android.downloadlib.activity.TTDelegateActivity;
import com.ss.android.downloadlib.addownload.b.e;
import com.ss.android.downloadlib.addownload.b.f;
import com.ss.android.downloadlib.addownload.b.g;
import com.ss.android.downloadlib.addownload.j;
import com.ss.android.downloadlib.e.c;
import com.ss.android.socialbase.appdownloader.f.d;
import com.ss.android.socialbase.downloader.g.a;
import com.umeng.analytics.pro.am;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/* compiled from: InnerOpenAppUtils */
public class h {
    public static g a(Context context, Uri uri) {
        if (context == null || uri == null || !BaseConstants.SCHEME_MARKET.equals(uri.getScheme())) {
            return new g(6, 12);
        }
        try {
            Intent intent = new Intent("android.intent.action.VIEW", uri);
            if (!l.a(context, intent)) {
                return new g(6, 13);
            }
            String i = d.i();
            if (l.d(context, i) && !d.f()) {
                intent.setPackage(i);
            }
            if (a.c().a("fix_jump_market")) {
                intent.addFlags(335544320);
            } else if (!(context instanceof Activity)) {
                intent.addFlags(268435456);
            }
            if (a.c().b("test_jump_market_failed") == 1) {
                c.a().a(false, "jump market error");
                return new g(6, 25);
            }
            intent.putExtra(BaseConstants.START_ONLY_FOR_ANDROID, true);
            context.startActivity(intent);
            return new g(5);
        } catch (Exception unused) {
            return new g(6, 14);
        }
    }

    public static g a(Context context, String str) {
        if (context == null || TextUtils.isEmpty(str)) {
            return new g(6, 11);
        }
        if (d.f() && l.d(context, "com.sec.android.app.samsungapps")) {
            return d(context, str);
        }
        return a(context, Uri.parse(BaseConstants.MARKET_PREFIX + str));
    }

    public static g a(Context context, e eVar, String str) {
        if (context == null || TextUtils.isEmpty(str)) {
            return new g(6, 11);
        }
        if (d.f() && l.d(context, "com.sec.android.app.samsungapps")) {
            return d(context, str);
        }
        if (!eVar.b.isAd() || !eVar.d.enableAM()) {
            return a(context, Uri.parse(BaseConstants.MARKET_PREFIX + str));
        }
        JSONArray optJSONArray = j.i().optJSONArray("am_plans");
        if (d.b() && com.ss.android.socialbase.appdownloader.f.a.a(optJSONArray, "am_0")) {
            b(context, eVar, str);
            return new g(7, "am_m1");
        } else if (d.d() && com.ss.android.socialbase.appdownloader.f.a.a(optJSONArray, "am_3")) {
            return c(context, eVar, str);
        } else {
            if (d.e() && com.ss.android.socialbase.appdownloader.f.a.a(optJSONArray, "am_2")) {
                d(context, eVar, str);
                return new g(7, "am_m2");
            } else if (!d.c() || !com.ss.android.socialbase.appdownloader.f.a.a(optJSONArray, "am_5")) {
                return a(context, Uri.parse(BaseConstants.MARKET_PREFIX + str));
            } else {
                e(context, eVar, str);
                return new g(7, "am_v1");
            }
        }
    }

    private static g d(Context context, String str) {
        try {
            Uri parse = Uri.parse("https://www.samsungapps.com/appquery/appDetail.as?appId=" + str);
            Intent intent = new Intent();
            intent.setClassName("com.sec.android.app.samsungapps", "com.sec.android.app.samsungapps.Main");
            intent.setData(parse);
            if (!(context instanceof Activity)) {
                intent.addFlags(268435456);
            }
            intent.putExtra(BaseConstants.START_ONLY_FOR_ANDROID, true);
            context.startActivity(intent);
            return new g(5);
        } catch (Exception unused) {
            return new g(6, 14);
        }
    }

    private static void b(final Context context, final e eVar, final String str) {
        com.ss.android.downloadlib.d.a().a(new Runnable() {
            /* class com.ss.android.downloadlib.g.h.AnonymousClass1 */

            public void run() {
                final JSONObject i = j.i();
                final String optString = i.optString("s");
                final JSONObject jSONObject = new JSONObject();
                String a2 = com.ss.android.socialbase.appdownloader.f.c.a(i.optString("x"), optString);
                JSONObject jSONObject2 = new JSONObject();
                l.a(jSONObject2, "p", str);
                l.a(jSONObject2, "i", Build.VERSION.INCREMENTAL);
                l.a(jSONObject2, u.r, Build.MODEL);
                l.a(jSONObject2, "im", b.a(context));
                l.a(jSONObject2, "d", b.b(context));
                l.a(jSONObject2, am.aI, u.r);
                byte[] bytes = jSONObject2.toString().getBytes();
                j.d().a(a2, j.q().a(bytes, bytes.length), "application/octet-stream;tt-data=a", 0, new q() {
                    /* class com.ss.android.downloadlib.g.h.AnonymousClass1.AnonymousClass1 */

                    @Override // com.ss.android.download.api.config.q
                    public void a(String str) {
                        h.b(context, str, str, eVar, jSONObject, i, optString);
                    }

                    @Override // com.ss.android.download.api.config.q
                    public void a(Throwable th) {
                        Context context = context;
                        com.ss.android.downloadlib.b.a.a(h.a(context, Uri.parse(BaseConstants.MARKET_PREFIX + str)), eVar, true);
                        l.a(jSONObject, "ttdownloader_message", th != null ? th.getMessage() : "null");
                        h.b(eVar, jSONObject, 4, 1);
                    }
                });
            }
        });
    }

    private static String a(String str, JSONObject jSONObject, String str2) {
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        String a = com.ss.android.socialbase.appdownloader.f.c.a(jSONObject.optString("g"), str2);
        String a2 = com.ss.android.socialbase.appdownloader.f.c.a(jSONObject.optString("h"), str2);
        return (TextUtils.isEmpty(a) || TextUtils.isEmpty(a2)) ? str : str.replace(a, a2);
    }

    private static g c(Context context, e eVar, String str) {
        Intent intent = new Intent(context, JumpKllkActivity.class);
        intent.addFlags(268435456);
        intent.putExtra("p", str);
        intent.putExtra("id", eVar.a);
        intent.putExtra(BaseConstants.START_ONLY_FOR_ANDROID, true);
        JSONObject jSONObject = new JSONObject();
        try {
            context.startActivity(intent);
            return new g(7, "am_kllk2");
        } catch (Throwable unused) {
            b(eVar, jSONObject, 1, 3);
            return a(context, Uri.parse(BaseConstants.MARKET_PREFIX + str));
        }
    }

    public static void a(Context context, String str, long j, boolean z) {
        JSONObject jSONObject = new JSONObject();
        e e = f.a().e(j);
        try {
            JSONObject i = j.i();
            String optString = i.optString("s");
            String a = com.ss.android.socialbase.appdownloader.f.c.a(i.optString("aa"), optString);
            String a2 = com.ss.android.socialbase.appdownloader.f.c.a(i.optString("ac"), optString);
            String a3 = com.ss.android.socialbase.appdownloader.f.c.a(i.optString("af"), optString);
            boolean a4 = com.ss.android.socialbase.appdownloader.f.a.a(i, context, a2);
            StringBuilder sb = new StringBuilder(String.format(a, str, a3, a2));
            Intent intent = new Intent("android.intent.action.VIEW");
            String i2 = d.i();
            if (l.d(context, i2)) {
                intent.setPackage(i2);
            }
            if (z) {
                sb.append(com.ss.android.socialbase.appdownloader.f.c.a(i.optString("ae"), optString));
            } else {
                intent.addFlags(335544320);
            }
            l.a(jSONObject, "mf", Boolean.valueOf(a4));
            l.a(jSONObject, "if", Boolean.valueOf(z));
            intent.setData(Uri.parse(sb.toString()));
            intent.putExtra(BaseConstants.START_ONLY_FOR_ANDROID, true);
            context.startActivity(intent);
            com.ss.android.downloadlib.b.a.a("am_kllk2", jSONObject, e, true);
            if (a4) {
                b(e, jSONObject, -1, 3);
            } else {
                b(e, jSONObject, 3, 3);
            }
        } catch (Exception unused) {
            Context context2 = j.getContext();
            com.ss.android.downloadlib.b.a.a(a(context2, Uri.parse(BaseConstants.MARKET_PREFIX + str)), e, true);
            b(e, jSONObject, 2, 3);
        }
    }

    private static boolean e(Context context, String str) {
        if (context == null) {
            context = j.getContext();
        }
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        Intent intent = new Intent("android.intent.action.VIEW");
        if (!(context instanceof Activity)) {
            intent.addFlags(268435456);
            if (a.c().a("fix_app_link_flag")) {
                intent.addFlags(32768);
            }
        }
        intent.setData(Uri.parse(str));
        intent.putExtra(BaseConstants.START_ONLY_FOR_ANDROID, true);
        String i = d.i();
        if (l.d(j.getContext(), i)) {
            intent.setPackage(i);
        }
        if (!l.a(j.getContext(), intent)) {
            return false;
        }
        try {
            context.startActivity(intent);
            return true;
        } catch (Exception unused) {
            return false;
        }
    }

    private static boolean a(Activity activity, String str, HashMap<String, String> hashMap) {
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.setData(Uri.parse(BaseConstants.MARKET_PREFIX + str));
        intent.putExtra(BaseConstants.START_ONLY_FOR_ANDROID, true);
        intent.putExtra("param", hashMap);
        String i = d.i();
        if (l.d(j.getContext(), i)) {
            intent.setPackage(i);
        }
        if (!l.a(j.getContext(), intent)) {
            return false;
        }
        try {
            activity.startActivity(intent);
            return true;
        } catch (Exception e) {
            c.a().a(e, "start v1");
            return false;
        }
    }

    /* access modifiers changed from: private */
    public static void b(Context context, String str, String str2, e eVar, JSONObject jSONObject, JSONObject jSONObject2, String str3) {
        l.a(jSONObject, "ttdownloader_type", (Object) 1);
        try {
            String a = a(com.ss.android.socialbase.appdownloader.f.c.a(new JSONObject(str2).optString("a")), jSONObject2, str3);
            l.a(jSONObject, "open_url", a);
            if (e(context, a)) {
                b(eVar, jSONObject, -1, 1);
                com.ss.android.downloadlib.b.a.a("am_m1", jSONObject, eVar, true);
                return;
            }
            com.ss.android.downloadlib.b.a.a(a(context, Uri.parse(BaseConstants.MARKET_PREFIX + str)), eVar, true);
            b(eVar, jSONObject, 2, 1);
        } catch (Exception unused) {
            com.ss.android.downloadlib.b.a.a(a(context, Uri.parse(BaseConstants.MARKET_PREFIX + str)), eVar, true);
            b(eVar, jSONObject, 3, 1);
        }
    }

    private static void d(final Context context, final e eVar, final String str) {
        com.ss.android.downloadlib.d.a().a(new Runnable() {
            /* class com.ss.android.downloadlib.g.h.AnonymousClass2 */

            public void run() {
                Context context = context;
                com.ss.android.downloadlib.b.a.a(h.a(context, Uri.parse(BaseConstants.MARKET_PREFIX + str)), eVar, true);
                JSONObject jSONObject = new JSONObject();
                try {
                    JSONObject i = j.i();
                    Thread.sleep((long) i.optInt("m2_delay_millis", 1000));
                    com.ss.android.downloadlib.a.b.a.a().a(context, true);
                    com.ss.android.downloadlib.a.b.b bVar = new com.ss.android.downloadlib.a.b.b();
                    bVar.a = 1;
                    bVar.b = 0;
                    bVar.c = String.format(com.ss.android.socialbase.appdownloader.f.c.a(i.optString("v"), i.optString("s")), str);
                    com.ss.android.downloadlib.a.b.a.a().a(bVar, (com.ss.android.downloadlib.a.b.d) null);
                    com.ss.android.downloadlib.a.b.a.a().b();
                    h.b(eVar, jSONObject, -1, 2);
                } catch (Throwable th) {
                    th.printStackTrace();
                    h.b(eVar, jSONObject, 1, 2);
                }
            }
        });
    }

    private static void e(final Context context, final e eVar, final String str) {
        com.ss.android.downloadlib.d.a().a(new Runnable() {
            /* class com.ss.android.downloadlib.g.h.AnonymousClass3 */

            public void run() {
                JSONObject i = j.i();
                String optString = i.optString("s");
                final JSONObject jSONObject = new JSONObject();
                String a2 = com.ss.android.socialbase.appdownloader.f.c.a(i.optString("x"), optString);
                JSONObject jSONObject2 = new JSONObject();
                l.a(jSONObject2, am.aI, "v");
                l.a(jSONObject2, "p", str);
                byte[] bytes = jSONObject2.toString().getBytes();
                j.d().a(a2, j.q().a(bytes, bytes.length), "application/octet-stream;tt-data=a", 0, new q() {
                    /* class com.ss.android.downloadlib.g.h.AnonymousClass3.AnonymousClass1 */

                    @Override // com.ss.android.download.api.config.q
                    public void a(String str) {
                        h.b(context, str, str, eVar, jSONObject);
                    }

                    @Override // com.ss.android.download.api.config.q
                    public void a(Throwable th) {
                        Context context = context;
                        com.ss.android.downloadlib.b.a.a(h.a(context, Uri.parse(BaseConstants.MARKET_PREFIX + str)), eVar, true);
                        l.a(jSONObject, "ttdownloader_message", th != null ? th.getMessage() : "null");
                        h.b(eVar, jSONObject, 7, 5);
                    }
                });
            }
        });
    }

    /* access modifiers changed from: private */
    public static void b(Context context, String str, String str2, e eVar, JSONObject jSONObject) {
        l.a(jSONObject, "ttdownloader_type", (Object) 5);
        try {
            String a = com.ss.android.socialbase.appdownloader.f.c.a(new JSONObject(str2).optString("a"));
            if (!TextUtils.isEmpty(a)) {
                TTDelegateActivity.a(str, eVar.a, a, jSONObject);
                return;
            }
            com.ss.android.downloadlib.b.a.a(a(context, Uri.parse(BaseConstants.MARKET_PREFIX + str)), eVar, true);
            b(eVar, jSONObject, 5, 5);
        } catch (Exception unused) {
            com.ss.android.downloadlib.b.a.a(a(context, Uri.parse(BaseConstants.MARKET_PREFIX + str)), eVar, true);
            b(eVar, jSONObject, 6, 5);
        }
    }

    public static void a(Activity activity, String str, long j, String str2, String str3) {
        JSONObject jSONObject;
        try {
            jSONObject = new JSONObject(str3);
        } catch (JSONException unused) {
            jSONObject = new JSONObject();
        }
        e e = f.a().e(j);
        try {
            JSONObject i = j.i();
            boolean a = com.ss.android.socialbase.appdownloader.f.a.a(i, activity, com.ss.android.socialbase.appdownloader.f.c.a(i.optString("bg"), i.optString("s")));
            HashMap<String, String> b = l.b(new JSONObject(str2));
            if (!a || b.isEmpty() || !a(activity, str, b)) {
                b(e, jSONObject, a ? b.isEmpty() ? 1 : 2 : 3, 5);
                com.ss.android.downloadlib.b.a.a(a(activity, Uri.parse(BaseConstants.MARKET_PREFIX + str)), e, true);
                return;
            }
            b(e, jSONObject, -1, 5);
            com.ss.android.downloadlib.b.a.a("am_v1", jSONObject, e, true);
        } catch (Exception unused2) {
            Context context = j.getContext();
            com.ss.android.downloadlib.b.a.a(a(context, Uri.parse(BaseConstants.MARKET_PREFIX + str)), e, true);
            b(e, jSONObject, 4, 5);
        }
    }

    /* access modifiers changed from: private */
    public static void b(e eVar, JSONObject jSONObject, int i, int i2) {
        l.a(jSONObject, "error_code", Integer.valueOf(i));
        l.a(jSONObject, "ttdownloader_type", Integer.valueOf(i2));
        l.a(jSONObject, d.i(), Integer.valueOf(l.b(j.getContext(), d.i())));
        com.ss.android.downloadlib.d.a.a().b("am_result", jSONObject, eVar);
    }

    static g b(Context context, String str) {
        if (TextUtils.isEmpty(str)) {
            return new g(4, 11);
        }
        if (context == null) {
            context = j.getContext();
        }
        Intent f = l.f(context, str);
        if (f == null) {
            return new g(4, 22);
        }
        f.putExtra(BaseConstants.START_ONLY_FOR_ANDROID, true);
        try {
            context.startActivity(f);
            return new g(3);
        } catch (Exception unused) {
            return new g(4, 23);
        }
    }

    static g a(Context context, String str, com.ss.android.downloadad.api.a.a aVar) {
        Intent f = l.f(context, str);
        if (f == null) {
            return new g(4, 22);
        }
        if (Build.VERSION.SDK_INT < 26 || j.i().optInt("open_package_mode") != 1 || j.k() == null || !j.k().a() || !aVar.q()) {
            f.putExtra(BaseConstants.START_ONLY_FOR_ANDROID, true);
            try {
                context.startActivity(f);
                return new g(3);
            } catch (Exception unused) {
                return new g(4, 23);
            }
        } else {
            TTDelegateActivity.b(str, aVar);
            return new g(3);
        }
    }

    static g a(String str, com.ss.android.downloadad.api.a.a aVar) {
        return a(j.getContext(), str, aVar);
    }

    static g b(String str, com.ss.android.downloadad.api.a.a aVar) {
        if (TextUtils.isEmpty(str)) {
            return new g(2, 21);
        }
        Context context = j.getContext();
        Uri parse = Uri.parse(str);
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.setData(parse);
        intent.addFlags(268435456);
        intent.putExtra("open_url", str);
        intent.putExtra(BaseConstants.START_ONLY_FOR_ANDROID, true);
        if (a.c().a("fix_app_link_flag")) {
            intent.addFlags(67108864);
        }
        if (!l.b(context, intent)) {
            return new g(2, 24);
        }
        if (j.i().optInt("open_url_mode") != 0 || j.k() == null || !j.k().a() || Build.VERSION.SDK_INT < 26 || !aVar.q()) {
            try {
                j.getContext().startActivity(intent);
            } catch (Exception unused) {
                return new g(2);
            }
        } else {
            TTDelegateActivity.a(str, aVar);
        }
        return new g(1);
    }

    static g a(com.ss.android.downloadad.api.a.b bVar, String str, String str2) {
        g b = b(str, bVar);
        return (com.ss.android.downloadlib.b.f.a(bVar) && b.getType() == 2) ? a(str2, bVar) : b;
    }

    static boolean c(Context context, String str) {
        if (context == null) {
            return false;
        }
        try {
            Uri parse = Uri.parse(str);
            Intent intent = new Intent("android.intent.action.VIEW");
            intent.setData(parse);
            intent.addFlags(268435456);
            intent.putExtra("open_url", str);
            intent.putExtra(BaseConstants.START_ONLY_FOR_ANDROID, true);
            context.startActivity(intent);
            return true;
        } catch (Throwable th) {
            th.printStackTrace();
            return false;
        }
    }
}