package com.ss.android.ugc.aweme.share;

import X.2UX;
import X.2nK;
import X.3i8;
import X.6n0;
import X.6wq;
import X.9EH;
import X.Lnj;
import X.M12;
import X.OLG;
import X.OLN;
import X.OLR;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.ss.android.ugc.aweme.openshare.IShareRespSendService;
import com.ss.android.ugc.aweme.openshare.Share;

public final class IShareRespSendServiceImpl implements IShareRespSendService {
    static {
        Covode.recordClassIndex(106872);
    }

    public final 6n0 LIZ() {
        return new 6wq();
    }

    public static IShareRespSendService LIZIZ() {
        MethodCollector.i(2100);
        IShareRespSendService iShareRespSendService = (IShareRespSendService) Lnj.LIZ(IShareRespSendService.class, false);
        if (iShareRespSendService != null) {
            MethodCollector.o(2100);
            return iShareRespSendService;
        }
        Object LIZIZ = Lnj.LIZIZ(IShareRespSendService.class, false);
        if (LIZIZ != null) {
            IShareRespSendService iShareRespSendService2 = (IShareRespSendService) LIZIZ;
            MethodCollector.o(2100);
            return iShareRespSendService2;
        }
        if (Lnj.bg == null) {
            synchronized (IShareRespSendService.class) {
                try {
                    if (Lnj.bg == null) {
                        Lnj.bg = new IShareRespSendServiceImpl();
                    }
                } catch (Throwable th) {
                    MethodCollector.o(2100);
                    throw th;
                }
            }
        }
        IShareRespSendServiceImpl iShareRespSendServiceImpl = (IShareRespSendServiceImpl) Lnj.bg;
        MethodCollector.o(2100);
        return iShareRespSendServiceImpl;
    }

    public final void LIZ(Activity activity, OLR olr) {
        M12.LIZ(activity);
        if (olr != null && !TextUtils.isEmpty(olr.mClientKey) && OLN.LIZ(olr.getShareRequestBundle()) != null) {
            Share.Request LIZ = OLN.LIZ(olr.getShareRequestBundle());
            Share.Response response = new Share.Response();
            response.errorCode = 0;
            response.state = LIZ.mState;
            response.subErrorCode = 0;
            LIZ(activity, LIZ, response);
        }
    }

    private boolean LIZ(Activity activity, Share.Request request, Share.Response response) {
        M12.LIZ(activity);
        boolean z = false;
        if (request == null) {
            return false;
        }
        String callerPackage = request.getCallerPackage();
        String str = request.callerLocalEntry;
        if (TextUtils.isEmpty(callerPackage) || response == null || TextUtils.isEmpty(str) || !response.checkArgs() || TextUtils.equals(9EH.LJJIFFI.LIZ().getPackageName(), callerPackage)) {
            return false;
        }
        Bundle bundle = new Bundle();
        response.toBundle(bundle);
        Intent intent = new Intent();
        intent.setComponent(new ComponentName(callerPackage, str));
        intent.putExtras(bundle);
        intent.addFlags(67108864);
        intent.addFlags(268435456);
        try {
            3i8.LIZ(intent, activity);
            activity.startActivity(intent);
            activity.finish();
            z = true;
            return true;
        } catch (Exception unused) {
            activity.finish();
            return z;
        }
    }

    public final void LIZ(Activity activity, OLR olr, Share.Request request, Share.Response response) {
        M12.LIZ(activity, request, response);
        if (olr != null && !TextUtils.isEmpty(olr.mClientKey) && OLN.LIZ(olr.getShareRequestBundle()) != null) {
            Share.Request LIZ = OLN.LIZ(olr.getShareRequestBundle());
            2UX r3 = new 2UX();
            r3.LIZ("launch_from", LIZ.mClientKey);
            String str = "";
            if (LIZ.extras != null) {
                str = LIZ.extras.getString("style_id", str);
            }
            r3.LIZ("style_id", str);
            r3.LIZ("error_code", response.subErrorCode);
            2nK.LIZ("share_error_status", r3.LIZ);
            LIZ(activity, request, response);
        }
    }

    public final void LIZ(Activity activity, OLR olr, String str, int i) {
        M12.LIZ(activity, str);
        if (olr != null && !TextUtils.isEmpty(olr.mClientKey) && OLN.LIZ(olr.getShareRequestBundle()) != null) {
            Share.Request LIZ = OLN.LIZ(olr.getShareRequestBundle());
            Share.Response response = new Share.Response();
            response.subErrorCode = i;
            response.errorCode = OLG.LIZ(i);
            response.state = LIZ.mState;
            response.errorMsg = str;
            2UX r3 = new 2UX();
            r3.LIZ("launch_from", LIZ.mClientKey);
            String str2 = "";
            if (LIZ.extras != null) {
                str2 = LIZ.extras.getString("style_id", str2);
            }
            r3.LIZ("style_id", str2);
            r3.LIZ("error_code", i);
            2nK.LIZ("share_error_status", r3.LIZ);
            LIZ(activity, LIZ, response);
        }
    }
}
