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

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


package com.vungle.warren.ui.presenter;

import android.content.ActivityNotFoundException;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import android.view.MotionEvent;
import android.webkit.WebView;
import android.webkit.WebViewRenderProcess;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.gms.measurement.api.AppMeasurementSdk;
import com.google.gson.m;
import com.google.gson.p;
import com.mbridge.msdk.playercommon.exoplayer2.text.ttml.TtmlNode;
import com.tapjoy.TJAdUnitConstants;
import com.vungle.warren.ClickCoordinateTracker;
import com.vungle.warren.SessionTracker;
import com.vungle.warren.VungleLogger;
import com.vungle.warren.analytics.AdAnalytics;
import com.vungle.warren.error.VungleException;
import com.vungle.warren.model.Advertisement;
import com.vungle.warren.model.Cookie;
import com.vungle.warren.model.JsonUtil;
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.omsdk.OMTracker;
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.WebAdContract;
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 com.vungle.warren.utility.ThreadUtil;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;

public class MRAIDAdPresenter implements WebAdContract.WebAdPresenter, WebViewAPI.MRAIDDelegate, WebViewAPI.WebClientErrorHandler {
    private static final String ACTION = "action";
    private static final String ACTION_WITH_VALUE = "actionWithValue";
    private static final String CLOSE = "close";
    private static final String CONSENT_ACTION = "consentAction";
    private static final String ERROR = "error";
    private static final String EXTRA_INCENTIVIZED_SENT = "incentivized_sent";
    private static final String EXTRA_REPORT = "saved_report";
    private static final String OPEN = "open";
    private static final String OPEN_DEEPLINK_SUCCESS = "deeplinkSuccess";
    private static final String OPEN_NON_MRAID = "openNonMraid";
    private static final String OPEN_PRIVACY = "openPrivacy";
    private static final String SET_ORIENTATION_PROPERTIES = "setOrientationProperties";
    private static final String SUCCESSFUL_VIEW = "successfulView";
    private static final String TAG = "com.vungle.warren.ui.presenter.MRAIDAdPresenter";
    private static final String TPAT = "tpat";
    private static final String USE_CUSTOM_CLOSE = "useCustomClose";
    private static final String USE_CUSTOM_PRIVACY = "useCustomPrivacy";
    private static final String VIDEO_VIEWED = "videoViewed";
    private WebAdContract.WebAdView adView;
    private boolean adViewed;
    private Advertisement advertisement;
    private final AdAnalytics analytics;
    private File assetDir;
    private boolean backEnabled;
    private AdContract.AdvertisementPresenter.EventListener bus;
    private ClickCoordinateTracker clickCoordinateTracker;
    private long duration;
    private DurationRecorder durationRecorder;
    private AsyncFileUtils.ExistenceOperation fileExistenceOperation;

    @Nullable
    private final String[] impressionUrls;
    private final OMTracker omTracker;

    @NonNull
    private final Placement placement;
    private Report report;
    private Repository repository;
    private final Scheduler scheduler;
    private WebViewAPI webClient;
    private Map<String, Cookie> cookieMap = new HashMap();
    private AtomicBoolean sendReportIncentivized = new AtomicBoolean(false);
    private AtomicBoolean isDestroying = new AtomicBoolean(false);
    private Repository.SaveCallback repoCallback = new Repository.SaveCallback() {
        boolean errorHappened = false;

        @Override
        public void onError(Exception exc) {
            if (this.errorHappened) {
                return;
            }
            this.errorHappened = true;
            VungleException vungleException = new VungleException(26);
            MRAIDAdPresenter.this.makeBusError(vungleException);
            VungleLogger.error(MRAIDAdPresenter.class.getSimpleName(), vungleException.getLocalizedMessage());
            MRAIDAdPresenter.this.closeView();
        }

        @Override
        public void onSaved() {
        }
    };

    public MRAIDAdPresenter(@NonNull Advertisement advertisement, @NonNull Placement placement, @NonNull Repository repository, @NonNull Scheduler scheduler, @NonNull AdAnalytics adAnalytics, @NonNull WebViewAPI webViewAPI, @Nullable OptionsState optionsState, @NonNull File file, @NonNull OMTracker oMTracker, @Nullable String[] strArr) {
        this.advertisement = advertisement;
        this.repository = repository;
        this.placement = placement;
        this.scheduler = scheduler;
        this.analytics = adAnalytics;
        this.webClient = webViewAPI;
        this.assetDir = file;
        this.omTracker = oMTracker;
        this.impressionUrls = strArr;
        loadData(optionsState);
        if (advertisement.isClickCoordinatesTrackingEnabled()) {
            this.clickCoordinateTracker = new ClickCoordinateTracker(advertisement, adAnalytics);
        }
    }

    public void closeView() {
        this.adView.close();
        this.scheduler.cancelAll();
    }

    private void download() {
        reportAction("cta", "");
        try {
            this.analytics.ping(new String[]{this.advertisement.getCTAURL(true)});
            this.adView.open(this.advertisement.getDeeplinkUrl(), this.advertisement.getCTAURL(false), new PresenterAppLeftCallback(this.bus, this.placement), new PresenterAdOpenCallback() {
                @Override
                public void onAdOpenType(PresenterAdOpenCallback.AdOpenType adOpenType) {
                    if (adOpenType == PresenterAdOpenCallback.AdOpenType.DEEP_LINK) {
                        MRAIDAdPresenter.this.reportAction(MRAIDAdPresenter.OPEN_DEEPLINK_SUCCESS, null);
                    }
                }
            });
        } catch (ActivityNotFoundException unused) {
            VungleLogger.error(MRAIDAdPresenter.class.getSimpleName() + "#download", "Download - Activity Not Found");
        }
    }

    public void handleWebViewException(@NonNull VungleException vungleException) {
        WebAdContract.WebAdView webAdView = this.adView;
        if (webAdView != null) {
            webAdView.removeWebView();
        }
        VungleLogger.error(MRAIDAdPresenter.class.getSimpleName() + "#handleWebViewException", "WebViewException: " + vungleException.getLocalizedMessage());
        reportErrorAndCloseAd(vungleException);
    }

    private void loadData(OptionsState optionsState) {
        Report report;
        this.cookieMap.put(Cookie.INCENTIVIZED_TEXT_COOKIE, this.repository.load(Cookie.INCENTIVIZED_TEXT_COOKIE, Cookie.class).get());
        this.cookieMap.put(Cookie.CONSENT_COOKIE, this.repository.load(Cookie.CONSENT_COOKIE, Cookie.class).get());
        this.cookieMap.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;
            }
        }
    }

    private void loadMraid(@NonNull File file) {
        final File file2 = new File(new File(file.getParent()).getPath() + File.separator + "index.html");
        this.fileExistenceOperation = AsyncFileUtils.isFileExistAsync(file2, new AsyncFileUtils.FileExistCallback() {
            @Override
            public void status(boolean z11) {
                if (!z11) {
                    MRAIDAdPresenter.this.makeBusError(new VungleException(27));
                    MRAIDAdPresenter.this.makeBusError(new VungleException(10));
                    MRAIDAdPresenter.this.adView.close();
                } else {
                    MRAIDAdPresenter.this.adView.showWebsite(Advertisement.FILE_SCHEME + file2.getPath());
                    MRAIDAdPresenter.this.recordPlayRemoteUrl();
                }
            }
        });
    }

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

    private void prepare(@Nullable OptionsState optionsState) {
        String string;
        this.webClient.setMRAIDDelegate(this);
        this.webClient.setErrorHandler(this);
        loadMraid(new File(this.assetDir.getPath() + File.separator + "template"));
        Cookie cookie = this.cookieMap.get(Cookie.INCENTIVIZED_TEXT_COOKIE);
        if (cookie != null) {
            this.advertisement.setIncentivizedText(cookie.getString("title"), cookie.getString(TtmlNode.TAG_BODY), cookie.getString("continue"), cookie.getString("close"));
        }
        if (cookie == null) {
            string = null;
        } else {
            string = cookie.getString("userID");
        }
        boolean z11 = false;
        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, false);
        }
        if (this.durationRecorder == null) {
            this.durationRecorder = new DurationRecorder(this.report, this.repository, this.repoCallback);
        }
        Cookie cookie2 = this.cookieMap.get(Cookie.CONSENT_COOKIE);
        if (cookie2 != null) {
            if (cookie2.getBoolean("is_country_data_protected").booleanValue() && "unknown".equals(cookie2.getString("consent_status"))) {
                z11 = true;
            }
            this.webClient.setConsentStatus(z11, cookie2.getString("consent_title"), cookie2.getString("consent_message"), cookie2.getString("button_accept"), cookie2.getString("button_deny"));
            if (z11) {
                cookie2.putValue("consent_status", Gdpr.OPTED_OUT_BY_TIMEOUT);
                cookie2.putValue("timestamp", Long.valueOf(System.currentTimeMillis() / 1000));
                cookie2.putValue("consent_source", "vungle_modal");
                this.repository.save(cookie2, this.repoCallback);
            }
        }
        int showCloseDelay = this.advertisement.getShowCloseDelay(this.placement.isIncentivized());
        if (showCloseDelay > 0) {
            this.scheduler.schedule(new Runnable() {
                @Override
                public void run() {
                    MRAIDAdPresenter.this.backEnabled = true;
                }
            }, showCloseDelay);
        } else {
            this.backEnabled = true;
        }
        this.adView.updateWindow();
        AdContract.AdvertisementPresenter.EventListener eventListener = this.bus;
        if (eventListener != null) {
            eventListener.onNext("start", null, this.placement.getId());
        }
    }

    private void recordMraidError(String str) {
        if (this.report != null && !TextUtils.isEmpty(str)) {
            this.report.recordError(str);
            this.repository.save(this.report, this.repoCallback);
        }
    }

    public void recordPlayRemoteUrl() {
        Report report;
        Advertisement advertisement = (Advertisement) this.repository.load(this.advertisement.getId(), Advertisement.class).get();
        if (advertisement != null && (report = this.report) != null) {
            report.setAllAssetDownloaded(advertisement.assetsFullyDownloaded);
            this.repository.save(this.report, this.repoCallback, false);
        }
    }

    private void reportErrorAndCloseAd(@NonNull VungleException vungleException) {
        makeBusError(vungleException);
        closeView();
    }

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

    @Override
    public void generateSaveState(@Nullable OptionsState optionsState) {
        if (optionsState == null) {
            return;
        }
        this.repository.save(this.report, this.repoCallback);
        optionsState.put(EXTRA_REPORT, this.report.getId());
        optionsState.put(EXTRA_INCENTIVIZED_SENT, this.sendReportIncentivized.get());
    }

    @Override
    public boolean handleExit() {
        if (this.backEnabled) {
            this.adView.showWebsite("javascript:window.vungle.mraidBridgeExt.requestMRAIDClose()");
            return false;
        }
        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:
                closeView();
                return;
            case 2:
                download();
                return;
            default:
                throw new IllegalArgumentException("Unknown action " + str);
        }
    }

    @Override
    public void onReceivedError(String str, boolean z11) {
        recordMraidError(str);
        VungleLogger.error(MRAIDAdPresenter.class.getSimpleName() + "#onReceivedError", str);
        if (z11) {
            reportErrorAndCloseAd(new VungleException(38));
        }
    }

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

    @Override
    public void onViewConfigurationChanged() {
        this.adView.updateWindow();
        this.webClient.notifyPropertiesChange(true);
    }

    @Override
    public void onViewTouched(MotionEvent motionEvent) {
        ClickCoordinateTracker clickCoordinateTracker = this.clickCoordinateTracker;
        if (clickCoordinateTracker != null) {
            clickCoordinateTracker.trackCoordinate(motionEvent);
        }
    }

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

    @Override
    public boolean processCommand(@NonNull String str, @NonNull m mVar) {
        char c11;
        float f11;
        char c12;
        char c13;
        Handler handler = new Handler(Looper.getMainLooper());
        str.hashCode();
        switch (str.hashCode()) {
            case -1912374177:
                if (str.equals(SUCCESSFUL_VIEW)) {
                    c11 = 0;
                    break;
                }
                c11 = 65535;
                break;
            case -1422950858:
                if (str.equals(ACTION)) {
                    c11 = 1;
                    break;
                }
                c11 = 65535;
                break;
            case -735200587:
                if (str.equals(ACTION_WITH_VALUE)) {
                    c11 = 2;
                    break;
                }
                c11 = 65535;
                break;
            case -660787472:
                if (str.equals(CONSENT_ACTION)) {
                    c11 = 3;
                    break;
                }
                c11 = 65535;
                break;
            case -511324706:
                if (str.equals(OPEN_PRIVACY)) {
                    c11 = 4;
                    break;
                }
                c11 = 65535;
                break;
            case -418575596:
                if (str.equals(OPEN_NON_MRAID)) {
                    c11 = 5;
                    break;
                }
                c11 = 65535;
                break;
            case -348095344:
                if (str.equals(USE_CUSTOM_PRIVACY)) {
                    c11 = 6;
                    break;
                }
                c11 = 65535;
                break;
            case 3417674:
                if (str.equals(OPEN)) {
                    c11 = 7;
                    break;
                }
                c11 = 65535;
                break;
            case 3566511:
                if (str.equals(TPAT)) {
                    c11 = '\b';
                    break;
                }
                c11 = 65535;
                break;
            case 94756344:
                if (str.equals("close")) {
                    c11 = '\t';
                    break;
                }
                c11 = 65535;
                break;
            case 96784904:
                if (str.equals("error")) {
                    c11 = '\n';
                    break;
                }
                c11 = 65535;
                break;
            case 133423073:
                if (str.equals(SET_ORIENTATION_PROPERTIES)) {
                    c11 = 11;
                    break;
                }
                c11 = 65535;
                break;
            case 1614272768:
                if (str.equals(USE_CUSTOM_CLOSE)) {
                    c11 = '\f';
                    break;
                }
                c11 = 65535;
                break;
            default:
                c11 = 65535;
                break;
        }
        switch (c11) {
            case 0:
                AdContract.AdvertisementPresenter.EventListener eventListener = this.bus;
                if (eventListener != null) {
                    eventListener.onNext(SUCCESSFUL_VIEW, null, this.placement.getId());
                }
                Cookie cookie = this.cookieMap.get(Cookie.CONFIG_COOKIE);
                if (this.placement.isIncentivized() && cookie != null && cookie.getBoolean("isReportIncentivizedEnabled").booleanValue() && !this.sendReportIncentivized.getAndSet(true)) {
                    m mVar2 = new m();
                    mVar2.u("placement_reference_id", new p(this.placement.getId()));
                    mVar2.u("app_id", new p(this.advertisement.getAppID()));
                    mVar2.u(ReportDBAdapter.ReportColumns.COLUMN_AD_START_TIME, new p(Long.valueOf(this.report.getAdStartTime())));
                    mVar2.u("user", new p(this.report.getUserID()));
                    this.analytics.ri(mVar2);
                }
                return true;
            case 2:
                String m11 = mVar.C("event").m();
                String m12 = mVar.C(AppMeasurementSdk.ConditionalUserProperty.VALUE).m();
                this.report.recordAction(m11, m12, System.currentTimeMillis());
                this.repository.save(this.report, this.repoCallback);
                if (m11.equals("videoViewed")) {
                    try {
                        f11 = Float.parseFloat(m12);
                    } catch (NumberFormatException unused) {
                        Log.e(TAG, "value for videoViewed is null !");
                        f11 = 0.0f;
                    }
                    AdContract.AdvertisementPresenter.EventListener eventListener2 = this.bus;
                    if (eventListener2 != null && f11 > 0.0f && !this.adViewed) {
                        this.adViewed = true;
                        eventListener2.onNext("adViewed", null, this.placement.getId());
                        String[] strArr = this.impressionUrls;
                        if (strArr != null) {
                            this.analytics.ping(strArr);
                        }
                    }
                    if (this.duration > 0) {
                        this.durationRecorder.update();
                    }
                }
                if (m11.equals("videoLength")) {
                    this.duration = Long.parseLong(m12);
                    reportAction("videoLength", m12);
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            MRAIDAdPresenter.this.webClient.notifyPropertiesChange(true);
                        }
                    });
                }
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        MRAIDAdPresenter.this.adView.setVisibility(true);
                    }
                });
                break;
            case 1:
                return true;
            case 3:
                Cookie cookie2 = this.cookieMap.get(Cookie.CONSENT_COOKIE);
                if (cookie2 == null) {
                    cookie2 = new Cookie(Cookie.CONSENT_COOKIE);
                }
                cookie2.putValue("consent_status", mVar.C("event").m());
                cookie2.putValue("consent_source", "vungle_modal");
                cookie2.putValue("timestamp", Long.valueOf(System.currentTimeMillis() / 1000));
                this.repository.save(cookie2, this.repoCallback);
                return true;
            case 4:
                this.adView.open(null, mVar.C("url").m(), new PresenterAppLeftCallback(this.bus, this.placement), null);
                return true;
            case 5:
            case 7:
                reportAction(JavascriptBridge.MraidHandler.DOWNLOAD_ACTION, null);
                if (OPEN.equalsIgnoreCase(str)) {
                    reportAction("mraidOpen", null);
                } else {
                    reportAction("nonMraidOpen", null);
                }
                String deeplinkUrl = this.advertisement.getDeeplinkUrl();
                String m13 = mVar.C("url").m();
                if ((deeplinkUrl != null && !deeplinkUrl.isEmpty()) || (m13 != null && !m13.isEmpty())) {
                    this.adView.open(deeplinkUrl, m13, new PresenterAppLeftCallback(this.bus, this.placement), new PresenterAdOpenCallback() {
                        @Override
                        public void onAdOpenType(PresenterAdOpenCallback.AdOpenType adOpenType) {
                            if (adOpenType == PresenterAdOpenCallback.AdOpenType.DEEP_LINK) {
                                MRAIDAdPresenter.this.reportAction(MRAIDAdPresenter.OPEN_DEEPLINK_SUCCESS, null);
                            }
                        }
                    });
                } else {
                    Log.e(TAG, "CTA destination URL is not configured properly");
                }
                AdContract.AdvertisementPresenter.EventListener eventListener3 = this.bus;
                if (eventListener3 != null) {
                    eventListener3.onNext(OPEN, "adClick", this.placement.getId());
                }
                return true;
            case 6:
                String m14 = mVar.C(USE_CUSTOM_PRIVACY).m();
                m14.hashCode();
                switch (m14.hashCode()) {
                    case 3178655:
                        if (m14.equals("gone")) {
                            c12 = 0;
                            break;
                        }
                        c12 = 65535;
                        break;
                    case 3569038:
                        if (m14.equals("true")) {
                            c12 = 1;
                            break;
                        }
                        c12 = 65535;
                        break;
                    case 97196323:
                        if (m14.equals("false")) {
                            c12 = 2;
                            break;
                        }
                        c12 = 65535;
                        break;
                    default:
                        c12 = 65535;
                        break;
                }
                switch (c12) {
                    case 0:
                    case 1:
                    case 2:
                        return true;
                    default:
                        throw new IllegalArgumentException("Unknown value " + m14);
                }
            case '\b':
                this.analytics.ping(this.advertisement.getTpatUrls(mVar.C("event").m()));
                return true;
            case '\t':
                reportAction("mraidClose", null);
                closeView();
                return true;
            case '\n':
                String asString = JsonUtil.getAsString(mVar, "code", null);
                final String format = String.format("%s Creative Id: %s", asString, this.advertisement.getCreativeId());
                Log.e(TAG, "Receive Creative error: " + format);
                recordMraidError(asString);
                ThreadUtil.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        MRAIDAdPresenter.this.handleWebViewException(new VungleException(40, format));
                    }
                });
                return true;
            case 11:
                String asString2 = JsonUtil.getAsString(mVar, "forceOrientation", null);
                if (!TextUtils.isEmpty(asString2)) {
                    String lowerCase = asString2.toLowerCase();
                    lowerCase.hashCode();
                    if (!lowerCase.equals(TJAdUnitConstants.String.PORTRAIT)) {
                        if (lowerCase.equals(TJAdUnitConstants.String.LANDSCAPE)) {
                            this.adView.setOrientation(6);
                        }
                    } else {
                        this.adView.setOrientation(7);
                    }
                }
                return true;
            case '\f':
                String m15 = mVar.C("sdkCloseButton").m();
                m15.hashCode();
                switch (m15.hashCode()) {
                    case -1901805651:
                        if (m15.equals("invisible")) {
                            c13 = 0;
                            break;
                        }
                        c13 = 65535;
                        break;
                    case 3178655:
                        if (m15.equals("gone")) {
                            c13 = 1;
                            break;
                        }
                        c13 = 65535;
                        break;
                    case 466743410:
                        if (m15.equals(TJAdUnitConstants.String.VISIBLE)) {
                            c13 = 2;
                            break;
                        }
                        c13 = 65535;
                        break;
                    default:
                        c13 = 65535;
                        break;
                }
                switch (c13) {
                    case 0:
                    case 1:
                    case 2:
                        return true;
                    default:
                        throw new IllegalArgumentException("Unknown value " + m15);
                }
            default:
                VungleLogger.error(MRAIDAdPresenter.class.getSimpleName() + "#processCommand", "Unknown MRAID Command");
                return true;
        }
    }

    public void reportAction(@NonNull String str, @Nullable String str2) {
        if (str.equals("videoLength")) {
            long parseLong = Long.parseLong(str2);
            this.duration = parseLong;
            this.report.setVideoLength(parseLong);
            this.repository.save(this.report, this.repoCallback);
            return;
        }
        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;
        }
        boolean z11 = optionsState.getBoolean(EXTRA_INCENTIVIZED_SENT, false);
        if (z11) {
            this.sendReportIncentivized.set(z11);
        }
        if (this.report == null) {
            this.adView.close();
            VungleLogger.error(MRAIDAdPresenter.class.getSimpleName() + "#restoreFromSave", "The advertisement was not started and cannot be restored.");
        }
    }

    @Override
    public void setAdVisibility(boolean z11) {
        this.webClient.setAdVisibility(z11);
        if (z11) {
            this.durationRecorder.start();
        } else {
            this.durationRecorder.stop();
        }
    }

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

    @Override
    public void start() {
        if (!this.adView.hasWebView()) {
            reportErrorAndCloseAd(new VungleException(31));
            return;
        }
        this.adView.setImmersiveMode();
        this.adView.resumeWeb();
        setAdVisibility(true);
    }

    @Override
    public void stop(@AdContract.AdStopReason int i11) {
        boolean z11;
        boolean z12;
        boolean z13;
        if ((i11 & 1) != 0) {
            z11 = true;
        } else {
            z11 = false;
        }
        if ((i11 & 2) != 0) {
            z12 = true;
        } else {
            z12 = false;
        }
        if ((i11 & 4) != 0) {
            z13 = true;
        } else {
            z13 = false;
        }
        this.adView.pauseWeb();
        setAdVisibility(false);
        if (!z11 && z12 && !this.isDestroying.getAndSet(true)) {
            WebViewAPI webViewAPI = this.webClient;
            String str = null;
            if (webViewAPI != null) {
                webViewAPI.setMRAIDDelegate(null);
            }
            if (z13) {
                reportAction("mraidCloseByApi", null);
            }
            this.repository.save(this.report, this.repoCallback);
            AdContract.AdvertisementPresenter.EventListener eventListener = this.bus;
            if (eventListener != null) {
                if (this.report.isCTAClicked()) {
                    str = "isCTAClicked";
                }
                eventListener.onNext(TtmlNode.END, str, this.placement.getId());
            }
        }
    }

    @Override
    public void attach(@NonNull WebAdContract.WebAdView webAdView, @Nullable OptionsState optionsState) {
        this.isDestroying.set(false);
        this.adView = webAdView;
        webAdView.setPresenter(this);
        AdContract.AdvertisementPresenter.EventListener eventListener = this.bus;
        if (eventListener != null) {
            eventListener.onNext("attach", this.advertisement.getCreativeId(), this.placement.getId());
        }
        this.omTracker.start();
        int settings = this.advertisement.getAdConfig().getSettings();
        if (settings > 0) {
            this.backEnabled = (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);
        webAdView.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());
    }
}