导航菜单

页面标题

页面副标题

MX Player v1.97.8 - DtbDeviceRegistration.java 源代码

正在查看: MX Player v1.97.8 应用的 DtbDeviceRegistration.java JAVA 源代码文件

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


package com.amazon.device.ads;

import android.content.Context;
import android.content.SharedPreferences;
import defpackage.i0;
import defpackage.qb9;
import defpackage.z31;
import java.util.HashMap;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

class DtbDeviceRegistration {
    private static final String AAX_VIDEO_HOST_NAME_KEY = "aaxVideoHostname";
    private static final String LOG_TAG = "com.amazon.device.ads.DtbDeviceRegistration";
    private static String amznAdId;
    private static String appId;
    private static DtbDeviceRegistration dtbDeviceRegistrationInstance;
    private final DtbMetrics metrics = new DtbMetrics();

    private DtbDeviceRegistration() {
    }

    private HashMap<String, Object> buildConfigInfoParams(String str) {
        HashMap<String, Object> d = xz3.d("appId", str);
        d.put("sdkVer", DtbCommonUtils.getSDKVersion());
        d.put("fp", "false");
        d.put("testMode", Boolean.toString(AdRegistration.isTestMode()));
        JSONObject paramsJsonGetSafe = DtbDeviceData.getDeviceDataInstance().getParamsJsonGetSafe();
        if (paramsJsonGetSafe != null) {
            d.put("dinfo", paramsJsonGetSafe);
        }
        JSONObject paramsJson = DtbPackageNativeData.getPackageNativeDataInstance(AdRegistration.getContext()).getParamsJson();
        if (paramsJson != null) {
            d.put("pkg", paramsJson);
        }
        if (AdRegistration.getCustomDictionary() != null && AdRegistration.getCustomDictionary().containsKey("mediationName")) {
            String str2 = AdRegistration.getCustomDictionary().get("mediationName");
            if (!DtbCommonUtils.isNullOrEmpty(str2)) {
                d.put("mediationName", str2);
            }
        }
        if (Math.random() <= DTBMetricsConfiguration.getClientConfigVal("distribution_pixel", DTBMetricsConfiguration.DISTRIBUTION_PIXEL_DEFAULT_VALUE.intValue(), "sample_rates").intValue() / 100.0f) {
            String sDKDistributionPlace = AdRegistration.getSDKDistributionPlace();
            if (!DtbCommonUtils.isNullOrEmpty(sDKDistributionPlace)) {
                d.put("distribution", sDKDistributionPlace);
            }
        }
        return d;
    }

    private HashMap<String, Object> buildSISParams(String str) {
        HashMap<String, Object> hashMap = new HashMap<>(DtbDeviceData.getDeviceDataInstance().getDeviceParams());
        String adId = DtbSharedPreferences.getInstance().getAdId();
        if (adId != null) {
            hashMap.put("adId", adId);
        }
        String idfa = DtbSharedPreferences.getInstance().getIdfa();
        Boolean optOut = DtbSharedPreferences.getInstance().getOptOut();
        if (!DtbCommonUtils.isNullOrEmpty(idfa)) {
            hashMap.put("idfa", idfa);
        }
        hashMap.put("oo", convertBooleanToFlag(optOut));
        if (str != null) {
            hashMap.put("appId", str);
        }
        JSONObject paramsJson = DtbPackageNativeData.getPackageNativeDataInstance(AdRegistration.getContext()).getParamsJson();
        if (paramsJson != null) {
            hashMap.put("pkg", paramsJson);
        }
        Context context = AdRegistration.getContext();
        if (context != null) {
            SharedPreferences b = uwd.b(context);
            Object obj = b.contains("IABTCF_gdprApplies") ? b.getAll().get("IABTCF_gdprApplies") : null;
            String string = b.getString("IABTCF_TCString", null);
            if (obj != null) {
                try {
                    if ((obj instanceof Integer) && (((Integer) obj).intValue() == 1 || ((Integer) obj).intValue() == 0)) {
                        hashMap.put("gdpr", obj);
                    } else if (((obj instanceof String) && ((String) obj).equals("1")) || ((String) obj).equals("0")) {
                        hashMap.put("gdpr", obj);
                    } else {
                        DtbLog.info("IABTCF_gdprApplies should be a 1 or 0 as per IAB guideline");
                    }
                } catch (ClassCastException unused) {
                    DtbLog.info("IABTCF_gdprApplies should be a number as per IAB guideline");
                }
            }
            if (string != null) {
                hashMap.put("gdpr_consent", string);
            }
        }
        String encodedNonIABString = AdRegistration.getEncodedNonIABString();
        if (!DtbCommonUtils.isNullOrEmpty(encodedNonIABString)) {
            hashMap.put("gdpr_custom", encodedNonIABString);
        }
        return hashMap;
    }

    private static String convertBooleanToFlag(Boolean bool) {
        return (bool != null && bool.booleanValue()) ? "1" : "0";
    }

    private synchronized void initializeAds() {
        boolean z;
        long currentTimeMillis = System.currentTimeMillis();
        long longValue = DtbSharedPreferences.getInstance().getSisLastCheckIn().longValue();
        if (DtbSharedPreferences.getInstance().getIsSisRegisterationSuccessful()) {
            long j = currentTimeMillis - longValue;
            if (j <= 86400000) {
                DtbLog.debug("SIS call not required, last registration duration:" + j + ", expiration:86400000");
                return;
            }
        }
        if (!DtbCommonUtils.isNetworkConnected()) {
            DtbLog.debug("Network is not available");
            return;
        }
        appId = AdRegistration.getAppKey();
        if (DtbCommonUtils.isOnMainThread()) {
            DtbLog.error(LOG_TAG, "Unable to fetch advertising identifier information on main thread.");
            return;
        }
        new DtbAdvertisingInfo();
        DtbDebugProperties.getInstance();
        registerConfig(appId);
        String sisEndpoint = DtbSharedPreferences.getInstance().getSisEndpoint();
        if (sisEndpoint.startsWith("null")) {
            DtbLog.debug("SIS is not ready");
            return;
        }
        StringBuilder sb = new StringBuilder(DtbDebugProperties.getSISUrl(sisEndpoint));
        if (longValue == 0) {
            DtbLog.info(LOG_TAG, "Trying to register ad id..");
            sb.append("/generate_did");
            z = false;
        } else {
            DtbLog.info(LOG_TAG, "Trying to update ad id..");
            sb.append("/update_dev_info");
            z = true;
        }
        HashMap<String, Object> buildSISParams = buildSISParams(appId);
        try {
            try {
                try {
                    DtbHttpClient dtbHttpClient = new DtbHttpClient(sb.toString());
                    dtbHttpClient.setUseSecure(DtbDebugProperties.getIsSecure(true));
                    dtbHttpClient.setParams(buildSISParams);
                    dtbHttpClient.enableQueryParams();
                    DtbMetric dtbMetric = z ? DtbMetric.SIS_LATENCY_UPDATE_DEVICE_INFO : DtbMetric.SIS_LATENCY_REGISTER_EVENT;
                    this.metrics.startTimer(dtbMetric);
                    dtbHttpClient.executePOST(60000);
                    this.metrics.stopTimer(dtbMetric);
                    if (DtbCommonUtils.isNullOrEmpty(dtbHttpClient.getResponse())) {
                        DtbLog.debug("No response from sis call.");
                        throw new Exception("SIS Response is null");
                    }
                    JSONObject jSONObject = (JSONObject) new JSONTokener(dtbHttpClient.getResponse()).nextValue();
                    DtbSharedPreferences.getInstance().setIsSisRegisterationSuccessful(isRegistrationRequestSuccessful(jSONObject));
                    if (DtbSharedPreferences.getInstance().getIsSisRegisterationSuccessful()) {
                        if (dtbMetric != null) {
                            this.metrics.resetMetric(dtbMetric);
                        }
                        pingSis(sisEndpoint, appId);
                    } else {
                        DtbLog.info(LOG_TAG, "ad id failed registration: " + jSONObject.toString());
                        throw new Exception("ad id failed registration: ");
                    }
                } catch (Exception e) {
                    DtbLog.error("Error registering device for ads:" + e.toString());
                    if (0 != 0) {
                        this.metrics.resetMetric(null);
                    }
                }
            } catch (JSONException e2) {
                DtbLog.error("JSON error parsing return from SIS: " + e2.getMessage());
                if (0 != 0) {
                    this.metrics.resetMetric(null);
                }
            }
        } catch (Throwable th) {
            if (0 != 0) {
                this.metrics.resetMetric(null);
            }
            throw th;
        }
    }

    private boolean isPingRequestSuccessful(JSONObject jSONObject) throws JSONException {
        if (!jSONObject.has("rcode")) {
            return false;
        }
        if (jSONObject.getInt("rcode") == 1) {
            DtbSharedPreferences.getInstance().saveSisLastPing(System.currentTimeMillis());
            DtbLog.info(LOG_TAG, "ad id is registered or updated successfully.");
            return true;
        }
        if (jSONObject.getInt("rcode") != 103 && (jSONObject.getInt("rcode") != 101 || !jSONObject.has("msg") || jSONObject.getInt("msg") != 103)) {
            return false;
        }
        DtbSharedPreferences.getInstance().saveSisLastPing(System.currentTimeMillis());
        DtbLog.info("gdpr consent not granted");
        return true;
    }

    private boolean isRegistrationRequestSuccessful(JSONObject jSONObject) throws JSONException {
        if (!jSONObject.has("rcode")) {
            return false;
        }
        DtbSharedPreferences.getInstance().saveSisLastCheckIn(System.currentTimeMillis());
        if (jSONObject.getInt("rcode") == 1 && jSONObject.has("adId")) {
            String string = jSONObject.getString("adId");
            if (jSONObject.has("idChanged") && jSONObject.getBoolean("idChanged")) {
                DtbLog.info(LOG_TAG, "ad id has changed, updating..");
                this.metrics.incrementMetric(DtbMetric.SIS_COUNTER_IDENTIFIED_DEVICE_CHANGED);
            }
            DtbSharedPreferences.getInstance().saveAdId(string);
            DtbLog.info(LOG_TAG, "ad id is registered or updated successfully.");
            return true;
        }
        if (jSONObject.getInt("rcode") != 103) {
            if (jSONObject.getInt("rcode") != 101 || !jSONObject.has("msg")) {
                return false;
            }
            if (jSONObject.optInt("msg") != 103 && !"need at least one native id in parameter".equals(jSONObject.get("msg"))) {
                return false;
            }
        }
        DtbSharedPreferences.getInstance().removeAdid();
        DtbLog.debug("No ad-id returned");
        return true;
    }

    public static void lambda$verifyRegistration$0() {
        dtbDeviceRegistrationInstance.initializeAds();
    }

    private boolean parseRegisterConfigResponse(String str, long j, boolean z) throws Exception {
        JSONObject jSONObject = (JSONObject) new JSONTokener(str).nextValue();
        if (jSONObject.has("pj")) {
            DtbSharedPreferences.getInstance().savePJTemplate(jSONObject.getJSONObject("pj"));
        } else {
            DtbSharedPreferences.getInstance().removePJTemplate();
        }
        if (!jSONObject.has(DtbDebugProperties.AAX_HOSTNAME) && !jSONObject.has("sisURL") && !jSONObject.has(AAX_VIDEO_HOST_NAME_KEY)) {
            DtbLog.info(LOG_TAG, "ad configuration failed load: " + jSONObject.toString());
            throw new Exception("ad configuration failed load");
        }
        if (jSONObject.has(DtbDebugProperties.AAX_HOSTNAME)) {
            DtbSharedPreferences.getInstance().saveAaxHostname(jSONObject.getString(DtbDebugProperties.AAX_HOSTNAME));
        }
        if (jSONObject.has("sisURL")) {
            z = DtbSharedPreferences.getInstance().saveSisEndpoint(jSONObject.getString("sisURL"));
        }
        if (jSONObject.has("ttl")) {
            DtbSharedPreferences.getInstance().saveConfigTtl(DtbCommonUtils.getMilliSeconds(jSONObject.getString("ttl")));
        }
        if (jSONObject.has(AAX_VIDEO_HOST_NAME_KEY)) {
            DtbSharedPreferences.getInstance().saveAaxVideoHostname(jSONObject.getString(AAX_VIDEO_HOST_NAME_KEY));
        }
        if (jSONObject.has("bidTimeout")) {
            DtbSharedPreferences.getInstance().saveBidTimeout(Integer.valueOf(jSONObject.getInt("bidTimeout")));
        } else {
            DtbSharedPreferences.getInstance().removeBidTimeout();
        }
        DtbSharedPreferences.getInstance().saveConfigLastCheckIn(j);
        DtbLog.info(LOG_TAG, "ad configuration loaded successfully.");
        return z;
    }

    private void pingSis(String str, String str2) {
        if (System.currentTimeMillis() - DtbSharedPreferences.getInstance().getSisLastPing() < 2592000000L) {
            return;
        }
        String adId = DtbSharedPreferences.getInstance().getAdId();
        if (adId == null || adId.isEmpty()) {
            DtbLog.info("error retrieving ad id, cancelling sis ping");
            return;
        }
        try {
            if (!DtbCommonUtils.isNetworkConnected()) {
                DtbLog.debug("Network is not available");
                return;
            }
            DtbHttpClient dtbHttpClient = new DtbHttpClient(str + "/ping");
            dtbHttpClient.setUseSecure(DtbDebugProperties.getIsSecure(true));
            HashMap<String, Object> hashMap = new HashMap<>();
            hashMap.put("appId", str2);
            hashMap.put("adId", adId);
            Context context = AdRegistration.getContext();
            if (context != null) {
                SharedPreferences b = uwd.b(context);
                Object obj = b.contains("IABTCF_gdprApplies") ? b.getAll().get("IABTCF_gdprApplies") : null;
                String string = b.getString("IABTCF_TCString", null);
                if (obj != null) {
                    try {
                        if ((obj instanceof Integer) && (((Integer) obj).intValue() == 1 || ((Integer) obj).intValue() == 0)) {
                            hashMap.put("gdpr", obj);
                        } else if (((obj instanceof String) && ((String) obj).equals("1")) || ((String) obj).equals("0")) {
                            hashMap.put("gdpr", obj);
                        } else {
                            DtbLog.info("IABTCF_gdprApplies should be a 1 or 0 as per IAB guideline");
                        }
                    } catch (ClassCastException unused) {
                        DtbLog.info("IABTCF_gdprApplies should be a number as per IAB guideline");
                    }
                }
                if (string != null) {
                    hashMap.put("gdpr_consent", string);
                }
            }
            String encodedNonIABString = AdRegistration.getEncodedNonIABString();
            if (!DtbCommonUtils.isNullOrEmpty(encodedNonIABString)) {
                hashMap.put("gdpr_custom", encodedNonIABString);
            }
            dtbHttpClient.setParams(hashMap);
            dtbHttpClient.executeGET(60000);
            if (DtbCommonUtils.isNullOrEmpty(dtbHttpClient.getResponse())) {
                DtbLog.debug("No response from sis ping.");
                throw new Exception("Ping SIS Response is null");
            }
            JSONObject jSONObject = (JSONObject) new JSONTokener(dtbHttpClient.getResponse()).nextValue();
            if (isPingRequestSuccessful(jSONObject)) {
                return;
            }
            DtbLog.info(LOG_TAG, "sis ping failed failed registration: " + jSONObject.toString());
            throw new Exception("sis ping failed registration: ");
        } catch (Exception e) {
            DtbLog.error("Error pinging sis: " + e.toString());
        }
    }

    private boolean registerConfig(String str) {
        boolean z;
        long currentTimeMillis = System.currentTimeMillis();
        long longValue = currentTimeMillis - DtbSharedPreferences.getInstance().getConfigLastCheckIn().longValue();
        long configTtl = DtbSharedPreferences.getInstance().getConfigTtl();
        StringBuilder c = qb9.c(longValue, "Config last checkin duration: ", ", Expiration: ");
        c.append(configTtl);
        DtbLog.debug(c.toString());
        boolean z2 = false;
        if (longValue <= 172800000) {
            DtbLog.debug("No config refresh required");
            return false;
        }
        if (!DtbCommonUtils.isNetworkConnected()) {
            DtbLog.debug("Network is not available");
            return false;
        }
        DtbHttpClient dtbHttpClient = new DtbHttpClient(z31.h(new StringBuilder(), DtbDebugProperties.getConfigHostName("mads.amazon-adsystem.com"), "/msdk/getConfig"));
        dtbHttpClient.addHeader("Accept", "application/json");
        dtbHttpClient.setUseSecure(DtbDebugProperties.getIsSecure(true));
        dtbHttpClient.setParams(buildConfigInfoParams(str));
        try {
            DtbMetrics dtbMetrics = this.metrics;
            DtbMetric dtbMetric = DtbMetric.CONFIG_DOWNLOAD_LATENCY;
            dtbMetrics.startTimer(dtbMetric);
            dtbHttpClient.executeGET(60000);
            this.metrics.stopTimer(dtbMetric);
        } catch (Exception e) {
            DtbLog.error("Error fetching DTB config: " + e.toString());
            z = false;
        }
        if (DtbCommonUtils.isNullOrEmpty(dtbHttpClient.getResponse())) {
            throw new Exception("Config Response is null");
        }
        z = parseRegisterConfigResponse(dtbHttpClient.getResponse(), currentTimeMillis, false);
        try {
            DTBMetricsConfiguration.getInstance().loadMobileClientConfig();
            double intValue = DTBMetricsConfiguration.getClientConfigVal("sampling_rate", DTBMetricsConfiguration.ANALYTIC_PIXEL_DEFAULT_VALUE.intValue(), "analytics").intValue() / 100.0f;
            String clientConfigVal = DTBMetricsConfiguration.getClientConfigVal("url", "", "analytics");
            String clientConfigVal2 = DTBMetricsConfiguration.getClientConfigVal("api_key", "", "analytics");
            if (i0.a != null && i0.b) {
                z2 = true;
            }
            if (!z2) {
                i0.a = AdRegistration.getContext();
                i0.c = "e9026ffd475a1a3691e6b2ce637a9b92aab1073ebf53a67c5f2583be8a804ecb";
                i0.c(1);
                i0.d = "https://prod.cm.publishers.advertising.a2z.com/logrecord/putlog";
                i0.e = "";
                new HashMap();
            }
            i0.c((int) intValue);
            if (clientConfigVal == null || clientConfigVal.trim().isEmpty()) {
                clientConfigVal = "https://prod.cm.publishers.advertising.a2z.com/logrecord/putlog";
            }
            i0.d = clientConfigVal;
            if (clientConfigVal2 == null || clientConfigVal2.trim().isEmpty()) {
                clientConfigVal2 = "e9026ffd475a1a3691e6b2ce637a9b92aab1073ebf53a67c5f2583be8a804ecb";
            }
            i0.c = clientConfigVal2;
        } catch (RuntimeException e2) {
            DtbLog.warn("Error when reading client config file for APSAndroidShared library" + e2.toString());
        }
        return z;
    }

    public static void verifyRegistration() {
        if (dtbDeviceRegistrationInstance == null) {
            dtbDeviceRegistrationInstance = new DtbDeviceRegistration();
        }
        DtbThreadService.getInstance().execute(new c0());
    }
}