正在查看: Vi App v10.18.0 应用的 RestAdapter.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Vi App v10.18.0 应用的 RestAdapter.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.yupptv.ottsdk.rest.network;
import android.content.Context;
import androidx.annotation.NonNull;
import com.chuckerteam.chucker.api.ChuckerCollector;
import com.chuckerteam.chucker.api.ChuckerInterceptor;
import com.google.gson.Gson;
import com.yupptv.ottsdk.OttSDK;
import com.yupptv.ottsdk.managers.Preferences.PreferenceManager;
import com.yupptv.ottsdk.managers.Preferences.PreferenceManagerImp;
import com.yupptv.ottsdk.utils.OttLog;
import com.yupptv.ottsdk.utils.PreferencesUtils;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import okhttp3.Cache;
import okhttp3.CacheControl;
import okhttp3.CertificatePinner;
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";
private static boolean enableCache = false;
private static volatile RestAdapter instance;
private static Context mContext;
private static Retrofit ottClientKeyLoginRetrofit;
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;
private static Retrofit viAppSectionsDataRetrofit;
public String mTrueClientIP = "";
public OkHttpClient okClient;
private PreferenceManager preferenceManager;
public 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 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() {
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() {
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) ? "" : this.preferenceManager.getAppInitialData().getApi();
if (this.preferenceManager == null) {
OttLog.error(TAG, "getAPIClient - preferencemanager null");
OttLog.error(TAG, "getAPIClient - preferencemanager creating new object");
this.preferenceManager = new PreferenceManagerImp(mContext, String.valueOf(OttSDK.getInstance().getDeviceID()));
}
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(api)).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 Gson().fromJson(jSONObject.toString(), cls);
} catch (Exception unused) {
return null;
}
}
public String getDomain(String str) {
return str.startsWith("https://") ? str.substring(8) : str;
}
public Retrofit getGuideClient() {
String api;
Retrofit retrofit2 = ottGuideRetrofit;
if (retrofit2 != null) {
return retrofit2;
}
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) ? "" : this.preferenceManager.getAppInitialData().getApi();
} else {
api = this.preferenceManager.getAppInitialData().getGuideURL();
}
Retrofit build = new Retrofit.Builder().baseUrl(api).client(getHttpClient(api)).addConverterFactory(GsonConverterFactory.create()).build();
ottGuideRetrofit = build;
return build;
}
public Retrofit getHeaderClient() {
Retrofit retrofit2 = ottHeaderRetrofit;
if (retrofit2 != null) {
return retrofit2;
}
Retrofit build = new Retrofit.Builder().baseUrl(OTT_BASE_URL).client(getHttpClient(OTT_BASE_URL)).addConverterFactory(GsonConverterFactory.create()).build();
ottHeaderRetrofit = build;
return build;
}
public OkHttpClient getHttpClient(String str) {
OkHttpClient.Builder addInterceptor;
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());
hashMap.put("ucv", String.valueOf(PreferencesUtils.getInt(mContext, PreferencesUtils.SDK_PREFERENCE_NAME, "api_header_ucv", OttSDK.ucvVersion)));
if (enableCache) {
OkHttpClient.Builder addNetworkInterceptor = new OkHttpClient.Builder().addNetworkInterceptor(getInterceptor(hashMap));
TimeUnit timeUnit = TimeUnit.SECONDS;
addInterceptor = addNetworkInterceptor.connectTimeout(60L, timeUnit).readTimeout(60L, timeUnit).writeTimeout(60L, timeUnit).addNetworkInterceptor(provideCacheInterceptor()).addInterceptor(httpLoggingInterceptor).cache(provideCache());
} else {
OkHttpClient.Builder addNetworkInterceptor2 = new OkHttpClient.Builder().addNetworkInterceptor(getInterceptor(hashMap));
TimeUnit timeUnit2 = TimeUnit.SECONDS;
addInterceptor = addNetworkInterceptor2.connectTimeout(60L, timeUnit2).readTimeout(60L, timeUnit2).writeTimeout(60L, timeUnit2).addInterceptor(httpLoggingInterceptor);
}
if (OttSDK.chuckersEnabled) {
addInterceptor.addNetworkInterceptor(new ChuckerInterceptor.Builder(mContext).collector(new ChuckerCollector(mContext)).maxContentLength(250000L).alwaysReadResponseBody(false).build());
}
if (OttSDK.sslPinningEnabled && OttSDK.getInstance() != null) {
CertificatePinner.Builder builder = new CertificatePinner.Builder();
String domain = getDomain(str);
String[] strArr = new String[1];
strArr[0] = OttSDK.getInstance() != null ? OttSDK.getInstance().getDomainCertificate() : "";
addInterceptor.certificatePinner(builder.add(domain, strArr).build());
}
OkHttpClient build = addInterceptor.build();
this.okClient = build;
return build;
}
public Retrofit getLocationClient() {
String api;
Retrofit retrofit2 = ottLocationRetrofit;
if (retrofit2 != null) {
return retrofit2;
}
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) ? "" : this.preferenceManager.getAppInitialData().getApi();
} else {
api = this.preferenceManager.getAppInitialData().getLocation();
}
if (this.preferenceManager == null) {
OttLog.error(TAG, "getAPIClient - preferencemanager null");
OttLog.error(TAG, "getAPIClient - preferencemanager creating new object");
this.preferenceManager = new PreferenceManagerImp(mContext, String.valueOf(OttSDK.getInstance().getDeviceID()));
}
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(api)).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) ? "" : this.preferenceManager.getAppInitialData().getApi();
} else {
api = this.preferenceManager.getAppInitialData().getOtpURL();
}
if (this.preferenceManager == null) {
OttLog.error(TAG, "getAPIClient - preferencemanager null");
OttLog.error(TAG, "getAPIClient - preferencemanager creating new object");
this.preferenceManager = new PreferenceManagerImp(mContext, String.valueOf(OttSDK.getInstance().getDeviceID()));
}
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(api)).addConverterFactory(GsonConverterFactory.create()).build();
if (this.preferenceManager.getSessionId() != null) {
OttLog.error(TAG, "Request header session id : " + this.preferenceManager.getSessionId());
}
return ottOTPRetrofit;
}
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) ? "" : this.preferenceManager.getAppInitialData().getApi();
} else {
api = this.preferenceManager.getAppInitialData().getPaymentGateWayUrl();
}
if (this.preferenceManager == null) {
OttLog.error(TAG, "getAPIClient - preferencemanager null");
OttLog.error(TAG, "getAPIClient - preferencemanager creating new object");
this.preferenceManager = new PreferenceManagerImp(mContext, String.valueOf(OttSDK.getInstance().getDeviceID()));
}
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(api)).addConverterFactory(GsonConverterFactory.create()).build();
if (this.preferenceManager.getSessionId() != null) {
OttLog.error(TAG, "Request header session id : " + this.preferenceManager.getSessionId());
}
return ottPaymentRetrofit;
}
public Retrofit getRetrofit() {
Retrofit build = new Retrofit.Builder().baseUrl(OTT_BASE_URL).client(getHttpClient(OTT_BASE_URL)).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) ? "" : this.preferenceManager.getAppInitialData().getApi();
} else {
api = this.preferenceManager.getAppInitialData().getSearch();
}
if (this.preferenceManager == null) {
OttLog.error(TAG, "getAPIClient - preferencemanager null");
OttLog.error(TAG, "getAPIClient - preferencemanager creating new object");
this.preferenceManager = new PreferenceManagerImp(mContext, String.valueOf(OttSDK.getInstance().getDeviceID()));
}
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(api)).addConverterFactory(GsonConverterFactory.create()).build();
ottSearchRetrofit = build;
return build;
}
public void resetClient() {
ottRetrofit = null;
ottClientKeyLoginRetrofit = null;
viAppSectionsDataRetrofit = null;
ottSearchRetrofit = null;
ottLocationRetrofit = null;
ottInstallReferrerRetrofit = null;
ottOTPRetrofit = null;
ottPaymentRetrofit = null;
ottGuideRetrofit = null;
ottLocalNowRetrofit = null;
}
public void setPreferenceManager(PreferenceManager preferenceManager) {
if (preferenceManager != null) {
this.preferenceManager = preferenceManager;
}
}
public static Interceptor provideCacheInterceptor(final int i2) {
return new Interceptor() {
public Response intercept(Interceptor.Chain chain) throws IOException {
return chain.proceed(chain.request()).newBuilder().header("Cache-Control", new CacheControl.Builder().maxAge(i2, TimeUnit.MINUTES).build().toString()).build();
}
};
}
public Retrofit getApiClient(boolean z, int i2) {
if (viAppSectionsDataRetrofit == null) {
PreferenceManager preferenceManager = this.preferenceManager;
String api = (preferenceManager == null || preferenceManager.getAppInitialData() == null || this.preferenceManager.getAppInitialData().getApi() == null) ? "" : this.preferenceManager.getAppInitialData().getApi();
if (this.preferenceManager == null) {
OttLog.error(TAG, "getAPIClient - preferencemanager null");
OttLog.error(TAG, "getAPIClient - preferencemanager creating new object");
this.preferenceManager = new PreferenceManagerImp(mContext, String.valueOf(OttSDK.getInstance().getDeviceID()));
}
if (this.preferenceManager.getAppInitialData() == null) {
OttLog.error(TAG, "getAPIClient - preferencemanager Appinitial data is null");
}
OttLog.error(TAG, "getAPIClient - baseurl : " + api);
viAppSectionsDataRetrofit = new Retrofit.Builder().baseUrl(api).client(getHttpClient(api, z, i2)).addConverterFactory(GsonConverterFactory.create()).build();
if (this.preferenceManager.getSessionId() != null) {
OttLog.error(TAG, "Request header session id : " + this.preferenceManager.getSessionId());
}
return viAppSectionsDataRetrofit;
}
if (this.preferenceManager.getSessionId() != null) {
OttLog.error(TAG, "Request header session id : using previous headers");
}
return viAppSectionsDataRetrofit;
}
public OkHttpClient getHttpClient(String str, boolean z, int i2) {
OkHttpClient.Builder addInterceptor;
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());
hashMap.put("ucv", String.valueOf(PreferencesUtils.getInt(mContext, PreferencesUtils.SDK_PREFERENCE_NAME, "api_header_ucv", OttSDK.ucvVersion)));
if (z) {
OkHttpClient.Builder addNetworkInterceptor = new OkHttpClient.Builder().addNetworkInterceptor(getInterceptor(hashMap));
TimeUnit timeUnit = TimeUnit.SECONDS;
addInterceptor = addNetworkInterceptor.connectTimeout(60L, timeUnit).readTimeout(60L, timeUnit).writeTimeout(60L, timeUnit).addNetworkInterceptor(provideCacheInterceptor(i2)).addInterceptor(httpLoggingInterceptor).cache(provideCache());
} else {
OkHttpClient.Builder addNetworkInterceptor2 = new OkHttpClient.Builder().addNetworkInterceptor(getInterceptor(hashMap));
TimeUnit timeUnit2 = TimeUnit.SECONDS;
addInterceptor = addNetworkInterceptor2.connectTimeout(60L, timeUnit2).readTimeout(60L, timeUnit2).writeTimeout(60L, timeUnit2).addInterceptor(httpLoggingInterceptor);
}
if (OttSDK.chuckersEnabled) {
addInterceptor.addNetworkInterceptor(new ChuckerInterceptor.Builder(mContext).collector(new ChuckerCollector(mContext)).maxContentLength(250000L).alwaysReadResponseBody(false).build());
}
if (OttSDK.sslPinningEnabled && OttSDK.getInstance() != null) {
CertificatePinner.Builder builder = new CertificatePinner.Builder();
String domain = getDomain(str);
String[] strArr = new String[1];
strArr[0] = OttSDK.getInstance() != null ? OttSDK.getInstance().getDomainCertificate() : "";
addInterceptor.certificatePinner(builder.add(domain, strArr).build());
}
OkHttpClient build = addInterceptor.build();
this.okClient = build;
return build;
}
}