b.java 源代码


package q1;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.text.TextUtils;
import com.bytedance.sdk.component.utils.l;
import com.bytedance.sdk.openadsdk.c.e;
import com.bytedance.sdk.openadsdk.c.n;
import com.bytedance.sdk.openadsdk.core.ab;
import com.bytedance.sdk.openadsdk.core.f.j;
import com.bytedance.sdk.openadsdk.core.o;
import com.bytedance.sdk.openadsdk.l.q;
import java.lang.ref.WeakReference;
import java.util.concurrent.atomic.AtomicBoolean;

public class b implements c {

    private WeakReference<Context> f25706a;

    protected com.bytedance.sdk.openadsdk.core.f.b f25707b;

    protected j f25708c;

    protected String f25709d;

    protected boolean f25710e = false;

    protected final AtomicBoolean f25711f = new AtomicBoolean(false);

    private boolean f25712g = false;

    public b(Context context, j jVar, String str) {
        this.f25706a = new WeakReference<>(context);
        this.f25708c = jVar;
        this.f25707b = jVar.T();
        this.f25709d = str;
        l.c("GPDownLoader", "====tag===" + str);
        if (o.a() == null) {
            o.a(context);
        }
    }

    public static boolean d(Context context, String str) {
        Intent launchIntentForPackage;
        if (context != null && str != null && !TextUtils.isEmpty(str)) {
            l.c("GPDownLoader", "gotoGooglePlay :market://details?id=" + str);
            Intent intent = new Intent("android.intent.action.VIEW");
            Uri parse = Uri.parse("market://details?id=" + str);
            intent.setData(parse);
            for (ResolveInfo resolveInfo : context.getPackageManager().queryIntentActivities(intent, 65536)) {
                if (resolveInfo.activityInfo.packageName.equals("com.android.vending") && (launchIntentForPackage = context.getPackageManager().getLaunchIntentForPackage("com.android.vending")) != null) {
                    ActivityInfo activityInfo = resolveInfo.activityInfo;
                    launchIntentForPackage.setComponent(new ComponentName(activityInfo.packageName, activityInfo.name));
                    launchIntentForPackage.setData(parse);
                    if (!(context instanceof Activity)) {
                        launchIntentForPackage.setFlags(268435456);
                    }
                    context.startActivity(launchIntentForPackage);
                    return true;
                }
            }
            try {
                Intent intent2 = new Intent("android.intent.action.VIEW", Uri.parse("https://play.google.com/store/apps/details?id=" + str));
                intent2.setFlags(268435456);
                context.startActivity(intent2);
                return true;
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }
        return false;
    }

    @Override
    public void a(boolean z6) {
        this.f25712g = z6;
    }

    public boolean b(Context context, String str) {
        return d(context, str);
    }

    public boolean c() {
        if (this.f25708c.U() != null) {
            String a7 = this.f25708c.U().a();
            if (!TextUtils.isEmpty(a7)) {
                Uri parse = Uri.parse(a7);
                Intent intent = new Intent("android.intent.action.VIEW");
                intent.setData(parse);
                if (q.a(f(), intent)) {
                    if (!(f() instanceof Activity)) {
                        intent.addFlags(268435456);
                    }
                    try {
                        e.f(o.a(), this.f25708c, this.f25709d, "open_url_app", null);
                        f().startActivity(intent);
                        n.a().a(this.f25708c, this.f25709d);
                        return true;
                    } catch (Throwable th) {
                        th.printStackTrace();
                    }
                }
            }
            if (!this.f25710e || this.f25711f.get()) {
                this.f25710e = true;
                e.f(f(), this.f25708c, this.f25709d, "open_fallback_url", null);
                return false;
            }
            return false;
        }
        return false;
    }

    @Override
    public boolean e() {
        this.f25711f.set(true);
        if (this.f25707b != null && b(f(), this.f25707b.c())) {
            return true;
        }
        return false;
    }

    public Context f() {
        WeakReference<Context> weakReference = this.f25706a;
        if (weakReference != null && weakReference.get() != null) {
            return this.f25706a.get();
        }
        return o.a();
    }

    @Override
    public boolean a() {
        Intent a7;
        if (this.f25707b == null) {
            return false;
        }
        j jVar = this.f25708c;
        if (jVar != null && jVar.am() == 0) {
            return false;
        }
        String c6 = this.f25707b.c();
        if (TextUtils.isEmpty(c6) || !q.b(f(), c6) || (a7 = q.a(f(), c6)) == null) {
            return false;
        }
        a7.putExtra("START_ONLY_FOR_ANDROID", true);
        try {
            f().startActivity(a7);
            e.f(f(), this.f25708c, this.f25709d, "click_open", null);
            return true;
        } catch (Throwable th) {
            th.printStackTrace();
            return false;
        }
    }

    @Override
    public void d() {
        if (f() == null) {
            return;
        }
        if (c()) {
            this.f25711f.set(true);
        } else {
            if (a() || e() || this.f25708c.T() != null || this.f25708c.I() == null) {
                return;
            }
            ab.a(f(), this.f25708c.I(), this.f25708c, q.a(this.f25709d), this.f25709d, true);
        }
    }
}