package p138.p176.p291.p323.p324;

import android.content.SharedPreferences;
import android.util.Base64;
import android.util.Log;
import java.security.KeyFactory;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import org.json.JSONException;
import org.json.JSONObject;
import p138.p176.p291.C5559;

/* JADX INFO: renamed from: ދ.ހ.ށ.ފ.ލ.ؠ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public class C5984 {

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public static final String[] f16837 = {"*", "FCM", "GCM", ""};

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final SharedPreferences f16838;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final String f16839;

    /* JADX WARN: Removed duplicated region for block: B:12:0x003e  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public C5984(C5559 c5559) {
        c5559.m8928();
        this.f16838 = c5559.f15975.getSharedPreferences("com.google.android.gms.appid", 0);
        c5559.m8928();
        String str = c5559.f15977.f15991;
        if (str == null) {
            c5559.m8928();
            str = c5559.f15977.f15988;
            if (str.startsWith("1:") || str.startsWith("2:")) {
                String[] strArrSplit = str.split(":");
                if (strArrSplit.length != 4) {
                    str = null;
                } else {
                    str = strArrSplit[1];
                    if (str.isEmpty()) {
                    }
                }
            }
        }
        this.f16839 = str;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public String m9322() {
        synchronized (this.f16838) {
            String strM9323 = m9323();
            if (strM9323 != null) {
                return strM9323;
            }
            return m9324();
        }
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final String m9323() {
        String string;
        synchronized (this.f16838) {
            string = this.f16838.getString("|S|id", null);
        }
        return string;
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final String m9324() {
        PublicKey publicKeyGeneratePublic;
        synchronized (this.f16838) {
            String strEncodeToString = null;
            String string = this.f16838.getString("|S||P|", null);
            if (string == null) {
                return null;
            }
            try {
                publicKeyGeneratePublic = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(Base64.decode(string, 8)));
            } catch (IllegalArgumentException | NoSuchAlgorithmException | InvalidKeySpecException e) {
                Log.w("ContentValues", "Invalid key stored " + e);
                publicKeyGeneratePublic = null;
            }
            if (publicKeyGeneratePublic == null) {
                return null;
            }
            try {
                byte[] bArrDigest = MessageDigest.getInstance("SHA1").digest(publicKeyGeneratePublic.getEncoded());
                bArrDigest[0] = (byte) (((bArrDigest[0] & 15) + 112) & 255);
                strEncodeToString = Base64.encodeToString(bArrDigest, 0, 8, 11);
            } catch (NoSuchAlgorithmException unused) {
                Log.w("ContentValues", "Unexpected error, device missing required algorithms");
            }
            return strEncodeToString;
        }
    }

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public String m9325() {
        synchronized (this.f16838) {
            String[] strArr = f16837;
            int length = strArr.length;
            int i = 0;
            while (true) {
                String string = null;
                if (i >= length) {
                    return null;
                }
                String str = strArr[i];
                String string2 = this.f16838.getString("|T|" + this.f16839 + "|" + str, null);
                if (string2 != null && !string2.isEmpty()) {
                    if (string2.startsWith("{")) {
                        try {
                            string = new JSONObject(string2).getString("token");
                        } catch (JSONException unused) {
                        }
                        string2 = string;
                    }
                    return string2;
                }
                i++;
            }
        }
    }
}
