package com.applovin.impl; import android.text.TextUtils; import android.util.Base64; import com.applovin.impl.sdk.utils.StringUtils; import java.io.UnsupportedEncodingException; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes.dex */ public class w { private final com.applovin.impl.sdk.j a; private final String b; public String b() { return this.b; } public enum a { UNSPECIFIED("UNSPECIFIED"), REGULAR("REGULAR"), AD_RESPONSE_JSON("AD_RESPONSE_JSON"); private final String a; @Override // java.lang.Enum public String toString() { return this.a; } a(String str) { this.a = str; } } public w(String str, com.applovin.impl.sdk.j jVar) { if (TextUtils.isEmpty(str)) { throw new IllegalArgumentException("Identifier is empty"); } if (jVar == null) { throw new IllegalArgumentException("No sdk specified"); } this.b = str; this.a = jVar; } public a c() { if (a(sj.S0) != null) { return a.REGULAR; } if (a(sj.T0) != null) { return a.AD_RESPONSE_JSON; } return a.UNSPECIFIED; } public String d() { String a2 = a(sj.S0); if (!TextUtils.isEmpty(a2)) { return a2; } String a3 = a(sj.T0); if (TextUtils.isEmpty(a3)) { return null; } return a3; } public JSONObject a() { if (c() != a.AD_RESPONSE_JSON) { return null; } try { try { JSONObject jSONObject = new JSONObject(new String(Base64.decode(this.b.substring(d().length()), 0), "UTF-8")); this.a.J(); if (com.applovin.impl.sdk.n.a()) { this.a.J().a("AdToken", "Decoded token into ad response: " + jSONObject); } return jSONObject; } catch (JSONException e) { this.a.J(); if (com.applovin.impl.sdk.n.a()) { this.a.J().a("AdToken", "Unable to decode token '" + this.b + "' into JSON", e); } this.a.E().a("AdToken", "decodeFullAdResponseStr", e); return null; } } catch (UnsupportedEncodingException e2) { this.a.J(); if (com.applovin.impl.sdk.n.a()) { this.a.J().a("AdToken", "Unable to process ad response from token '" + this.b + "'", e2); } this.a.E().a("AdToken", "decodeFullAdResponse", e2); return null; } } public String toString() { return "AdToken{id=" + StringUtils.prefixToIndex(32, this.b) + ", type=" + c() + '}'; } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof w)) { return false; } String str = this.b; String str2 = ((w) obj).b; return str != null ? str.equals(str2) : str2 == null; } public int hashCode() { String str = this.b; if (str != null) { return str.hashCode(); } return 0; } private String a(sj sjVar) { for (String str : this.a.c(sjVar)) { if (this.b.startsWith(str)) { return str; } } return null; } }