package com.appsflyer.internal;

import android.content.ContentResolver;
import android.content.Context;
import android.os.Build;
import android.provider.Settings;
import com.appsflyer.AFLogger;
import com.appsflyer.AppsFlyerProperties;
import com.appsflyer.ServerParameters;
import com.appsflyer.internal.u;
import com.appsflyer.internal.x;
import com.appsflyer.share.Constants;
import com.google.android.gms.ads.identifier.AdvertisingIdClient;
import com.google.android.gms.common.GoogleApiAvailability;
import java.util.Map;

public final class v {

    public static class c extends IllegalStateException {
        public c(String str) {
            super(str);
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:19:0x0045, code lost:
        if (r8.length() == 0) goto L_0x0047;
     */
    /* JADX WARNING: Removed duplicated region for block: B:33:0x0090 A[SYNTHETIC, Splitter:B:33:0x0090] */
    /* JADX WARNING: Removed duplicated region for block: B:48:0x00eb  */
    /* JADX WARNING: Removed duplicated region for block: B:51:0x00fc  */
    /* JADX WARNING: Removed duplicated region for block: B:54:0x0117  */
    /* JADX WARNING: Removed duplicated region for block: B:56:0x0132 A[ADDED_TO_REGION] */
    /* JADX WARNING: Removed duplicated region for block: B:59:? A[ADDED_TO_REGION, RETURN, SYNTHETIC] */
    /* renamed from: ˎ  reason: contains not printable characters */
    public static void m1247(Context context, Map<String, Object> map) {
        int i;
        String str;
        boolean z;
        String str2;
        String str3;
        Throwable th;
        AFLogger.afInfoLog("Trying to fetch GAID..");
        StringBuilder sb = new StringBuilder();
        try {
            i = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context);
        } catch (Throwable th2) {
            AFLogger.afErrorLog(th2.getMessage(), th2);
            i = -1;
        }
        boolean z2 = false;
        try {
            Class.forName("com.google.android.gms.ads.identifier.AdvertisingIdClient");
            AdvertisingIdClient.Info advertisingIdInfo = AdvertisingIdClient.getAdvertisingIdInfo(context);
            if (advertisingIdInfo != null) {
                str = advertisingIdInfo.getId();
                try {
                    String bool = Boolean.toString(!advertisingIdInfo.isLimitAdTrackingEnabled());
                    if (str != null) {
                        try {
                        } catch (Throwable th3) {
                            th = th3;
                            str3 = bool;
                            z = true;
                            AFLogger.afErrorLog(th.getMessage(), th);
                            sb.append(th.getClass().getSimpleName());
                            sb.append(" |");
                            AFLogger.afInfoLog("WARNING: Google Play Services is missing.");
                            if (AppsFlyerProperties.getInstance().getBoolean(AppsFlyerProperties.ENABLE_GPS_FALLBACK, true)) {
                                try {
                                    x.c r8 = x.m1249(context);
                                    String str4 = r8.f2149;
                                    if (!r8.f2148) {
                                        z2 = true;
                                    }
                                    String bool2 = Boolean.toString(z2);
                                    if (str4 == null || str4.length() == 0) {
                                        sb.append("emptyOrNull (bypass) |");
                                    }
                                    str2 = bool2;
                                    str = str4;
                                } catch (Throwable th4) {
                                    AFLogger.afErrorLog(th4.getMessage(), th4);
                                    sb.append(th4.getClass().getSimpleName());
                                    sb.append(" |");
                                    str = AppsFlyerProperties.getInstance().getString(ServerParameters.ADVERTISING_ID_PARAM);
                                    str2 = AppsFlyerProperties.getInstance().getString("advertiserIdEnabled");
                                    if (th4.getLocalizedMessage() != null) {
                                        AFLogger.afInfoLog(th4.getLocalizedMessage());
                                    } else {
                                        AFLogger.afInfoLog(th4.toString());
                                    }
                                }
                            } else {
                                str2 = str3;
                            }
                            if (context.getClass().getName().equals("android.app.ReceiverRestrictedContext")) {
                            }
                            if (sb.length() > 0) {
                            }
                            if (str != null) {
                                return;
                            }
                            return;
                        }
                    }
                    sb.append("emptyOrNull |");
                    str2 = bool;
                    z = true;
                } catch (Throwable th5) {
                    th = th5;
                    str3 = null;
                    z = false;
                    AFLogger.afErrorLog(th.getMessage(), th);
                    sb.append(th.getClass().getSimpleName());
                    sb.append(" |");
                    AFLogger.afInfoLog("WARNING: Google Play Services is missing.");
                    if (AppsFlyerProperties.getInstance().getBoolean(AppsFlyerProperties.ENABLE_GPS_FALLBACK, true)) {
                    }
                    if (context.getClass().getName().equals("android.app.ReceiverRestrictedContext")) {
                    }
                    if (sb.length() > 0) {
                    }
                    if (str != null) {
                    }
                }
                if (context.getClass().getName().equals("android.app.ReceiverRestrictedContext")) {
                    str = AppsFlyerProperties.getInstance().getString(ServerParameters.ADVERTISING_ID_PARAM);
                    str2 = AppsFlyerProperties.getInstance().getString("advertiserIdEnabled");
                    sb.append("context = android.app.ReceiverRestrictedContext |");
                }
                if (sb.length() > 0) {
                    StringBuilder sb2 = new StringBuilder();
                    sb2.append(i);
                    sb2.append(": ");
                    sb2.append((Object) sb);
                    map.put("gaidError", sb2.toString());
                }
                if (str != null && str2 != null) {
                    map.put(ServerParameters.ADVERTISING_ID_PARAM, str);
                    map.put("advertiserIdEnabled", str2);
                    AppsFlyerProperties.getInstance().set(ServerParameters.ADVERTISING_ID_PARAM, str);
                    AppsFlyerProperties.getInstance().set("advertiserIdEnabled", str2);
                    map.put("isGaidWithGps", String.valueOf(z));
                    return;
                }
                return;
            }
            sb.append("gpsAdInfo-null |");
            throw new c("GpsAdIndo is null");
        } catch (Throwable th6) {
            th = th6;
            str = null;
            str3 = null;
            z = false;
            AFLogger.afErrorLog(th.getMessage(), th);
            sb.append(th.getClass().getSimpleName());
            sb.append(" |");
            AFLogger.afInfoLog("WARNING: Google Play Services is missing.");
            if (AppsFlyerProperties.getInstance().getBoolean(AppsFlyerProperties.ENABLE_GPS_FALLBACK, true)) {
            }
            if (context.getClass().getName().equals("android.app.ReceiverRestrictedContext")) {
            }
            if (sb.length() > 0) {
            }
            if (str != null) {
            }
        }
    }

    /* renamed from: ˏ  reason: contains not printable characters */
    public static u m1248(ContentResolver contentResolver) {
        String str;
        if (contentResolver == null || AppsFlyerProperties.getInstance().getString("amazon_aid") != null || !"Amazon".equals(Build.MANUFACTURER)) {
            return null;
        }
        int i = Settings.Secure.getInt(contentResolver, "limit_ad_tracking", 2);
        if (i == 0) {
            return new u(u.e.AMAZON, Settings.Secure.getString(contentResolver, Constants.URL_ADVERTISING_ID), false);
        } else if (i == 2) {
            return null;
        } else {
            try {
                str = Settings.Secure.getString(contentResolver, Constants.URL_ADVERTISING_ID);
            } catch (Throwable th) {
                AFLogger.afErrorLog("Couldn't fetch Amazon Advertising ID (Ad-Tracking is limited!)", th);
                str = "";
            }
            return new u(u.e.AMAZON, str, true);
        }
    }
}
