package com.ss.android.ugc.aweme.legoImp.task;

import X.0HH;
import X.2HX;
import X.2Ye;
import X.3i8;
import X.8Zd;
import X.8Ze;
import X.8cV;
import X.8ec;
import X.9Ft;
import X.9Fx;
import X.9LK;
import X.C5749MCe;
import X.M6C;
import X.M6P;
import X.M7A;
import X.S9P;
import X.Tet;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.abmock.SettingsManager;
import com.facebook.applinks.a;
import com.ss.android.ugc.aweme.ActivityRouterServiceImpl;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONException;
import org.json.JSONObject;

public class AppLinkDataTask implements 8Ze {
    static {
        Covode.recordClassIndex(90393);
    }

    public boolean meetTrigger() {
        return true;
    }

    public String prefix() {
        return "task_";
    }

    public boolean serialExecute() {
        return false;
    }

    public int targetProcess() {
        return 1;
    }

    public List triggerOtherLegoComponents() {
        return null;
    }

    public 9Ft triggerType() {
        return 8Zd.LIZ(this);
    }

    public 9Fx scenesType() {
        return 9Fx.DEFAULT;
    }

    public 8ec type() {
        return 8ec.BOOT_FINISH;
    }

    public String key() {
        return getClass().getSimpleName();
    }

    private void LIZ(final Context context) {
        final long uptimeMillis = SystemClock.uptimeMillis();
        M6C.LIZ(context, new M6P() {
            static {
                Covode.recordClassIndex(90394);
            }

            public final void LIZ(M6C m6c) {
                Bundle bundle;
                String uri;
                a aVar = m6c.LIZIZ;
                if (aVar != null && (bundle = aVar.LIZLLL) != null) {
                    String string = bundle.getString("com.facebook.platform.APPLINK_NATIVE_URL");
                    if (!TextUtils.isEmpty(string) && !S9P.LJI.LIZ(string)) {
                        JSONObject jSONObject = new JSONObject();
                        try {
                            jSONObject.put("channel", "facebook");
                            jSONObject.put("url", string);
                            if (m6c.LIZ() == null) {
                                uri = "";
                            } else {
                                uri = m6c.LIZ().toString();
                            }
                            jSONObject.put("target", uri);
                            jSONObject.put("total_time", SystemClock.uptimeMillis() - 2HX.LIZ.LJFF);
                            jSONObject.put("fetch_time", SystemClock.uptimeMillis() - uptimeMillis);
                        } catch (JSONException e) {
                            0HH.LIZ(e);
                        }
                        9LK.LIZ("deep_link", jSONObject);
                        ArrayList arrayList = new ArrayList();
                        arrayList.add(new Tet("facebook_code_start_url", string));
                        new C5749MCe(2Ye.LIZ, M7A.POST, (List<Tet>) arrayList, String.class).LIZ();
                        Intent intent = new Intent(context, ActivityRouterServiceImpl.LIZIZ().LIZ());
                        intent.setAction("android.intent.action.VIEW");
                        intent.setData(m6c.LIZ());
                        intent.putExtra("dl_from", "facebook");
                        intent.addFlags(268435456);
                        intent.putExtra("from_notification", false);
                        intent.putExtra("from_task", true);
                        Context context = context;
                        3i8.LIZ(intent, context);
                        context.startActivity(intent);
                    }
                }
            }
        });
    }

    public void run(Context context) {
        if (SettingsManager.LIZ().LIZ("fb_ddl_switch", true)) {
            try {
                LIZ(context);
            } catch (Throwable th) {
                8cV.LIZ(th, "fetchDeferredAppLinkData retry failed");
            }
        }
    }
}
