Kufar v3.2.0版本的 MD5 值为:6a4d203db1c561c7e3bcd50d23fed59f

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


package com.rudderstack.android.sdk.core;

import android.app.Application;
import android.content.Context;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.ironsource.mediationsdk.adunit.data.DataKeys;
import com.rudderstack.android.sdk.core.EventRepository;
import com.rudderstack.android.sdk.core.RudderConfig;
import com.rudderstack.android.sdk.core.ecomm.ECommerceParamNames;
import com.rudderstack.android.sdk.core.util.Utils;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class RudderClient {
    private static final int NUMBER_OF_FLUSH_CALLS_IN_QUEUE = 1;
    private static String _advertisingId;
    private static String _anonymousId;
    private static String _deviceToken;
    private static Application application;
    private static RudderOption defaultOptions;
    private static RudderClient instance;
    private static EventRepository repository;
    final ExecutorService flushExecutorService;
    final RejectedExecutionHandler handler;

    public static class Builder {
        private Application application;
        private RudderConfig config;
        private int logLevel;
        private String writeKey;

        public Builder(Context context) {
            this(context, null);
        }

        @Nullable
        public RudderClient build() {
            if (this.application == null) {
                RudderLogger.logError("Context is null. Aborting initialization. Returning null Client");
                return null;
            }
            if (TextUtils.isEmpty(this.writeKey)) {
                RudderLogger.logError("writeKey is null. Aborting initialization. Returning null Client");
                return null;
            }
            return RudderClient.getInstance(this.application, this.writeKey, this.config);
        }

        public Builder logLevel(int i11) {
            if (this.config == null) {
                this.config = new RudderConfig();
            }
            this.config.setLogLevel(i11);
            return this;
        }

        public Builder recordScreenViews() {
            if (this.config == null) {
                this.config = new RudderConfig();
            }
            this.config.setRecordScreenViews(true);
            return this;
        }

        public Builder trackApplicationLifecycleEvents() {
            if (this.config == null) {
                this.config = new RudderConfig();
            }
            this.config.setTrackLifecycleEvents(true);
            return this;
        }

        public Builder withRudderConfig(RudderConfig rudderConfig) {
            if (this.config != null) {
                RudderLogger.logWarn("RudderClient: Builder: replacing old config");
            }
            this.config = rudderConfig;
            return this;
        }

        public Builder withRudderConfigBuilder(RudderConfig.Builder builder) {
            if (this.config != null) {
                RudderLogger.logWarn("RudderClient: Builder: replacing old config");
            }
            this.config = builder.build();
            return this;
        }

        public Builder(Context context, String str) {
            if (context == null) {
                RudderLogger.logError("context can not be null");
            }
            if (TextUtils.isEmpty(str)) {
                RudderLogger.logDebug("WriteKey is not specified in constructor. looking for string file");
                if (context != null) {
                    str = Utils.getWriteKeyFromStrings(context);
                }
            }
            if (TextUtils.isEmpty(str)) {
                RudderLogger.logError("WriteKey can not be null or empty");
            }
            if (context != null) {
                this.application = (Application) context.getApplicationContext();
            }
            this.writeKey = str;
        }
    }

    public interface Callback {
        void onReady(Object obj);
    }

    private RudderClient() {
        ThreadPoolExecutor.DiscardOldestPolicy discardOldestPolicy = new ThreadPoolExecutor.DiscardOldestPolicy();
        this.handler = discardOldestPolicy;
        this.flushExecutorService = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(1), discardOldestPolicy);
        RudderLogger.logVerbose("RudderClient: constructor invoked.");
    }

    private void dumpMessage(@NonNull RudderMessage rudderMessage) {
        EventRepository eventRepository = repository;
        if (eventRepository != null) {
            eventRepository.processMessage(rudderMessage);
        }
    }

    @Nullable
    public static Application getApplication() {
        return application;
    }

    public static RudderOption getDefaultOptions() {
        return defaultOptions;
    }

    @NonNull
    public static RudderClient getInstance(@NonNull Context context, @Nullable String str) {
        return getInstance(context, str, new RudderConfig());
    }

    private static boolean getOptOutStatus() {
        EventRepository eventRepository = repository;
        if (eventRepository == null) {
            RudderLogger.logError("SDK is not initialised. Hence dropping the event");
            return true;
        }
        if (eventRepository.getOptStatus()) {
            RudderLogger.logDebug("User Opted out for tracking the activity, hence dropping the event");
            return true;
        }
        return false;
    }

    public static void lambda$flush$0() {
        repository.flushSync();
    }

    public static void putAdvertisingId(@NonNull String str) {
        if (instance == null) {
            _advertisingId = str;
        } else {
            if (getOptOutStatus()) {
                return;
            }
            RudderElementCache.cachedContext.updateWithAdvertisingId(str);
        }
    }

    public static void putAnonymousId(@NonNull String str) {
        EventRepository eventRepository;
        if (instance == null) {
            _anonymousId = str;
        } else if (!getOptOutStatus() && (eventRepository = repository) != null) {
            eventRepository.updateAnonymousId(str);
        }
    }

    public static void putDeviceToken(@NonNull String str) {
        if (instance == null) {
            _deviceToken = str;
        } else {
            if (getOptOutStatus()) {
                return;
            }
            RudderElementCache.cachedContext.putDeviceToken(str);
        }
    }

    public static void setAnonymousId(@NonNull String str) {
        putAnonymousId(str);
    }

    public static void setSingletonInstance(@NonNull RudderClient rudderClient) {
        instance = rudderClient;
    }

    private static void updateConfigWithValidValuesIfNecessary(@NonNull RudderConfig rudderConfig) {
        if (TextUtils.isEmpty(rudderConfig.getDataPlaneUrl())) {
            RudderLogger.logVerbose("getInstance: EndPointUri is blank or null. using default.");
            rudderConfig.setDataPlaneUrl("https://hosted.rudderlabs.com");
        }
        if (rudderConfig.getFlushQueueSize() < 0 || rudderConfig.getFlushQueueSize() > 100) {
            RudderLogger.logVerbose("getInstance: FlushQueueSize is wrong. using default.");
            rudderConfig.setFlushQueueSize(30);
        }
        if (rudderConfig.getDbCountThreshold() < 0) {
            RudderLogger.logVerbose("getInstance: DbCountThreshold is wrong. using default.");
            rudderConfig.setDbCountThreshold(10000);
        }
        if (rudderConfig.getSleepTimeOut() < 1) {
            RudderLogger.logVerbose("getInstance: SleepTimeOut is wrong. using default.");
            rudderConfig.setSleepTimeOut(10);
        }
    }

    public static void updateWithAdvertisingId(@NonNull String str) {
        putAdvertisingId(str);
    }

    @NonNull
    public static RudderClient with(@NonNull Context context) {
        RudderClient rudderClient = instance;
        if (rudderClient == null) {
            return getInstance(context, Utils.getWriteKeyFromStrings(context));
        }
        return rudderClient;
    }

    public void alias(@NonNull RudderMessageBuilder rudderMessageBuilder) {
        if (getOptOutStatus()) {
            return;
        }
        alias(rudderMessageBuilder.build());
    }

    public void cancelPeriodicWorkRequest() {
        EventRepository eventRepository = repository;
        if (eventRepository != null) {
            eventRepository.cancelPeriodicFlushWorker();
        }
    }

    public void endSession() {
        EventRepository eventRepository = repository;
        if (eventRepository == null) {
            return;
        }
        eventRepository.endSession();
    }

    public void flush() {
        if (!getOptOutStatus() && repository != null) {
            this.flushExecutorService.submit(new Runnable() {
                @Override
                public final void run() {
                    RudderClient.lambda$flush$0();
                }
            });
        }
    }

    public RudderContext getRudderContext() {
        if (getOptOutStatus()) {
            return null;
        }
        return RudderElementCache.getCachedContext();
    }

    @Deprecated
    public void group(@NonNull RudderMessageBuilder rudderMessageBuilder) {
        if (getOptOutStatus()) {
            return;
        }
        group(rudderMessageBuilder.build());
    }

    public void identify(@NonNull RudderMessage rudderMessage) {
        if (getOptOutStatus()) {
            return;
        }
        rudderMessage.setType(MessageType.IDENTIFY);
        dumpMessage(rudderMessage);
    }

    public void onIntegrationReady(String str, Callback callback) {
        EventRepository eventRepository;
        if (!getOptOutStatus() && (eventRepository = repository) != null) {
            eventRepository.onIntegrationReady(str, callback);
        }
    }

    public void optOut(boolean z11) {
        EventRepository eventRepository = repository;
        if (eventRepository != null) {
            eventRepository.saveOptStatus(z11);
            RudderLogger.logInfo("optOut() flag is set to " + z11);
            return;
        }
        RudderLogger.logError("SDK is not initialised. Hence aborting optOut API call");
    }

    public void reset() {
        RudderElementCache.reset();
        EventRepository eventRepository = repository;
        if (eventRepository != null) {
            eventRepository.reset();
        }
    }

    public void screen(@NonNull RudderMessageBuilder rudderMessageBuilder) {
        if (getOptOutStatus()) {
            return;
        }
        screen(rudderMessageBuilder.build());
    }

    public void shutdown() {
        EventRepository eventRepository = repository;
        if (eventRepository != null) {
            eventRepository.shutDown();
        }
    }

    public void startSession() {
        startSession(Utils.getCurrentTimeInSecondsLong());
    }

    public void track(@NonNull RudderMessageBuilder rudderMessageBuilder) {
        if (getOptOutStatus()) {
            return;
        }
        track(rudderMessageBuilder.build());
    }

    @NonNull
    public static RudderClient getInstance(@NonNull Context context, @Nullable String str, @NonNull RudderConfig.Builder builder) {
        return getInstance(context, str, builder.build());
    }

    public void startSession(@NonNull Long l11) {
        if (repository == null) {
            return;
        }
        if (Long.toString(l11.longValue()).length() < 10) {
            RudderLogger.logError("RudderClient: startSession: Length of the session Id supplied should be atleast 10, hence ignoring it");
        } else {
            repository.startSession(l11);
        }
    }

    @NonNull
    public static RudderClient getInstance(@NonNull Context context, @Nullable String str, @NonNull RudderConfig rudderConfig, @Nullable RudderOption rudderOption) {
        defaultOptions = rudderOption;
        return getInstance(context, str, rudderConfig);
    }

    public void alias(@NonNull RudderMessage rudderMessage) {
        if (getOptOutStatus()) {
            return;
        }
        rudderMessage.setType(MessageType.ALIAS);
        dumpMessage(rudderMessage);
    }

    @Deprecated
    public void group(@NonNull RudderMessage rudderMessage) {
        if (getOptOutStatus()) {
            return;
        }
        rudderMessage.setType(MessageType.GROUP);
        dumpMessage(rudderMessage);
    }

    public void screen(@NonNull RudderMessage rudderMessage) {
        if (getOptOutStatus()) {
            return;
        }
        rudderMessage.setType(MessageType.SCREEN);
        dumpMessage(rudderMessage);
    }

    public void track(@NonNull RudderMessage rudderMessage) {
        if (getOptOutStatus()) {
            return;
        }
        rudderMessage.setType(MessageType.TRACK);
        dumpMessage(rudderMessage);
    }

    public void identify(@NonNull RudderTraits rudderTraits, @Nullable RudderOption rudderOption) {
        if (getOptOutStatus()) {
            return;
        }
        RudderMessage build = new RudderMessageBuilder().setEventName(MessageType.IDENTIFY).setUserId(rudderTraits.getId()).setRudderOption(rudderOption).build();
        build.updateTraits(rudderTraits);
        build.updateExternalIds(rudderOption);
        identify(build);
    }

    @NonNull
    public static RudderClient getInstance(@NonNull Context context, @Nullable String str, @Nullable RudderConfig rudderConfig) {
        if (instance == null) {
            RudderLogger.logVerbose("getInstance: instance null. creating instance");
            if (!TextUtils.isEmpty(str)) {
                if (rudderConfig == null) {
                    RudderLogger.logVerbose("getInstance: config null. creating default config");
                    rudderConfig = new RudderConfig();
                } else {
                    RudderLogger.logVerbose("getInstance: config present. using config.");
                    updateConfigWithValidValuesIfNecessary(rudderConfig);
                }
                application = (Application) context.getApplicationContext();
                instance = new RudderClient();
                if (application != null) {
                    RudderLogger.logVerbose("getInstance: creating EventRepository.");
                    repository = new EventRepository(application, rudderConfig, new EventRepository.Identifiers(str, _deviceToken, _anonymousId, _advertisingId));
                }
            } else {
                throw new IllegalArgumentException("RudderClient: getInstance: writeKey can not be null or empty");
            }
        }
        return instance;
    }

    public void alias(String str) {
        if (getOptOutStatus()) {
            return;
        }
        alias(str, null);
    }

    public void group(@NonNull String str) {
        if (getOptOutStatus()) {
            return;
        }
        group(str, null);
    }

    public void screen(@NonNull String str) {
        if (getOptOutStatus()) {
            return;
        }
        RudderProperty rudderProperty = new RudderProperty();
        rudderProperty.put("name", str);
        screen(new RudderMessageBuilder().setEventName(str).setProperty(rudderProperty).build());
    }

    public void track(@NonNull String str) {
        if (getOptOutStatus()) {
            return;
        }
        track(new RudderMessageBuilder().setEventName(str).build());
    }

    public void alias(@NonNull String str, @Nullable RudderOption rudderOption) {
        String anonymousId;
        if (getOptOutStatus()) {
            return;
        }
        Map<String, Object> traits = getRudderContext().getTraits();
        if (traits.containsKey(DataKeys.USER_ID)) {
            anonymousId = (String) traits.get(DataKeys.USER_ID);
        } else if (traits.containsKey("id")) {
            anonymousId = (String) traits.get("id");
        } else {
            anonymousId = RudderContext.getAnonymousId();
        }
        traits.put(DataKeys.USER_ID, str);
        traits.put("id", str);
        RudderMessage build = new RudderMessageBuilder().setUserId(str).setRudderOption(rudderOption).setPreviousId(anonymousId).build();
        build.updateTraits(traits);
        alias(build);
    }

    public void group(@NonNull String str, @Nullable RudderTraits rudderTraits) {
        if (getOptOutStatus()) {
            return;
        }
        group(str, rudderTraits, null);
    }

    public void track(@NonNull String str, @Nullable RudderProperty rudderProperty) {
        if (getOptOutStatus()) {
            return;
        }
        track(new RudderMessageBuilder().setEventName(str).setProperty(rudderProperty).build());
    }

    public void group(@NonNull String str, @Nullable RudderTraits rudderTraits, @Nullable RudderOption rudderOption) {
        if (getOptOutStatus()) {
            return;
        }
        group(new RudderMessageBuilder().setGroupId(str).setGroupTraits(rudderTraits).setRudderOption(rudderOption).build());
    }

    public void screen(@NonNull String str, @Nullable RudderProperty rudderProperty) {
        if (getOptOutStatus()) {
            return;
        }
        if (rudderProperty == null) {
            rudderProperty = new RudderProperty();
        }
        rudderProperty.put("name", str);
        screen(new RudderMessageBuilder().setEventName(str).setProperty(rudderProperty).build());
    }

    public void track(@NonNull String str, @Nullable RudderProperty rudderProperty, @Nullable RudderOption rudderOption) {
        if (getOptOutStatus()) {
            return;
        }
        track(new RudderMessageBuilder().setEventName(str).setProperty(rudderProperty).setRudderOption(rudderOption).build());
    }

    public void identify(@NonNull RudderTraits rudderTraits) {
        if (getOptOutStatus()) {
            return;
        }
        identify(rudderTraits, null);
    }

    public void screen(@NonNull String str, @NonNull String str2, @Nullable RudderProperty rudderProperty, @Nullable RudderOption rudderOption) {
        if (getOptOutStatus()) {
            return;
        }
        if (rudderProperty == null) {
            rudderProperty = new RudderProperty();
        }
        rudderProperty.put(ECommerceParamNames.CATEGORY, str2);
        rudderProperty.put("name", str);
        screen(new RudderMessageBuilder().setEventName(str).setProperty(rudderProperty).setRudderOption(rudderOption).build());
    }

    public void identify(@NonNull RudderTraitsBuilder rudderTraitsBuilder) {
        if (getOptOutStatus()) {
            return;
        }
        identify(rudderTraitsBuilder.build());
    }

    public void identify(@NonNull String str) {
        if (getOptOutStatus()) {
            return;
        }
        identify(new RudderTraitsBuilder().setId(str));
    }

    public void identify(@NonNull String str, @Nullable RudderTraits rudderTraits, @Nullable RudderOption rudderOption) {
        if (getOptOutStatus()) {
            return;
        }
        if (rudderTraits == null) {
            rudderTraits = new RudderTraits();
        }
        rudderTraits.putId(str);
        identify(rudderTraits, rudderOption);
    }

    public void screen(@NonNull String str, @Nullable RudderProperty rudderProperty, @Nullable RudderOption rudderOption) {
        if (getOptOutStatus()) {
            return;
        }
        if (rudderProperty == null) {
            rudderProperty = new RudderProperty();
        }
        rudderProperty.put("name", str);
        screen(new RudderMessageBuilder().setEventName(str).setProperty(rudderProperty).setRudderOption(rudderOption).build());
    }

    @Nullable
    public static RudderClient getInstance() {
        return instance;
    }
}