Kufar v3.2.0版本的 MD5 值为:6a4d203db1c561c7e3bcd50d23fed59f

以下内容为反编译后的 LocalAdPresenter.java 源代码,内容仅作参考


package com.vungle.warren.ui.presenter;

import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewRenderProcess;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.gson.m;
import com.google.gson.p;
import com.mbridge.msdk.playercommon.exoplayer2.text.ttml.TtmlNode;
import com.vungle.warren.SessionTracker;
import com.vungle.warren.VungleLogger;
import com.vungle.warren.analytics.AdAnalytics;
import com.vungle.warren.analytics.AnalyticsEvent;
import com.vungle.warren.error.VungleException;
import com.vungle.warren.model.Advertisement;
import com.vungle.warren.model.Cookie;
import com.vungle.warren.model.Placement;
import com.vungle.warren.model.Report;
import com.vungle.warren.model.ReportDBAdapter;
import com.vungle.warren.model.SessionData;
import com.vungle.warren.model.token.Gdpr;
import com.vungle.warren.persistence.Repository;
import com.vungle.warren.session.SessionAttribute;
import com.vungle.warren.session.SessionEvent;
import com.vungle.warren.ui.DurationRecorder;
import com.vungle.warren.ui.JavascriptBridge;
import com.vungle.warren.ui.PresenterAdOpenCallback;
import com.vungle.warren.ui.PresenterAppLeftCallback;
import com.vungle.warren.ui.contract.AdContract;
import com.vungle.warren.ui.contract.LocalAdContract;
import com.vungle.warren.ui.state.OptionsState;
import com.vungle.warren.ui.view.WebViewAPI;
import com.vungle.warren.utility.AsyncFileUtils;
import com.vungle.warren.utility.Scheduler;
import java.io.File;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;

public class LocalAdPresenter implements LocalAdContract.LocalPresenter, WebViewAPI.WebClientErrorHandler {
    static final String EXTRA_INCENTIVIZED_SENT = "incentivized_sent";
    static final String EXTRA_IN_POST = "in_post_roll";
    static final String EXTRA_IS_MUTED = "is_muted_mode";
    static final String EXTRA_REPORT = "saved_report";
    static final String EXTRA_VIDEO_POSITION = "videoPosition";
    static final String HTTPS_VUNGLE_COM_PRIVACY = "https://vungle.com/privacy/";
    public static final int INCENTIVIZED_TRESHOLD = 75;
    static final String TAG = "LocalAdPresenter";
    private LocalAdContract.LocalView adView;
    private boolean adViewed;
    private Advertisement advertisement;
    private final AdAnalytics analytics;
    private File assetDir;
    private AdContract.AdvertisementPresenter.EventListener bus;
    private int duration;
    private DurationRecorder durationRecorder;
    private AsyncFileUtils.ExistenceOperation fileExistenceOperation;

    @Nullable
    private final String[] impressionUrls;
    private boolean inPost;
    private boolean muted;

    @NonNull
    private Placement placement;
    private int progress;
    private Report report;
    private Repository repository;
    private final Scheduler scheduler;
    private boolean userExitEnabled;
    private int videoPosition;
    private final WebViewAPI webViewAPI;
    private final Map<String, Cookie> cookies = new HashMap();
    private String dialogTitle = "Are you sure?";
    private String dialogBody = "If you exit now, you will not get your reward";
    private String dialogContinue = "Continue";
    private String dialogClose = "Close";
    private AtomicBoolean sendReportIncentivized = new AtomicBoolean(false);
    private AtomicBoolean isDestroying = new AtomicBoolean(false);
    private LinkedList<Advertisement.Checkpoint> checkpointList = new LinkedList<>();
    private Repository.SaveCallback repoCallback = new Repository.SaveCallback() {
        boolean errorHappened = false;

        @Override
        public void onError(Exception exc) {
            if (this.errorHappened) {
                return;
            }
            this.errorHappened = true;
            LocalAdPresenter.this.makeBusError(26);
            VungleLogger.error(LocalAdPresenter.class.getSimpleName() + "#onError", new VungleException(26).getLocalizedMessage());
            LocalAdPresenter.this.closeAndReport();
        }

        @Override
        public void onSaved() {
        }
    };
    private AtomicBoolean busy = new AtomicBoolean(false);

    public LocalAdPresenter(@NonNull Advertisement advertisement, @NonNull Placement placement, @NonNull Repository repository, @NonNull Scheduler scheduler, @NonNull AdAnalytics adAnalytics, @NonNull WebViewAPI webViewAPI, @Nullable OptionsState optionsState, @NonNull File file, @Nullable String[] strArr) {
        this.advertisement = advertisement;
        this.placement = placement;
        this.scheduler = scheduler;
        this.analytics = adAnalytics;
        this.webViewAPI = webViewAPI;
        this.repository = repository;
        this.assetDir = file;
        this.impressionUrls = strArr;
        if (advertisement.getCheckpoints() != null) {
            this.checkpointList.addAll(advertisement.getCheckpoints());
            Collections.sort(this.checkpointList);
        }
        loadData(optionsState);
    }

    public void closeAndReport() {
        if (this.busy.get()) {
            Log.w(TAG, "Busy with closing");
            return;
        }
        this.busy.set(true);
        reportAction("close", null);
        this.scheduler.cancelAll();
        this.adView.close();
    }

    public void continueWithPostroll() {
        if (this.advertisement.hasPostroll()) {
            playPost();
        } else {
            closeAndReport();
        }
    }

    private void download() {
        AdContract.AdvertisementPresenter.EventListener eventListener;
        reportAction("cta", "");
        try {
            this.analytics.ping(this.advertisement.getTpatUrls(AnalyticsEvent.Ad.postrollClick));
            this.analytics.ping(this.advertisement.getTpatUrls("click_url"));
            this.analytics.ping(this.advertisement.getTpatUrls("video_click"));
            this.analytics.ping(new String[]{this.advertisement.getCTAURL(true)});
            reportAction(JavascriptBridge.MraidHandler.DOWNLOAD_ACTION, null);
            String ctaurl = this.advertisement.getCTAURL(false);
            if (ctaurl != null && !ctaurl.isEmpty()) {
                this.adView.open(this.advertisement.getDeeplinkUrl(), ctaurl, new PresenterAppLeftCallback(this.bus, this.placement), new PresenterAdOpenCallback() {
                    @Override
                    public void onAdOpenType(PresenterAdOpenCallback.AdOpenType adOpenType) {
                        if (adOpenType == PresenterAdOpenCallback.AdOpenType.DEEP_LINK) {
                            LocalAdPresenter.this.reportAction("deeplinkSuccess", null);
                        }
                    }
                });
                eventListener = this.bus;
                if (eventListener == null) {
                    eventListener.onNext("open", "adClick", this.placement.getId());
                    return;
                }
                return;
            }
            Log.e(TAG, "CTA destination URL is not configured properly");
            eventListener = this.bus;
            if (eventListener == null) {
            }
        } catch (ActivityNotFoundException unused) {
            Log.e(TAG, "Unable to find destination activity");
            VungleLogger.error(LocalAdPresenter.class.getSimpleName() + "#download", "Download - Activity Not Found");
        }
    }

    private void handleWebViewException(@VungleException.ExceptionCode int i11) {
        LocalAdContract.LocalView localView = this.adView;
        if (localView != null) {
            localView.removeWebView();
        }
        reportErrorAndCloseAd(i11);
    }

    private boolean isWebPageBlank() {
        String websiteUrl = this.adView.getWebsiteUrl();
        if (!TextUtils.isEmpty(websiteUrl) && !"about:blank".equalsIgnoreCase(websiteUrl)) {
            return false;
        }
        return true;
    }

    private void loadData(OptionsState optionsState) {
        Report report;
        this.cookies.put(Cookie.INCENTIVIZED_TEXT_COOKIE, this.repository.load(Cookie.INCENTIVIZED_TEXT_COOKIE, Cookie.class).get());
        this.cookies.put(Cookie.CONSENT_COOKIE, this.repository.load(Cookie.CONSENT_COOKIE, Cookie.class).get());
        this.cookies.put(Cookie.CONFIG_COOKIE, this.repository.load(Cookie.CONFIG_COOKIE, Cookie.class).get());
        if (optionsState != null) {
            String string = optionsState.getString(EXTRA_REPORT);
            if (TextUtils.isEmpty(string)) {
                report = null;
            } else {
                report = (Report) this.repository.load(string, Report.class).get();
            }
            if (report != null) {
                this.report = report;
            }
        }
    }

    public void makeBusError(@VungleException.ExceptionCode int i11) {
        AdContract.AdvertisementPresenter.EventListener eventListener = this.bus;
        if (eventListener != null) {
            eventListener.onError(new VungleException(i11), this.placement.getId());
        }
    }

    private boolean needShowGDPR(@Nullable Cookie cookie) {
        if (cookie != null && cookie.getBoolean("is_country_data_protected").booleanValue() && "unknown".equals(cookie.getString("consent_status"))) {
            return true;
        }
        return false;
    }

    private void playPost() {
        final File file = new File(new File(this.assetDir.getPath()).getPath() + File.separator + "index.html");
        this.fileExistenceOperation = AsyncFileUtils.isFileExistAsync(file, new AsyncFileUtils.FileExistCallback() {
            @Override
            public void status(boolean z11) {
                if (z11) {
                    LocalAdPresenter.this.adView.showWebsite(Advertisement.FILE_SCHEME + file.getPath());
                    LocalAdPresenter.this.analytics.ping(LocalAdPresenter.this.advertisement.getTpatUrls(AnalyticsEvent.Ad.postrollView));
                    LocalAdPresenter.this.inPost = true;
                    return;
                }
                LocalAdPresenter.this.makeBusError(27);
                LocalAdPresenter.this.makeBusError(10);
                VungleLogger.error(LocalAdPresenter.class.getSimpleName() + "#playPost", "Error Rendering Postroll");
                LocalAdPresenter.this.closeAndReport();
            }
        });
    }

    private void prepare(@Nullable OptionsState optionsState) {
        String string;
        restoreFromSave(optionsState);
        Cookie cookie = this.cookies.get(Cookie.INCENTIVIZED_TEXT_COOKIE);
        if (cookie == null) {
            string = null;
        } else {
            string = cookie.getString("userID");
        }
        if (this.report == null) {
            Report report = new Report(this.advertisement, this.placement, System.currentTimeMillis(), string);
            this.report = report;
            report.setTtDownload(this.advertisement.getTtDownload());
            this.repository.save(this.report, this.repoCallback);
        }
        if (this.durationRecorder == null) {
            this.durationRecorder = new DurationRecorder(this.report, this.repository, this.repoCallback);
        }
        this.webViewAPI.setErrorHandler(this);
        this.adView.showCTAOverlay(this.advertisement.isCtaOverlayEnabled(), this.advertisement.getCtaClickArea());
        AdContract.AdvertisementPresenter.EventListener eventListener = this.bus;
        if (eventListener != null) {
            eventListener.onNext("start", null, this.placement.getId());
        }
    }

    private void reportError(@NonNull String str) {
        this.report.recordError(str);
        this.repository.save(this.report, this.repoCallback);
        makeBusError(27);
        if (!this.inPost && this.advertisement.hasPostroll()) {
            playPost();
        } else {
            makeBusError(10);
            this.adView.close();
        }
    }

    private void reportErrorAndCloseAd(@VungleException.ExceptionCode int i11) {
        makeBusError(i11);
        VungleLogger.error(LocalAdPresenter.class.getSimpleName(), "WebViewException: " + new VungleException(i11).getLocalizedMessage());
        closeAndReport();
    }

    private void showDialog(String str, String str2, String str3, String str4, DialogInterface.OnClickListener onClickListener) {
        this.adView.pauseVideo();
        this.adView.showDialog(str, str2, str3, str4, onClickListener);
    }

    private void showGDPR(@NonNull final Cookie cookie) {
        DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i11) {
                String str;
                if (i11 == -2) {
                    str = "opted_out";
                } else if (i11 == -1) {
                    str = "opted_in";
                } else {
                    str = Gdpr.OPTED_OUT_BY_TIMEOUT;
                }
                cookie.putValue("consent_status", str);
                cookie.putValue("timestamp", Long.valueOf(System.currentTimeMillis() / 1000));
                cookie.putValue("consent_source", "vungle_modal");
                LocalAdPresenter.this.repository.save(cookie, null);
                LocalAdPresenter.this.start();
            }
        };
        cookie.putValue("consent_status", Gdpr.OPTED_OUT_BY_TIMEOUT);
        cookie.putValue("timestamp", Long.valueOf(System.currentTimeMillis() / 1000));
        cookie.putValue("consent_source", "vungle_modal");
        this.repository.save(cookie, this.repoCallback);
        showDialog(cookie.getString("consent_title"), cookie.getString("consent_message"), cookie.getString("button_accept"), cookie.getString("button_deny"), onClickListener);
    }

    private void showIncetivizedDialog() {
        String str = this.dialogTitle;
        String str2 = this.dialogBody;
        String str3 = this.dialogContinue;
        String str4 = this.dialogClose;
        Cookie cookie = this.cookies.get(Cookie.INCENTIVIZED_TEXT_COOKIE);
        if (cookie != null) {
            str = cookie.getString("title");
            if (TextUtils.isEmpty(str)) {
                str = this.dialogTitle;
            }
            str2 = cookie.getString(TtmlNode.TAG_BODY);
            if (TextUtils.isEmpty(str2)) {
                str2 = this.dialogBody;
            }
            str3 = cookie.getString("continue");
            if (TextUtils.isEmpty(str3)) {
                str3 = this.dialogContinue;
            }
            str4 = cookie.getString("close");
            if (TextUtils.isEmpty(str4)) {
                str4 = this.dialogClose;
            }
        }
        showDialog(str, str2, str3, str4, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i11) {
                if (i11 == -2) {
                    LocalAdPresenter.this.reportAction(AnalyticsEvent.Ad.videoClose, null);
                    LocalAdPresenter.this.continueWithPostroll();
                }
            }
        });
    }

    @Override
    public void detach(@AdContract.AdStopReason int i11) {
        AsyncFileUtils.ExistenceOperation existenceOperation = this.fileExistenceOperation;
        if (existenceOperation != null) {
            existenceOperation.cancel();
        }
        stop(i11);
        this.adView.destroyAdView(0L);
    }

    @Override
    public void generateSaveState(@Nullable OptionsState optionsState) {
        String id2;
        int i11;
        if (optionsState == null) {
            return;
        }
        this.repository.save(this.report, this.repoCallback);
        Report report = this.report;
        if (report == null) {
            id2 = null;
        } else {
            id2 = report.getId();
        }
        optionsState.put(EXTRA_REPORT, id2);
        optionsState.put(EXTRA_INCENTIVIZED_SENT, this.sendReportIncentivized.get());
        optionsState.put(EXTRA_IN_POST, this.inPost);
        optionsState.put(EXTRA_IS_MUTED, this.muted);
        LocalAdContract.LocalView localView = this.adView;
        if (localView != null && localView.isVideoPlaying()) {
            i11 = this.adView.getVideoPosition();
        } else {
            i11 = this.videoPosition;
        }
        optionsState.put(EXTRA_VIDEO_POSITION, i11);
    }

    @Override
    public boolean handleExit() {
        if (this.inPost) {
            closeAndReport();
            return true;
        }
        if (!this.userExitEnabled) {
            return false;
        }
        if (this.placement.isIncentivized() && this.progress <= 75) {
            showIncetivizedDialog();
            return false;
        }
        reportAction(AnalyticsEvent.Ad.videoClose, null);
        if (this.advertisement.hasPostroll()) {
            playPost();
            return false;
        }
        closeAndReport();
        return true;
    }

    @Override
    public void onDownload() {
        download();
    }

    @Override
    public boolean onMediaError(@NonNull String str) {
        reportError(str);
        VungleLogger.error(LocalAdPresenter.class.getSimpleName() + "#onMediaError", "Media Error: " + str);
        return false;
    }

    @Override
    public void onMraidAction(@NonNull String str) {
        str.hashCode();
        char c11 = 65535;
        switch (str.hashCode()) {
            case -314498168:
                if (str.equals(JavascriptBridge.MraidHandler.PRIVACY_ACTION)) {
                    c11 = 0;
                    break;
                }
                break;
            case 94756344:
                if (str.equals("close")) {
                    c11 = 1;
                    break;
                }
                break;
            case 1427818632:
                if (str.equals(JavascriptBridge.MraidHandler.DOWNLOAD_ACTION)) {
                    c11 = 2;
                    break;
                }
                break;
        }
        switch (c11) {
            case 0:
                return;
            case 1:
                closeAndReport();
                return;
            case 2:
                download();
                closeAndReport();
                return;
            default:
                VungleLogger.error(LocalAdPresenter.class.getSimpleName() + "#onMraidAction", "Unknown MRAID Command");
                throw new IllegalArgumentException("Unknown action " + str);
        }
    }

    @Override
    public void onMute(boolean z11) {
        this.muted = z11;
        if (z11) {
            reportAction("mute", "true");
        } else {
            reportAction("unmute", "false");
        }
    }

    @Override
    public void onPrivacy() {
        this.adView.open(null, HTTPS_VUNGLE_COM_PRIVACY, new PresenterAppLeftCallback(this.bus, this.placement), null);
    }

    @Override
    public void onProgressUpdate(int i11, float f11) {
        this.progress = (int) ((i11 / f11) * 100.0f);
        this.videoPosition = i11;
        this.durationRecorder.update();
        AdContract.AdvertisementPresenter.EventListener eventListener = this.bus;
        if (eventListener != null) {
            eventListener.onNext("percentViewed:" + this.progress, null, this.placement.getId());
        }
        AdContract.AdvertisementPresenter.EventListener eventListener2 = this.bus;
        if (eventListener2 != null && i11 > 0 && !this.adViewed) {
            this.adViewed = true;
            eventListener2.onNext("adViewed", null, this.placement.getId());
            String[] strArr = this.impressionUrls;
            if (strArr != null) {
                this.analytics.ping(strArr);
            }
        }
        reportAction("video_viewed", String.format(Locale.ENGLISH, "%d", Integer.valueOf(i11)));
        if (this.progress == 100) {
            if (this.checkpointList.peekLast() != null && this.checkpointList.peekLast().getPercentage() == 100) {
                this.analytics.ping(this.checkpointList.pollLast().getUrls());
            }
            continueWithPostroll();
        }
        this.report.recordProgress(this.videoPosition);
        this.repository.save(this.report, this.repoCallback);
        while (this.checkpointList.peek() != null && this.progress > this.checkpointList.peek().getPercentage()) {
            this.analytics.ping(this.checkpointList.poll().getUrls());
        }
        Cookie cookie = this.cookies.get(Cookie.CONFIG_COOKIE);
        if (this.placement.isIncentivized() && this.progress > 75 && cookie != null && cookie.getBoolean("isReportIncentivizedEnabled").booleanValue() && !this.sendReportIncentivized.getAndSet(true)) {
            m mVar = new m();
            mVar.u("placement_reference_id", new p(this.placement.getId()));
            mVar.u("app_id", new p(this.advertisement.getAppID()));
            mVar.u(ReportDBAdapter.ReportColumns.COLUMN_AD_START_TIME, new p(Long.valueOf(this.report.getAdStartTime())));
            mVar.u("user", new p(this.report.getUserID()));
            this.analytics.ri(mVar);
        }
    }

    @Override
    public void onReceivedError(String str, boolean z11) {
        Report report = this.report;
        if (report != null) {
            report.recordError(str);
            this.repository.save(this.report, this.repoCallback);
            VungleLogger.error(LocalAdPresenter.class.getSimpleName() + "onReceivedError", str);
        }
    }

    @Override
    public void onRenderProcessUnresponsive(@NonNull WebView webView, @Nullable WebViewRenderProcess webViewRenderProcess) {
        handleWebViewException(32);
        VungleLogger.error(LocalAdPresenter.class.getSimpleName() + "#onRenderProcessUnresponsive", new VungleException(32).getLocalizedMessage());
    }

    @Override
    public void onVideoStart(int i11, float f11) {
        reportAction("videoLength", String.format(Locale.ENGLISH, "%d", Integer.valueOf((int) f11)));
    }

    @Override
    public void onViewConfigurationChanged() {
        this.webViewAPI.notifyPropertiesChange(true);
        this.adView.refreshDialogIfVisible();
    }

    @Override
    public boolean onWebRenderingProcessGone(WebView webView, boolean z11) {
        handleWebViewException(31);
        VungleLogger.error(LocalAdPresenter.class.getSimpleName() + "#onWebRenderingProcessGone", new VungleException(31).getLocalizedMessage());
        return true;
    }

    public void reportAction(@NonNull String str, @Nullable String str2) {
        if (str.equals("videoLength")) {
            int parseInt = Integer.parseInt(str2);
            this.duration = parseInt;
            this.report.setVideoLength(parseInt);
            this.repository.save(this.report, this.repoCallback);
            return;
        }
        char c11 = 65535;
        switch (str.hashCode()) {
            case -840405966:
                if (str.equals("unmute")) {
                    c11 = 0;
                    break;
                }
                break;
            case 3363353:
                if (str.equals("mute")) {
                    c11 = 1;
                    break;
                }
                break;
            case 1370606900:
                if (str.equals(AnalyticsEvent.Ad.videoClose)) {
                    c11 = 2;
                    break;
                }
                break;
        }
        switch (c11) {
            case 0:
            case 1:
            case 2:
                this.analytics.ping(this.advertisement.getTpatUrls(str));
                break;
        }
        this.report.recordAction(str, str2, System.currentTimeMillis());
        this.repository.save(this.report, this.repoCallback);
    }

    @Override
    public void restoreFromSave(@Nullable OptionsState optionsState) {
        if (optionsState == null) {
            return;
        }
        if (optionsState.getBoolean(EXTRA_INCENTIVIZED_SENT, false)) {
            this.sendReportIncentivized.set(true);
        }
        this.inPost = optionsState.getBoolean(EXTRA_IN_POST, this.inPost);
        this.muted = optionsState.getBoolean(EXTRA_IS_MUTED, this.muted);
        this.videoPosition = optionsState.getInt(EXTRA_VIDEO_POSITION, this.videoPosition).intValue();
    }

    @Override
    public void setEventListener(@Nullable AdContract.AdvertisementPresenter.EventListener eventListener) {
        this.bus = eventListener;
    }

    @Override
    public void start() {
        this.durationRecorder.start();
        if (!this.adView.hasWebView()) {
            reportErrorAndCloseAd(31);
            VungleLogger.error(LocalAdPresenter.class.getSimpleName() + "#start", new VungleException(31).getLocalizedMessage());
            return;
        }
        this.adView.setImmersiveMode();
        this.adView.resumeWeb();
        Cookie cookie = this.cookies.get(Cookie.CONSENT_COOKIE);
        if (needShowGDPR(cookie)) {
            showGDPR(cookie);
            return;
        }
        if (this.inPost) {
            if (isWebPageBlank()) {
                playPost();
                return;
            }
            return;
        }
        if (!this.adView.isVideoPlaying() && !this.adView.isDialogVisible()) {
            this.adView.playVideo(new File(this.assetDir.getPath() + File.separator + "video"), this.muted, this.videoPosition);
            int showCloseDelay = this.advertisement.getShowCloseDelay(this.placement.isIncentivized());
            if (showCloseDelay > 0) {
                this.scheduler.schedule(new Runnable() {
                    @Override
                    public void run() {
                        LocalAdPresenter.this.userExitEnabled = true;
                        if (!LocalAdPresenter.this.inPost) {
                            LocalAdPresenter.this.adView.showCloseButton();
                        }
                    }
                }, showCloseDelay);
            } else {
                this.userExitEnabled = true;
                this.adView.showCloseButton();
            }
        }
    }

    @Override
    public void stop(@AdContract.AdStopReason int i11) {
        boolean z11;
        this.durationRecorder.stop();
        boolean z12 = false;
        if ((i11 & 1) != 0) {
            z11 = true;
        } else {
            z11 = false;
        }
        if ((i11 & 2) != 0) {
            z12 = true;
        }
        this.adView.pauseWeb();
        if (this.adView.isVideoPlaying()) {
            this.videoPosition = this.adView.getVideoPosition();
            this.adView.pauseVideo();
        }
        if (!z11 && z12) {
            if (!this.isDestroying.getAndSet(true)) {
                String str = null;
                reportAction("close", null);
                this.scheduler.cancelAll();
                AdContract.AdvertisementPresenter.EventListener eventListener = this.bus;
                if (eventListener != null) {
                    if (this.report.isCTAClicked()) {
                        str = "isCTAClicked";
                    }
                    eventListener.onNext(TtmlNode.END, str, this.placement.getId());
                    return;
                }
                return;
            }
            return;
        }
        if (this.inPost || z12) {
            this.adView.showWebsite("about:blank");
        }
    }

    @Override
    public void attach(@NonNull LocalAdContract.LocalView localView, @Nullable OptionsState optionsState) {
        this.isDestroying.set(false);
        this.adView = localView;
        localView.setPresenter(this);
        AdContract.AdvertisementPresenter.EventListener eventListener = this.bus;
        if (eventListener != null) {
            eventListener.onNext("attach", this.advertisement.getCreativeId(), this.placement.getId());
        }
        int settings = this.advertisement.getAdConfig().getSettings();
        if (settings > 0) {
            this.muted = (settings & 1) == 1;
            this.userExitEnabled = (settings & 2) == 2;
        }
        int adOrientation = this.advertisement.getAdConfig().getAdOrientation();
        int i11 = 6;
        if (adOrientation == 3) {
            int orientation = this.advertisement.getOrientation();
            if (orientation != 0) {
                if (orientation != 1) {
                    i11 = -1;
                }
            }
            i11 = 7;
        } else {
            if (adOrientation != 0) {
                if (adOrientation != 1) {
                    i11 = 4;
                }
            }
            i11 = 7;
        }
        Log.d(TAG, "Requested Orientation " + i11);
        localView.setOrientation(i11);
        prepare(optionsState);
        SessionTracker.getInstance().trackEvent(new SessionData.Builder().setEvent(SessionEvent.PLAY_AD).addData(SessionAttribute.SUCCESS, true).addData(SessionAttribute.EVENT_ID, this.advertisement.getId()).build());
    }
}