package com.ironsource.sdk.controller; import android.content.Context; import com.ironsource.environment.StringUtils; import com.ironsource.hm; import com.ironsource.i9; import com.ironsource.mediationsdk.logger.IronLog; import com.ironsource.mj; import com.ironsource.rt; import com.ironsource.sdk.utils.Logger; import com.ironsource.wp; import java.util.Iterator; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes4.dex */ public class u { private static final String d = "u"; private static final String e = "updateToken"; private static final String f = "getToken"; private static final String g = "functionName"; private static final String h = "functionParams"; private static final String i = "success"; private static final String j = "fail"; private Context b; private hm a = new hm(); private rt c = new rt(); public static class b { String a; JSONObject b; String c; String d; private b() { } } public u(Context context) { this.b = context; } private b a(String str) throws JSONException { JSONObject jSONObject = new JSONObject(str); b bVar = new b(); bVar.a = jSONObject.optString("functionName"); bVar.b = jSONObject.optJSONObject("functionParams"); bVar.c = jSONObject.optString("success"); bVar.d = jSONObject.optString("fail"); return bVar; } private void a(b bVar, mj mjVar) { try { JSONObject a2 = this.c.a(); Iterator keys = a2.keys(); while (keys.hasNext()) { String next = keys.next(); Object obj = a2.get(next); if (obj instanceof String) { a2.put(next, StringUtils.encodeURI((String) obj)); } } mjVar.a(true, bVar.c, a2); } catch (Exception e2) { i9.d().a(e2); mjVar.a(false, bVar.d, e2.getMessage()); } } public void a(String str, mj mjVar) throws Exception { b a2 = a(str); if (e.equals(a2.a)) { a(a2.b, a2, mjVar); return; } if (f.equals(a2.a)) { a(a2, mjVar); return; } Logger.i(d, "unhandled API request " + str); } public void a(JSONObject jSONObject, b bVar, mj mjVar) { wp wpVar = new wp(); try { this.a.a(jSONObject); mjVar.a(true, bVar.c, wpVar); } catch (Exception e2) { i9.d().a(e2); IronLog.INTERNAL.error(e2.toString()); Logger.i(d, "updateToken exception " + e2.getMessage()); mjVar.a(false, bVar.d, wpVar); } } }