MOD v1.0版本的 MD5 值为:449e0342737a08b14addca8850efd1a4

以下内容为反编译后的 KOuKoYrHiEdXrMuIsFxOpYjHhCmXq.java 源代码,内容仅作参考


package com.wait.source;

import android.net.Uri;
import android.util.Log;
import bolts.Task;
import com.amazon.core.services.applicationinformation.ApplicationInformation;
import com.amazon.mobile.ssnap.clientstore.featurestore.FetchResponse;
import com.amazon.mobile.ssnap.clientstore.filestore.FileStore;
import com.amazon.platform.service.ShopKitProvider;
import com.wait.source.KOuKoYrHiEdXrMuIsFxOpYjHhCmXq$;
import com.wait.source.LruCache.AccessLayerLruCache;
import com.wait.source.api.SourceEnum;
import com.wait.source.metrics.EventLogger;
import com.wait.source.metrics.RCSMetricPublisher;
import com.wait.source.metrics.RCSMetrics;
import com.wait.source.utils.StringFileReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.function.BiConsumer;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@Singleton
public class KOuKoYrHiEdXrMuIsFxOpYjHhCmXq {
    private static final String CDN_HOST = "https://m.media-amazon.com/images/S";
    private static final String CONFIG_PATH = "ssnap-msa/%s/runtimeConfig/android/%s.json";
    protected static final int MAX_NUM_RETRIES = 3;
    private static final String MBP_CONFIG_PATH = "mbp-ssnap-msa/%s/runtimeConfig/android/%s.json";
    private static final String TAG = "KOuKoYrHiEdXrMuIsFxOpYjHhCmXq";
    private final AccessLayerLruCache accessLayerLruCache;
    private final FileStore configServiceFileStore;
    private final EventLogger eventLogger;
    private final StringFileReader fileReader;
    private final ConfigCache inMemoryConfigCache;
    private ConcurrentMap<String, Boolean> isTaskRunning = new ConcurrentHashMap();
    private final RCSMetricPublisher metricPublisher;
    private final PersistentConfigCache persistentConfigCache;

    @Inject
    public KOuKoYrHiEdXrMuIsFxOpYjHhCmXq(EventLogger eventLogger, RCSMetricPublisher rCSMetricPublisher, @Named("PermissionFileStore") FileStore fileStore, ConfigCache configCache, PersistentConfigCache persistentConfigCache, AccessLayerLruCache accessLayerLruCache, StringFileReader stringFileReader) {
        this.eventLogger = eventLogger;
        this.metricPublisher = rCSMetricPublisher;
        this.configServiceFileStore = fileStore;
        this.inMemoryConfigCache = configCache;
        this.persistentConfigCache = persistentConfigCache;
        this.accessLayerLruCache = accessLayerLruCache;
        this.fileReader = stringFileReader;
    }

    public InputStream get(SourceEnum sourceEnum, String str) throws FileNotFoundException {
        scheduleSync(sourceEnum, str);
        Boolean bool = Boolean.FALSE;
        try {
            ApplicationInformation applicationInformation = (ApplicationInformation) ShopKitProvider.getService(ApplicationInformation.class);
            if (applicationInformation != null && applicationInformation.isSafeMode()) {
                bool = Boolean.TRUE;
            }
        } catch (Exception unused) {
        }
        if (bool.booleanValue()) {
            throw new FileNotFoundException("App enter safe mode, use built-in config");
        }
        if (this.inMemoryConfigCache.exists(str)) {
            return this.inMemoryConfigCache.get(str);
        }
        return this.persistentConfigCache.get(str);
    }

    private void scheduleSync(SourceEnum sourceEnum, String str) {
        if (this.isTaskRunning.containsKey(str)) {
            this.metricPublisher.recordCounterEvent(RCSMetrics.DOWNLOAD_CONFIG_REQUEST_DUPLICATE.getName(), str);
            EventLogger eventLogger = this.eventLogger;
            eventLogger.recordEvent(TAG + ":DuplicateDownload:" + str);
            return;
        }
        this.isTaskRunning.put(str, Boolean.TRUE);
        asyncDownload(sourceEnum, str, Boolean.FALSE, new KOuKoYrHiEdXrMuIsFxOpYjHhCmXq$.ExternalSyntheticLambda1(this, str));
    }

    public void lambda$scheduleSync$0(String str, File file, Exception exc) {
        this.isTaskRunning.remove(str);
    }

    void asyncDownload(SourceEnum sourceEnum, String str, Boolean bool, BiConsumer<File, Exception> biConsumer, int i) {
        Uri fileUrl = getFileUrl(sourceEnum, str);
        this.configServiceFileStore.getFileAsync(FileStore.CachePolicy.REMOTE, fileUrl).continueWith(new KOuKoYrHiEdXrMuIsFxOpYjHhCmXq$.ExternalSyntheticLambda0(this, System.currentTimeMillis(), str, fileUrl, i, biConsumer, bool, sourceEnum));
    }

    public Object lambda$asyncDownload$1(long j, String str, Uri uri, int i, BiConsumer biConsumer, Boolean bool, SourceEnum sourceEnum, Task task) throws Exception {
        Exception exc;
        this.metricPublisher.recordTimerEvent(RCSMetrics.DOWNLOAD_CONFIG_REQUEST_LATENCY.getName(), System.currentTimeMillis() - j, str);
        String str2 = TAG;
        Log.d(str2, "Downloading config from SSNAP: " + str + " url:" + uri + " numRetries:" + i);
        if (task.isCancelled()) {
            this.metricPublisher.recordCounterEvent(RCSMetrics.DOWNLOAD_CONFIG_REQUEST_CANCEL.getName(), str);
            this.eventLogger.recordTime(str2 + ":TaskCompletedTimer:Canceled", j);
            biConsumer.accept(null, new Exception("Downloading " + str + " is cancelled"));
        } else {
            if (task.isFaulted()) {
                this.metricPublisher.recordCounterEvent(RCSMetrics.DOWNLOAD_CONFIG_REQUEST_FAULT.getName(), str);
                this.eventLogger.recordTime(str2 + ":TaskCompletedTimer:Faulted", j);
                exc = new Exception("Downloading " + str + " occur fault", task.getError());
            } else {
                File file = (File) ((FetchResponse) task.getResult()).getResponse();
                if (jsonVerification(file, str)) {
                    if (bool.booleanValue()) {
                        this.accessLayerLruCache.update(str, (File) ((FetchResponse) task.getResult()).getResponse());
                    } else {
                        cacheResult(str, (File) ((FetchResponse) task.getResult()).getResponse());
                    }
                    biConsumer.accept(file, null);
                    this.metricPublisher.recordCounterEvent(RCSMetrics.DOWNLOAD_CONFIG_REQUEST_SUCCESS.getName(), str, 0.2d);
                    this.eventLogger.recordTime(str2 + ":TaskCompletedTimer:Success", j);
                } else {
                    this.metricPublisher.recordCounterEvent(RCSMetrics.DOWNLOAD_CONFIG_REQUEST_INVALID_JSON.getName(), str);
                    this.eventLogger.recordTime(str2 + ":TaskCompletedTimer:FaultyFile", j);
                    this.eventLogger.recordEvent(str2 + ":FileJSONVerification:Exception:" + str);
                    exc = new Exception("Downloading " + str + " json verification failed");
                }
            }
            if (exc != null) {
                if (i < MAX_NUM_RETRIES) {
                    asyncDownload(sourceEnum, str, bool, biConsumer, i + 1);
                } else {
                    biConsumer.accept(null, exc);
                }
            }
            return null;
        }
        exc = null;
        if (exc != null) {
        }
        return null;
    }

    void asyncDownload(SourceEnum sourceEnum, String str, Boolean bool, BiConsumer<File, Exception> biConsumer) {
        asyncDownload(sourceEnum, str, bool, biConsumer, 0);
    }

    private void cacheResult(String str, File file) throws IOException {
        if (!this.inMemoryConfigCache.exists(str)) {
            this.persistentConfigCache.update(str, file);
        }
        this.inMemoryConfigCache.update(str, file);
    }

    protected boolean jsonVerification(File file, String str) {
        try {
            try {
                String readFile = this.fileReader.readFile(file);
                try {
                    new JSONObject(readFile);
                    EventLogger eventLogger = this.eventLogger;
                    StringBuilder sb = new StringBuilder();
                    String str2 = TAG;
                    sb.append(str2);
                    sb.append(":FileJSONVerification:JSONException");
                    eventLogger.recordEvent(sb.toString(), 0);
                    EventLogger eventLogger2 = this.eventLogger;
                    eventLogger2.recordEvent(str2 + ":FileJSONVerification:IOException", 0);
                    return true;
                } catch (JSONException unused) {
                    new JSONArray(readFile);
                    EventLogger eventLogger3 = this.eventLogger;
                    StringBuilder sb2 = new StringBuilder();
                    String str3 = TAG;
                    sb2.append(str3);
                    sb2.append(":FileJSONVerification:JSONException");
                    eventLogger3.recordEvent(sb2.toString(), 0);
                    EventLogger eventLogger4 = this.eventLogger;
                    eventLogger4.recordEvent(str3 + ":FileJSONVerification:IOException", 0);
                    return true;
                }
            } catch (IOException unused2) {
                this.metricPublisher.recordCounterEvent(RCSMetrics.DOWNLOAD_CONFIG_IO_EXCEPTION.getName(), str);
                EventLogger eventLogger5 = this.eventLogger;
                eventLogger5.recordEvent(TAG + ":FileJSONVerification:IOException");
                return false;
            }
        } catch (JSONException unused3) {
            EventLogger eventLogger6 = this.eventLogger;
            StringBuilder sb3 = new StringBuilder();
            String str4 = TAG;
            sb3.append(str4);
            sb3.append(":FileJSONVerification:JSONException:All");
            eventLogger6.recordEvent(sb3.toString());
            EventLogger eventLogger7 = this.eventLogger;
            eventLogger7.recordEvent(str4 + ":FileJSONVerification:JSONException:" + "".length());
            EventLogger eventLogger8 = this.eventLogger;
            eventLogger8.recordEvent(str4 + ":FileJSONVerification:JSONException");
            return false;
        }
    }

    Uri getFileUrl(SourceEnum sourceEnum, String str) {
        int i = 1.$SwitchMap$com$amazon$mShop$runtimeconfig$api$SourceEnum[sourceEnum.ordinal()];
        return Uri.parse(CDN_HOST).buildUpon().appendEncodedPath(String.format(sourceEnum == SourceEnum.MBP ? MBP_CONFIG_PATH : CONFIG_PATH, i != 1 ? i != 2 ? i != MAX_NUM_RETRIES ? "prod" : "gamma" : "beta" : "alpha", str)).build();
    }

    public void getAsync(SourceEnum sourceEnum, String str, Boolean bool, BiConsumer<String, Exception> biConsumer) {
        asyncDownload(sourceEnum, str, bool, new KOuKoYrHiEdXrMuIsFxOpYjHhCmXq$.ExternalSyntheticLambda2(this, biConsumer, str));
    }

    public void lambda$getAsync$2(BiConsumer biConsumer, String str, File file, Exception exc) {
        if (exc != null) {
            biConsumer.accept(null, exc);
            this.metricPublisher.recordCounterEvent(RCSMetrics.DOWNLOAD_CONFIG_CALLBACK_ERROR.getName(), str);
            return;
        }
        try {
            String readFile = this.fileReader.readFile(file);
            this.metricPublisher.recordCounterEvent(RCSMetrics.DOWNLOAD_CONFIG_CALLBACK_SUCCESS.getName(), str);
            biConsumer.accept(readFile, null);
        } catch (Exception e) {
            this.metricPublisher.recordCounterEvent(RCSMetrics.DOWNLOAD_CONFIG_IO_EXCEPTION.getName(), str);
            biConsumer.accept(null, e);
        }
    }

    public InputStream getConfigFromCacheWithName(String str) throws IOException {
        try {
            return this.accessLayerLruCache.get(str);
        } catch (IOException e) {
            Log.d(TAG, e.getMessage());
            throw e;
        }
    }

    public void clearCacheWithPrefixWithSuffixToKeep(String str, String str2, char c) throws IOException {
        try {
            this.accessLayerLruCache.clearCacheWithPrefixWithSuffixToKeep(str, str2, c);
        } catch (IOException e) {
            Log.d(TAG, e.getMessage());
            throw e;
        }
    }
}