package p138.p176.p177.p242.p265.p266;

import android.content.Context;
import android.content.ServiceConnection;
import android.net.Uri;
import android.os.Bundle;
import p138.p176.p177.p242.p246.p252.C4306;
import p138.p176.p177.p242.p258.p263.C4495;
import p138.p176.p177.p242.p258.p263.InterfaceC4688;
import p138.p176.p177.p242.p258.p263.InterfaceC4728;

/* JADX INFO: renamed from: ދ.ހ.֏.ހ.ބ.֏.ͺ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class RunnableC4832 implements Runnable {

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final /* synthetic */ InterfaceC4728 f14541;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final /* synthetic */ ServiceConnection f14542;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public final /* synthetic */ ServiceConnectionC4872 f14543;

    public RunnableC4832(ServiceConnectionC4872 serviceConnectionC4872, InterfaceC4728 interfaceC4728, ServiceConnection serviceConnection) {
        this.f14543 = serviceConnectionC4872;
        this.f14541 = interfaceC4728;
        this.f14542 = serviceConnection;
    }

    /* JADX WARN: Removed duplicated region for block: B:15:0x0060  */
    /* JADX WARN: Removed duplicated region for block: B:45:0x011a  */
    /* JADX WARN: Removed duplicated region for block: B:46:0x012a  */
    /* JADX WARN: Removed duplicated region for block: B:55:0x018a  */
    /* JADX WARN: Removed duplicated region for block: B:59:0x0199 A[ORIG_RETURN, RETURN] */
    @Override // java.lang.Runnable
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void run() {
        Bundle bundleMo7475;
        ServiceConnectionC4872 serviceConnectionC4872 = this.f14543;
        C4880 c4880 = serviceConnectionC4872.f14643;
        String str = serviceConnectionC4872.f14642;
        InterfaceC4728 interfaceC4728 = this.f14541;
        ServiceConnection serviceConnection = this.f14542;
        c4880.f14686.mo8163().mo8008();
        if (interfaceC4728 != null) {
            Bundle bundle = new Bundle();
            bundle.putString("package_name", str);
            try {
                bundleMo7475 = interfaceC4728.mo7475(bundle);
                if (bundleMo7475 == null) {
                    c4880.f14686.mo8165().f14444.m8034("Install Referrer Service returned a null response");
                }
            } catch (Exception e) {
                c4880.f14686.mo8165().f14444.m8035("Exception occurred while retrieving the Install Referrer", e.getMessage());
            }
            c4880.f14686.mo8163().mo8008();
            if (bundleMo7475 != null) {
                long j = bundleMo7475.getLong("install_begin_timestamp_seconds", 0L) * 1000;
                if (j == 0) {
                    c4880.f14686.mo8165().f14444.m8034("Service response is missing Install Referrer install timestamp");
                } else {
                    String string = bundleMo7475.getString("install_referrer");
                    if (string == null || string.isEmpty()) {
                        c4880.f14686.mo8165().f14444.m8034("No referrer defined in Install Referrer response");
                    } else {
                        c4880.f14686.mo8165().f14452.m8035("InstallReferrer API result", string);
                        Bundle bundleM8238 = c4880.f14686.m8504().m8238(Uri.parse(string.length() != 0 ? "?".concat(string) : new String("?")));
                        if (bundleM8238 == null) {
                            c4880.f14686.mo8165().f14444.m8034("No campaign params defined in Install Referrer result");
                        } else {
                            String string2 = bundleM8238.getString("medium");
                            if ((string2 == null || "(not set)".equalsIgnoreCase(string2) || "organic".equalsIgnoreCase(string2)) ? false : true) {
                                long j2 = bundleMo7475.getLong("referrer_click_timestamp_seconds", 0L) * 1000;
                                if (j2 == 0) {
                                    c4880.f14686.mo8165().f14444.m8034("Install Referrer is missing click timestamp for ad campaign");
                                } else {
                                    bundleM8238.putLong("click_timestamp", j2);
                                    if (j != c4880.f14686.m8501().f14654.m8316()) {
                                        C4974 c4974 = c4880.f14686;
                                        C4785 c4785 = c4974.f15014;
                                        c4974.mo8165().f14452.m8034("Install Referrer campaign has already been logged");
                                    } else if (!((InterfaceC4688) C4495.f13903.mo7259()).mo7486() || !c4880.f14686.f15015.m8177(C4915.f14909) || c4880.f14686.m8495()) {
                                        c4880.f14686.m8501().f14654.m8317(j);
                                        C4974 c49742 = c4880.f14686;
                                        C4785 c47852 = c49742.f15014;
                                        c49742.mo8165().f14452.m8035("Logging Install Referrer campaign from sdk with ", "referrer API");
                                        bundleM8238.putString("_cis", "referrer API");
                                        c4880.f14686.m8503().m7972("auto", "_cmp", bundleM8238);
                                    }
                                }
                            } else if (j != c4880.f14686.m8501().f14654.m8316()) {
                            }
                        }
                    }
                }
            }
            if (serviceConnection == null) {
                C4306 c4306M7206 = C4306.m7206();
                Context context = c4880.f14686.f15009;
                if (c4306M7206 == null) {
                    throw null;
                }
                context.unbindService(serviceConnection);
                return;
            }
            return;
        }
        c4880.f14686.mo8165().f14447.m8034("Attempting to use Install Referrer Service while it is not initialized");
        bundleMo7475 = null;
        c4880.f14686.mo8163().mo8008();
        if (bundleMo7475 != null) {
        }
        if (serviceConnection == null) {
        }
    }
}
