Luno v7.28.0版本的 MD5 值为:08d81b3b88ef7df48c89cb5d56dc11a2

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


package siftscience.android;

import android.content.Context;
import android.util.Log;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.SerializedName;
import java.util.StringJoiner;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public final class Sift {
    static final String SDK_VERSION = "1.0.0";
    private static final String TAG = "siftscience.android.Sift";
    private static volatile AppStateCollector appStateCollector;
    private static volatile DevicePropertiesCollector devicePropertiesCollector;
    private static volatile ExecutorService executors;
    private static volatile SiftImpl instance;
    private static volatile String unboundUserId;
    static final Gson GSON = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
    private static volatile boolean hasUnboundUserId = false;

    public static class Config {
        private static final String DEFAULT_SERVER_URL_FORMAT = "https://api3.siftscience.com/v3/accounts/%s/mobile_events";

        @SerializedName(alternate = {"accountId"}, value = "account_id")
        public final String accountId;

        @SerializedName(alternate = {"beaconKey"}, value = "beacon_key")
        public final String beaconKey;

        @SerializedName(alternate = {"disallowLocationCollection"}, value = "disallow_location_collection")
        public final boolean disallowLocationCollection;

        @SerializedName(alternate = {"serverUrlFormat"}, value = "server_url_format")
        public final String serverUrlFormat;

        public boolean equals(Object obj) {
            if (!(obj instanceof Config)) {
                return false;
            }
            Config config = (Config) obj;
            return Utils.equals(this.accountId, config.accountId) && Utils.equals(this.beaconKey, config.beaconKey) && Utils.equals(this.serverUrlFormat, config.serverUrlFormat) && Utils.equals(Boolean.valueOf(this.disallowLocationCollection), Boolean.valueOf(config.disallowLocationCollection));
        }

        public boolean isValid() {
            StringJoiner stringJoiner = new StringJoiner(", ");
            String str = this.accountId;
            if (str == null || str.isEmpty()) {
                stringJoiner.add("accountId");
            }
            String str2 = this.beaconKey;
            if (str2 == null || str2.isEmpty()) {
                stringJoiner.add("beacon key");
            }
            String str3 = this.serverUrlFormat;
            if (str3 == null || str3.isEmpty()) {
                stringJoiner.add("server URL format");
            }
            boolean z = stringJoiner.length() == 0;
            if (!z) {
                String unused = Sift.TAG;
                StringBuilder sb = new StringBuilder();
                sb.append("The following configuration properties are missing or empty: ");
                sb.append(stringJoiner.toString());
            }
            return z;
        }

        public static class Builder {
            private String accountId;
            private String beaconKey;
            private boolean disallowLocationCollection;
            private String serverUrlFormat;

            public Builder() {
                this.serverUrlFormat = Config.DEFAULT_SERVER_URL_FORMAT;
            }

            public Config build() {
                return new Config(this.accountId, this.beaconKey, this.serverUrlFormat, this.disallowLocationCollection);
            }

            public Builder withAccountId(String str) {
                this.accountId = str;
                return this;
            }

            public Builder withBeaconKey(String str) {
                this.beaconKey = str;
                return this;
            }

            public Builder withDisallowLocationCollection(boolean z) {
                this.disallowLocationCollection = z;
                return this;
            }

            public Builder withServerUrlFormat(String str) {
                this.serverUrlFormat = str;
                return this;
            }

            public Builder(Config config) {
                this.accountId = config.accountId;
                this.beaconKey = config.beaconKey;
                this.serverUrlFormat = config.serverUrlFormat;
                this.disallowLocationCollection = config.disallowLocationCollection;
            }
        }

        public Config() {
            this(null, null, DEFAULT_SERVER_URL_FORMAT, false);
        }

        private Config(String str, String str2, String str3, boolean z) {
            this.accountId = str;
            this.beaconKey = str2;
            this.serverUrlFormat = str3;
            this.disallowLocationCollection = z;
        }
    }

    private Sift() {
    }

    public static void close() {
        if (executors == null || executors.isShutdown()) {
            return;
        }
        executors.shutdown();
        try {
            executors.awaitTermination(1L, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            Log.e(TAG, "Interrupted when awaiting executor termination", e);
        }
    }

    public static void collect() {
        if (executors == null || (executors != null && executors.isShutdown())) {
            executors = Executors.newSingleThreadScheduledExecutor();
        }
        executors.submit(new Runnable() {
            @Override
            public void run() {
                Sift.appStateCollector.collect();
                Sift.devicePropertiesCollector.collect();
            }
        });
    }

    public static void open(Context context, Config config, String str) {
        synchronized (Sift.class) {
            if (instance == null) {
                Context applicationContext = context.getApplicationContext();
                instance = new SiftImpl(applicationContext, config, unboundUserId, hasUnboundUserId);
                devicePropertiesCollector = new DevicePropertiesCollector(instance, applicationContext);
                appStateCollector = new AppStateCollector(instance, applicationContext);
                unboundUserId = null;
                hasUnboundUserId = false;
            } else if (config != null) {
                instance.setConfig(config);
            }
        }
        AppStateCollector appStateCollector2 = appStateCollector;
        if (str == null) {
            str = context.getClass().getSimpleName();
        }
        appStateCollector2.setActivityName(str);
    }

    public static void pause() {
        SiftImpl siftImpl = instance;
        if (siftImpl != null) {
            siftImpl.save();
        }
        AppStateCollector appStateCollector2 = appStateCollector;
        if (appStateCollector2 != null) {
            appStateCollector2.disconnectLocationServices();
        }
    }

    public static void resume(Context context) {
        resume(context, null);
    }

    public static synchronized void setUserId(String str) {
        synchronized (Sift.class) {
            if (instance != null) {
                instance.setUserId(str);
            } else {
                unboundUserId = str;
                hasUnboundUserId = true;
            }
        }
    }

    public static synchronized void unsetUserId() {
        synchronized (Sift.class) {
            setUserId(null);
        }
    }

    public static void resume(Context context, String str) {
        AppStateCollector appStateCollector2 = appStateCollector;
        if (appStateCollector2 != null) {
            appStateCollector2.reconnectLocationServices();
            if (str == null) {
                str = context.getClass().getSimpleName();
            }
            appStateCollector2.setActivityName(str);
        }
    }

    public static void open(Context context, String str) {
        open(context, null, str);
    }

    public static void open(Context context, Config config) {
        open(context, config, null);
    }

    public static void open(Context context) {
        open(context, null, null);
    }
}