package com.facebook.internal; import android.content.Context; import android.content.Intent; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import androidx.browser.customtabs.CustomTabsService; import com.facebook.FacebookSdk; import com.facebook.internal.instrument.crashshield.CrashShieldHandler; import java.util.HashSet; import java.util.Iterator; import java.util.List; import kotlin.collections.ArraysKt___ArraysKt; import kotlin.jvm.internal.Intrinsics; /* loaded from: classes2.dex */ public final class CustomTabUtils { public static final CustomTabUtils INSTANCE = new CustomTabUtils(); private static final String[] CHROME_PACKAGES = {"com.android.chrome", "com.chrome.beta", "com.chrome.dev"}; private CustomTabUtils() { } public static final String getDefaultRedirectURI() { if (CrashShieldHandler.isObjectCrashing(CustomTabUtils.class)) { return null; } try { return Intrinsics.stringPlus(Validate.CUSTOM_TAB_REDIRECT_URI_PREFIX, FacebookSdk.getApplicationContext().getPackageName()); } catch (Throwable th) { CrashShieldHandler.handleThrowable(th, CustomTabUtils.class); return null; } } public static final String getValidRedirectURI(String developerDefinedRedirectURI) { if (CrashShieldHandler.isObjectCrashing(CustomTabUtils.class)) { return null; } try { Intrinsics.checkNotNullParameter(developerDefinedRedirectURI, "developerDefinedRedirectURI"); Validate validate = Validate.INSTANCE; return Validate.hasCustomTabRedirectActivity(FacebookSdk.getApplicationContext(), developerDefinedRedirectURI) ? developerDefinedRedirectURI : Validate.hasCustomTabRedirectActivity(FacebookSdk.getApplicationContext(), getDefaultRedirectURI()) ? getDefaultRedirectURI() : ""; } catch (Throwable th) { CrashShieldHandler.handleThrowable(th, CustomTabUtils.class); return null; } } public static final String getChromePackage() { HashSet hashSet; if (CrashShieldHandler.isObjectCrashing(CustomTabUtils.class)) { return null; } try { Context applicationContext = FacebookSdk.getApplicationContext(); List queryIntentServices = applicationContext.getPackageManager().queryIntentServices(new Intent(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION), 0); Intrinsics.checkNotNullExpressionValue(queryIntentServices, "context.packageManager.queryIntentServices(serviceIntent, 0)"); hashSet = ArraysKt___ArraysKt.toHashSet(CHROME_PACKAGES); Iterator it = queryIntentServices.iterator(); while (it.hasNext()) { ServiceInfo serviceInfo = it.next().serviceInfo; if (serviceInfo != null && hashSet.contains(serviceInfo.packageName)) { return serviceInfo.packageName; } } return null; } catch (Throwable th) { CrashShieldHandler.handleThrowable(th, CustomTabUtils.class); return null; } } }