discord-jadx/app/src/main/java/c/i/a/f/c/a/f/b/a.java

193 lines
6.7 KiB
Java

package c.i.a.f.c.a.f.b;
import android.accounts.Account;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.text.TextUtils;
import androidx.annotation.Nullable;
import c.i.a.f.c.a.f.c;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.common.api.Scope;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/* compiled from: com.google.android.gms:play-services-base@@17.3.0 */
public class a {
public static final Lock a = new ReentrantLock();
@Nullable
public static a b;
/* renamed from: c reason: collision with root package name */
public final Lock f1021c = new ReentrantLock();
public final SharedPreferences d;
public a(Context context) {
this.d = context.getSharedPreferences("com.google.android.gms.signin", 0);
}
public static a a(Context context) {
Objects.requireNonNull(context, "null reference");
Lock lock = a;
lock.lock();
try {
if (b == null) {
b = new a(context.getApplicationContext());
}
a aVar = b;
lock.unlock();
return aVar;
} catch (Throwable th) {
a.unlock();
throw th;
}
}
public static String f(String str, String str2) {
return c.d.b.a.a.g(c.d.b.a.a.m(str2, str.length() + 1), str, ":", str2);
}
@Nullable
public GoogleSignInAccount b() {
String g;
String g2 = g("defaultGoogleSignInAccount");
if (TextUtils.isEmpty(g2) || (g = g(f("googleSignInAccount", g2))) == null) {
return null;
}
try {
return GoogleSignInAccount.w0(g);
} catch (JSONException unused) {
return null;
}
}
@Nullable
public GoogleSignInOptions c() {
String g;
String g2 = g("defaultGoogleSignInAccount");
if (TextUtils.isEmpty(g2) || (g = g(f("googleSignInOptions", g2))) == null) {
return null;
}
try {
return GoogleSignInOptions.w0(g);
} catch (JSONException unused) {
return null;
}
}
public void d(GoogleSignInAccount googleSignInAccount, GoogleSignInOptions googleSignInOptions) {
Objects.requireNonNull(googleSignInAccount, "null reference");
Objects.requireNonNull(googleSignInOptions, "null reference");
e("defaultGoogleSignInAccount", googleSignInAccount.q);
String str = googleSignInAccount.q;
String f = f("googleSignInAccount", str);
JSONObject jSONObject = new JSONObject();
try {
String str2 = googleSignInAccount.j;
if (str2 != null) {
jSONObject.put("id", str2);
}
String str3 = googleSignInAccount.k;
if (str3 != null) {
jSONObject.put("tokenId", str3);
}
String str4 = googleSignInAccount.l;
if (str4 != null) {
jSONObject.put("email", str4);
}
String str5 = googleSignInAccount.m;
if (str5 != null) {
jSONObject.put("displayName", str5);
}
String str6 = googleSignInAccount.f2280s;
if (str6 != null) {
jSONObject.put("givenName", str6);
}
String str7 = googleSignInAccount.t;
if (str7 != null) {
jSONObject.put("familyName", str7);
}
Uri uri = googleSignInAccount.n;
if (uri != null) {
jSONObject.put("photoUrl", uri.toString());
}
String str8 = googleSignInAccount.o;
if (str8 != null) {
jSONObject.put("serverAuthCode", str8);
}
jSONObject.put("expirationTime", googleSignInAccount.p);
jSONObject.put("obfuscatedIdentifier", googleSignInAccount.q);
JSONArray jSONArray = new JSONArray();
List<Scope> list = googleSignInAccount.r;
Scope[] scopeArr = (Scope[]) list.toArray(new Scope[list.size()]);
Arrays.sort(scopeArr, c.i);
int i = 0;
for (Scope scope : scopeArr) {
jSONArray.put(scope.j);
}
jSONObject.put("grantedScopes", jSONArray);
jSONObject.remove("serverAuthCode");
e(f, jSONObject.toString());
String f2 = f("googleSignInOptions", str);
JSONObject jSONObject2 = new JSONObject();
try {
JSONArray jSONArray2 = new JSONArray();
Collections.sort(googleSignInOptions.p, GoogleSignInOptions.n);
ArrayList<Scope> arrayList = googleSignInOptions.p;
int size = arrayList.size();
while (i < size) {
Scope scope2 = arrayList.get(i);
i++;
jSONArray2.put(scope2.j);
}
jSONObject2.put("scopes", jSONArray2);
Account account = googleSignInOptions.q;
if (account != null) {
jSONObject2.put("accountName", account.name);
}
jSONObject2.put("idTokenRequested", googleSignInOptions.r);
jSONObject2.put("forceCodeForRefreshToken", googleSignInOptions.t);
jSONObject2.put("serverAuthRequested", googleSignInOptions.f2281s);
if (!TextUtils.isEmpty(googleSignInOptions.u)) {
jSONObject2.put("serverClientId", googleSignInOptions.u);
}
if (!TextUtils.isEmpty(googleSignInOptions.v)) {
jSONObject2.put("hostedDomain", googleSignInOptions.v);
}
e(f2, jSONObject2.toString());
} catch (JSONException e) {
throw new RuntimeException(e);
}
} catch (JSONException e2) {
throw new RuntimeException(e2);
}
}
public final void e(String str, String str2) {
this.f1021c.lock();
try {
this.d.edit().putString(str, str2).apply();
} finally {
this.f1021c.unlock();
}
}
@Nullable
public final String g(String str) {
this.f1021c.lock();
try {
return this.d.getString(str, null);
} finally {
this.f1021c.unlock();
}
}
}