正在查看: Chaupal v3.2 应用的 RestAdapter.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Chaupal v3.2 应用的 RestAdapter.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.yupptv.ottsdk.rest.network;
import android.content.Context;
import androidx.annotation.NonNull;
import com.google.gson.d;
import com.yupptv.ottsdk.managers.Preferences.PreferenceManager;
import com.yupptv.ottsdk.model.AppInitialData;
import com.yupptv.ottsdk.model.Configuration;
import com.yupptv.ottsdk.utils.OttLog;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import l3.a;
import l3.b;
import okhttp3.Cache;
import okhttp3.CacheControl;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.logging.HttpLoggingInterceptor;
import org.json.JSONObject;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class RestAdapter {
public static String TAG = "RestAdapter";
public static final long TIMEOUT_DURATION = 60;
private static boolean enableCache = false;
private static volatile RestAdapter instance;
private static Context mContext;
private static Retrofit ottGuideRetrofit;
private static Retrofit ottHeaderRetrofit;
private static Retrofit ottInstallReferrerRetrofit;
private static Retrofit ottLocalNowRetrofit;
private static Retrofit ottLocationRetrofit;
private static Retrofit ottOTPRetrofit;
private static Retrofit ottPaymentRetrofit;
private static Retrofit ottRetrofit;
private static Retrofit ottSearchRetrofit;
String mTrueClientIP = HttpUrl.FRAGMENT_ENCODE_SET;
OkHttpClient okClient;
private PreferenceManager preferenceManager;
static String OTT_BASE_URL = "https://paas.globaltakeoff.net";
private static Retrofit retrofit = new Retrofit.Builder().baseUrl(OTT_BASE_URL).addConverterFactory(GsonConverterFactory.create()).build();
private RestAdapter() {
}
public boolean checkForConfigValue(PreferenceManager preferenceManager) {
Configuration configurationData;
return (preferenceManager == null || (configurationData = preferenceManager.getConfigurationData()) == null || configurationData.getConfigs() == null || configurationData.getConfigs().getIsBoxIdRequiredInApi() == null || !configurationData.getConfigs().getIsBoxIdRequiredInApi().equalsIgnoreCase("true")) ? false : true;
}
public boolean checkUrlContainsInInitJson(AppInitialData appInitialData, HttpUrl httpUrl) {
if (appInitialData.getSearch() != null && httpUrl.toString().contains(appInitialData.getSearch())) {
return true;
}
if (appInitialData.getApi() != null && httpUrl.toString().contains(appInitialData.getApi())) {
return true;
}
if (appInitialData.getGuideURL() != null && httpUrl.toString().contains(appInitialData.getGuideURL())) {
return true;
}
if (appInitialData.getLocation() != null && httpUrl.toString().contains(appInitialData.getLocation())) {
return true;
}
if (appInitialData.getOtpURL() != null && httpUrl.toString().contains(appInitialData.getOtpURL())) {
return true;
}
if (appInitialData.getPaymentGateWayUrl() != null && httpUrl.toString().contains(appInitialData.getPaymentGateWayUrl())) {
return true;
}
if (appInitialData.getReferralURL() == null || !httpUrl.toString().contains(appInitialData.getReferralURL())) {
return appInitialData.getAllstates() != null && httpUrl.toString().contains(appInitialData.getAllstates());
}
return true;
}
public static void enableCache(boolean z) {
enableCache = z;
}
public static RestAdapter getInstance(Context context) {
mContext = context;
if (instance == null) {
synchronized (RestAdapter.class) {
if (instance == null) {
instance = new RestAdapter();
}
}
}
return instance;
}
@NonNull
private Interceptor getInterceptor(final HashMap<String, String> hashMap) {
return new Interceptor() {
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
Request build;
Request request = chain.request();
String httpUrl = request.url().toString();
Request.Builder newBuilder = request.newBuilder();
for (Map.Entry entry : hashMap.entrySet()) {
newBuilder.addHeader((String) entry.getKey(), (String) entry.getValue());
}
String str = RestAdapter.this.mTrueClientIP;
if (str != null && str.length() > 0) {
OttLog.error(RestAdapter.TAG, "sending trueclient ip " + RestAdapter.this.mTrueClientIP);
newBuilder.header("True-Client-IP", RestAdapter.this.mTrueClientIP);
}
if (httpUrl.contains("%26") || httpUrl.contains("%3D")) {
if (httpUrl.contains("%26")) {
httpUrl = httpUrl.replace("%26", "&");
}
if (httpUrl.contains("%3D")) {
httpUrl = httpUrl.replace("%3D", "=");
}
build = newBuilder.url(httpUrl).build();
} else {
build = newBuilder.build();
}
return chain.proceed(build);
}
};
}
private static Cache provideCache() {
try {
return new Cache(new File(mContext.getCacheDir(), "http-cache"), 10485760L);
} catch (Exception unused) {
return null;
}
}
public static Interceptor provideCacheInterceptor() {
return new Interceptor() {
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
return chain.proceed(chain.request()).newBuilder().header("Cache-Control", new CacheControl.Builder().maxAge(2, TimeUnit.MINUTES).build().toString()).build();
}
};
}
public void cancelAll() {
OkHttpClient okHttpClient = this.okClient;
if (okHttpClient != null) {
okHttpClient.dispatcher().cancelAll();
}
}
public Retrofit getApiClient() {
if (ottRetrofit != null) {
if (this.preferenceManager.getSessionId() != null) {
OttLog.error(TAG, "Request header session id : using previous headers");
}
return ottRetrofit;
}
PreferenceManager preferenceManager = this.preferenceManager;
String api = (preferenceManager == null || preferenceManager.getAppInitialData() == null || this.preferenceManager.getAppInitialData().getApi() == null) ? HttpUrl.FRAGMENT_ENCODE_SET : this.preferenceManager.getAppInitialData().getApi();
if (this.preferenceManager == null) {
OttLog.error(TAG, "getAPIClient - preferencemanager null");
}
if (this.preferenceManager.getAppInitialData() == null) {
OttLog.error(TAG, "getAPIClient - preferencemanager Appinitial data is null");
}
OttLog.error(TAG, "getAPIClient - baseurl : " + api);
ottRetrofit = new Retrofit.Builder().baseUrl(api).client(getHttpClient()).addConverterFactory(GsonConverterFactory.create()).build();
if (this.preferenceManager.getSessionId() != null) {
OttLog.error(TAG, "Request header session id : " + this.preferenceManager.getSessionId());
}
return ottRetrofit;
}
public <T> Object getDataFromJSONObject(JSONObject jSONObject, Class<T> cls) {
try {
return new d().h(jSONObject.toString(), cls);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public Retrofit getGuideClient() {
String api;
Retrofit retrofit3 = ottGuideRetrofit;
if (retrofit3 != null) {
return retrofit3;
}
PreferenceManager preferenceManager = this.preferenceManager;
if (preferenceManager == null || preferenceManager.getAppInitialData() == null || this.preferenceManager.getAppInitialData().getGuideURL() == null || this.preferenceManager.getAppInitialData().getGuideURL().trim().length() <= 0) {
PreferenceManager preferenceManager2 = this.preferenceManager;
api = (preferenceManager2 == null || preferenceManager2.getAppInitialData() == null || this.preferenceManager.getAppInitialData().getApi() == null) ? HttpUrl.FRAGMENT_ENCODE_SET : this.preferenceManager.getAppInitialData().getApi();
} else {
api = this.preferenceManager.getAppInitialData().getGuideURL();
}
Retrofit build = new Retrofit.Builder().baseUrl(api).client(getHttpClient()).addConverterFactory(GsonConverterFactory.create()).build();
ottGuideRetrofit = build;
return build;
}
public Retrofit getHeaderClient() {
Retrofit retrofit3 = ottHeaderRetrofit;
if (retrofit3 != null) {
return retrofit3;
}
Retrofit build = new Retrofit.Builder().baseUrl(OTT_BASE_URL).client(getHttpClient()).addConverterFactory(GsonConverterFactory.create()).build();
ottHeaderRetrofit = build;
return build;
}
public OkHttpClient getHttpClient() {
final AppInitialData appInitialData = this.preferenceManager.getAppInitialData();
Interceptor interceptor = new Interceptor() {
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
AppInitialData appInitialData2;
Request request = chain.request();
HttpUrl url = request.url();
if (url != null && url.queryParameter("box_id") == null && (appInitialData2 = appInitialData) != null && RestAdapter.this.checkUrlContainsInInitJson(appInitialData2, url)) {
RestAdapter restAdapter = RestAdapter.this;
if (restAdapter.checkForConfigValue(restAdapter.preferenceManager)) {
return chain.proceed(request.newBuilder().url(url.newBuilder().addQueryParameter("box_id", RestAdapter.this.preferenceManager.getDeviceUniqueId()).build()).build());
}
}
return chain.proceed(chain.request());
}
};
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.NONE);
HashMap<String, String> hashMap = new HashMap<>();
if (this.preferenceManager.getSessionId() != null) {
hashMap.put("session-id", this.preferenceManager.getSessionId());
OttLog.error(TAG, "Request header session id : " + this.preferenceManager.getSessionId());
}
if (this.preferenceManager.getTenantCode() != null) {
hashMap.put("tenant-code", this.preferenceManager.getTenantCode());
}
hashMap.put("box-id", this.preferenceManager.getDeviceUniqueId());
if (enableCache) {
OkHttpClient.Builder addNetworkInterceptor = new OkHttpClient.Builder().addNetworkInterceptor(getInterceptor(hashMap));
TimeUnit timeUnit = TimeUnit.SECONDS;
this.okClient = addNetworkInterceptor.connectTimeout(60L, timeUnit).readTimeout(60L, timeUnit).writeTimeout(60L, timeUnit).addNetworkInterceptor(provideCacheInterceptor()).addInterceptor(httpLoggingInterceptor).addInterceptor(interceptor).addNetworkInterceptor(new b.a(mContext).c(new a(mContext)).d(250000L).a(false).b()).cache(provideCache()).build();
} else {
OkHttpClient.Builder addNetworkInterceptor2 = new OkHttpClient.Builder().addNetworkInterceptor(getInterceptor(hashMap));
TimeUnit timeUnit2 = TimeUnit.SECONDS;
this.okClient = addNetworkInterceptor2.connectTimeout(60L, timeUnit2).readTimeout(60L, timeUnit2).writeTimeout(60L, timeUnit2).addInterceptor(httpLoggingInterceptor).addInterceptor(interceptor).addNetworkInterceptor(new b.a(mContext).c(new a(mContext)).d(250000L).a(false).b()).build();
}
return this.okClient;
}
public Retrofit getLocationClient() {
String api;
Retrofit retrofit3 = ottLocationRetrofit;
if (retrofit3 != null) {
return retrofit3;
}
PreferenceManager preferenceManager = this.preferenceManager;
if (preferenceManager == null || preferenceManager.getAppInitialData() == null || this.preferenceManager.getAppInitialData().getLocation() == null) {
PreferenceManager preferenceManager2 = this.preferenceManager;
api = (preferenceManager2 == null || preferenceManager2.getAppInitialData() == null || this.preferenceManager.getAppInitialData().getApi() == null) ? HttpUrl.FRAGMENT_ENCODE_SET : this.preferenceManager.getAppInitialData().getApi();
} else {
api = this.preferenceManager.getAppInitialData().getLocation();
}
if (this.preferenceManager == null) {
OttLog.error(TAG, "getLocationClient - preferencemanager null");
}
if (this.preferenceManager.getAppInitialData() == null) {
OttLog.error(TAG, "getLocationClient - preferencemanager Appinitial data is null");
}
OttLog.error(TAG, "getLocationClient - baseurl : " + api);
Retrofit build = new Retrofit.Builder().baseUrl(api).client(getHttpClient()).addConverterFactory(GsonConverterFactory.create()).build();
ottLocationRetrofit = build;
return build;
}
public Retrofit getOTPClient() {
String api;
if (ottOTPRetrofit != null) {
if (this.preferenceManager.getSessionId() != null) {
OttLog.error(TAG, "Request header session id : using previous headers");
}
return ottOTPRetrofit;
}
PreferenceManager preferenceManager = this.preferenceManager;
if (preferenceManager == null || preferenceManager.getAppInitialData() == null || this.preferenceManager.getAppInitialData().getOtpURL() == null || this.preferenceManager.getAppInitialData().getOtpURL().trim().length() <= 0) {
PreferenceManager preferenceManager2 = this.preferenceManager;
api = (preferenceManager2 == null || preferenceManager2.getAppInitialData() == null || this.preferenceManager.getAppInitialData().getApi() == null) ? HttpUrl.FRAGMENT_ENCODE_SET : this.preferenceManager.getAppInitialData().getApi();
} else {
api = this.preferenceManager.getAppInitialData().getOtpURL();
}
if (this.preferenceManager == null) {
OttLog.error(TAG, "getAPIClient - preferencemanager null");
}
if (this.preferenceManager.getAppInitialData() == null) {
OttLog.error(TAG, "getAPIClient - preferencemanager Appinitial data is null");
}
OttLog.error(TAG, "getAPIClient - baseurl : " + api);
ottOTPRetrofit = new Retrofit.Builder().baseUrl(api).client(getHttpClient()).addConverterFactory(GsonConverterFactory.create()).build();
if (this.preferenceManager.getSessionId() != null) {
OttLog.error(TAG, "Request header session id : " + this.preferenceManager.getSessionId());
}
return ottOTPRetrofit;
}
public Retrofit getOttClient() {
return ottRetrofit;
}
public Retrofit getPaymentClient() {
String api;
if (ottPaymentRetrofit != null) {
if (this.preferenceManager.getSessionId() != null) {
OttLog.error(TAG, "Request header session id : using previous headers");
}
return ottPaymentRetrofit;
}
PreferenceManager preferenceManager = this.preferenceManager;
if (preferenceManager == null || preferenceManager.getAppInitialData() == null || this.preferenceManager.getAppInitialData().getPaymentGateWayUrl() == null || this.preferenceManager.getAppInitialData().getPaymentGateWayUrl().trim().length() <= 0) {
PreferenceManager preferenceManager2 = this.preferenceManager;
api = (preferenceManager2 == null || preferenceManager2.getAppInitialData() == null || this.preferenceManager.getAppInitialData().getApi() == null) ? HttpUrl.FRAGMENT_ENCODE_SET : this.preferenceManager.getAppInitialData().getApi();
} else {
api = this.preferenceManager.getAppInitialData().getPaymentGateWayUrl();
}
if (this.preferenceManager == null) {
OttLog.error(TAG, "getAPIClient - preferencemanager null");
}
if (this.preferenceManager.getAppInitialData() == null) {
OttLog.error(TAG, "getAPIClient - preferencemanager Appinitial data is null");
}
OttLog.error(TAG, "getAPIClient - baseurl : " + api);
ottPaymentRetrofit = new Retrofit.Builder().baseUrl(api).client(getHttpClient()).addConverterFactory(GsonConverterFactory.create()).build();
if (this.preferenceManager.getSessionId() != null) {
OttLog.error(TAG, "Request header session id : " + this.preferenceManager.getSessionId());
}
return ottPaymentRetrofit;
}
public PreferenceManager getPreferenceManager() {
return this.preferenceManager;
}
public Retrofit getReferrerClient() {
String api;
Retrofit retrofit3 = ottInstallReferrerRetrofit;
if (retrofit3 != null) {
return retrofit3;
}
PreferenceManager preferenceManager = this.preferenceManager;
if (preferenceManager == null || preferenceManager.getAppInitialData() == null || this.preferenceManager.getAppInitialData().getReferralURL() == null) {
PreferenceManager preferenceManager2 = this.preferenceManager;
api = (preferenceManager2 == null || preferenceManager2.getAppInitialData() == null || this.preferenceManager.getAppInitialData().getApi() == null) ? HttpUrl.FRAGMENT_ENCODE_SET : this.preferenceManager.getAppInitialData().getApi();
} else {
api = this.preferenceManager.getAppInitialData().getReferralURL();
}
if (this.preferenceManager == null) {
OttLog.error(TAG, "getLocationClient - preferencemanager null");
}
if (this.preferenceManager.getAppInitialData() == null) {
OttLog.error(TAG, "getLocationClient - preferencemanager Appinitial data is null");
}
OttLog.error(TAG, "getLocationClient - baseurl : " + api);
Retrofit build = new Retrofit.Builder().baseUrl(api).client(getHttpClient()).addConverterFactory(GsonConverterFactory.create()).build();
ottInstallReferrerRetrofit = build;
return build;
}
public Retrofit getRetrofit() {
Retrofit build = new Retrofit.Builder().baseUrl(OTT_BASE_URL).client(getHttpClient()).addConverterFactory(GsonConverterFactory.create()).build();
retrofit = build;
return build;
}
public Retrofit getSearchClient() {
String api;
if (ottSearchRetrofit != null) {
if (this.preferenceManager.getSessionId() != null) {
OttLog.error(TAG, "Request header session id : " + this.preferenceManager.getSessionId());
}
return ottSearchRetrofit;
}
PreferenceManager preferenceManager = this.preferenceManager;
if (preferenceManager == null || preferenceManager.getAppInitialData() == null || this.preferenceManager.getAppInitialData().getSearch() == null) {
PreferenceManager preferenceManager2 = this.preferenceManager;
api = (preferenceManager2 == null || preferenceManager2.getAppInitialData() == null || this.preferenceManager.getAppInitialData().getApi() == null) ? HttpUrl.FRAGMENT_ENCODE_SET : this.preferenceManager.getAppInitialData().getApi();
} else {
api = this.preferenceManager.getAppInitialData().getSearch();
}
if (this.preferenceManager == null) {
OttLog.error(TAG, "getSearchClient - preferencemanager null");
}
if (this.preferenceManager.getAppInitialData() == null) {
OttLog.error(TAG, "getSearchClient - preferencemanager Appinitial data is null");
}
OttLog.error(TAG, "getSearchClient - baseurl : " + api);
Retrofit build = new Retrofit.Builder().baseUrl(api).client(getHttpClient()).addConverterFactory(GsonConverterFactory.create()).build();
ottSearchRetrofit = build;
return build;
}
public void resetClient() {
ottRetrofit = null;
ottSearchRetrofit = null;
ottLocationRetrofit = null;
ottInstallReferrerRetrofit = null;
ottOTPRetrofit = null;
ottPaymentRetrofit = null;
ottGuideRetrofit = null;
ottLocalNowRetrofit = null;
}
public void setPreferenceManager(PreferenceManager preferenceManager) {
this.preferenceManager = preferenceManager;
}
public void setTrueClientIP(String str) {
this.mTrueClientIP = str;
}
}