Wolves Themes v1.0版本的 MD5 值为:cddc92b47f6b7c4a195c9625507eb51c

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


package com.vungle.warren.network;

import android.annotation.SuppressLint;
import android.app.Application;
import android.app.UiModeManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationManager;
import android.media.AudioManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.PowerManager;
import android.os.StatFs;
import android.os.storage.StorageManager;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.annotation.RestrictTo;
import android.support.v4.content.PermissionChecker;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import com.applovin.sdk.AppLovinEventTypes;
import com.google.android.gms.ads.identifier.AdvertisingIdClient;
import com.google.android.gms.common.util.DeviceProperties;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.ironsource.sdk.constants.LocationConst;
import com.moat.analytics.mobile.vng.MoatAnalytics;
import com.moat.analytics.mobile.vng.MoatOptions;
import com.mobvista.msdk.base.entity.CampaignUnit;
import com.tapjoy.TJAdUnitConstants;
import com.tapjoy.TapjoyConstants;
import com.vungle.warren.error.VungleError;
import com.vungle.warren.model.Cookie;
import com.vungle.warren.persistence.Designer;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class VungleApiClient {
    private static String HEADER_UA = null;
    public static final String MANUFACTURER_AMAZON = "Amazon";
    private static final String TAG = "VungleApiClient";
    private static VungleApiClient _instance;
    private static VungleApi api;
    private static OkHttpClient client;
    private static Cookie consentCookie;
    private static Callback<ResponseBody> defaultCallback;
    private String advertisingID;
    private JsonObject appBody;
    private WeakReference<Context> context;
    private Designer designer;
    private JsonObject deviceBody;
    private boolean enableMoat;
    private boolean limitAdTracking;
    private JsonObject location;
    private String newEndpoint;
    private String reportAdEndpoint;
    private String requestAdEndpoint;
    private String riEndpoint;
    private VungleApi timeoutApi;
    private JsonObject userBody;
    private boolean willPlayAdEnabled;
    private String willPlayAdEndpoint;
    private int willPlayAdTimeout;

    public enum WrapperFramework {
        admob,
        air,
        cocos2dx,
        corona,
        dfp,
        heyzap,
        marmalade,
        mopub,
        unity,
        fyber,
        ironsource,
        upsight,
        appodeal,
        aerserv,
        adtoapp,
        tapdaq,
        none
    }

    static {
        HEADER_UA = MANUFACTURER_AMAZON.equals(Build.MANUFACTURER) ? "VungleAmazon/6.2.5" : "VungleDroid/6.2.5";
    }

    private VungleApiClient() {
        Interceptor headerInteceptor = new Interceptor() {
            @Override
            public Response intercept(Interceptor.Chain chain) throws IOException {
                Request original = chain.request();
                Request request = original.newBuilder().header("Vungle-Version", "5.1.0").header("User-Agent", VungleApiClient.HEADER_UA).build();
                return chain.proceed(request);
            }
        };
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        client = new OkHttpClient.Builder().addInterceptor(interceptor).addInterceptor(headerInteceptor).build();
        Retrofit retrofit = new Retrofit.Builder().baseUrl(" https://ads.api.vungle.com/").addConverterFactory(GsonConverterFactory.create()).client(client).build();
        api = (VungleApi) retrofit.create(VungleApi.class);
    }

    public static void overrideApi(VungleApi override) {
        VungleApiClient vungleApiClient = _instance;
        api = override;
    }

    public static void addWrapperInfo(WrapperFramework wrapperFramework, String wrapperFrameworkVersion) {
        if (wrapperFramework != null && wrapperFramework != WrapperFramework.none) {
            HEADER_UA += ";" + wrapperFramework;
            if (wrapperFrameworkVersion != null && !wrapperFrameworkVersion.isEmpty()) {
                HEADER_UA += "/" + wrapperFrameworkVersion;
            }
        }
    }

    public static void init(final Context context, String appID, Designer designer) {
        _instance = new VungleApiClient();
        _instance.context = new WeakReference<>(context);
        _instance.designer = designer;
        JsonObject app = new JsonObject();
        app.addProperty("id", appID);
        app.addProperty(TJAdUnitConstants.String.BUNDLE, context.getPackageName());
        try {
            app.addProperty("ver", context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName);
        } catch (PackageManager.NameNotFoundException e) {
            app.addProperty("ver", "1.0");
        }
        JsonObject device = new JsonObject();
        device.addProperty("make", Build.MANUFACTURER);
        device.addProperty("model", Build.MODEL);
        device.addProperty("osv", Build.VERSION.RELEASE);
        device.addProperty("carrier", ((TelephonyManager) context.getSystemService("phone")).getNetworkOperatorName());
        device.addProperty("os", MANUFACTURER_AMAZON.equals(Build.MANUFACTURER) ? "amazon" : TapjoyConstants.TJC_DEVICE_PLATFORM_TYPE);
        DisplayMetrics dm = new DisplayMetrics();
        WindowManager windowManager = (WindowManager) context.getSystemService("window");
        windowManager.getDefaultDisplay().getMetrics(dm);
        device.addProperty("w", Integer.valueOf(dm.widthPixels));
        device.addProperty("h", Integer.valueOf(dm.heightPixels));
        JsonObject ext = new JsonObject();
        JsonObject vungle = new JsonObject();
        ext.add("vungle", vungle);
        device.add("ext", ext);
        if (Build.VERSION.SDK_INT >= 17) {
            device.addProperty("ua", WebSettings.getDefaultUserAgent(context));
            _instance.deviceBody = device;
        } else if (Looper.getMainLooper() == Looper.myLooper()) {
            device.addProperty("ua", new WebView(context.getApplicationContext()).getSettings().getUserAgentString());
            _instance.deviceBody = device;
        } else {
            _instance.deviceBody = device;
            final CountDownLatch latch = new CountDownLatch(1);
            Handler handler = new Handler(Looper.getMainLooper());
            handler.post(new Runnable() {
                @Override
                public void run() {
                    VungleApiClient._instance.deviceBody.addProperty("ua", new WebView(context.getApplicationContext()).getSettings().getUserAgentString());
                    latch.countDown();
                }
            });
            try {
                latch.await();
            } catch (InterruptedException e2) {
                e2.printStackTrace();
            }
        }
        if (context.checkCallingOrSelfPermission("android.permission.ACCESS_COARSE_LOCATION") == 0 || context.checkCallingOrSelfPermission("android.permission.ACCESS_FINE_LOCATION") == 0) {
            Location location = null;
            LocationManager locationManager = (LocationManager) context.getSystemService("location");
            List<String> providers = locationManager.getProviders(true);
            if (providers != null) {
                for (String provider : providers) {
                    Location locationFromProvider = locationManager.getLastKnownLocation(provider);
                    if (locationFromProvider != null && (location == null || locationFromProvider.getAccuracy() < location.getAccuracy())) {
                        location = locationFromProvider;
                    }
                }
                if (location != null) {
                    JsonObject locationJsonObj = new JsonObject();
                    locationJsonObj.addProperty(LocationConst.ACCURACY, String.valueOf(location.getAccuracy()));
                    locationJsonObj.addProperty(LocationConst.LATITUDE, String.valueOf(location.getLatitude()));
                    locationJsonObj.addProperty(LocationConst.LONGITUDE, String.valueOf(location.getLongitude()));
                    locationJsonObj.addProperty("speed", String.valueOf(location.getSpeed()));
                    locationJsonObj.addProperty("timestamp", Long.valueOf(location.getTime()));
                    _instance.location = locationJsonObj;
                }
            }
        } else {
            Log.d(TAG, "Location permission was not granted, location information will not be included");
        }
        new AdvertistingIDTask().execute(new Void[0]);
        _instance.appBody = app;
    }

    public static void config(@NonNull Collection<String> placements, @NonNull final Callback<JsonObject> callback) {
        try {
            JsonObject body = new JsonObject();
            body.add("device", _instance.getDeviceBody());
            body.add(TapjoyConstants.TJC_APP_PLACEMENT, _instance.appBody);
            body.add("user", _instance.getUserBody());
            JsonObject request = new JsonObject();
            JsonArray placementsArray = new JsonArray();
            for (String placement : placements) {
                placementsArray.add(placement);
            }
            request.add("placements", placementsArray);
            request.addProperty("is_auto_cached_enforced", (Boolean) true);
            body.add("request", request);
            VungleApiClient vungleApiClient = _instance;
            api.config(body).enqueue(new Callback<JsonObject>() {
                @Override
                public void onResponse(Call<JsonObject> call, retrofit2.Response<JsonObject> response) {
                    if (!response.isSuccessful()) {
                        Callback.this.onResponse(call, response);
                        return;
                    }
                    JsonObject jsonObject = response.body();
                    Log.d(VungleApiClient.TAG, "Config Response: " + jsonObject);
                    JsonObject endpoints = jsonObject.getAsJsonObject("endpoints");
                    HttpUrl newUrl = HttpUrl.parse(endpoints.get("new").getAsString());
                    HttpUrl adsUrl = HttpUrl.parse(endpoints.get(CampaignUnit.JSON_KEY_ADS).getAsString());
                    HttpUrl willPlayAdUrl = HttpUrl.parse(endpoints.get("will_play_ad").getAsString());
                    HttpUrl reportAdUrl = HttpUrl.parse(endpoints.get("report_ad").getAsString());
                    HttpUrl reportIncentivized = HttpUrl.parse(endpoints.get("ri").getAsString());
                    VungleApiClient._instance.newEndpoint = newUrl.toString();
                    VungleApiClient._instance.requestAdEndpoint = adsUrl.toString();
                    VungleApiClient._instance.willPlayAdEndpoint = willPlayAdUrl.toString();
                    VungleApiClient._instance.reportAdEndpoint = reportAdUrl.toString();
                    VungleApiClient._instance.riEndpoint = reportIncentivized.toString();
                    JsonObject willPlayAd = jsonObject.getAsJsonObject("will_play_ad");
                    VungleApiClient._instance.willPlayAdTimeout = willPlayAd.get("request_timeout").getAsInt();
                    VungleApiClient._instance.willPlayAdEnabled = willPlayAd.get(TJAdUnitConstants.String.ENABLED).getAsBoolean();
                    JsonObject moatViewability = jsonObject.getAsJsonObject("viewability");
                    VungleApiClient._instance.enableMoat = moatViewability.get("moat").getAsBoolean();
                    Callback.this.onResponse(call, response);
                    if (VungleApiClient._instance.willPlayAdEnabled) {
                        Log.v(VungleApiClient.TAG, "willPlayAd is enabled, generating a timeout client.");
                        VungleApiClient unused = VungleApiClient._instance;
                        OkHttpClient timeoutClient = VungleApiClient.client.newBuilder().readTimeout(VungleApiClient._instance.willPlayAdTimeout, TimeUnit.MILLISECONDS).build();
                        Retrofit timeoutRetro = new Retrofit.Builder().client(timeoutClient).addConverterFactory(GsonConverterFactory.create()).baseUrl("https://api.vungle.com/").build();
                        VungleApiClient._instance.timeoutApi = (VungleApi) timeoutRetro.create(VungleApi.class);
                    }
                    if (VungleApiClient.getMoatEnabled()) {
                        MoatOptions options = new MoatOptions();
                        options.disableAdIdCollection = true;
                        options.disableLocationServices = true;
                        options.loggingEnabled = true;
                        MoatAnalytics.getInstance().start(options, (Application) ((Context) VungleApiClient._instance.context.get()).getApplicationContext());
                    }
                }

                @Override
                public void onFailure(Call<JsonObject> call, Throwable throwable) {
                    Log.e(VungleApiClient.TAG, "Failed to configure.", throwable);
                    Callback.this.onFailure(call, throwable);
                }
            });
        } catch (IllegalStateException notInitialized) {
            callback.onFailure(null, notInitialized);
        }
    }

    public static Call<JsonObject> reportNew() throws IllegalStateException {
        if (_instance.newEndpoint == null) {
            throw new IllegalStateException("API Client not configured yet! Must call /config first.");
        }
        HashMap<String, String> query = new HashMap<>(2);
        query.put("app_id", _instance.appBody.get("id").getAsString());
        query.put("ifa", _instance.advertisingID);
        VungleApiClient vungleApiClient = _instance;
        return api.reportNew(_instance.newEndpoint, query);
    }

    public static Call<JsonObject> requestAd(String placement) throws IllegalStateException {
        if (_instance.requestAdEndpoint == null) {
            throw new IllegalStateException("API Client not configured yet! Must call /config first.");
        }
        JsonObject body = new JsonObject();
        body.add("device", _instance.getDeviceBody());
        body.add(TapjoyConstants.TJC_APP_PLACEMENT, _instance.appBody);
        body.add("user", _instance.getUserBody());
        JsonObject request = new JsonObject();
        JsonArray placementsArray = new JsonArray();
        placementsArray.add(placement);
        request.add("placements", placementsArray);
        body.add("request", request);
        VungleApiClient vungleApiClient = _instance;
        return api.ads(_instance.requestAdEndpoint, body);
    }

    public static Callback<ResponseBody> defaultCallback() {
        if (defaultCallback == null) {
            defaultCallback = new Callback<ResponseBody>() {
                @Override
                public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) {
                }

                @Override
                public void onFailure(Call<ResponseBody> call, Throwable throwable) {
                    Log.e("Vungle", "Failed to call URL " + call.request().url());
                }
            };
        }
        return defaultCallback;
    }

    public static Call<JsonObject> willPlayAd(String placementID, boolean autoCached, String adToken) throws IllegalStateException, VungleError {
        if (_instance.willPlayAdEndpoint == null) {
            throw new IllegalStateException("API Client not configured yet! Must call /config first.");
        }
        if (!_instance.willPlayAdEnabled) {
            throw new VungleError(6);
        }
        JsonObject body = new JsonObject();
        body.add("device", _instance.getDeviceBody());
        body.add(TapjoyConstants.TJC_APP_PLACEMENT, _instance.appBody);
        body.add("user", _instance.getUserBody());
        JsonObject request = new JsonObject();
        JsonObject placement = new JsonObject();
        placement.addProperty("reference_id", placementID);
        placement.addProperty("is_auto_cached", Boolean.valueOf(autoCached));
        request.add("placement", placement);
        request.addProperty("ad_token", adToken);
        body.add("request", request);
        return _instance.timeoutApi.willPlayAd(_instance.willPlayAdEndpoint, body);
    }

    public static Call<JsonObject> reportAd(JsonObject request) {
        if (_instance.reportAdEndpoint == null) {
            throw new IllegalStateException("API Client not configured yet! Must call /config first.");
        }
        JsonObject body = new JsonObject();
        body.add("device", _instance.getDeviceBody());
        body.add(TapjoyConstants.TJC_APP_PLACEMENT, _instance.appBody);
        body.add("request", request);
        body.add("user", _instance.getUserBody());
        VungleApiClient vungleApiClient = _instance;
        return api.reportAd(_instance.reportAdEndpoint, body);
    }

    public static Call<JsonObject> ri(JsonObject request) {
        if (_instance.riEndpoint == null) {
            throw new IllegalStateException("API Client not configured yet! Must call /config first.");
        }
        JsonObject body = new JsonObject();
        body.add("device", _instance.getDeviceBody());
        body.add(TapjoyConstants.TJC_APP_PLACEMENT, _instance.appBody);
        body.add("request", request);
        VungleApiClient vungleApiClient = _instance;
        return api.ri(_instance.riEndpoint, body);
    }

    public static Call<ResponseBody> pingTPAT(String url) {
        VungleApiClient vungleApiClient = _instance;
        return api.pingTPAT(url);
    }

    @SuppressLint({"HardwareIds"})
    private JsonObject getDeviceBody() throws IllegalStateException {
        String batteryState;
        boolean isTV;
        String connectionType;
        String dataSaverStatus;
        if (this.context.get() == null) {
            throw new IllegalStateException("Context is null, SDK not initialized");
        }
        JsonObject android2 = new JsonObject();
        if (this.advertisingID != null) {
            android2.addProperty(MANUFACTURER_AMAZON.equals(Build.MANUFACTURER) ? "amazon_advertising_id" : "gaid", this.advertisingID);
            this.deviceBody.addProperty("ifa", this.advertisingID);
            this.deviceBody.addProperty("lmt", Integer.valueOf(this.limitAdTracking ? 1 : 0));
        } else {
            String androidID = Settings.Secure.getString(this.context.get().getContentResolver(), TapjoyConstants.TJC_ANDROID_ID);
            this.deviceBody.addProperty("ifa", androidID);
            this.deviceBody.addProperty("lmt", (Number) 0);
        }
        new AdvertistingIDTask().execute(new Void[0]);
        Intent batteryStatus = this.context.get().registerReceiver(null, new IntentFilter("android.intent.action.BATTERY_CHANGED"));
        int level = batteryStatus.getIntExtra(AppLovinEventTypes.USER_COMPLETED_LEVEL, -1);
        int scale = batteryStatus.getIntExtra("scale", -1);
        if (level > 0 && scale > 0) {
            android2.addProperty("battery_level", Float.valueOf(level / scale));
        }
        int status = batteryStatus.getIntExtra("status", -1);
        if (status == -1) {
            batteryState = "UNKNOWN";
        } else if (status == 2 || status == 5) {
            switch (batteryStatus.getIntExtra("plugged", -1)) {
                case 1:
                    batteryState = "BATTERY_PLUGGED_AC";
                    break;
                case 2:
                    batteryState = "BATTERY_PLUGGED_USB";
                    break;
                case 3:
                default:
                    batteryState = "BATTERY_PLUGGED_OTHERS";
                    break;
                case 4:
                    batteryState = "BATTERY_PLUGGED_WIRELESS";
                    break;
            }
        } else {
            batteryState = "NOT_CHARGING";
        }
        android2.addProperty("battery_state", batteryState);
        if (Build.VERSION.SDK_INT >= 21) {
            PowerManager powerManager = (PowerManager) this.context.get().getSystemService("power");
            android2.addProperty("battery_saver_enabled", Integer.valueOf(powerManager.isPowerSaveMode() ? 1 : 0));
        }
        if (PermissionChecker.checkCallingOrSelfPermission(_instance.context.get(), "android.permission.ACCESS_NETWORK_STATE") == 0) {
            ConnectivityManager cm = (ConnectivityManager) this.context.get().getSystemService("connectivity");
            NetworkInfo info = cm.getActiveNetworkInfo();
            if (info == null) {
                connectionType = "NONE";
            } else {
                switch (info.getType()) {
                    case 0:
                        connectionType = "MOBILE";
                        break;
                    case 1:
                    case 6:
                        connectionType = "WIFI";
                        break;
                    case 2:
                    case 3:
                    case 4:
                    case 5:
                    case 8:
                    default:
                        connectionType = "UNKNOWN";
                        break;
                    case 7:
                        connectionType = "BLUETOOTH";
                        break;
                    case 9:
                        connectionType = "ETHERNET";
                        break;
                }
            }
            android2.addProperty(TapjoyConstants.TJC_CONNECTION_TYPE, connectionType);
            android2.addProperty("connection_type_detail", "WIFI");
            if (Build.VERSION.SDK_INT >= 24) {
                if (cm.isActiveNetworkMetered()) {
                    switch (cm.getRestrictBackgroundStatus()) {
                        case 1:
                            dataSaverStatus = "DISABLED";
                            break;
                        case 2:
                            dataSaverStatus = "WHITELISTED";
                            break;
                        case 3:
                            dataSaverStatus = "ENABLED";
                            break;
                        default:
                            dataSaverStatus = "UNKNOWN";
                            break;
                    }
                    android2.addProperty("data_saver_status", dataSaverStatus);
                    android2.addProperty("network_metered", (Number) 1);
                } else {
                    android2.addProperty("data_saver_status", "NOT_APPLICABLE");
                    android2.addProperty("network_metered", (Number) 0);
                }
            }
        }
        android2.addProperty("locale", Locale.getDefault().toString());
        android2.addProperty("language", Locale.getDefault().getLanguage());
        android2.addProperty("time_zone", TimeZone.getDefault().getID());
        if (this.context.get() != null) {
            AudioManager audio = (AudioManager) this.context.get().getSystemService("audio");
            if (audio != null) {
                int max = audio.getStreamMaxVolume(3);
                int current = audio.getStreamVolume(3);
                float vol = current / max;
                android2.addProperty("volume_level", Float.valueOf(vol));
                android2.addProperty("sound_enabled", Integer.valueOf(current > 0 ? 1 : 0));
            }
            StatFs stats = new StatFs(this.designer.getCacheDirectory().getPath());
            long bytesAvailable = -1;
            if (Build.VERSION.SDK_INT >= 26) {
                StorageManager storageManager = (StorageManager) this.context.get().getSystemService(StorageManager.class);
                if (storageManager != null) {
                    try {
                        bytesAvailable = storageManager.getCacheQuotaBytes(storageManager.getUuidForPath(this.designer.getCacheDirectory()));
                    } catch (IOException e) {
                        Log.e(TAG, "Unable to check available bytes");
                    }
                }
            } else {
                bytesAvailable = Build.VERSION.SDK_INT >= 18 ? stats.getBlockSizeLong() * stats.getAvailableBlocksLong() : stats.getBlockSize() * stats.getAvailableBlocks();
            }
            android2.addProperty("storage_bytes_available", Long.valueOf(bytesAvailable));
            if (MANUFACTURER_AMAZON.equals(Build.MANUFACTURER)) {
                isTV = this.context.get().getApplicationContext().getPackageManager().hasSystemFeature("amazon.hardware.fire_tv");
            } else if (Build.VERSION.SDK_INT >= 23) {
                UiModeManager uiModeManager = (UiModeManager) this.context.get().getSystemService("uimode");
                isTV = uiModeManager.getCurrentModeType() == 4;
            } else {
                isTV = this.context.get().getApplicationContext().getPackageManager().hasSystemFeature(DeviceProperties.FEATURE_TV_1) || !this.context.get().getApplicationContext().getPackageManager().hasSystemFeature("android.hardware.touchscreen");
            }
            android2.addProperty("is_tv", Boolean.valueOf(isTV));
            android2.addProperty("os_api_level", Integer.valueOf(Build.VERSION.SDK_INT));
            boolean canInstallNonMarket = false;
            try {
                if (Build.VERSION.SDK_INT >= 26) {
                    if (this.context.get().checkCallingOrSelfPermission("android.permission.REQUEST_INSTALL_PACKAGES") == 0) {
                        canInstallNonMarket = this.context.get().getApplicationContext().getPackageManager().canRequestPackageInstalls();
                    }
                } else {
                    canInstallNonMarket = Settings.Secure.getInt(this.context.get().getContentResolver(), "install_non_market_apps") == 1;
                }
            } catch (Settings.SettingNotFoundException e2) {
                Log.e(TAG, "isInstallNonMarketAppsEnabled Settings not found", e2);
            }
            android2.addProperty("is_sideload_enabled", Boolean.valueOf(canInstallNonMarket));
        } else {
            android2.addProperty("volume_level", (Number) 0);
            android2.addProperty("sound_enabled", (Number) 0);
        }
        boolean isSDPresent = Environment.getExternalStorageState().equals("mounted");
        android2.addProperty("sd_card_available", Integer.valueOf(isSDPresent ? 1 : 0));
        android2.addProperty("os_name", Build.FINGERPRINT);
        android2.addProperty("vduid", "");
        if (_instance.location != null) {
            android2.add("location", _instance.location);
        }
        this.deviceBody.getAsJsonObject("ext").getAsJsonObject("vungle").add(MANUFACTURER_AMAZON.equals(Build.MANUFACTURER) ? "amazon" : TapjoyConstants.TJC_DEVICE_PLATFORM_TYPE, android2);
        return this.deviceBody;
    }

    @RestrictTo({RestrictTo.Scope.LIBRARY})
    public static void updateConsentCookie(Cookie cookie) {
        consentCookie = cookie;
    }

    private JsonObject getUserBody() {
        String status;
        String source;
        long timestamp;
        if (this.userBody == null) {
            this.userBody = new JsonObject();
        }
        if (consentCookie != null) {
            status = consentCookie.getString("consent_status");
            source = consentCookie.getString("consent_source");
            timestamp = consentCookie.getLong("timestamp").longValue();
        } else {
            status = "unknown";
            source = "no_interaction";
            timestamp = 0;
        }
        JsonObject gdpr = new JsonObject();
        gdpr.addProperty("consent_status", status);
        gdpr.addProperty("consent_source", source);
        gdpr.addProperty("consent_timestamp", Long.valueOf(timestamp));
        this.userBody.add("gdpr", gdpr);
        return this.userBody;
    }

    public static boolean getMoatEnabled() {
        return _instance.enableMoat && Build.VERSION.SDK_INT >= 16;
    }

    public static class AdvertistingIDTask extends AsyncTask<Void, Void, String> {
        private AdvertistingIDTask() {
        }

        @Override
        public String doInBackground(Void... voids) {
            String advertId = null;
            try {
            } catch (Exception e) {
                Log.e(VungleApiClient.TAG, "Cannot get Advertising ID");
            }
            if (VungleApiClient.MANUFACTURER_AMAZON.equals(Build.MANUFACTURER)) {
                try {
                    ContentResolver cr = ((Context) VungleApiClient._instance.context.get()).getContentResolver();
                    VungleApiClient._instance.limitAdTracking = Settings.Secure.getInt(cr, "limit_ad_tracking") == 1;
                    advertId = Settings.Secure.getString(cr, TapjoyConstants.TJC_ADVERTISING_ID);
                    VungleApiClient._instance.advertisingID = advertId;
                } catch (Settings.SettingNotFoundException ex) {
                    Log.w(VungleApiClient.TAG, "Error getting Amazon advertising info", ex);
                }
                return advertId;
            }
            try {
                AdvertisingIdClient.Info idInfo = AdvertisingIdClient.getAdvertisingIdInfo((Context) VungleApiClient._instance.context.get());
                if (idInfo != null) {
                    advertId = idInfo.getId();
                    VungleApiClient._instance.limitAdTracking = idInfo.isLimitAdTrackingEnabled();
                    VungleApiClient._instance.advertisingID = advertId;
                    VungleApiClient._instance.deviceBody.addProperty("ifa", advertId);
                }
            } catch (NoClassDefFoundError ex2) {
                Log.e(VungleApiClient.TAG, "Play services Not available: " + ex2.getLocalizedMessage());
                advertId = Settings.Secure.getString(((Context) VungleApiClient._instance.context.get()).getContentResolver(), TapjoyConstants.TJC_ADVERTISING_ID);
            }
            return advertId;
            Log.e(VungleApiClient.TAG, "Cannot get Advertising ID");
            return advertId;
        }
    }
}