导航菜单

页面标题

页面副标题

Zepto v25.1.4 - MapplsService.java 源代码

正在查看: Zepto v25.1.4 应用的 MapplsService.java JAVA 源代码文件

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


package com.mappls.sdk.services.api;

import androidx.annotation.Keep;
import androidx.annotation.RestrictTo;
import com.google.gson.GsonBuilder;
import com.mappls.sdk.services.account.MapplsAccountManager;
import com.mappls.sdk.services.utils.ApiCallHelper;
import com.mappls.sdk.services.utils.MapplsUtils;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import kotlin.jvm.internal.Intrinsics;
import okhttp3.Call;
import okhttp3.CertificatePinner;
import okhttp3.Headers;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.internal.Util;
import okhttp3.internal.http.RealInterceptorChain;
import okhttp3.logging.HttpLoggingInterceptor;
import org.npci.upi.security.pinactivitycomponent.CLConstants;
import retrofit2.Call;
import retrofit2.CallAdapter;
import retrofit2.Callback;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

@Keep
public abstract class MapplsService<T, S> {
    protected static final int MAX_URL_SIZE = 8192;
    protected static OkHttpClient atlasOkHttpClient;
    protected static OkHttpClient loginAtlasOkHttpClient;
    protected static OkHttpClient loginOkHttpClient;
    protected static OkHttpClient okHttpClient;
    protected static OkHttpClient plainOkHttpClient;
    private Call<T> call;
    private Call.Factory callFactory;
    private final boolean enableDebug = false;
    HostnameVerifier hostnameVerifier = new AnonymousClass1();
    private Retrofit retrofit;
    private S service;
    private final Class<S> serviceType;

    public class AnonymousClass1 implements HostnameVerifier {
        @Override
        public final boolean verify(String str, SSLSession sSLSession) {
            if (!MapplsAccountManager.getInstance().isDisableHostnameVerifier()) {
                return true;
            }
            try {
                Certificate[] peerCertificates = sSLSession.getPeerCertificates();
                if (peerCertificates == null || peerCertificates.length == 0 || !str.equalsIgnoreCase(sSLSession.getPeerHost())) {
                    return false;
                }
                try {
                    TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
                    trustManagerFactory.init((KeyStore) null);
                    TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
                    if (trustManagers.length == 1) {
                        TrustManager trustManager = trustManagers[0];
                        if (trustManager instanceof X509TrustManager) {
                            X509TrustManager x509TrustManager = (X509TrustManager) trustManager;
                            for (Certificate certificate : peerCertificates) {
                                x509TrustManager.checkServerTrusted(new X509Certificate[]{(X509Certificate) certificate}, "RSA");
                            }
                            return true;
                        }
                    }
                    throw new IllegalStateException("Unexpected default trust managers:" + Arrays.toString(trustManagers));
                } catch (KeyStoreException e2) {
                    e = e2;
                    e.printStackTrace();
                    return false;
                } catch (NoSuchAlgorithmException e3) {
                    e = e3;
                    e.printStackTrace();
                    return false;
                } catch (CertificateException e4) {
                    e = e4;
                    e.printStackTrace();
                    return false;
                }
            } catch (SSLPeerUnverifiedException e5) {
                e5.printStackTrace();
                return false;
            }
        }
    }

    public static class OAuthInterceptor implements Interceptor {
        public OkHttpClient a;

        public static void a(Request.Builder builder, String str) {
            builder.d("Authorization", String.format("bearer %s", str));
        }

        @Override
        public final okhttp3.Response intercept(okhttp3.Interceptor.Chain r13) {
            throw new UnsupportedOperationException("Method not decompiled: com.mappls.sdk.services.api.MapplsService.OAuthInterceptor.intercept(okhttp3.Interceptor$Chain):okhttp3.Response");
        }
    }

    public static class UserAgentInterceptor implements Interceptor {
        @Override
        public final Response intercept(Interceptor.Chain chain) {
            RealInterceptorChain realInterceptorChain = (RealInterceptorChain) chain;
            Request request = realInterceptorChain.f6794e;
            Headers.Builder e2 = request.c.e();
            e2.f("User-Agent");
            String value = ApiCallHelper.getHeaderUserAgent();
            Intrinsics.checkNotNullParameter("User-Agent", CLConstants.FIELD_PAY_INFO_NAME);
            Intrinsics.checkNotNullParameter(value, "value");
            Headers.Companion.a("User-Agent");
            e2.c("User-Agent", value);
            Headers d2 = e2.d();
            Request.Builder b = request.b();
            b.e(d2);
            return realInterceptorChain.a(b.b());
        }
    }

    public MapplsService(Class<S> cls) {
        this.serviceType = cls;
    }

    public static void initProxy() {
        okHttpClient = null;
        atlasOkHttpClient = null;
        loginAtlasOkHttpClient = null;
        loginOkHttpClient = null;
    }

    public static void initTimeOut() {
        loginAtlasOkHttpClient = null;
        loginOkHttpClient = null;
    }

    public abstract String baseUrl();

    @RestrictTo
    public void cancelCall() {
        getCall().cancel();
    }

    public retrofit2.Call<T> cloneCall() {
        return getCall().clone();
    }

    @RestrictTo
    public void enqueueCall(Callback<T> callback) {
        getCall().B0(callback);
    }

    @RestrictTo
    public retrofit2.Response<T> executeCall() throws IOException {
        return getCall().s();
    }

    public synchronized OkHttpClient getAtlasOkHttpClient() {
        try {
            if (atlasOkHttpClient == null) {
                OkHttpClient.Builder builder = new OkHttpClient.Builder();
                OAuthInterceptor oAuthInterceptor = new OAuthInterceptor();
                SDKConfigInterceptor sDKConfigInterceptor = new SDKConfigInterceptor();
                builder.a(new UserAgentInterceptor());
                builder.a(sDKConfigInterceptor);
                builder.a(oAuthInterceptor);
                builder.a(new RegionInterceptor());
                if (MapplsApiConfiguration.getInstance().proxyHost != null) {
                    builder.e(new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(MapplsApiConfiguration.getInstance().proxyHost, MapplsApiConfiguration.getInstance().proxyPort.intValue())));
                }
                if (isEnableDebug()) {
                    HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
                    httpLoggingInterceptor.b();
                    builder.a(httpLoggingInterceptor);
                }
                builder.f6643f = false;
                if (MapplsApiConfiguration.getInstance().getCertificateHash() != null) {
                    CertificatePinner.Builder builder2 = new CertificatePinner.Builder();
                    Iterator<String> it = MapplsApiConfiguration.getInstance().getCertificateHash().iterator();
                    while (it.hasNext()) {
                        builder2.a("sha256/" + it.next());
                    }
                    builder.b(builder2.b());
                } else {
                    builder.d(this.hostnameVerifier);
                }
                OkHttpClient okHttpClient2 = new OkHttpClient(builder);
                atlasOkHttpClient = okHttpClient2;
                oAuthInterceptor.a = okHttpClient2;
                sDKConfigInterceptor.a = okHttpClient2;
            }
        } catch (Throwable th) {
            throw th;
        }
        return atlasOkHttpClient;
    }

    public retrofit2.Call<T> getCall() {
        if (this.call == null) {
            this.call = initializeCall();
        }
        return this.call;
    }

    public List<CallAdapter.Factory> getCallAdapterFactory() {
        return new ArrayList();
    }

    public Call.Factory getCallFactory() {
        return this.callFactory;
    }

    public GsonBuilder getGsonBuilder() {
        return new GsonBuilder();
    }

    public synchronized OkHttpClient getLoginAtlasOkHttpClient() {
        try {
            if (loginAtlasOkHttpClient == null) {
                OkHttpClient.Builder builder = new OkHttpClient.Builder();
                LoginOAuthInterceptor loginOAuthInterceptor = new LoginOAuthInterceptor();
                InitialiserInterceptor initialiserInterceptor = new InitialiserInterceptor();
                SDKConfigInterceptor sDKConfigInterceptor = new SDKConfigInterceptor();
                builder.a(new UserAgentInterceptor());
                builder.a(new AnalyticsInterceptor());
                builder.a(sDKConfigInterceptor);
                builder.a(initialiserInterceptor);
                builder.a(loginOAuthInterceptor);
                builder.a(new RegionInterceptor());
                builder.a(new AddParametersInterceptor());
                if (MapplsApiConfiguration.getInstance().proxyHost != null) {
                    builder.e(new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(MapplsApiConfiguration.getInstance().proxyHost, MapplsApiConfiguration.getInstance().proxyPort.intValue())));
                }
                if (isEnableDebug()) {
                    HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
                    httpLoggingInterceptor.b();
                    builder.a(httpLoggingInterceptor);
                }
                builder.f6643f = false;
                long j2 = MapplsApiConfiguration.getInstance().timeOut;
                TimeUnit unit = TimeUnit.SECONDS;
                Intrinsics.checkNotNullParameter(unit, "unit");
                builder.x = Util.b(unit, j2);
                builder.c(MapplsApiConfiguration.getInstance().timeOut, unit);
                builder.f(MapplsApiConfiguration.getInstance().timeOut, unit);
                builder.g(MapplsApiConfiguration.getInstance().timeOut, unit);
                if (MapplsApiConfiguration.getInstance().getCertificateHash() != null) {
                    CertificatePinner.Builder builder2 = new CertificatePinner.Builder();
                    Iterator<String> it = MapplsApiConfiguration.getInstance().getCertificateHash().iterator();
                    while (it.hasNext()) {
                        builder2.a("sha256/" + it.next());
                    }
                    builder.b(builder2.b());
                } else {
                    builder.d(this.hostnameVerifier);
                }
                OkHttpClient okHttpClient2 = new OkHttpClient(builder);
                loginAtlasOkHttpClient = okHttpClient2;
                initialiserInterceptor.setHttpClient(okHttpClient2);
                loginOAuthInterceptor.setHttpClient(loginAtlasOkHttpClient);
                sDKConfigInterceptor.a = loginAtlasOkHttpClient;
            }
        } catch (Throwable th) {
            throw th;
        }
        return loginAtlasOkHttpClient;
    }

    public synchronized OkHttpClient getLoginOkHttpClient() {
        try {
            if (loginOkHttpClient == null) {
                OkHttpClient.Builder builder = new OkHttpClient.Builder();
                InitialiserInterceptor initialiserInterceptor = new InitialiserInterceptor();
                SDKConfigInterceptor sDKConfigInterceptor = new SDKConfigInterceptor();
                builder.a(new UserAgentInterceptor());
                builder.a(new AnalyticsInterceptor());
                builder.a(sDKConfigInterceptor);
                builder.a(initialiserInterceptor);
                builder.a(new RegionInterceptor());
                builder.a(new AddParametersInterceptor());
                if (MapplsApiConfiguration.getInstance().proxyHost != null) {
                    builder.e(new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(MapplsApiConfiguration.getInstance().proxyHost, MapplsApiConfiguration.getInstance().proxyPort.intValue())));
                }
                if (isEnableDebug()) {
                    HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
                    httpLoggingInterceptor.b();
                    builder.a(httpLoggingInterceptor);
                }
                builder.f6643f = false;
                long j2 = MapplsApiConfiguration.getInstance().timeOut;
                TimeUnit unit = TimeUnit.SECONDS;
                Intrinsics.checkNotNullParameter(unit, "unit");
                builder.x = Util.b(unit, j2);
                builder.c(MapplsApiConfiguration.getInstance().timeOut, unit);
                builder.f(MapplsApiConfiguration.getInstance().timeOut, unit);
                builder.g(MapplsApiConfiguration.getInstance().timeOut, unit);
                if (MapplsApiConfiguration.getInstance().getCertificateHash() != null) {
                    CertificatePinner.Builder builder2 = new CertificatePinner.Builder();
                    Iterator<String> it = MapplsApiConfiguration.getInstance().getCertificateHash().iterator();
                    while (it.hasNext()) {
                        builder2.a("sha256/" + it.next());
                    }
                    builder.b(builder2.b());
                } else {
                    builder.d(this.hostnameVerifier);
                }
                OkHttpClient okHttpClient2 = new OkHttpClient(builder);
                loginOkHttpClient = okHttpClient2;
                initialiserInterceptor.setHttpClient(okHttpClient2);
                sDKConfigInterceptor.a = loginOkHttpClient;
            }
        } catch (Throwable th) {
            throw th;
        }
        return loginOkHttpClient;
    }

    public S getLoginService(boolean z) {
        S s = this.service;
        if (s != null) {
            return s;
        }
        Retrofit.Builder builder = new Retrofit.Builder();
        builder.a(baseUrl());
        builder.f7420d.add(new GsonConverterFactory(getGsonBuilder().a()));
        for (CallAdapter.Factory factory : getCallAdapterFactory()) {
            ArrayList arrayList = builder.f7421e;
            Objects.requireNonNull(factory, "factory == null");
            arrayList.add(factory);
        }
        if (getCallFactory() != null) {
            Call.Factory callFactory = getCallFactory();
            Objects.requireNonNull(callFactory, "factory == null");
            builder.b = callFactory;
        } else {
            OkHttpClient loginAtlasOkHttpClient2 = z ? getLoginAtlasOkHttpClient() : getLoginOkHttpClient();
            Objects.requireNonNull(loginAtlasOkHttpClient2, "client == null");
            builder.b = loginAtlasOkHttpClient2;
        }
        Retrofit b = builder.b();
        this.retrofit = b;
        S s2 = (S) b.b(this.serviceType);
        this.service = s2;
        return s2;
    }

    public synchronized OkHttpClient getOkHttpClient() {
        try {
            if (okHttpClient == null) {
                OkHttpClient.Builder builder = new OkHttpClient.Builder();
                SDKConfigInterceptor sDKConfigInterceptor = new SDKConfigInterceptor();
                builder.a(new UserAgentInterceptor());
                builder.a(new RegionInterceptor());
                builder.a(sDKConfigInterceptor);
                if (MapplsApiConfiguration.getInstance().proxyHost != null) {
                    builder.e(new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(MapplsApiConfiguration.getInstance().proxyHost, MapplsApiConfiguration.getInstance().proxyPort.intValue())));
                }
                if (isEnableDebug()) {
                    HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
                    httpLoggingInterceptor.b();
                    builder.a(httpLoggingInterceptor);
                }
                builder.f6643f = false;
                if (MapplsApiConfiguration.getInstance().getCertificateHash() != null) {
                    CertificatePinner.Builder builder2 = new CertificatePinner.Builder();
                    Iterator<String> it = MapplsApiConfiguration.getInstance().getCertificateHash().iterator();
                    while (it.hasNext()) {
                        builder2.a("sha256/" + it.next());
                    }
                    builder.b(builder2.b());
                } else {
                    builder.d(this.hostnameVerifier);
                }
                OkHttpClient okHttpClient2 = new OkHttpClient(builder);
                okHttpClient = okHttpClient2;
                sDKConfigInterceptor.a = okHttpClient2;
            }
        } catch (Throwable th) {
            throw th;
        }
        return okHttpClient;
    }

    public synchronized OkHttpClient getPlainOkHttpClient() {
        try {
            if (plainOkHttpClient == null) {
                OkHttpClient.Builder builder = new OkHttpClient.Builder();
                builder.a(new UserAgentInterceptor());
                if (MapplsApiConfiguration.getInstance().proxyHost != null) {
                    builder.e(new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(MapplsApiConfiguration.getInstance().proxyHost, MapplsApiConfiguration.getInstance().proxyPort.intValue())));
                }
                builder.d(this.hostnameVerifier);
                builder.f6643f = false;
                if (isEnableDebug()) {
                    HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
                    httpLoggingInterceptor.b();
                    builder.a(httpLoggingInterceptor);
                }
                plainOkHttpClient = new OkHttpClient(builder);
            }
        } catch (Throwable th) {
            throw th;
        }
        return plainOkHttpClient;
    }

    public S getPlainService() {
        S s = this.service;
        if (s != null) {
            return s;
        }
        Retrofit.Builder builder = new Retrofit.Builder();
        builder.a(baseUrl());
        builder.f7420d.add(new GsonConverterFactory(getGsonBuilder().a()));
        OkHttpClient plainOkHttpClient2 = getPlainOkHttpClient();
        Objects.requireNonNull(plainOkHttpClient2, "client == null");
        builder.b = plainOkHttpClient2;
        Retrofit b = builder.b();
        this.retrofit = b;
        S s2 = (S) b.b(this.serviceType);
        this.service = s2;
        return s2;
    }

    public S getService(boolean z) {
        S s = this.service;
        if (s != null) {
            return s;
        }
        Retrofit.Builder builder = new Retrofit.Builder();
        builder.a(baseUrl());
        builder.f7420d.add(new GsonConverterFactory(getGsonBuilder().a()));
        for (CallAdapter.Factory factory : getCallAdapterFactory()) {
            ArrayList arrayList = builder.f7421e;
            Objects.requireNonNull(factory, "factory == null");
            arrayList.add(factory);
        }
        if (MapplsApiConfiguration.getInstance().getCertificateHash() == null && SDKPreferenceHelper.a(MapplsUtils.getSDKContext()).a.getString("com.mappls.sdk.services.api.SDK_CONFIG_KEY", null) != null) {
            if (Long.valueOf(SDKPreferenceHelper.a(MapplsUtils.getSDKContext()).a.getLong("com.mappls.sdk.services.api.SDK_CONFIG_LAST_DOWNLOAD_KEY", 0L)).longValue() + 604800000 < System.currentTimeMillis()) {
                MapplsApiConfiguration.getInstance().setValidationData(null);
                SDKPreferenceHelper.a(MapplsUtils.getSDKContext()).b(null);
            } else {
                MapplsApiConfiguration.getInstance().setValidationData(SDKPreferenceHelper.a(MapplsUtils.getSDKContext()).a.getString("com.mappls.sdk.services.api.SDK_CONFIG_KEY", null));
                if (MapplsApiConfiguration.getInstance().getExpiry().longValue() * 1000 <= System.currentTimeMillis()) {
                    MapplsApiConfiguration.getInstance().setValidationData(null);
                    SDKPreferenceHelper.a(MapplsUtils.getSDKContext()).b(null);
                }
            }
        }
        if (getCallFactory() != null) {
            Call.Factory callFactory = getCallFactory();
            Objects.requireNonNull(callFactory, "factory == null");
            builder.b = callFactory;
        } else {
            OkHttpClient atlasOkHttpClient2 = z ? getAtlasOkHttpClient() : getOkHttpClient();
            Objects.requireNonNull(atlasOkHttpClient2, "client == null");
            builder.b = atlasOkHttpClient2;
        }
        Retrofit b = builder.b();
        this.retrofit = b;
        S s2 = (S) b.b(this.serviceType);
        this.service = s2;
        return s2;
    }

    public abstract retrofit2.Call<T> initializeCall();

    public boolean isEnableDebug() {
        return false;
    }

    @RestrictTo
    public boolean isExecuted() {
        return getCall().v0();
    }

    public void setCallFactory(Call.Factory factory) {
        this.callFactory = factory;
    }
}