导航菜单

页面标题

页面副标题

Zepto v25.1.4 - RemoteConfigurationManager.java 源代码

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

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


package com.amazonaws.mobileconnectors.remoteconfiguration;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.v4.media.a;
import com.amazonaws.mobileconnectors.remoteconfiguration.exceptions.MalformedAppConfigIdException;
import com.amazonaws.mobileconnectors.remoteconfiguration.internal.ArcusThrottler;
import com.amazonaws.mobileconnectors.remoteconfiguration.internal.Arn;
import com.amazonaws.mobileconnectors.remoteconfiguration.internal.AttributesImpl;
import com.amazonaws.mobileconnectors.remoteconfiguration.internal.ConfigurationDb;
import com.amazonaws.mobileconnectors.remoteconfiguration.internal.ConfigurationImpl;
import com.amazonaws.mobileconnectors.remoteconfiguration.internal.gear.Checks;
import com.amazonaws.mobileconnectors.remoteconfiguration.internal.gear.LocalConfigInstanceIdGenerationHelper;
import com.amazonaws.mobileconnectors.remoteconfiguration.internal.model.RemoteConfiguration;
import com.amazonaws.mobileconnectors.remoteconfiguration.internal.model.RemoteConfigurationImpl;
import com.amazonaws.mobileconnectors.remoteconfiguration.internal.net.AndroidRemoteConfigurationFetcher;
import com.amazonaws.mobileconnectors.remoteconfiguration.internal.net.RemoteConfigurationFetcher;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.json.JSONObject;

public class RemoteConfigurationManager {

    public final String f7614a;

    public final ConfigurationDb f7615b;

    public final RemoteConfigurationFetcher f7616c;
    public final Attributes d;
    public final SharedPreferences e;
    public int f;
    public final ArcusThrottler g;

    public RemoteConfigurationManager(Builder builder) {
        this(builder.f7618b, builder.f7617a, builder.f7619c, builder.d);
    }

    public static void a(String str) {
        try {
            Arn.fromArn(str);
        } catch (IllegalArgumentException e) {
            throw new MalformedAppConfigIdException("Invalid appConfigId ARN.", e);
        }
    }

    public static void b(String str) {
        try {
            Arn.fromArn(str);
        } catch (IllegalArgumentException e) {
            throw new MalformedAppConfigIdException("Invalid appConfigId ARN.", e);
        }
    }

    public static Builder forAppId(Context context, String str) {
        return new Builder(context, str);
    }

    public static RemoteConfigurationManager getInstance(String str) {
        Checks.checkNotNull(str, "The App Configuration ID may not be null");
        return Builder.e.get(str);
    }

    public Attributes openAttributes() {
        return this.d;
    }

    public Configuration openConfiguration() {
        return this.f7615b.readConfiguration();
    }

    public void overwriteConfiguration(JSONObject jSONObject) {
        Checks.checkNotNull(jSONObject, "The Configuration cannot be null");
        this.f7615b.saveConfiguration(new RemoteConfigurationImpl(new ConfigurationImpl(jSONObject.toString(), new Date()), this.f7614a, 3, null, false));
    }

    public void setRampingKey(String str) {
        if (str == null) {
            throw new NullPointerException("The ramping key cannot be null.");
        }
        if (str.isEmpty() || str.length() > 64) {
            throw new IllegalArgumentException("The ramping key cannot be empty and its length is limited to 64 characters.");
        }
        String generateLocalConfigInstanceId = LocalConfigInstanceIdGenerationHelper.generateLocalConfigInstanceId(str);
        SharedPreferences.Editor edit = this.e.edit();
        edit.putString("localConfigurationInstanceId", generateLocalConfigInstanceId);
        edit.apply();
    }

    public void sync(ConfigurationSyncCallback configurationSyncCallback) {
        Checks.checkNotNull(configurationSyncCallback, "ConfigurationSyncCallback cannot be null");
        b(configurationSyncCallback);
    }

    public RemoteConfigurationManager(Context context, String str, JSONObject jSONObject, boolean z) {
        this(context, str, jSONObject, ConfigurationDb.getOrCreateInstance(context, str), "https://arcus-uswest.amazon.com", z);
    }

    public static Builder forAppId(Context context, String str, boolean z) {
        return new Builder(context, str, z);
    }

    public final String a() {
        return a.s(new StringBuilder(), this.f7614a, "_configuration.prefs");
    }

    public final void b(ConfigurationSyncCallback configurationSyncCallback) {
        ExecutorService newSingleThreadExecutor = Executors.newSingleThreadExecutor();
        newSingleThreadExecutor.submit(new androidx.core.content.res.a(17, this, configurationSyncCallback));
        newSingleThreadExecutor.shutdown();
    }

    public RemoteConfigurationManager(Context context, String str, JSONObject jSONObject, ConfigurationDb configurationDb, String str2, boolean z) {
        this.g = new ArcusThrottler();
        Checks.checkNotNull(context, "appContext cannot be null");
        Checks.checkNotNull(str, "appConfigId cannot be null");
        b(str);
        context = z ? context : context.getApplicationContext();
        try {
            URL url = new URL(str2);
            this.f7614a = str;
            this.e = context.getSharedPreferences(a(), 0);
            AttributesImpl attributesImpl = new AttributesImpl(context);
            this.d = attributesImpl;
            this.f = attributesImpl.hashCode();
            this.f7615b = configurationDb;
            this.f7616c = new AndroidRemoteConfigurationFetcher(context, url);
            if (jSONObject != null) {
                RemoteConfiguration readRemoteConfiguration = configurationDb.readRemoteConfiguration(str);
                if (readRemoteConfiguration == null || readRemoteConfiguration.getOrigin() == 1) {
                    configurationDb.saveConfiguration(new RemoteConfigurationImpl(new ConfigurationImpl(jSONObject.toString(), new Date()), str, 1, null, false));
                }
            }
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException("Invalid endpoint", e);
        }
    }

    public static class Builder {
        public static final ConcurrentHashMap<String, RemoteConfigurationManager> e = new ConcurrentHashMap<>();

        public final String f7617a;

        public final Context f7618b;

        public JSONObject f7619c;
        public boolean d;

        public Builder(Context context, String str) {
            this.f7619c = new JSONObject();
            this.d = false;
            if (context == null) {
                throw new NullPointerException("The Context may not be null");
            }
            if (str == null) {
                throw new NullPointerException("The App Configuration ID may not be null");
            }
            RemoteConfigurationManager.a(str);
            this.f7618b = context;
            this.f7617a = str;
        }

        public RemoteConfigurationManager createOrGet() {
            String str = this.f7617a;
            if (str == null) {
                throw new IllegalStateException("An App Configuration ID must be specified");
            }
            ConcurrentHashMap<String, RemoteConfigurationManager> concurrentHashMap = e;
            if (!concurrentHashMap.containsKey(str)) {
                if (this.f7618b == null) {
                    throw new IllegalStateException("The Context may not be null");
                }
                String str2 = this.f7617a;
                if (str2 == null) {
                    throw new IllegalStateException("The App Configuration ID may not be null");
                }
                if (this.f7619c == null) {
                    throw new IllegalStateException("The default configuration may not be null");
                }
                concurrentHashMap.putIfAbsent(str2, new RemoteConfigurationManager(this));
            }
            return concurrentHashMap.get(this.f7617a);
        }

        public Builder withDefaultConfiguration(JSONObject jSONObject) {
            if (jSONObject == null) {
                throw new NullPointerException("The default configuration may not be null");
            }
            this.f7619c = jSONObject;
            return this;
        }

        public Builder(Context context, String str, boolean z) {
            this(context, str);
            this.d = z;
        }
    }
}