导航菜单

页面标题

页面副标题

Housing v14.7.8 - QBSettings.java 源代码

正在查看: Housing v14.7.8 应用的 QBSettings.java JAVA 源代码文件

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


package com.quickblox.auth.session;

import android.content.Context;
import android.text.TextUtils;
import com.quickblox.BuildConfig;
import com.quickblox.core.LogLevel;
import com.quickblox.core.QBPreferenceSettingsSaver;
import com.quickblox.core.QBSettingsSaver;
import com.quickblox.core.ServiceZone;
import com.quickblox.core.StoringMechanism;
import com.quickblox.core.SubscribePushStrategy;
import com.quickblox.core.account.model.QBAccountSettings;
import com.quickblox.core.helper.Decorators;
import com.quickblox.core.helper.Lo;
import com.quickblox.core.helper.Utils;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public final class QBSettings {
    private static final String PREFIX_CHAT_RESOURCE = "android";
    private static String initClassName = "com.quickblox.messages.QBPushNotifications";
    static QBSettings qbSettings;
    private String accountKey;
    private String applicationId;
    private String authorizationKey;
    private String authorizationSecret;
    private Context context;
    private QBSettingsStorage storage;
    private AutoUpdateMode updateMode;
    private String versionName = BuildConfig.VERSION_NAME;
    private SubscribePushStrategy subscribePushStrategy = SubscribePushStrategy.ALWAYS;
    private boolean enablePushNotification = true;
    private LogLevel logLevel = LogLevel.DEBUG;
    private boolean autoCreateSession = true;
    private Map<ServiceZone, String> apiEndpointsMap = new HashMap();
    private Map<ServiceZone, String> chatEndpointsMap = new HashMap();
    private ServiceZone zone = ServiceZone.AUTOMATIC;
    private String contentBucketName = "qbprod";
    private String restApiVersion = "0.1.1";
    private String chatDefaultResource = "";
    private StoringMechanism storingMechanism = StoringMechanism.SECURED;

    public static final class AutoUpdateMode {
        protected Date lastUpdateTime;
        private QBSettingsSaver settingsSaver;
        protected long updateTimePeriod;

        private AutoUpdateMode() {
            this.updateTimePeriod = 0L;
            this.lastUpdateTime = new Date(0L);
            this.updateTimePeriod = TimeUnit.HOURS.toMillis(1L);
        }

        public boolean isUpdatePeriodExpired() {
            return new Date(this.lastUpdateTime.getTime() + this.updateTimePeriod).before(new Date());
        }

        public void restoreSettings(QBSettings qBSettings) {
            QBAccountSettings qBAccountSettings = new QBAccountSettings();
            setLastUpdateTime(this.settingsSaver.restore(qBAccountSettings));
            String apiEndpoint = qBAccountSettings.getApiEndpoint();
            ServiceZone serviceZone = ServiceZone.AUTOMATIC;
            qBSettings.setApiEndpoint(apiEndpoint, serviceZone);
            qBSettings.setChatEndpoint(qBAccountSettings.getChatEndpoint(), serviceZone);
            Lo.g("Restored custom endpoints. ApiEndpoint: " + qBAccountSettings.getApiEndpoint() + ", ChatEndpoint: " + qBAccountSettings.getChatEndpoint() + ". lastUpdateTime: " + this.lastUpdateTime);
        }

        public void setLastUpdateTime(Date date) {
            this.lastUpdateTime = date;
        }

        public void updateSettings(QBAccountSettings qBAccountSettings, QBSettings qBSettings) {
            setLastUpdateTime(new Date());
            qBSettings.setEndpoints(qBAccountSettings);
            this.settingsSaver.save(qBAccountSettings, this.lastUpdateTime);
        }

        public AutoUpdateMode(Context context, String str) {
            this();
            this.settingsSaver = new QBPreferenceSettingsSaver(context.getApplicationContext(), a.l("QBSettings-", str));
        }
    }

    private QBSettings() {
    }

    public static synchronized QBSettings getInstance() {
        QBSettings qBSettings;
        synchronized (QBSettings.class) {
            try {
                if (qbSettings == null) {
                    qbSettings = new QBSettings();
                    QBClassInitializer.initClass(initClassName);
                }
                qBSettings = qbSettings;
            } catch (Throwable th) {
                throw th;
            }
        }
        return qBSettings;
    }

    private void invalidateEndpointsRetrievalTimer() {
        setUpdateMode(null);
    }

    private void restoreSettings() {
        this.storage.restoreSettings(this);
    }

    public void setApiEndpoint(String str, ServiceZone serviceZone) {
        this.apiEndpointsMap.put(serviceZone, str);
    }

    public void setChatEndpoint(String str, ServiceZone serviceZone) {
        this.chatEndpointsMap.put(serviceZone, str);
    }

    public QBSettings setEndpoints(QBAccountSettings qBAccountSettings) {
        String apiEndpoint = qBAccountSettings.getApiEndpoint();
        ServiceZone serviceZone = ServiceZone.AUTOMATIC;
        setApiEndpoint(apiEndpoint, serviceZone);
        setChatEndpoint(qBAccountSettings.getChatEndpoint(), serviceZone);
        setContentBucketName(qBAccountSettings.getBucketName());
        return this;
    }

    private void setRestoredEnableNotification(boolean z) {
        this.enablePushNotification = z;
    }

    private void setRestoredSubscribePushStrategy(String str) {
        this.subscribePushStrategy = TextUtils.isEmpty(str) ? SubscribePushStrategy.ALWAYS : SubscribePushStrategy.valueOf(str);
    }

    private void setUpdateMode(AutoUpdateMode autoUpdateMode) {
        this.updateMode = autoUpdateMode;
        if (autoUpdateMode != null) {
            autoUpdateMode.restoreSettings(this);
        }
    }

    private void setupEndpointsRetrievalTimer(Context context) {
        setUpdateMode(new AutoUpdateMode(context, context.getPackageName()));
    }

    private void updateSettings() {
        this.storage.updateSettings(this);
    }

    public boolean availableCredentials() {
        return (!TextUtils.isEmpty(this.applicationId) && !TextUtils.isEmpty(this.authorizationKey) && !TextUtils.isEmpty(this.authorizationSecret)) && (this.zone != ServiceZone.AUTOMATIC ? TextUtils.isEmpty(getInstance().getApiEndpoint()) ^ true : true);
    }

    public void checkInit() {
        Decorators.requireNonNullInRuntime(this.applicationId, "applicationId is null. You must call QBSettings.getInstance().init(Context, String, String, String) before using the QuickBlox library.");
        Decorators.requireNonNullInRuntime(this.authorizationKey, "authorizationKey is null. You must call QBSettings.getInstance().init(Context, String, String, String) before using the QuickBlox library.");
        Decorators.requireNonNullInRuntime(this.authorizationSecret, "authorizationSecret is null. You must call QBSettings.getInstance().init(Context, String, String, String) before using the QuickBlox library.");
    }

    @Deprecated
    public QBSettings fastConfigInit(String str, String str2, String str3) {
        Decorators.requireNonNull(str, "applicationId must not be null");
        Decorators.requireNonNull(str2, "authorizationKey must not be null");
        Decorators.requireNonNull(str3, "authorizationSecret must not be null");
        this.context = this.context;
        this.applicationId = str;
        this.authorizationKey = str2;
        this.authorizationSecret = str3;
        return this;
    }

    public String getAccountKey() {
        return this.accountKey;
    }

    public String getApiEndpoint() {
        String str = this.apiEndpointsMap.get(this.zone);
        if (!TextUtils.isEmpty(str)) {
            return str;
        }
        Lo.g("There is no information about api endpoint, use the default one.");
        return "https://api.quickblox.com";
    }

    public String getApiVersion() {
        return this.restApiVersion;
    }

    public String getApplicationId() {
        return this.applicationId;
    }

    public String getAuthorizationKey() {
        return this.authorizationKey;
    }

    public String getAuthorizationSecret() {
        return this.authorizationSecret;
    }

    @Deprecated
    public String getChatDefaultResource() {
        return this.chatDefaultResource;
    }

    public String getChatEndpoint() {
        String str = this.chatEndpointsMap.get(this.zone);
        if (!TextUtils.isEmpty(str)) {
            return str;
        }
        Lo.g("There is no information about chat server endpoint, use the default one.");
        return "chat.quickblox.com";
    }

    @Deprecated
    public String getChatServerDomain() {
        return getChatEndpoint();
    }

    @Deprecated
    public String getContentBucketName() {
        return this.contentBucketName;
    }

    public Context getContext() {
        return this.context;
    }

    public LogLevel getLogLevel() {
        return this.logLevel;
    }

    @Deprecated
    public String getServerApiDomain() {
        return getApiEndpoint();
    }

    public StoringMechanism getStoringMehanism() {
        return this.storingMechanism;
    }

    public SubscribePushStrategy getSubscribePushStrategy() {
        return this.subscribePushStrategy;
    }

    public AutoUpdateMode getUpdateMode() {
        return this.updateMode;
    }

    public String getVersionName() {
        return this.versionName;
    }

    public ServiceZone getZone() {
        return this.zone;
    }

    public QBSettings init(Context context, String str) {
        this.context = context.getApplicationContext();
        this.storage = new QBPreferenceSettingsStorage(context);
        this.applicationId = str;
        setupEndpointsRetrievalTimer(context.getApplicationContext());
        String generateDeviceId = Utils.generateDeviceId();
        StringBuilder sb = new StringBuilder("android");
        sb.append(!TextUtils.isEmpty(generateDeviceId) ? a.l("_", generateDeviceId) : "");
        this.chatDefaultResource = sb.toString();
        QBSessionManager.getInstance().init(context);
        restoreSettings();
        return this;
    }

    public boolean isAutoCreateSession() {
        return this.autoCreateSession;
    }

    public boolean isEnablePushNotification() {
        return this.enablePushNotification;
    }

    public QBSettings setAccountKey(String str) {
        this.accountKey = str;
        return this;
    }

    public QBSettings setApiVersion(String str) {
        this.restApiVersion = str;
        return this;
    }

    @Deprecated
    public QBSettings setApplicationId(String str) {
        this.applicationId = str;
        return this;
    }

    @Deprecated
    public QBSettings setAuthorizationKey(String str) {
        this.authorizationKey = str;
        return this;
    }

    @Deprecated
    public QBSettings setAuthorizationSecret(String str) {
        this.authorizationSecret = str;
        return this;
    }

    public void setAutoCreateSession(boolean z) {
        this.autoCreateSession = z;
    }

    @Deprecated
    public QBSettings setChatServerDomain(String str) {
        ServiceZone serviceZone = ServiceZone.PRODUCTION;
        setChatEndpoint(str, serviceZone);
        setZone(serviceZone);
        return this;
    }

    @Deprecated
    public QBSettings setContentBucketName(String str) {
        this.contentBucketName = str;
        return this;
    }

    public void setEnablePushNotification(boolean z) {
        this.enablePushNotification = z;
        updateSettings();
    }

    public QBSettings setLogLevel(LogLevel logLevel) {
        this.logLevel = logLevel;
        return this;
    }

    @Deprecated
    public QBSettings setServerApiDomain(String str) {
        if (!str.contains("http")) {
            str = "https://".concat(str);
        }
        ServiceZone serviceZone = ServiceZone.PRODUCTION;
        setApiEndpoint(str, serviceZone);
        setZone(serviceZone);
        return this;
    }

    public void setStoringMehanism(StoringMechanism storingMechanism) {
        this.storingMechanism = storingMechanism;
    }

    public void setSubscribePushStrategy(SubscribePushStrategy subscribePushStrategy) {
        if (subscribePushStrategy == null) {
            throw new IllegalArgumentException("SubscribePushStrategy should not be null.");
        }
        this.subscribePushStrategy = subscribePushStrategy;
        updateSettings();
    }

    public QBSettings setZone(ServiceZone serviceZone) {
        this.zone = serviceZone;
        if (serviceZone != ServiceZone.AUTOMATIC) {
            invalidateEndpointsRetrievalTimer();
        }
        return this;
    }

    public String toString() {
        StringBuilder sb = new StringBuilder("QBSettings{applicationId=");
        sb.append(this.applicationId);
        sb.append(", authorizationKey='");
        sb.append(this.authorizationKey);
        sb.append("', authorizationSecret='");
        sb.append(this.authorizationSecret);
        sb.append("', logLevel=");
        sb.append(this.logLevel);
        sb.append(", zone='");
        sb.append(this.zone);
        sb.append("', apiEndpointsMap='");
        sb.append(this.apiEndpointsMap.toString());
        sb.append("', chatEndpointsMap='");
        sb.append(this.chatEndpointsMap.toString());
        sb.append("', restApiVersion='");
        return a.r(sb, this.restApiVersion, "'}");
    }

    public QBSettings setEndpoints(String str, String str2, ServiceZone serviceZone) {
        if (serviceZone == ServiceZone.AUTOMATIC) {
            throw new IllegalArgumentException("Automatic zone type should not be set manually.");
        }
        if (!TextUtils.isEmpty(str) && !str.startsWith("http")) {
            str = "https://".concat(str);
        }
        setApiEndpoint(str, serviceZone);
        setChatEndpoint(str2, serviceZone);
        return this;
    }

    public QBSettings init(Context context, String str, String str2, String str3) {
        String str4;
        Decorators.requireNonNull(context, "context must not be null");
        Decorators.requireNonNull(str, "applicationId must not be null");
        Decorators.requireNonNull(str2, "authorizationKey must not be null");
        Decorators.requireNonNull(str3, "authorizationSecret must not be null");
        this.context = context.getApplicationContext();
        this.storage = new QBPreferenceSettingsStorage(context);
        this.applicationId = str;
        this.authorizationKey = str2;
        this.authorizationSecret = str3;
        setupEndpointsRetrievalTimer(context.getApplicationContext());
        String generateDeviceId = Utils.generateDeviceId();
        StringBuilder sb = new StringBuilder("android");
        if (!TextUtils.isEmpty(generateDeviceId)) {
            str4 = a.l("_", generateDeviceId);
        } else {
            str4 = "";
        }
        sb.append(str4);
        this.chatDefaultResource = sb.toString();
        QBSessionManager.getInstance().init(context);
        restoreSettings();
        return this;
    }
}