package com.facebook.gamingservices; import android.app.Activity; import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; import android.os.Bundle; import androidx.fragment.app.Fragment; import com.facebook.AccessToken; import com.facebook.FacebookCallback; import com.facebook.FacebookException; import com.facebook.FacebookSdk; import com.facebook.gamingservices.TournamentShareDialog; import com.facebook.gamingservices.cloudgaming.CloudGameLoginHandler; import com.facebook.gamingservices.cloudgaming.internal.SDKConstants; import com.facebook.gamingservices.internal.TournamentShareDialogURIBuilder; import com.facebook.internal.AppCall; import com.facebook.internal.CallbackManagerImpl; import com.facebook.internal.FacebookDialogBase; import com.facebook.internal.FragmentWrapper; import com.facebook.internal.NativeProtocol; import com.facebook.internal.instrument.crashshield.AutoHandleExceptions; import com.facebook.share.internal.ResultProcessor; import com.facebook.share.internal.ShareInternalUtility; import java.util.ArrayList; import java.util.List; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.jvm.internal.Intrinsics; @AutoHandleExceptions /* loaded from: classes2.dex */ public final class TournamentShareDialog extends FacebookDialogBase { public static final Companion Companion = new Companion(null); private static final int defaultRequestCode = CallbackManagerImpl.RequestCodeOffset.TournamentShareDialog.toRequestCode(); private Number score; private Tournament tournament; public final Number getScore() { return this.score; } public final Tournament getTournament() { return this.tournament; } public final void setScore(Number number) { this.score = number; } public final void setTournament(Tournament tournament) { this.tournament = tournament; } public static final class Companion { public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } private Companion() { } } /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ public TournamentShareDialog(Activity activity) { super(activity, defaultRequestCode); Intrinsics.checkNotNullParameter(activity, "activity"); } /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */ public TournamentShareDialog(Fragment fragment) { this(new FragmentWrapper(fragment)); Intrinsics.checkNotNullParameter(fragment, "fragment"); } /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */ public TournamentShareDialog(android.app.Fragment fragment) { this(new FragmentWrapper(fragment)); Intrinsics.checkNotNullParameter(fragment, "fragment"); } private TournamentShareDialog(FragmentWrapper fragmentWrapper) { super(fragmentWrapper, defaultRequestCode); } public final void show(Number score, TournamentConfig newTournamentConfig) { Intrinsics.checkNotNullParameter(score, "score"); Intrinsics.checkNotNullParameter(newTournamentConfig, "newTournamentConfig"); this.score = score; showImpl(newTournamentConfig, FacebookDialogBase.BASE_AUTOMATIC_MODE); } public final void show(Number score, Tournament tournament) { Intrinsics.checkNotNullParameter(score, "score"); Intrinsics.checkNotNullParameter(tournament, "tournament"); this.score = score; this.tournament = tournament; showImpl((TournamentConfig) null, FacebookDialogBase.BASE_AUTOMATIC_MODE); } @Override // com.facebook.internal.FacebookDialogBase public void showImpl(TournamentConfig tournamentConfig, Object mode) { Intrinsics.checkNotNullParameter(mode, "mode"); if (CloudGameLoginHandler.isRunningInCloud()) { return; } super.showImpl((TournamentShareDialog) tournamentConfig, mode); } @Override // com.facebook.internal.FacebookDialogBase public void registerCallbackImpl(CallbackManagerImpl callbackManager, final FacebookCallback callback) { Intrinsics.checkNotNullParameter(callbackManager, "callbackManager"); Intrinsics.checkNotNullParameter(callback, "callback"); final ResultProcessor resultProcessor = new ResultProcessor(callback) { // from class: com.facebook.gamingservices.TournamentShareDialog$registerCallbackImpl$resultProcessor$1 final /* synthetic */ FacebookCallback $callback; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ { super(callback); this.$callback = callback; } @Override // com.facebook.share.internal.ResultProcessor public void onSuccess(AppCall appCall, Bundle bundle) { Intrinsics.checkNotNullParameter(appCall, "appCall"); if (bundle != null) { if (bundle.getString("error_message") != null) { this.$callback.onError(new FacebookException(bundle.getString("error_message"))); return; } else if (bundle.getString(SDKConstants.PARAM_TOURNAMENTS_ID) != null) { this.$callback.onSuccess(new TournamentShareDialog.Result(bundle)); return; } } onCancel(appCall); } }; callbackManager.registerCallback(getRequestCode(), new CallbackManagerImpl.Callback() { // from class: com.facebook.gamingservices.TournamentShareDialog$$ExternalSyntheticLambda0 @Override // com.facebook.internal.CallbackManagerImpl.Callback public final boolean onActivityResult(int i, Intent intent) { boolean m554registerCallbackImpl$lambda0; m554registerCallbackImpl$lambda0 = TournamentShareDialog.m554registerCallbackImpl$lambda0(TournamentShareDialog.this, resultProcessor, i, intent); return m554registerCallbackImpl$lambda0; } }); } /* JADX INFO: Access modifiers changed from: private */ /* renamed from: registerCallbackImpl$lambda-0, reason: not valid java name */ public static final boolean m554registerCallbackImpl$lambda0(TournamentShareDialog this$0, ResultProcessor resultProcessor, int i, Intent intent) { Intrinsics.checkNotNullParameter(this$0, "this$0"); ShareInternalUtility shareInternalUtility = ShareInternalUtility.INSTANCE; return ShareInternalUtility.handleActivityResult(this$0.getRequestCode(), i, intent, resultProcessor); } @Override // com.facebook.internal.FacebookDialogBase public List.ModeHandler> getOrderedModeHandlers() { ArrayList arrayList = new ArrayList(); arrayList.add(new FacebookAppHandler(this)); arrayList.add(new AppSwitchHandler(this)); return arrayList; } @Override // com.facebook.internal.FacebookDialogBase public AppCall createBaseAppCall() { return new AppCall(getRequestCode(), null, 2, null); } public static final class Result { private String requestID; private String tournamentID; public final String getRequestID() { return this.requestID; } public final String getTournamentID() { return this.tournamentID; } public final void setRequestID(String str) { this.requestID = str; } public final void setTournamentID(String str) { this.tournamentID = str; } public Result(Bundle results) { Intrinsics.checkNotNullParameter(results, "results"); if (results.getString("request") != null) { this.requestID = results.getString("request"); } this.tournamentID = results.getString(SDKConstants.PARAM_TOURNAMENTS_ID); } } public final class FacebookAppHandler extends FacebookDialogBase.ModeHandler { final /* synthetic */ TournamentShareDialog this$0; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ public FacebookAppHandler(TournamentShareDialog this$0) { super(this$0); Intrinsics.checkNotNullParameter(this$0, "this$0"); this.this$0 = this$0; } @Override // com.facebook.internal.FacebookDialogBase.ModeHandler public boolean canShow(TournamentConfig tournamentConfig, boolean z) { PackageManager packageManager = FacebookSdk.getApplicationContext().getPackageManager(); Intrinsics.checkNotNullExpressionValue(packageManager, "getApplicationContext().packageManager"); Intent intent = new Intent("com.facebook.games.gaming_services.DEEPLINK"); intent.setType("text/plain"); return intent.resolveActivity(packageManager) != null; } @Override // com.facebook.internal.FacebookDialogBase.ModeHandler public AppCall createAppCall(TournamentConfig tournamentConfig) { Bundle bundleForUpdating$facebook_gamingservices_release; AccessToken currentAccessToken = AccessToken.Companion.getCurrentAccessToken(); AppCall createBaseAppCall = this.this$0.createBaseAppCall(); Intent intent = new Intent("com.facebook.games.gaming_services.DEEPLINK"); intent.setType("text/plain"); if (currentAccessToken == null || currentAccessToken.isExpired()) { throw new FacebookException("Attempted to share tournament with an invalid access token"); } if (currentAccessToken.getGraphDomain() != null && !Intrinsics.areEqual(FacebookSdk.GAMING, currentAccessToken.getGraphDomain())) { throw new FacebookException("Attempted to share tournament while user is not gaming logged in"); } String applicationId = currentAccessToken.getApplicationId(); Number score = this.this$0.getScore(); if (score == null) { throw new FacebookException("Attempted to share tournament without a score"); } if (tournamentConfig != null) { bundleForUpdating$facebook_gamingservices_release = TournamentShareDialogURIBuilder.INSTANCE.bundleForCreating$facebook_gamingservices_release(tournamentConfig, score, applicationId); } else { Tournament tournament = this.this$0.getTournament(); bundleForUpdating$facebook_gamingservices_release = tournament == null ? null : TournamentShareDialogURIBuilder.INSTANCE.bundleForUpdating$facebook_gamingservices_release(tournament.identifier, score, applicationId); } NativeProtocol nativeProtocol = NativeProtocol.INSTANCE; NativeProtocol.setupProtocolRequestIntent(intent, createBaseAppCall.getCallId().toString(), "", NativeProtocol.PROTOCOL_VERSION_20210906, bundleForUpdating$facebook_gamingservices_release); createBaseAppCall.setRequestIntent(intent); return createBaseAppCall; } } public final class AppSwitchHandler extends FacebookDialogBase.ModeHandler { final /* synthetic */ TournamentShareDialog this$0; @Override // com.facebook.internal.FacebookDialogBase.ModeHandler public boolean canShow(TournamentConfig tournamentConfig, boolean z) { return true; } /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ public AppSwitchHandler(TournamentShareDialog this$0) { super(this$0); Intrinsics.checkNotNullParameter(this$0, "this$0"); this.this$0 = this$0; } @Override // com.facebook.internal.FacebookDialogBase.ModeHandler public AppCall createAppCall(TournamentConfig tournamentConfig) { Uri uriForUpdating$facebook_gamingservices_release; AppCall createBaseAppCall = this.this$0.createBaseAppCall(); AccessToken currentAccessToken = AccessToken.Companion.getCurrentAccessToken(); if (currentAccessToken == null || currentAccessToken.isExpired()) { throw new FacebookException("Attempted to share tournament with an invalid access token"); } if (currentAccessToken.getGraphDomain() != null && !Intrinsics.areEqual(FacebookSdk.GAMING, currentAccessToken.getGraphDomain())) { throw new FacebookException("Attempted to share tournament without without gaming login"); } Number score = this.this$0.getScore(); if (score == null) { throw new FacebookException("Attempted to share tournament without a score"); } if (tournamentConfig != null) { uriForUpdating$facebook_gamingservices_release = TournamentShareDialogURIBuilder.INSTANCE.uriForCreating$facebook_gamingservices_release(tournamentConfig, score, currentAccessToken.getApplicationId()); } else { Tournament tournament = this.this$0.getTournament(); uriForUpdating$facebook_gamingservices_release = tournament == null ? null : TournamentShareDialogURIBuilder.INSTANCE.uriForUpdating$facebook_gamingservices_release(tournament.identifier, score, currentAccessToken.getApplicationId()); } Intent intent = new Intent("android.intent.action.VIEW", uriForUpdating$facebook_gamingservices_release); TournamentShareDialog tournamentShareDialog = this.this$0; tournamentShareDialog.startActivityForResult(intent, tournamentShareDialog.getRequestCode()); return createBaseAppCall; } } }