OurPlay v5.5.9版本的 MD5 值为:d4e139798f4c2243a1145c8af5e21046

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


package com.github.shadowsocks.database;

import android.net.Uri;
import android.util.Base64;
import android.util.Log;
import android.util.LongSparseArray;
import androidx.room.Dao;
import androidx.room.Entity;
import androidx.room.Ignore;
import androidx.room.Insert;
import androidx.room.PrimaryKey;
import androidx.room.Query;
import androidx.room.Update;
import com.excelliance.kxqp.bitmap.bean.RankingItem;
import com.github.shadowsocks.plugin.PluginConfiguration;
import com.github.shadowsocks.plugin.PluginOptions;
import com.github.shadowsocks.preference.DataStore;
import com.github.shadowsocks.utils.h;
import com.google.android.gms.common.Scopes;
import com.umeng.commonsdk.framework.UMModuleRegister;
import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import kotlin.Metadata;
import kotlin.TypeCastException;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.Lambda;
import kotlin.jvm.internal.g;
import kotlin.jvm.internal.k;
import kotlin.sequences.Sequence;
import kotlin.sequences.j;
import kotlin.text.Charsets;
import kotlin.text.MatchResult;
import kotlin.text.Regex;
import kotlin.text.m;
import kotlin.u;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;

@Entity
@Metadata(bv = {1, 0, 3}, d1 = {"\u0000J\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0002\b\u0005\n\u0002\u0010\u000b\n\u0002\b\u000f\n\u0002\u0010\t\n\u0002\b#\n\u0002\u0010\b\n\u0002\b\u001d\n\u0002\u0010\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\b\u0007\u0018\u0000 g2\u00020\u0001:\u0002ghB\u0005¢\u0006\u0002\u0010\u0002J\u000e\u0010[\u001a\u00020\\2\u0006\u0010]\u001a\u00020\u0000J\u0006\u0010^\u001a\u00020\\J\u0006\u0010_\u001a\u00020\\J\u0018\u0010`\u001a\u00020a2\u0010\b\u0002\u0010b\u001a\n\u0012\u0004\u0012\u00020\u0000\u0018\u00010cJ\b\u0010d\u001a\u00020\u0004H\u0016J\u0006\u0010e\u001a\u00020fR\u001c\u0010\u0003\u001a\u0004\u0018\u00010\u0004X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0005\u0010\u0006\"\u0004\b\u0007\u0010\bR\u001a\u0010\t\u001a\u00020\nX\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u000b\u0010\f\"\u0004\b\r\u0010\u000eR\u001e\u0010\u000f\u001a\u00020\n8\u0006@\u0006X\u0087\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0010\u0010\f\"\u0004\b\u0011\u0010\u000eR\u0011\u0010\u0012\u001a\u00020\u00048F¢\u0006\u0006\u001a\u0004\b\u0013\u0010\u0006R\u0011\u0010\u0014\u001a\u00020\u00048F¢\u0006\u0006\u001a\u0004\b\u0015\u0010\u0006R\u001a\u0010\u0016\u001a\u00020\u0004X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0017\u0010\u0006\"\u0004\b\u0018\u0010\bR\u001e\u0010\u0019\u001a\u00020\u001a8\u0006@\u0006X\u0087\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u001b\u0010\u001c\"\u0004\b\u001d\u0010\u001eR\u001a\u0010\u001f\u001a\u00020\u0004X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b \u0010\u0006\"\u0004\b!\u0010\bR\u001a\u0010\"\u001a\u00020\nX\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b#\u0010\f\"\u0004\b$\u0010\u000eR\u001c\u0010%\u001a\u0004\u0018\u00010\u0004X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b&\u0010\u0006\"\u0004\b'\u0010\bR\u001a\u0010(\u001a\u00020\u0004X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b)\u0010\u0006\"\u0004\b*\u0010\bR\u001c\u0010+\u001a\u0004\u0018\u00010\u0004X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b,\u0010\u0006\"\u0004\b-\u0010\bR\u001a\u0010.\u001a\u00020\u0004X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b/\u0010\u0006\"\u0004\b0\u0010\bR\u001c\u00101\u001a\u0004\u0018\u00010\u0004X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b2\u0010\u0006\"\u0004\b3\u0010\bR\u001c\u00104\u001a\u0004\u0018\u00010\u0004X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b5\u0010\u0006\"\u0004\b6\u0010\bR\u001a\u00107\u001a\u00020\nX\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b8\u0010\f\"\u0004\b9\u0010\u000eR\u001a\u0010:\u001a\u00020\u0004X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b;\u0010\u0006\"\u0004\b<\u0010\bR\u001a\u0010=\u001a\u00020>X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b?\u0010@\"\u0004\bA\u0010BR\u001a\u0010C\u001a\u00020\u0004X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\bD\u0010\u0006\"\u0004\bE\u0010\bR\u001a\u0010F\u001a\u00020\u0004X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\bG\u0010\u0006\"\u0004\bH\u0010\bR\u001a\u0010I\u001a\u00020\u001aX\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\bJ\u0010\u001c\"\u0004\bK\u0010\u001eR\u001a\u0010L\u001a\u00020\u001aX\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\bM\u0010\u001c\"\u0004\bN\u0010\u001eR\u001e\u0010O\u001a\u0004\u0018\u00010\u001aX\u0086\u000e¢\u0006\u0010\n\u0002\u0010T\u001a\u0004\bP\u0010Q\"\u0004\bR\u0010SR\u001a\u0010U\u001a\u00020\nX\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\bV\u0010\f\"\u0004\bW\u0010\u000eR\u001a\u0010X\u001a\u00020\u001aX\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\bY\u0010\u001c\"\u0004\bZ\u0010\u001e¨\u0006i"}, d2 = {"Lcom/github/shadowsocks/database/Profile;", "Ljava/io/Serializable;", "()V", "andid", "", "getAndid", "()Ljava/lang/String;", "setAndid", "(Ljava/lang/String;)V", "bypass", "", "getBypass", "()Z", "setBypass", "(Z)V", "dirty", "getDirty", "setDirty", "formattedAddress", "getFormattedAddress", "formattedName", "getFormattedName", com.alipay.sdk.cons.c.f, "getHost", "setHost", "id", "", "getId", "()J", "setId", "(J)V", "individual", "getIndividual", "setIndividual", "ipv6", "getIpv6", "setIpv6", "loginDownNode", "getLoginDownNode", "setLoginDownNode", com.alipay.sdk.packet.e.q, "getMethod", "setMethod", "name", "getName", "setName", "password", "getPassword", "setPassword", "pkgName", "getPkgName", "setPkgName", "plugin", "getPlugin", "setPlugin", "proxyApps", "getProxyApps", "setProxyApps", "remoteDns", "getRemoteDns", "setRemoteDns", "remotePort", "", "getRemotePort", "()I", "setRemotePort", "(I)V", "rid", "getRid", "setRid", "route", "getRoute", "setRoute", "rx", "getRx", "setRx", "tx", "getTx", "setTx", "udpFallback", "getUdpFallback", "()Ljava/lang/Long;", "setUdpFallback", "(Ljava/lang/Long;)V", "Ljava/lang/Long;", "udpdns", "getUdpdns", "setUdpdns", "userOrder", "getUserOrder", "setUserOrder", "copyFeatureSettingsTo", "", Scopes.PROFILE, "deserialize", "serialize", "toJson", "Lorg/json/JSONObject;", "profiles", "Landroid/util/LongSparseArray;", "toString", "toUri", "Landroid/net/Uri;", "Companion", "Dao", "core_release"}, k = 1, mv = {1, 1, 13})
public final class Profile implements Serializable {

    @PrimaryKey(autoGenerate = true)
    private long f15936b;
    private boolean j;
    private boolean k;
    private boolean l;
    private long o;
    private long p;
    private long q;

    @Nullable
    private String r;

    @Nullable
    private Long s;

    @Nullable
    private String t;

    @Nullable
    private String u;

    @Ignore
    private boolean w;

    @Nullable
    private String x;

    public static final a f15935a = new a(null);
    private static final Regex y = new Regex("(?i)ss://[-a-zA-Z0-9+&@#/%?=.~*'()|!:,;\\[\\]]*[-a-zA-Z0-9+&@#/%=.~*'()|\\[\\]]");
    private static final Regex z = new Regex("^(.+?):(.*)$");
    private static final Regex A = new Regex("^(.+?):(.*)@(.+?):(\\d+?)$");

    @Nullable
    private String c = "";

    @NotNull
    private String d = "198.199.101.152";
    private int e = 8388;

    @NotNull
    private String f = "u1rRWTssNv0p";

    @NotNull
    private String g = "aes-256-cfb";

    @NotNull
    private String h = "all";

    @NotNull
    private String i = "8.8.8.8";
    private boolean m = true;

    @NotNull
    private String n = "";

    @NotNull
    private String v = "0";

    @Dao
    @Metadata(bv = {1, 0, 3}, d1 = {"\u0000,\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\t\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0002\b\u0004\n\u0002\u0010\u000b\n\u0000\n\u0002\u0010 \n\u0002\b\u0004\bg\u0018\u00002\u00020\u0001J\u0010\u0010\u0002\u001a\u00020\u00032\u0006\u0010\u0004\u001a\u00020\u0005H'J\u0010\u0010\u0006\u001a\u00020\u00072\u0006\u0010\b\u001a\u00020\u0003H'J\b\u0010\t\u001a\u00020\u0007H'J\u0013\u0010\n\u001a\u0004\u0018\u00010\u00052\u0006\u0010\b\u001a\u00020\u0003H§\u0002J\b\u0010\u000b\u001a\u00020\fH'J\u000e\u0010\r\u001a\b\u0012\u0004\u0012\u00020\u00050\u000eH'J\u000f\u0010\u000f\u001a\u0004\u0018\u00010\u0003H'¢\u0006\u0002\u0010\u0010J\u0010\u0010\u0011\u001a\u00020\u00072\u0006\u0010\u0004\u001a\u00020\u0005H'¨\u0006\u0012"}, d2 = {"Lcom/github/shadowsocks/database/Profile$Dao;", "", "create", "", "value", "Lcom/github/shadowsocks/database/Profile;", "delete", "", "id", "deleteAll", "get", "isNotEmpty", "", "list", "", "nextOrder", "()Ljava/lang/Long;", RankingItem.KEY_UPDATE, "core_release"}, k = 1, mv = {1, 1, 13})
    public interface b {
        @Insert
        long a(@NotNull Profile profile);

        @Query("SELECT * FROM `Profile` WHERE `id` = :id")
        @Nullable
        Profile a(long j);

        @Query("SELECT * FROM `Profile` ORDER BY `userOrder`")
        @NotNull
        List<Profile> a();

        @Query("SELECT MAX(`userOrder`) + 1 FROM `Profile`")
        @Nullable
        Long b();

        @Query("SELECT 1 FROM `Profile` LIMIT 1")
        boolean c();

        @Query("DELETE FROM `Profile` WHERE `id` = :id")
        int delete(long id);

        @Update
        int update(@NotNull Profile profile);
    }

    @Metadata(bv = {1, 0, 3}, d1 = {"\u0000D\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\t\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\r\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\b\u0086\u0003\u0018\u00002\u00020\u0001:\u0001\u0016B\u0007\b\u0002¢\u0006\u0002\u0010\u0002J\"\u0010\u000b\u001a\b\u0012\u0004\u0012\u00020\r0\f2\b\u0010\u000e\u001a\u0004\u0018\u00010\u000f2\n\b\u0002\u0010\u0010\u001a\u0004\u0018\u00010\rJ.\u0010\u0011\u001a\u00020\u00122\u0006\u0010\u0013\u001a\u00020\u00042\n\b\u0002\u0010\u0010\u001a\u0004\u0018\u00010\r2\u0012\u0010\u0014\u001a\u000e\u0012\u0004\u0012\u00020\r\u0012\u0004\u0012\u00020\u00120\u0015R\u000e\u0010\u0003\u001a\u00020\u0004X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\u0005\u001a\u00020\u0006X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0007\u001a\u00020\u0006X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\b\u001a\u00020\tX\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\n\u001a\u00020\u0006X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\u0017"}, d2 = {"Lcom/github/shadowsocks/database/Profile$Companion;", "", "()V", "TAG", "", "legacyPattern", "Lkotlin/text/Regex;", "pattern", "serialVersionUID", "", "userInfoPattern", "findAllUrls", "Lkotlin/sequences/Sequence;", "Lcom/github/shadowsocks/database/Profile;", "data", "", "feature", "parseJson", "", "json", "create", "Lkotlin/Function1;", "JsonParser", "core_release"}, k = 1, mv = {1, 1, 13})
    public static final class a {
        private a() {
        }

        public a(g gVar) {
            this();
        }

        @Metadata(bv = {1, 0, 3}, d1 = {"\u0000\u000e\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\u0010\u0000\u001a\u0004\u0018\u00010\u00012\u0006\u0010\u0002\u001a\u00020\u0003H\n¢\u0006\u0002\b\u0004"}, d2 = {"<anonymous>", "Lcom/github/shadowsocks/database/Profile;", "it", "Lkotlin/text/MatchResult;", "invoke"}, k = 3, mv = {1, 1, 13})
        static final class b extends Lambda implements Function1<MatchResult, Profile> {

            final Profile f15939a;

            b(Profile profile) {
                super(1);
                this.f15939a = profile;
            }

            @Override
            @Nullable
            public final Profile invoke(@NotNull MatchResult matchResult) {
                Profile profile;
                Character d;
                k.b(matchResult, "it");
                Uri parse = Uri.parse(matchResult.a());
                k.a((Object) parse, "Uri.parse(this)");
                try {
                    if (parse.getUserInfo() == null) {
                        Regex regex = Profile.A;
                        byte[] decode = Base64.decode(parse.getHost(), 1);
                        k.a((Object) decode, "Base64.decode(uri.host, Base64.NO_PADDING)");
                        MatchResult b2 = regex.b(new String(decode, Charsets.f19034a));
                        if (b2 != null) {
                            profile = new Profile();
                            Profile profile2 = this.f15939a;
                            if (profile2 != null) {
                                profile2.a(profile);
                            }
                            String str = b2.b().get(1);
                            if (str == null) {
                                throw new TypeCastException("null cannot be cast to non-null type java.lang.String");
                            }
                            String lowerCase = str.toLowerCase();
                            k.a((Object) lowerCase, "(this as java.lang.String).toLowerCase()");
                            profile.d(lowerCase);
                            profile.c(b2.b().get(2));
                            profile.b(b2.b().get(3));
                            profile.a(Integer.parseInt(b2.b().get(4)));
                            profile.h(parse.getQueryParameter("plugin"));
                            profile.a(parse.getFragment());
                        } else {
                            Log.e("ShadowParser", "Unrecognized URI: " + matchResult.a());
                            return null;
                        }
                    } else {
                        Regex regex2 = Profile.z;
                        byte[] decode2 = Base64.decode(parse.getUserInfo(), 11);
                        k.a((Object) decode2, "Base64.decode(uri.userIn…_WRAP or Base64.URL_SAFE)");
                        MatchResult b3 = regex2.b(new String(decode2, Charsets.f19034a));
                        if (b3 != null) {
                            profile = new Profile();
                            Profile profile3 = this.f15939a;
                            if (profile3 != null) {
                                profile3.a(profile);
                            }
                            profile.d(b3.b().get(1));
                            profile.c(b3.b().get(2));
                            try {
                                URI uri = new URI(matchResult.a());
                                String host = uri.getHost();
                                if (host == null) {
                                    host = "";
                                }
                                profile.b(host);
                                Character c = m.c(profile.getD());
                                if (c != null && c.charValue() == '[' && (d = m.d(profile.getD())) != null && d.charValue() == ']') {
                                    String d2 = profile.getD();
                                    int length = profile.getD().length() - 1;
                                    if (d2 == null) {
                                        throw new TypeCastException("null cannot be cast to non-null type java.lang.String");
                                    }
                                    String substring = d2.substring(1, length);
                                    k.a((Object) substring, "(this as java.lang.Strin…ing(startIndex, endIndex)");
                                    profile.b(substring);
                                }
                                profile.a(uri.getPort());
                                profile.h(parse.getQueryParameter("plugin"));
                                String fragment = parse.getFragment();
                                if (fragment == null) {
                                    fragment = "";
                                }
                                profile.a(fragment);
                            } catch (URISyntaxException unused) {
                                Log.e("ShadowParser", "Invalid URI: " + matchResult.a());
                                return null;
                            }
                        } else {
                            Log.e("ShadowParser", "Unknown user info: " + matchResult.a());
                            return null;
                        }
                    }
                    return profile;
                } catch (IllegalArgumentException unused2) {
                    Log.e("ShadowParser", "Invalid base64 detected: " + matchResult.a());
                    return null;
                }
            }
        }

        @NotNull
        public final Sequence<Profile> a(@Nullable CharSequence charSequence, @Nullable Profile profile) {
            Regex regex = Profile.y;
            if (charSequence == null) {
            }
            return j.c(j.b(Regex.b(regex, charSequence, 0, 2, null), new b(profile)));
        }

        @Metadata(bv = {1, 0, 3}, d1 = {"\u00006\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010%\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0000\b\u0002\u0018\u00002\b\u0012\u0004\u0012\u00020\u00020\u0001B\u0011\u0012\n\b\u0002\u0010\u0003\u001a\u0004\u0018\u00010\u0002¢\u0006\u0002\u0010\u0004J\u001a\u0010\u0007\u001a\u00020\b2\u0012\u0010\t\u001a\u000e\u0012\u0004\u0012\u00020\u0002\u0012\u0004\u0012\u00020\b0\nJ\u000e\u0010\u000b\u001a\u00020\b2\u0006\u0010\f\u001a\u00020\rJ\u001c\u0010\u000e\u001a\u0004\u0018\u00010\u00022\u0006\u0010\f\u001a\u00020\u000f2\b\b\u0002\u0010\u0010\u001a\u00020\u0011H\u0002R\u001a\u0010\u0005\u001a\u000e\u0012\u0004\u0012\u00020\u0002\u0012\u0004\u0012\u00020\u00020\u0006X\u0082\u0004¢\u0006\u0002\n\u0000R\u0010\u0010\u0003\u001a\u0004\u0018\u00010\u0002X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\u0012"}, d2 = {"Lcom/github/shadowsocks/database/Profile$Companion$JsonParser;", "Ljava/util/ArrayList;", "Lcom/github/shadowsocks/database/Profile;", "feature", "(Lcom/github/shadowsocks/database/Profile;)V", "fallbackMap", "", "finalize", "", "create", "Lkotlin/Function1;", UMModuleRegister.PROCESS, "json", "", "tryParse", "Lorg/json/JSONObject;", "fallback", "", "core_release"}, k = 1, mv = {1, 1, 13})
        private static final class C0636a extends ArrayList<Profile> {

            private final Map<Profile, Profile> f15937a;

            private final Profile f15938b;

            public C0636a() {
                this(null, 1, 0 == true ? 1 : 0);
            }

            public C0636a(@Nullable Profile profile) {
                this.f15938b = profile;
                this.f15937a = new LinkedHashMap();
            }

            public C0636a(Profile profile, int i, g gVar) {
                this((i & 1) != 0 ? (Profile) null : profile);
            }

            public int a() {
                return super.size();
            }

            public boolean a(Profile profile) {
                return super.contains(profile);
            }

            public int b(Profile profile) {
                return super.indexOf(profile);
            }

            public int c(Profile profile) {
                return super.lastIndexOf(profile);
            }

            @Override
            public final boolean contains(Object obj) {
                if (obj instanceof Profile) {
                    return a((Profile) obj);
                }
                return false;
            }

            public boolean d(Profile profile) {
                return super.remove(profile);
            }

            @Override
            public final int indexOf(Object obj) {
                if (obj instanceof Profile) {
                    return b((Profile) obj);
                }
                return -1;
            }

            @Override
            public final int lastIndexOf(Object obj) {
                if (obj instanceof Profile) {
                    return c((Profile) obj);
                }
                return -1;
            }

            @Override
            public final boolean remove(Object obj) {
                if (obj instanceof Profile) {
                    return d((Profile) obj);
                }
                return false;
            }

            @Override
            public final int size() {
                return a();
            }

            static Profile a(C0636a c0636a, JSONObject jSONObject, boolean z, int i, Object obj) {
                if ((i & 2) != 0) {
                    z = false;
                }
                return c0636a.a(jSONObject, z);
            }

            private final Profile a(JSONObject jSONObject, boolean z) {
                int optInt;
                Profile a2;
                String n;
                Iterable<Object> a3;
                String optString = jSONObject.optString("server");
                String str = optString;
                if ((str == null || str.length() == 0) || (optInt = jSONObject.optInt("server_port")) <= 0) {
                    return null;
                }
                String optString2 = jSONObject.optString("password");
                String str2 = optString2;
                if (str2 == null || str2.length() == 0) {
                    return null;
                }
                String optString3 = jSONObject.optString(com.alipay.sdk.packet.e.q);
                String str3 = optString3;
                if (str3 == null || str3.length() == 0) {
                    return null;
                }
                Profile profile = new Profile();
                profile.b(optString);
                profile.a(optInt);
                profile.c(optString2);
                profile.d(optString3);
                Profile profile2 = this.f15938b;
                if (profile2 != null) {
                    profile2.a(profile);
                }
                String optString4 = jSONObject.optString("plugin");
                String str4 = optString4;
                if (!(str4 == null || str4.length() == 0)) {
                    profile.h(new PluginOptions(optString4, jSONObject.optString("plugin_opts")).a(false));
                }
                profile.a(jSONObject.optString("remarks"));
                String optString5 = jSONObject.optString("route", profile.getH());
                k.a((Object) optString5, "json.optString(\"route\", route)");
                profile.e(optString5);
                if (!z) {
                    String optString6 = jSONObject.optString("remote_dns", profile.getI());
                    k.a((Object) optString6, "json.optString(\"remote_dns\", remoteDns)");
                    profile.f(optString6);
                    profile.d(jSONObject.optBoolean("ipv6", profile.getM()));
                    JSONObject optJSONObject = jSONObject.optJSONObject("proxy_apps");
                    if (optJSONObject != null) {
                        profile.a(optJSONObject.optBoolean("enabled", profile.getJ()));
                        profile.b(optJSONObject.optBoolean("bypass", profile.getK()));
                        JSONArray optJSONArray = optJSONObject.optJSONArray("android_list");
                        if (optJSONArray == null || (a3 = com.github.shadowsocks.utils.b.a(optJSONArray)) == null || (n = kotlin.collections.m.a(a3, "\n", null, null, 0, null, null, 62, null)) == null) {
                            n = profile.getN();
                        }
                        profile.g(n);
                    }
                    profile.c(jSONObject.optBoolean("udpdns", profile.getL()));
                    JSONObject optJSONObject2 = jSONObject.optJSONObject("udp_fallback");
                    if (optJSONObject2 != null && (a2 = a(optJSONObject2, true)) != null) {
                        this.f15937a.put(profile, a2);
                    }
                }
                return profile;
            }

            public final void a(@NotNull Object obj) {
                k.b(obj, "json");
                if (obj instanceof JSONObject) {
                    JSONObject jSONObject = (JSONObject) obj;
                    Profile a2 = a(this, jSONObject, false, 2, null);
                    if (a2 != null) {
                        add(a2);
                        return;
                    }
                    Iterator<String> keys = jSONObject.keys();
                    k.a((Object) keys, "json.keys()");
                    while (keys.hasNext()) {
                        Object obj2 = jSONObject.get(keys.next());
                        k.a(obj2, "json.get(key)");
                        a(obj2);
                    }
                    return;
                }
                if (obj instanceof JSONArray) {
                    Iterator<Object> it = com.github.shadowsocks.utils.b.a((JSONArray) obj).iterator();
                    while (it.hasNext()) {
                        a(it.next());
                    }
                }
            }

            public final void a(@NotNull Function1<? super Profile, u> function1) {
                Object obj;
                Long valueOf;
                k.b(function1, "create");
                List<Profile> b2 = ProfileManager.f15946a.b();
                if (b2 == null) {
                    b2 = kotlin.collections.m.a();
                }
                for (Map.Entry<Profile, Profile> entry : this.f15937a.entrySet()) {
                    Profile key = entry.getKey();
                    Profile value = entry.getValue();
                    Iterator<T> it = b2.iterator();
                    while (true) {
                        if (!it.hasNext()) {
                            obj = null;
                            break;
                        }
                        obj = it.next();
                        Profile profile = (Profile) obj;
                        boolean z = true;
                        if (k.a((Object) value.getD(), (Object) profile.getD()) && value.getE() == profile.getE() && k.a((Object) value.getF(), (Object) profile.getF()) && k.a((Object) value.getG(), (Object) profile.getG())) {
                            String r = profile.getR();
                            if (r == null || r.length() == 0) {
                                if (!z) {
                                    break;
                                }
                            }
                        }
                        z = false;
                        if (!z) {
                        }
                    }
                    Profile profile2 = (Profile) obj;
                    if (profile2 == null) {
                        function1.invoke(value);
                        valueOf = Long.valueOf(value.getF15936b());
                    } else {
                        valueOf = Long.valueOf(profile2.getF15936b());
                    }
                    key.a(valueOf);
                    ProfileManager.f15946a.b(key);
                }
            }
        }

        public final void a(@NotNull String str, @Nullable Profile profile, @NotNull Function1<? super Profile, u> function1) {
            k.b(str, "json");
            k.b(function1, "create");
            C0636a c0636a = new C0636a(profile);
            Object nextValue = new JSONTokener(str).nextValue();
            k.a(nextValue, "JSONTokener(json).nextValue()");
            c0636a.a(nextValue);
            Iterator<Profile> it = c0636a.iterator();
            while (it.hasNext()) {
                Profile next = it.next();
                k.a((Object) next, Scopes.PROFILE);
                function1.invoke(next);
            }
            c0636a.a(function1);
        }
    }

    public final long getF15936b() {
        return this.f15936b;
    }

    public final void a(long j) {
        this.f15936b = j;
    }

    public final void a(@Nullable String str) {
        this.c = str;
    }

    @Nullable
    public final String getC() {
        return this.c;
    }

    public final void b(@NotNull String str) {
        k.b(str, "<set-?>");
        this.d = str;
    }

    @NotNull
    public final String getD() {
        return this.d;
    }

    public final void a(int i) {
        this.e = i;
    }

    public final int getE() {
        return this.e;
    }

    public final void c(@NotNull String str) {
        k.b(str, "<set-?>");
        this.f = str;
    }

    @NotNull
    public final String getF() {
        return this.f;
    }

    public final void d(@NotNull String str) {
        k.b(str, "<set-?>");
        this.g = str;
    }

    @NotNull
    public final String getG() {
        return this.g;
    }

    public final void e(@NotNull String str) {
        k.b(str, "<set-?>");
        this.h = str;
    }

    @NotNull
    public final String getH() {
        return this.h;
    }

    public final void f(@NotNull String str) {
        k.b(str, "<set-?>");
        this.i = str;
    }

    @NotNull
    public final String getI() {
        return this.i;
    }

    public final void a(boolean z2) {
        this.j = z2;
    }

    public final boolean getJ() {
        return this.j;
    }

    public final void b(boolean z2) {
        this.k = z2;
    }

    public final boolean getK() {
        return this.k;
    }

    public final void c(boolean z2) {
        this.l = z2;
    }

    public final boolean getL() {
        return this.l;
    }

    public final void d(boolean z2) {
        this.m = z2;
    }

    public final boolean getM() {
        return this.m;
    }

    public final void g(@NotNull String str) {
        k.b(str, "<set-?>");
        this.n = str;
    }

    @NotNull
    public final String getN() {
        return this.n;
    }

    public final void b(long j) {
        this.o = j;
    }

    public final long getO() {
        return this.o;
    }

    public final void c(long j) {
        this.p = j;
    }

    public final long getP() {
        return this.p;
    }

    public final void d(long j) {
        this.q = j;
    }

    public final long getQ() {
        return this.q;
    }

    public final void h(@Nullable String str) {
        this.r = str;
    }

    @Nullable
    public final String getR() {
        return this.r;
    }

    public final void a(@Nullable Long l) {
        this.s = l;
    }

    @Nullable
    public final Long getS() {
        return this.s;
    }

    public final void i(@Nullable String str) {
        this.t = str;
    }

    @Nullable
    public final String getT() {
        return this.t;
    }

    public final void j(@Nullable String str) {
        this.u = str;
    }

    @Nullable
    public final String getU() {
        return this.u;
    }

    public final void k(@NotNull String str) {
        k.b(str, "<set-?>");
        this.v = str;
    }

    @NotNull
    public final String getV() {
        return this.v;
    }

    public final void e(boolean z2) {
        this.w = z2;
    }

    public final boolean getW() {
        return this.w;
    }

    public final void l(@Nullable String str) {
        this.x = str;
    }

    @Nullable
    public final String getX() {
        return this.x;
    }

    @NotNull
    public final String x() {
        String str = m.a((CharSequence) this.d, (CharSequence) ":", false, 2, (Object) null) ? "[%s]:%d" : "%s:%d";
        Object[] objArr = {this.d, Integer.valueOf(this.e)};
        String format = String.format(str, Arrays.copyOf(objArr, objArr.length));
        k.a((Object) format, "java.lang.String.format(this, *args)");
        return format;
    }

    @NotNull
    public final String y() {
        String str = this.c;
        if (str == null || str.length() == 0) {
            return "";
        }
        String str2 = this.c;
        if (str2 != null) {
            return str2;
        }
        k.a();
        return str2;
    }

    public final void a(@NotNull Profile profile) {
        k.b(profile, Scopes.PROFILE);
        profile.h = this.h;
        profile.m = this.m;
        profile.j = this.j;
        profile.k = this.k;
        profile.n = this.n;
        profile.l = this.l;
    }

    @NotNull
    public final Uri z() {
        String str;
        Uri.Builder scheme = new Uri.Builder().scheme("ss");
        Locale locale = Locale.ENGLISH;
        k.a((Object) locale, "Locale.ENGLISH");
        Object[] objArr = new Object[3];
        String str2 = this.g + ':' + this.f;
        Charset charset = Charsets.f19034a;
        if (str2 == null) {
            throw new TypeCastException("null cannot be cast to non-null type java.lang.String");
        }
        byte[] bytes = str2.getBytes(charset);
        k.a((Object) bytes, "(this as java.lang.String).getBytes(charset)");
        objArr[0] = Base64.encodeToString(bytes, 11);
        if (m.a((CharSequence) this.d, ':', false, 2, (Object) null)) {
            str = '[' + this.d + ']';
        } else {
            str = this.d;
        }
        boolean z2 = true;
        objArr[1] = str;
        objArr[2] = Integer.valueOf(this.e);
        String format = String.format(locale, "%s@%s:%d", Arrays.copyOf(objArr, objArr.length));
        k.a((Object) format, "java.lang.String.format(locale, this, *args)");
        Uri.Builder encodedAuthority = scheme.encodedAuthority(format);
        String str3 = this.r;
        if (str3 == null) {
            str3 = "";
        }
        PluginConfiguration pluginConfiguration = new PluginConfiguration(str3);
        if (pluginConfiguration.getF16051b().length() > 0) {
            encodedAuthority.appendQueryParameter("plugin", pluginConfiguration.a().a(false));
        }
        String str4 = this.c;
        if (str4 != null && str4.length() != 0) {
            z2 = false;
        }
        if (!z2) {
            encodedAuthority.fragment(this.c);
        }
        Uri build = encodedAuthority.build();
        k.a((Object) build, "builder.build()");
        return build;
    }

    @NotNull
    public String toString() {
        String uri = z().toString();
        k.a((Object) uri, "toUri().toString()");
        return uri;
    }

    @NotNull
    public static JSONObject a(Profile profile, LongSparseArray longSparseArray, int i, Object obj) {
        if ((i & 1) != 0) {
            longSparseArray = (LongSparseArray) null;
        }
        return profile.a((LongSparseArray<Profile>) longSparseArray);
    }

    @NotNull
    public final JSONObject a(@Nullable LongSparseArray<Profile> longSparseArray) {
        Profile profile;
        JSONObject jSONObject = new JSONObject();
        jSONObject.put("server", this.d);
        jSONObject.put("server_port", this.e);
        jSONObject.put("password", this.f);
        jSONObject.put(com.alipay.sdk.packet.e.q, this.g);
        if (longSparseArray != null) {
            String str = this.r;
            if (str == null) {
                str = "";
            }
            PluginOptions a2 = new PluginConfiguration(str).a();
            if (a2.getF16059a().length() > 0) {
                jSONObject.put("plugin", a2.getF16059a());
                jSONObject.put("plugin_opts", a2.toString());
            }
            jSONObject.put("remarks", this.c);
            jSONObject.put("route", this.h);
            jSONObject.put("remote_dns", this.i);
            jSONObject.put("ipv6", this.m);
            JSONObject jSONObject2 = new JSONObject();
            jSONObject2.put("enabled", this.j);
            if (this.j) {
                jSONObject2.put("bypass", this.k);
                jSONObject2.put("android_list", new JSONArray((Collection) m.b((CharSequence) this.n, new String[]{"\n"}, false, 0, 6, (Object) null)));
            }
            jSONObject.put("proxy_apps", jSONObject2);
            jSONObject.put("udpdns", this.l);
            Long l = this.s;
            if (l != null && (profile = longSparseArray.get(l.longValue())) != null) {
                String str2 = profile.r;
                if (str2 == null || str2.length() == 0) {
                    jSONObject.put("udp_fallback", a(profile, null, 1, null));
                }
            }
        }
        return jSONObject;
    }

    public final void A() {
        DataStore.f16084b.a(Long.valueOf(this.f15936b));
        DataStore.f16084b.b().putString("profileName", this.c);
        DataStore.f16084b.b().putString("proxy", this.d);
        DataStore.f16084b.b().putString("remotePortNum", String.valueOf(this.e));
        DataStore.f16084b.b().putString("sitekey", this.f);
        DataStore.f16084b.b().putString("route", this.h);
        DataStore.f16084b.b().putString("remoteDns", this.i);
        DataStore.f16084b.b().putString("encMethod", this.g);
        DataStore.f16084b.a(this.j);
        DataStore.f16084b.b(this.k);
        DataStore.f16084b.b().putBoolean("isUdpDns", this.l);
        DataStore.f16084b.b().putBoolean("isIpv6", this.m);
        DataStore.f16084b.c(this.n);
        DataStore dataStore = DataStore.f16084b;
        String str = this.r;
        if (str == null) {
            str = "";
        }
        dataStore.d(str);
        DataStore.f16084b.b(this.s);
        DataStore.f16084b.b().g("profileDirty");
    }

    public final void B() {
        boolean z2;
        if (this.f15936b != 0) {
            Long p = DataStore.f16084b.p();
            long j = this.f15936b;
            if (p == null || p.longValue() != j) {
                z2 = false;
                if (z2) {
                    throw new IllegalStateException("Check failed.".toString());
                }
                DataStore.f16084b.a((Long) null);
                String e = DataStore.f16084b.b().e("profileName");
                if (e == null) {
                    e = "";
                }
                this.c = e;
                String e2 = DataStore.f16084b.b().e("proxy");
                if (e2 == null) {
                    e2 = "";
                }
                this.d = e2;
                this.e = h.a(DataStore.f16084b.b().e("remotePortNum"), 8388, 1);
                String e3 = DataStore.f16084b.b().e("sitekey");
                if (e3 == null) {
                    e3 = "";
                }
                this.f = e3;
                String e4 = DataStore.f16084b.b().e("encMethod");
                if (e4 == null) {
                    e4 = "";
                }
                this.g = e4;
                String e5 = DataStore.f16084b.b().e("route");
                if (e5 == null) {
                    e5 = "";
                }
                this.h = e5;
                String e6 = DataStore.f16084b.b().e("remoteDns");
                if (e6 == null) {
                    e6 = "";
                }
                this.i = e6;
                this.j = DataStore.f16084b.q();
                this.k = DataStore.f16084b.r();
                this.l = DataStore.f16084b.b().getBoolean("isUdpDns", false);
                this.m = DataStore.f16084b.b().getBoolean("isIpv6", false);
                this.n = DataStore.f16084b.s();
                this.r = DataStore.f16084b.t();
                this.s = DataStore.f16084b.u();
                return;
            }
        }
        z2 = true;
        if (z2) {
        }
    }
}