导航菜单

页面标题

页面副标题

小柿子 v1.3.8 - WMSdkConfig.java 源代码

正在查看: 小柿子 v1.3.8 应用的 WMSdkConfig.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.windmill.sdk.strategy;

import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import com.czhj.sdk.common.ClientMetadata;
import com.czhj.sdk.common.models.Config;
import com.czhj.sdk.common.network.Networking;
import com.czhj.sdk.common.network.SigmobRequestQueue;
import com.czhj.sdk.common.track.TrackManager;
import com.czhj.volley.VolleyError;
import com.windmill.sdk.WindMillAd;
import com.windmill.sdk.base.WMLogUtil;
import com.windmill.sdk.models.Android;
import com.windmill.sdk.models.Common;
import com.windmill.sdk.models.CommonEndpointsConfig;
import com.windmill.sdk.models.SdkConfig;
import com.windmill.sdk.models.SdkConfigResponse;
import com.windmill.sdk.strategy.g;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.List;

public class WMSdkConfig {
    private static final String CONFIG_FILE_NAME = "/tb_config";
    private static final String SDK_CONFIG_URL = "https://adservice.sigmob.cn/w/config";
    private static final String SDK_CONFIG_URL_BACK = "https://c.tobidad.cn/w/config";
    private static final String SDK_CONFIG_VER = "sdkConfigVer";
    private static final String SDK_GDPR_URL = "https://adservice.sigmob.cn/extconfig?";
    public static String _TIMEOUT = "_timeout";
    private static String backupConfigUrl = "";
    private static WMSdkConfig gInstance = null;
    private static boolean isRetry = false;
    private static String lance = "";
    private static boolean mIsGDPRRegion = false;
    private a mOnSDKUpdateListener;
    private final String ver = "tb-4.5.4";
    private long mRefreshTimeMillis = 0;
    private SdkConfig mSdkConfig = null;
    private SdkConfig mDefaultSDKConfig = null;
    private String STRATEGY_URL = "https://adservice.sigmob.cn/strategy/v6";
    private String BIDDING_URL = "https://adservice.sigmob.cn/waterfall/v1";
    private String SDK_LOG_URL = "https://dc.sigmob.cn/log";
    private final Handler mHandler = new Handler(Looper.getMainLooper());
    private final Runnable mRefreshRunnable = new Runnable() {
        @Override
        public void run() {
            WMSdkConfig.this.scheduleRefreshSDKConfigRunnable();
        }
    };
    private boolean mCurrentAutoRefreshStatus = true;

    public interface a {
        void a();
    }

    private WMSdkConfig() {
        initDefaultSDKConfig();
        loadFromFile();
    }

    private void cancelRefreshTimer() {
        Handler handler = this.mHandler;
        if (handler != null) {
            handler.removeCallbacks(this.mRefreshRunnable);
        }
    }

    public String getBackupConfigUrl() {
        try {
            String str = getCommonConfig().endpoints.config;
            if (!TextUtils.isEmpty(str)) {
                if (str.indexOf(63) == -1) {
                    return str + "?" + getServerQueryString();
                }
                return str + "&" + getServerQueryString();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "https://c.tobidad.cn/w/config?" + getServerQueryString();
    }

    public static String getConfigUrl() {
        if (!TextUtils.isEmpty(backupConfigUrl)) {
            return backupConfigUrl;
        }
        if (TextUtils.isEmpty(lance)) {
            return "https://adservice.sigmob.cn/w/config?" + getServerQueryString();
        }
        return lance + "?" + getServerQueryString();
    }

    public static String getGDPRRegionURL() {
        return SDK_GDPR_URL + getServerQueryString();
    }

    public static String getServerQueryString() {
        return "appId=" + WindMillAd.sharedAds().getAppId() + "&sdkVersion=4.5.4";
    }

    public void handleUpdateConfig(SdkConfig sdkConfig) {
        Common common;
        if (sdkConfig == null || (common = sdkConfig.common_config) == null) {
            return;
        }
        this.mSdkConfig = sdkConfig;
        this.mRefreshTimeMillis = common.configRefresh.intValue() * 1000;
        a aVar = this.mOnSDKUpdateListener;
        if (aVar != null) {
            aVar.a();
        }
        Config.sharedInstance().update(mIsGDPRRegion, isDisableBootMark(), getOaidApiDisable(), getDisable_up_OAid(), getLogUrl(), getSendLogInterval(), getMaxSendLogRecords(), getLog_enc());
        TrackManager.getInstance().setRetryExpiredTime(getTracking_expiration_time());
        TrackManager.getInstance().setRetryInterval(getTracking_retry_interval());
    }

    private void initDefaultSDKConfig() {
        if (this.mDefaultSDKConfig == null) {
            SdkConfig.Builder builder = new SdkConfig.Builder();
            Common.Builder builder2 = new Common.Builder();
            Android.Builder builder3 = new Android.Builder();
            CommonEndpointsConfig.Builder builder4 = new CommonEndpointsConfig.Builder();
            builder4.log(this.SDK_LOG_URL);
            builder4.strategy(this.STRATEGY_URL);
            builder4.bidding_url(this.BIDDING_URL);
            builder4.config(SDK_CONFIG_URL_BACK);
            builder2.endpoints(builder4.build());
            builder2.configRefresh(1000);
            Boolean bool = Boolean.TRUE;
            builder2.disable_up_location(bool);
            Boolean bool2 = Boolean.FALSE;
            builder2.is_gdpr_region(bool2);
            builder2.enable_debug_level(bool2);
            builder3.disable_boot_mark(bool);
            builder3.oaid_api_is_disable(bool);
            builder3.enable_permission(bool2);
            builder3.enable_report_crash(bool2);
            builder.common_config(builder2.build());
            builder.android_config(builder3.build());
            this.mDefaultSDKConfig = builder.build();
        }
    }

    public static boolean isGDPRRegion() {
        return mIsGDPRRegion;
    }

    private void loadConfig() {
        SigmobRequestQueue requestQueue = Networking.getRequestQueue();
        g gVar = new g(getConfigUrl(), new g.a() {
            @Override
            public void a(SdkConfigResponse sdkConfigResponse) {
                WMLogUtil.dd(WMLogUtil.TAG, "SdkConfigResponse:" + sdkConfigResponse.toString());
                boolean unused = WMSdkConfig.isRetry = false;
                SdkConfig sdkConfig = sdkConfigResponse.config;
                if (sdkConfigResponse.code.intValue() != 0 || sdkConfig == null) {
                    WMLogUtil.e("ConfigResponseError:" + sdkConfigResponse.error_message);
                } else {
                    WMSdkConfig.this.handleUpdateConfig(sdkConfig);
                    WMSdkConfig.this.saveToFile(sdkConfig);
                }
                WMSdkConfig.this.scheduleRefreshTimerIfEnabled();
            }

            public void onErrorResponse(VolleyError volleyError) {
                WMLogUtil.e("ConfigResponseError:" + volleyError.toString());
                String unused = WMSdkConfig.backupConfigUrl = WMSdkConfig.this.getBackupConfigUrl();
                if (WMSdkConfig.isRetry) {
                    WMSdkConfig.this.scheduleRefreshTimerIfEnabled();
                } else {
                    boolean unused2 = WMSdkConfig.isRetry = true;
                    WMSdkConfig.this.mHandler.post(WMSdkConfig.this.mRefreshRunnable);
                }
            }
        });
        if (requestQueue == null) {
            WMLogUtil.e("queue is null");
            scheduleRefreshTimerIfEnabled();
        } else {
            requestQueue.add(gVar);
            WMLogUtil.i(WMLogUtil.TAG, "start update sdk config");
        }
    }

    private void loadFromFile() {
        if (ClientMetadata.getInstance() == null) {
            handleUpdateConfig(this.mDefaultSDKConfig);
            return;
        }
        ObjectInputStream objectInputStream = null;
        String string = com.windmill.sdk.utils.i.a(ClientMetadata.getInstance().getContext()).getString(SDK_CONFIG_VER, null);
        File file = new File(com.windmill.sdk.utils.e.a() + CONFIG_FILE_NAME);
        if ("tb-4.5.4".equals(string)) {
            try {
                if (file.exists()) {
                    try {
                        ObjectInputStream objectInputStream2 = new ObjectInputStream(new FileInputStream(file));
                        try {
                            handleUpdateConfig((SdkConfig) SdkConfig.ADAPTER.decode(objectInputStream2));
                            objectInputStream2.close();
                        } catch (Throwable th) {
                            th = th;
                            objectInputStream = objectInputStream2;
                            try {
                                handleUpdateConfig(this.mDefaultSDKConfig);
                                WMLogUtil.e(th.getMessage());
                                if (objectInputStream != null) {
                                    objectInputStream.close();
                                    return;
                                }
                                return;
                            } catch (Throwable th2) {
                                if (objectInputStream != null) {
                                    try {
                                        objectInputStream.close();
                                    } catch (Throwable th3) {
                                        WMLogUtil.e(th3.getMessage());
                                    }
                                }
                                throw th2;
                            }
                        }
                    } catch (Throwable th4) {
                        th = th4;
                    }
                    return;
                }
            } catch (Throwable th5) {
                WMLogUtil.e(th5.getMessage());
                return;
            }
        }
        handleUpdateConfig(this.mDefaultSDKConfig);
    }

    public void saveToFile(SdkConfig sdkConfig) {
        ObjectOutputStream objectOutputStream;
        if (sdkConfig != null) {
            ObjectOutputStream objectOutputStream2 = null;
            File file = new File(com.windmill.sdk.utils.e.a() + CONFIG_FILE_NAME);
            if (file.exists()) {
                file.delete();
            }
            file.getParentFile().mkdirs();
            try {
                try {
                    try {
                        objectOutputStream = new ObjectOutputStream(new FileOutputStream(file));
                    } catch (IOException e) {
                        e = e;
                    }
                } catch (Throwable th) {
                    th = th;
                }
                try {
                    sdkConfig.encode(objectOutputStream);
                    com.windmill.sdk.utils.i.a(ClientMetadata.getInstance().getContext()).edit().putString(SDK_CONFIG_VER, "tb-4.5.4").apply();
                    objectOutputStream.close();
                } catch (IOException e5) {
                    e = e5;
                    objectOutputStream2 = objectOutputStream;
                    WMLogUtil.e(e.getMessage());
                    if (objectOutputStream2 != null) {
                        objectOutputStream2.close();
                    }
                } catch (Throwable th2) {
                    th = th2;
                    objectOutputStream2 = objectOutputStream;
                    if (objectOutputStream2 != null) {
                        try {
                            objectOutputStream2.close();
                        } catch (IOException e6) {
                            WMLogUtil.e(e6.getMessage());
                        }
                    }
                    throw th;
                }
            } catch (IOException e7) {
                WMLogUtil.e(e7.getMessage());
            }
        }
    }

    public void scheduleRefreshSDKConfigRunnable() {
        if (ClientMetadata.getInstance() == null) {
            return;
        }
        if (ClientMetadata.getInstance().isNetworkConnected(getConfigUrl()) && com.windmill.sdk.a.a.b()) {
            loadConfig();
        } else {
            WMLogUtil.e("Can't load an ad because  is no network or can not CollectPersonalInformation");
            scheduleRefreshTimerIfEnabled();
        }
    }

    public void scheduleRefreshTimerIfEnabled() {
        cancelRefreshTimer();
        if (this.mCurrentAutoRefreshStatus) {
            this.mHandler.postDelayed(this.mRefreshRunnable, Math.max(30000L, this.mRefreshTimeMillis));
        }
    }

    public static WMSdkConfig sharedInstance() {
        if (gInstance == null) {
            synchronized (WMSdkConfig.class) {
                if (gInstance == null) {
                    gInstance = new WMSdkConfig();
                }
            }
        }
        return gInstance;
    }

    public int enableReport_log() {
        if (getSdkConfig() == null || getAndroidConfig() == null) {
            return 0;
        }
        return getAndroidConfig().report_log.intValue();
    }

    public Android getAndroidConfig() {
        return getSdkConfig().android_config;
    }

    public String getBiddingUrl() {
        String str = getCommonConfig().endpoints.bidding_url;
        if (TextUtils.isEmpty(str)) {
            return this.BIDDING_URL + "?" + getServerQueryString();
        }
        if (str.indexOf(63) == -1) {
            return str + "?" + getServerQueryString();
        }
        return str + "&" + getServerQueryString();
    }

    public Common getCommonConfig() {
        return getSdkConfig().common_config;
    }

    public int getDisable_up_OAid() {
        if (getSdkConfig() == null || getAndroidConfig() == null) {
            return 0;
        }
        return getAndroidConfig().disable_up_oaid.intValue();
    }

    public long getLoadPeriodTime() {
        Integer num = getCommonConfig().load_interval;
        if (num == null || num.intValue() < 1) {
            return 0L;
        }
        return num.intValue() * 1000;
    }

    public List<Integer> getLogBlackList() {
        return getCommonConfig().dclog_blacklist;
    }

    public String getLogUrl() {
        String str = getCommonConfig().endpoints.log;
        if (TextUtils.isEmpty(str)) {
            return this.SDK_LOG_URL + "?" + getServerQueryString();
        }
        if (str.indexOf(63) == -1) {
            return str + "?" + getServerQueryString();
        }
        return str + "&" + getServerQueryString();
    }

    public boolean getLog_enc() {
        if (getCommonConfig() != null) {
            return getCommonConfig().log_enc.booleanValue();
        }
        return false;
    }

    public int getMaxSendLogRecords() {
        int intValue = getCommonConfig().max_send_log_records.intValue();
        if (intValue < 10) {
            return 100;
        }
        return intValue;
    }

    public boolean getOaidApiDisable() {
        if (getSdkConfig() == null || getAndroidConfig() == null) {
            return true;
        }
        return getAndroidConfig().oaid_api_is_disable.booleanValue();
    }

    public long getReadyExpired() {
        int intValue = getCommonConfig().ready_expire_timestamp.intValue();
        if (intValue < 1) {
            intValue = 900;
        }
        return intValue * 1000;
    }

    public SdkConfig getSdkConfig() {
        SdkConfig sdkConfig = this.mSdkConfig;
        return sdkConfig == null ? this.mDefaultSDKConfig : sdkConfig;
    }

    public int getSendLogInterval() {
        int intValue = getCommonConfig().send_log_interval.intValue();
        if (intValue < 3) {
            return 3;
        }
        return intValue;
    }

    public String getStrategyUrl() {
        String str = getCommonConfig().endpoints.strategy;
        if (TextUtils.isEmpty(str)) {
            return this.STRATEGY_URL + "?" + getServerQueryString();
        }
        if (str.indexOf(63) == -1) {
            return str + "?" + getServerQueryString();
        }
        return str + "&" + getServerQueryString();
    }

    public int getTracking_expiration_time() {
        if (getCommonConfig() == null || getCommonConfig().tracking_expiration_time.intValue() < 1) {
            return 86400;
        }
        return getCommonConfig().tracking_expiration_time.intValue();
    }

    public int getTracking_retry_interval() {
        if (getCommonConfig() == null || getCommonConfig().tracking_retry_interval.intValue() < 10) {
            return 180;
        }
        return getCommonConfig().tracking_retry_interval.intValue();
    }

    public boolean isDisableBootMark() {
        if (getSdkConfig() == null || getAndroidConfig() == null) {
            return true;
        }
        return getAndroidConfig().disable_boot_mark.booleanValue();
    }

    public boolean isDisable_up_location() {
        if (getSdkConfig() == null || getCommonConfig().disable_up_location == null) {
            return true;
        }
        return getCommonConfig().disable_up_location.booleanValue();
    }

    public boolean isEnable_debug_level() {
        if (getSdkConfig() == null || getCommonConfig().enable_debug_level == null) {
            return false;
        }
        return getCommonConfig().enable_debug_level.booleanValue();
    }

    public boolean isEnable_permission() {
        if (getSdkConfig() == null || getAndroidConfig() == null) {
            return false;
        }
        return getAndroidConfig().enable_permission.booleanValue();
    }

    public boolean isEnable_report_crash() {
        if (getSdkConfig() == null || getAndroidConfig() == null) {
            return false;
        }
        return getAndroidConfig().enable_report_crash.booleanValue();
    }

    public long loadAdTimeout(String str) {
        int i = 0;
        try {
            i = com.windmill.sdk.utils.i.a(ClientMetadata.getInstance().getContext()).getInt(str + _TIMEOUT, 0);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return i;
    }

    public WMSdkConfig setOnSDKUpdateListener(a aVar) {
        this.mOnSDKUpdateListener = aVar;
        return gInstance;
    }

    public void startUpdate() {
        cancelRefreshTimer();
        Handler handler = this.mHandler;
        if (handler != null) {
            handler.post(this.mRefreshRunnable);
        }
    }
}