Stick Squad 3 v1.2.5.9版本的 MD5 值为:375cf7f77a7075270cd68d1397368279

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


package com.fusepowered.nx.monetization.mraid;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import com.fusepowered.l1.StaticParams;
import com.fusepowered.mraid1.MRAIDNativeFeature;
import com.fusepowered.nx.common.Log;
import com.fusepowered.nx.common.StringConstants;
import com.fusepowered.nx.monetization.mraid.objects.ObjectNames;
import com.fusepowered.nx.monetization.theme.ThemeElementTypes;
import com.fusepowered.u1.properties.UnityAdsConstants;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;

public class MRAIDUtils {
    private static final String JS_QUOTE = "'";

    public enum JSDialogAction {
        PROMPT,
        CONFIRM,
        ALERT,
        BEFORE_UNLOAD
    }

    public static String wrapInJSQuotes(String s) {
        return JS_QUOTE + s + JS_QUOTE;
    }

    public static Map<String, String> decodeData(String data) {
        if (data == null || data.trim().length() == 0) {
            return new HashMap(0);
        }
        HashMap hashMap = new HashMap();
        try {
            Map<String, String> decodedData = new HashMap<>();
            try {
                String[] params = data.split("&");
                for (String param : params) {
                    String[] pair = param.split("=");
                    if (pair.length == 2) {
                        decodedData.put(URLDecoder.decode(pair[0]), URLDecoder.decode(pair[1]));
                    }
                }
                return decodedData;
            } catch (Exception e) {
                return decodedData;
            }
        } catch (Exception e2) {
            return hashMap;
        }
    }

    public static String getExceptionDescription(Throwable e) {
        return e != null ? e.getClass().getSimpleName() + ": " + e.getMessage() : "";
    }

    public enum PlacementType {
        INLINE("inline"),
        INTERSTITIAL("interstitial");

        private final String placement;

        PlacementType(String s) {
            this.placement = s;
        }

        public String getValue() {
            return this.placement;
        }

        public String getName() {
            return MRAIDUtils.wrapInJSQuotes(this.placement);
        }

        @Override
        public String toString() {
            return this.placement;
        }
    }

    public enum Orientation {
        PORTRAIT(StaticParams.ORIENTATION_PORT),
        LANDSCAPE(StaticParams.ORIENTATION_LAND),
        NONE(UnityAdsConstants.UNITY_ADS_WEBVIEW_VIEWTYPE_NONE);

        private final String value;

        Orientation(String s) {
            this.value = s;
        }

        public String getValue() {
            return this.value;
        }

        public static Orientation getOrientation(String s) {
            for (Orientation orientation : values()) {
                if (orientation.getValue().equals(s)) {
                    return orientation;
                }
            }
            return NONE;
        }
    }

    public enum Events {
        READY("ready"),
        ERROR("error"),
        STATE_CHANGE("stateChange"),
        VIEWABLE_CHANGE("viewableChange"),
        SIZE_CHANGE("sizeChange");

        private final String event;

        Events(String e) {
            this.event = e;
        }

        public String getEvent() {
            return "\"" + this.event + "\"";
        }
    }

    public enum States {
        LOADING("loading"),
        DEFAULT(UnityAdsConstants.UNITY_ADS_ZONE_DEFAULT_KEY),
        EXPANDED("expanded"),
        RESIZED("resized"),
        HIDDEN("hidden");

        private final String state;

        States(String s) {
            this.state = s;
        }

        public String getName() {
            return MRAIDUtils.wrapInJSQuotes(this.state);
        }
    }

    public enum Features {
        SMS(MRAIDNativeFeature.SMS),
        TEL("tel"),
        CALENDAR(MRAIDNativeFeature.CALENDAR),
        STORE_PICTURE(MRAIDNativeFeature.STORE_PICTURE),
        INLINE_VIDEO(MRAIDNativeFeature.INLINE_VIDEO);

        private final String feature;
        private Boolean supported = null;
        private int supportLevel = 0;

        Features(String s) {
            this.feature = s;
        }

        public String getName() {
            return MRAIDUtils.wrapInJSQuotes(this.feature);
        }

        public boolean isSupported(Activity activity) {
            if (this.supported == null) {
                this.supported = MRAIDDeviceManager.checkFeatureSupport(activity, this);
                this.supportLevel = MRAIDDeviceManager.checkSupportLevel(activity, this);
            }
            return this.supported.booleanValue();
        }

        public int getSupportLevel() {
            return this.supportLevel;
        }
    }

    public enum JSCommands {
        SHOW_AD("showAd"),
        GET_VERSION("getVersion"),
        ADD_EVENT_LISTENER("addEventListener"),
        REMOVE_EVENT_LISTENER("removeEventListener"),
        FIRE_EVENT("fireEvent"),
        FIRE_CHANGE_EVENT("fireChangeEvent"),
        FIRE_ERROR_EVENT("fireErrorEvent"),
        GET_STATE("getState"),
        SET_STATE("setState"),
        SET_FEATURE_SUPPORT("setFeatureSupport"),
        SET_NATIVE_VIDEO_FEATURE_SUPPORT("setNativeVideoFeatureSupport"),
        SUPPORTS("supports"),
        GET_PLACEMENT_TYPE("getPlacementType"),
        SET_PLACEMENT_TYPE("setPlacementType"),
        GET_SCREEN_SIZE("getScreenSize"),
        SET_SCREEN_SIZE("setScreenSize"),
        GET_MAX_SIZE("getMaxSize"),
        SET_MAX_SIZE("setMaxSize"),
        USE_CUSTOM_CLOSE(ObjectNames.ExpandProperties.USE_CUSTOM_CLOSE),
        OPEN(UnityAdsConstants.UNITY_ADS_WEBVIEW_API_OPEN),
        CLOSE(UnityAdsConstants.UNITY_ADS_WEBVIEW_API_CLOSE),
        EXPAND("expand"),
        RESIZE("resize"),
        GET_ORIENTATION_PROPERTIES("getOrientationProperties"),
        SET_ORIENTATION_PROPERTIES("setOrientationProperties"),
        GET_EXPAND_PROPERTIES("getExpandProperties"),
        SET_EXPAND_PROPERTIES("setExpandProperties"),
        GET_RESIZE_PROPERTIES("getResizeProperties"),
        SET_RESIZE_PROPERTIES("setResizeProperties"),
        GET_DEFAULT_POSITION("getDefaultPosition"),
        SET_DEFAULT_POSITION("setDefaultPosition"),
        GET_CURRENT_POSITION("getCurrentPosition"),
        SET_CURRENT_POSITION("setCurrentPosition"),
        CREATE_CALENDAR_EVENT("createCalendarEvent"),
        PLAY_VIDEO(UnityAdsConstants.UNITY_ADS_WEBVIEW_API_PLAYVIDEO),
        STORE_PICTURE(MRAIDNativeFeature.STORE_PICTURE),
        IS_VIEWABLE("isViewable"),
        SET_IS_VIEWABLE("setIsViewable"),
        CALL_SDK("callSdk"),
        LOG("log"),
        SET_IS_DEBUG_MODE("setIsDebugMode"),
        GET_PAGE_SIZE("getPageSize"),
        CALL_RECEIVED("callReceived"),
        TRACK_VIDEO("video");

        private final String command;

        JSCommands(String cmd) {
            this.command = cmd;
        }

        public String getCommand() {
            return this.command;
        }

        public JSCommand instance() {
            return new JSCommand(this);
        }
    }

    static class JSCommand {
        private final JSCommands command;
        private String jsObjectName;
        private String[] parameters;

        private JSCommand(JSCommands command) {
            this.jsObjectName = "mraid";
            this.command = command;
        }

        public JSCommands getCommand() {
            return this.command;
        }

        public void setParams(String... params) {
            this.parameters = params;
        }

        public String[] getParams() {
            return this.parameters;
        }

        public void setJsObjectName(String objectName) {
            this.jsObjectName = objectName;
        }

        public String getParamsAsString() {
            String params = "";
            if (this.parameters != null && this.parameters.length > 0) {
                params = this.parameters[0];
                for (int i = 1; i < this.parameters.length; i++) {
                    params = params + "," + this.parameters[i];
                }
            }
            return params;
        }

        public String getJSCall() {
            return "javascript:" + this.jsObjectName + "." + this.command.getCommand() + "(" + getParamsAsString() + ");";
        }
    }

    enum UrlScheme {
        OPEN("mraid://open"),
        CLOSE("mraid://close"),
        PLAY_VIDEO("mraid://playVideo"),
        EXPAND("mraid://expand"),
        RESIZE("mraid://resize"),
        STORE_PICTURE("mraid://storePicture"),
        SET_RESIZE_PROPERTIES("mraid://setResizeProperties"),
        SET_EXPAND_PROPERTIES("mraid://setExpandProperties"),
        SET_ORIENTATION_PROPERTIES("mraid://setOrientationProperties"),
        LOADED("nativex://loaded"),
        LOG("nativex://log"),
        USE_CUSTOM_CLOSE("mraid://useCustomClose"),
        CREATE_CALENDAR_EVENT("mraid://createCalendarEvent/"),
        SIZE_SCRIPT_SET_PAGE_SIZE("nativeXSizeScript://setPageSize/"),
        NON_REWARD_CLOSE("webview:dismissView"),
        NON_REWARD_CLOSE_OLD("w3imaap:dismissView"),
        GOOGLE_MARKET("http://market.android.com/details"),
        GOOGLE_PLAY("https://play.google.com/"),
        MARKET_CUSTOM_SCHEME("market://"),
        AD_CONVERTED("nativex://adConverted/");

        private final String scheme;

        UrlScheme(String scheme) {
            this.scheme = scheme;
        }

        public String getScheme() {
            return this.scheme;
        }

        public static UrlScheme checkForScheme(String url) {
            for (UrlScheme scheme : values()) {
                if (url.startsWith(scheme.getScheme())) {
                    return scheme;
                }
            }
            return null;
        }
    }

    public enum ClosePosition {
        TOP_LEFT("top-left", ThemeElementTypes.MRAID_CLOSE_BUTTON_TOP_LEFT),
        TOP_RIGHT("top-right", ThemeElementTypes.MRAID_CLOSE_BUTTON_TOP_RIGHT),
        TOP_CENTER("top-center", ThemeElementTypes.MRAID_CLOSE_BUTTON_TOP_CENTER),
        CENTER("center", ThemeElementTypes.MRAID_CLOSE_BUTTON_CENTER),
        BOTTOM_LEFT("bottom-left", ThemeElementTypes.MRAID_CLOSE_BUTTON_BOTTOM_LEFT),
        BOTTOM_RIGHT("bottom-right", ThemeElementTypes.MRAID_CLOSE_BUTTON_BOTTOM_RIGHT),
        BOTTOM_CENTER("bottom-center", ThemeElementTypes.MRAID_CLOSE_BUTTON_BOTTOM_CENTER);

        private final String position;
        private final ThemeElementTypes themeElement;

        ClosePosition(String s, ThemeElementTypes themeElement) {
            this.position = s;
            this.themeElement = themeElement;
        }

        public String getName() {
            return this.position;
        }

        public ThemeElementTypes getThemeElementType() {
            return this.themeElement;
        }

        public static ClosePosition getPosition(String s) {
            for (ClosePosition position : values()) {
                if (position.position.equals(s)) {
                    return position;
                }
            }
            return TOP_RIGHT;
        }
    }

    public enum NativeXEvents {
        VIDEO_CANCELLED("videoCancelled");

        private final String event;

        NativeXEvents(String e) {
            this.event = e;
        }

        public String getEvent() {
            return "\"" + this.event + "\"";
        }
    }

    public static void analyseUrl(Context context, String url) {
        try {
            if (checkForDeepLinking(url)) {
                launchApplication(context, url);
            } else {
                startMRAIDBrowser(context, url);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static boolean checkForDeepLinking(String url) {
        return url.startsWith("package") || url.startsWith("action") || url.startsWith("unity");
    }

    private static void launchApplication(Context context, String url) {
        if (url.startsWith("package")) {
            Uri packageUri = Uri.parse(url);
            String applicationPackageName = packageUri.getHost();
            String activityName = packageUri.getLastPathSegment();
            if (applicationPackageName != null && activityName == null) {
                try {
                    Log.d("Android DeepLinking package:" + applicationPackageName);
                    context.startActivity(context.getPackageManager().getLaunchIntentForPackage(applicationPackageName));
                    return;
                } catch (ActivityNotFoundException e) {
                    Log.e("Error in Android DeepLinking using package name. ActivityNotFound exception thrown.");
                    return;
                }
            }
            if (applicationPackageName != null) {
                try {
                    Log.d("Android DeepLinking package:" + applicationPackageName + " activity:" + activityName);
                    Intent intent = new Intent();
                    intent.setComponent(new ComponentName(applicationPackageName, applicationPackageName + "." + activityName));
                    intent.setFlags(268435456);
                    context.startActivity(intent);
                    return;
                } catch (ActivityNotFoundException e2) {
                    Log.e("Error in Android DeepLinking same application using component name. ActivityNotFound exception thrown.");
                    return;
                }
            }
            Log.e("Error in Android DeepLinking 'package' URI format. Has to be package://packageName/activityName");
            return;
        }
        if (url.startsWith("action")) {
            String action = null;
            String dataScheme = null;
            String[] splitStrings = url.split("&");
            if (splitStrings.length > 0) {
                String actionSplit = null;
                String dataSchemeSplit = null;
                if (splitStrings.length > 1) {
                    actionSplit = splitStrings[0];
                }
                if (splitStrings.length >= 2) {
                    dataSchemeSplit = splitStrings[1];
                }
                if (actionSplit != null) {
                    String[] actionSplitStrings = actionSplit.split("=");
                    if (actionSplitStrings.length == 2 && actionSplitStrings[0].equals("action")) {
                        action = actionSplitStrings[1];
                    }
                } else {
                    Log.e("Error in Android DeepLinking other application URI format. Has to be action=actionName");
                }
                if (dataSchemeSplit != null) {
                    String[] dataSchemeSplitStrings = dataSchemeSplit.split("=");
                    if (dataSchemeSplitStrings.length == 2 && dataSchemeSplitStrings[0].equals("data")) {
                        dataScheme = dataSchemeSplitStrings[1];
                    }
                } else {
                    Log.d("Error in Android DeepLinking other application URI format. Has to be data=dataURI");
                }
            }
            if (action != null) {
                try {
                    Log.d("Android DeepLinking action:" + action + " dataScheme:" + dataScheme);
                    Intent intent2 = new Intent();
                    intent2.setAction(action);
                    if (dataScheme != null) {
                        intent2.setData(Uri.parse(dataScheme));
                    }
                    intent2.setFlags(268435456);
                    context.startActivity(intent2);
                    return;
                } catch (ActivityNotFoundException e3) {
                    Log.e("Error in Android DeepLinking other application. ActivityNotFound exception thrown.");
                    return;
                }
            }
            Log.e("Error in Android DeepLinking other application. Action name is not defined.");
            return;
        }
        if (url.startsWith("unity")) {
            Uri packageUri2 = Uri.parse(url);
            String applicationPackageName2 = packageUri2.getHost();
            String sceneName = packageUri2.getLastPathSegment();
            if (applicationPackageName2 != null && sceneName == null) {
                Log.d("Unity DeepLinking package:" + applicationPackageName2);
                context.startActivity(context.getPackageManager().getLaunchIntentForPackage(applicationPackageName2));
                return;
            } else {
                if (applicationPackageName2 != null) {
                    Log.d("Unity DeepLinking package:" + applicationPackageName2 + " sceneName:" + sceneName);
                    Intent intent3 = new Intent(StringConstants.ACTION_DEEPLINK);
                    intent3.putExtra(StringConstants.PACKAGE_NAME, applicationPackageName2);
                    intent3.putExtra(StringConstants.SCENE_NAME, sceneName);
                    context.sendBroadcast(intent3);
                    return;
                }
                Log.e("Error in Unity DeepLinking URI format. Both package name and scene name couldn't be found.");
                return;
            }
        }
        Log.e("Error in DeepLinking URI format. None of the URI format was found.");
    }

    public static void startMRAIDBrowser(Context context, String url) {
        Intent browserIntent = new Intent("android.intent.action.VIEW");
        browserIntent.setData(Uri.parse(url));
        browserIntent.addFlags(268435456);
        context.startActivity(browserIntent);
    }
}