奈斯漫画.apk(点击下载) / AppConfiguration.java


package io.realm.mongodb;

import android.content.Context;
import com.alibaba.android.arouter.utils.Consts;
import io.realm.Realm;
import io.realm.internal.Util;
import io.realm.internal.log.obfuscator.ApiKeyObfuscator;
import io.realm.internal.log.obfuscator.CustomFunctionObfuscator;
import io.realm.internal.log.obfuscator.EmailPasswordObfuscator;
import io.realm.internal.log.obfuscator.RegexPatternObfuscator;
import io.realm.internal.log.obfuscator.TokenObfuscator;
import io.realm.internal.network.LoggingInterceptor;
import io.realm.log.RealmLog;
import io.realm.mongodb.Credentials;
import io.realm.mongodb.ErrorCode;
import io.realm.mongodb.log.obfuscator.HttpLogObfuscator;
import io.realm.mongodb.sync.ClientResetRequiredError;
import io.realm.mongodb.sync.SyncSession;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import org.bson.codecs.BsonValueCodecProvider;
import org.bson.codecs.DocumentCodecProvider;
import org.bson.codecs.IterableCodecProvider;
import org.bson.codecs.MapCodecProvider;
import org.bson.codecs.ValueCodecProvider;
import org.bson.codecs.configuration.CodecRegistries;
import org.bson.codecs.configuration.CodecRegistry;

public class AppConfiguration {
    public static final String DEFAULT_AUTHORIZATION_HEADER_NAME = "Authorization";
    public static final String DEFAULT_BASE_URL = "https://realm.mongodb.com";
    public static final CodecRegistry DEFAULT_BSON_CODEC_REGISTRY = CodecRegistries.fromRegistries(CodecRegistries.fromProviders(new ValueCodecProvider(), new BsonValueCodecProvider(), new DocumentCodecProvider(), new IterableCodecProvider(), new MapCodecProvider()));
    public static final long DEFAULT_REQUEST_TIMEOUT = 60;
    public static final Map<String, RegexPatternObfuscator> loginObfuscators = getLoginObfuscators();
    private final String appId;
    private final String appName;
    private final String appVersion;
    private final String authorizationHeaderName;
    private final URL baseUrl;
    private final CodecRegistry codecRegistry;
    private final Map<String, String> customHeaders;
    private final SyncSession.ClientResetHandler defaultClientResetHandler;
    private final SyncSession.ErrorHandler defaultErrorHandler;
    @Nullable
    private final byte[] encryptionKey;
    @Nullable
    private final HttpLogObfuscator httpLogObfuscator;
    private final long requestTimeoutMs;
    private final File syncRootDir;

    /* synthetic */ AppConfiguration(String str, String str2, String str3, URL url, SyncSession.ErrorHandler errorHandler, SyncSession.ClientResetHandler clientResetHandler, byte[] bArr, long j, String str4, Map map, File file, CodecRegistry codecRegistry2, HttpLogObfuscator httpLogObfuscator2, AnonymousClass1 r15) {
        this(str, str2, str3, url, errorHandler, clientResetHandler, bArr, j, str4, map, file, codecRegistry2, httpLogObfuscator2);
    }

    private AppConfiguration(String str, String str2, String str3, URL url, SyncSession.ErrorHandler errorHandler, SyncSession.ClientResetHandler clientResetHandler, @Nullable byte[] bArr, long j, String str4, Map<String, String> map, File file, CodecRegistry codecRegistry2, @Nullable HttpLogObfuscator httpLogObfuscator2) {
        byte[] bArr2;
        this.appId = str;
        this.appName = str2;
        this.appVersion = str3;
        this.baseUrl = url;
        this.defaultErrorHandler = errorHandler;
        this.defaultClientResetHandler = clientResetHandler;
        if (bArr == null) {
            bArr2 = null;
        } else {
            bArr2 = Arrays.copyOf(bArr, bArr.length);
        }
        this.encryptionKey = bArr2;
        this.requestTimeoutMs = j;
        this.authorizationHeaderName = Util.isEmptyString(str4) ? DEFAULT_AUTHORIZATION_HEADER_NAME : str4;
        this.customHeaders = Collections.unmodifiableMap(map);
        this.syncRootDir = file;
        this.codecRegistry = codecRegistry2;
        this.httpLogObfuscator = httpLogObfuscator2;
    }

    public String getAppId() {
        return this.appId;
    }

    @Nullable
    public String getAppName() {
        return this.appName;
    }

    @Nullable
    public String getAppVersion() {
        return this.appVersion;
    }

    public URL getBaseUrl() {
        return this.baseUrl;
    }

    @Nullable
    public byte[] getEncryptionKey() {
        byte[] bArr = this.encryptionKey;
        if (bArr == null) {
            return null;
        }
        return Arrays.copyOf(bArr, bArr.length);
    }

    public long getRequestTimeoutMs() {
        return this.requestTimeoutMs;
    }

    public String getAuthorizationHeaderName() {
        return this.authorizationHeaderName;
    }

    public Map<String, String> getCustomRequestHeaders() {
        return this.customHeaders;
    }

    public SyncSession.ErrorHandler getDefaultErrorHandler() {
        return this.defaultErrorHandler;
    }

    public SyncSession.ClientResetHandler getDefaultClientResetHandler() {
        return this.defaultClientResetHandler;
    }

    public File getSyncRootDirectory() {
        return this.syncRootDir;
    }

    public CodecRegistry getDefaultCodecRegistry() {
        return this.codecRegistry;
    }

    @Nullable
    public HttpLogObfuscator getHttpLogObfuscator() {
        return this.httpLogObfuscator;
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        AppConfiguration appConfiguration = (AppConfiguration) obj;
        if (this.requestTimeoutMs != appConfiguration.requestTimeoutMs || !this.appId.equals(appConfiguration.appId)) {
            return false;
        }
        String str = this.appName;
        if (str == null ? appConfiguration.appName != null : !str.equals(appConfiguration.appName)) {
            return false;
        }
        String str2 = this.appVersion;
        if (str2 == null ? appConfiguration.appVersion != null : !str2.equals(appConfiguration.appVersion)) {
            return false;
        }
        if (!this.baseUrl.toString().equals(appConfiguration.baseUrl.toString()) || !this.defaultErrorHandler.equals(appConfiguration.defaultErrorHandler) || !Arrays.equals(this.encryptionKey, appConfiguration.encryptionKey) || !this.authorizationHeaderName.equals(appConfiguration.authorizationHeaderName) || !this.customHeaders.equals(appConfiguration.customHeaders) || !this.syncRootDir.equals(appConfiguration.syncRootDir) || !this.codecRegistry.equals(appConfiguration.codecRegistry)) {
            return false;
        }
        HttpLogObfuscator httpLogObfuscator2 = this.httpLogObfuscator;
        HttpLogObfuscator httpLogObfuscator3 = appConfiguration.httpLogObfuscator;
        if (httpLogObfuscator2 != null) {
            return httpLogObfuscator2.equals(httpLogObfuscator3);
        }
        if (httpLogObfuscator3 == null) {
            return true;
        }
        return false;
    }

    public int hashCode() {
        int hashCode = this.appId.hashCode() * 31;
        String str = this.appName;
        int i = 0;
        int hashCode2 = (hashCode + (str != null ? str.hashCode() : 0)) * 31;
        String str2 = this.appVersion;
        int hashCode3 = str2 != null ? str2.hashCode() : 0;
        long j = this.requestTimeoutMs;
        int hashCode4 = (((((((((((((((((hashCode2 + hashCode3) * 31) + this.baseUrl.toString().hashCode()) * 31) + this.defaultErrorHandler.hashCode()) * 31) + Arrays.hashCode(this.encryptionKey)) * 31) + ((int) (j ^ (j >>> 32)))) * 31) + this.authorizationHeaderName.hashCode()) * 31) + this.customHeaders.hashCode()) * 31) + this.syncRootDir.hashCode()) * 31) + this.codecRegistry.hashCode()) * 31;
        HttpLogObfuscator httpLogObfuscator2 = this.httpLogObfuscator;
        if (httpLogObfuscator2 != null) {
            i = httpLogObfuscator2.hashCode();
        }
        return hashCode4 + i;
    }

    private static Map<String, RegexPatternObfuscator> getLoginObfuscators() {
        HashMap hashMap = new HashMap();
        hashMap.put(Credentials.Provider.API_KEY.getId(), ApiKeyObfuscator.obfuscator());
        hashMap.put(Credentials.Provider.APPLE.getId(), TokenObfuscator.obfuscator());
        hashMap.put(Credentials.Provider.CUSTOM_FUNCTION.getId(), CustomFunctionObfuscator.obfuscator());
        hashMap.put(Credentials.Provider.EMAIL_PASSWORD.getId(), EmailPasswordObfuscator.obfuscator());
        hashMap.put(Credentials.Provider.FACEBOOK.getId(), TokenObfuscator.obfuscator());
        hashMap.put(Credentials.Provider.GOOGLE.getId(), TokenObfuscator.obfuscator());
        hashMap.put(Credentials.Provider.JWT.getId(), TokenObfuscator.obfuscator());
        return hashMap;
    }

    /* access modifiers changed from: package-private */
    /* renamed from: io.realm.mongodb.AppConfiguration$1  reason: invalid class name */
    public static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] $SwitchMap$io$realm$mongodb$ErrorCode$Category;

        /* JADX WARNING: Can't wrap try/catch for region: R(6:0|1|2|3|4|6) */
        /* JADX WARNING: Code restructure failed: missing block: B:7:?, code lost:
            return;
         */
        /* JADX WARNING: Failed to process nested try/catch */
        /* JADX WARNING: Missing exception handler attribute for start block: B:3:0x0012 */
        static {
            int[] iArr = new int[ErrorCode.Category.values().length];
            $SwitchMap$io$realm$mongodb$ErrorCode$Category = iArr;
            iArr[ErrorCode.Category.FATAL.ordinal()] = 1;
            $SwitchMap$io$realm$mongodb$ErrorCode$Category[ErrorCode.Category.RECOVERABLE.ordinal()] = 2;
        }
    }

    public static class Builder {
        private String appId;
        private String appName;
        private String appVersion;
        private String authorizationHeaderName;
        private URL baseUrl = createUrl(AppConfiguration.DEFAULT_BASE_URL);
        private CodecRegistry codecRegistry = AppConfiguration.DEFAULT_BSON_CODEC_REGISTRY;
        private Map<String, String> customHeaders = new HashMap();
        private SyncSession.ClientResetHandler defaultClientResetHandler = new SyncSession.ClientResetHandler() {
            /* class io.realm.mongodb.AppConfiguration.Builder.AnonymousClass2 */

            @Override // io.realm.mongodb.sync.SyncSession.ClientResetHandler
            public void onClientReset(SyncSession syncSession, ClientResetRequiredError clientResetRequiredError) {
                RealmLog.error("Client Reset required for: " + syncSession.getConfiguration().getServerUrl(), new Object[0]);
            }
        };
        private SyncSession.ErrorHandler defaultErrorHandler = new SyncSession.ErrorHandler() {
            /* class io.realm.mongodb.AppConfiguration.Builder.AnonymousClass1 */

            @Override // io.realm.mongodb.sync.SyncSession.ErrorHandler
            public void onError(SyncSession syncSession, AppException appException) {
                String format = String.format(Locale.US, "Session Error[%s]: %s", syncSession.getConfiguration().getServerUrl(), appException.toString());
                int i = AnonymousClass1.$SwitchMap$io$realm$mongodb$ErrorCode$Category[appException.getErrorCode().getCategory().ordinal()];
                if (i == 1) {
                    RealmLog.error(format, new Object[0]);
                } else if (i == 2) {
                    RealmLog.info(format, new Object[0]);
                } else {
                    throw new IllegalArgumentException("Unsupported error category: " + appException.getErrorCode().getCategory());
                }
            }
        };
        private byte[] encryptionKey;
        @Nullable
        private HttpLogObfuscator httpLogObfuscator = new HttpLogObfuscator(LoggingInterceptor.LOGIN_FEATURE, AppConfiguration.loginObfuscators);
        private long requestTimeoutMs = TimeUnit.MILLISECONDS.convert(60, TimeUnit.SECONDS);
        private File syncRootDir;

        public Builder(String str) {
            Util.checkEmpty(str, "appId");
            this.appId = str;
            Context applicationContext = Realm.getApplicationContext();
            if (applicationContext != null) {
                File file = new File(applicationContext.getFilesDir(), "mongodb-realm");
                if (file.exists() || file.mkdir()) {
                    this.syncRootDir = file;
                    return;
                }
                throw new IllegalStateException("Could not create Sync root dir: " + file.getAbsolutePath());
            }
            throw new IllegalStateException("Call `Realm.init(Context)` before calling this method.");
        }

        public Builder encryptionKey(@ParametersAreNonnullByDefault byte[] bArr) {
            Util.checkNull(bArr, ApiKeyObfuscator.API_KEY_KEY);
            if (bArr.length == 64) {
                this.encryptionKey = Arrays.copyOf(bArr, bArr.length);
                return this;
            }
            throw new IllegalArgumentException(String.format(Locale.US, "The provided key must be %s bytes. Yours was: %s", 64, Integer.valueOf(bArr.length)));
        }

        public Builder baseUrl(String str) {
            Util.checkNull(str, "baseUrl");
            this.baseUrl = createUrl(str);
            return this;
        }

        public Builder appName(String str) {
            Util.checkEmpty(str, "appName");
            this.appName = str;
            return this;
        }

        public Builder appVersion(String str) {
            Util.checkEmpty(str, "appVersion");
            this.appVersion = str;
            return this;
        }

        public Builder requestTimeout(long j, TimeUnit timeUnit) {
            if (j >= 1) {
                Util.checkNull(timeUnit, "unit");
                this.requestTimeoutMs = TimeUnit.MICROSECONDS.convert(j, timeUnit);
                return this;
            }
            throw new IllegalArgumentException("A timeout above 0 is required: " + j);
        }

        public Builder authorizationHeaderName(String str) {
            Util.checkEmpty(str, "headerName");
            this.authorizationHeaderName = str;
            return this;
        }

        public Builder addCustomRequestHeader(String str, String str2) {
            Util.checkEmpty(str, "headerName");
            Util.checkNull(str2, "headerValue");
            this.customHeaders.put(str, str2);
            return this;
        }

        public Builder addCustomRequestHeaders(@Nullable Map<String, String> map) {
            if (map != null) {
                this.customHeaders.putAll(map);
            }
            return this;
        }

        public Builder defaultSyncErrorHandler(SyncSession.ErrorHandler errorHandler) {
            Util.checkNull(errorHandler, "errorHandler");
            this.defaultErrorHandler = errorHandler;
            return this;
        }

        public Builder defaultClientResetHandler(SyncSession.ClientResetHandler clientResetHandler) {
            Util.checkNull(clientResetHandler, "handler");
            this.defaultClientResetHandler = clientResetHandler;
            return this;
        }

        public Builder syncRootDirectory(File file) {
            Util.checkNull(file, "rootDir");
            if (file.isFile()) {
                throw new IllegalArgumentException("'rootDir' is a file, not a directory: " + file.getAbsolutePath() + Consts.DOT);
            } else if (!file.exists() && !file.mkdirs()) {
                throw new IllegalArgumentException("Could not create the specified directory: " + file.getAbsolutePath() + Consts.DOT);
            } else if (file.canWrite()) {
                this.syncRootDir = file;
                return this;
            } else {
                throw new IllegalArgumentException("Realm directory is not writable: " + file.getAbsolutePath() + Consts.DOT);
            }
        }

        private URL createUrl(String str) {
            try {
                return new URL(str);
            } catch (MalformedURLException unused) {
                throw new IllegalArgumentException(str);
            }
        }

        public Builder codecRegistry(CodecRegistry codecRegistry2) {
            Util.checkNull(codecRegistry2, "codecRegistry");
            this.codecRegistry = codecRegistry2;
            return this;
        }

        public Builder httpLogObfuscator(@Nullable HttpLogObfuscator httpLogObfuscator2) {
            this.httpLogObfuscator = httpLogObfuscator2;
            return this;
        }

        public AppConfiguration build() {
            return new AppConfiguration(this.appId, this.appName, this.appVersion, this.baseUrl, this.defaultErrorHandler, this.defaultClientResetHandler, this.encryptionKey, this.requestTimeoutMs, this.authorizationHeaderName, this.customHeaders, this.syncRootDir, this.codecRegistry, this.httpLogObfuscator, null);
        }
    }
}