package com.tencent.mm.plugin.appbrand.jsapi.bluetooth;

import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.plugin.appbrand.jsapi.ah;
import com.tencent.mm.plugin.appbrand.jsapi.bluetooth.sdk.c.d;
import com.tencent.mm.plugin.appbrand.jsapi.c;
import com.tencent.mm.sdk.platformtools.ab;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

class o$a extends ah {
    private static final int CTRL_INDEX = 190;
    private static final String NAME = "onBluetoothDeviceFound";
    private static JSONObject hDD = new JSONObject();
    private static o$a hDI = new o$a();

    private o$a() {
    }

    static {
        AppMethodBeat.i(94211);
        AppMethodBeat.o(94211);
    }

    public static synchronized void a(c cVar, d dVar) {
        synchronized (o$a.class) {
            AppMethodBeat.i(94209);
            if (cVar == null) {
                ab.e("MicroMsg.JsApiStartBluetoothDevicesDiscovery", "OnBluetoothAdapterStateChangeEvent dispatch fail, service is null");
                AppMethodBeat.o(94209);
            } else {
                JSONArray jSONArray = new JSONArray();
                try {
                    jSONArray.put(dVar.aCq());
                } catch (JSONException e) {
                    ab.e("MicroMsg.JsApiStartBluetoothDevicesDiscovery", "put JSON data error : %s", new Object[]{e});
                }
                try {
                    hDD.remove("devices");
                    hDD.put("devices", jSONArray);
                } catch (JSONException e2) {
                    ab.e("MicroMsg.JsApiStartBluetoothDevicesDiscovery", "put JSON data error : %s", new Object[]{e2});
                }
                if (cVar == null) {
                    ab.w("MicroMsg.JsApiStartBluetoothDevicesDiscovery", "service is null, fail");
                    AppMethodBeat.o(94209);
                } else {
                    hDI.b(cVar, cVar.aBw()).AM(hDD.toString()).aCj();
                    ab.i("MicroMsg.JsApiStartBluetoothDevicesDiscovery", "OnBluetoothDeviceFoundEvent %s", new Object[]{hDD.toString()});
                    AppMethodBeat.o(94209);
                }
            }
        }
    }

    public static synchronized void a(c cVar, List<d> list) {
        synchronized (o$a.class) {
            AppMethodBeat.i(94210);
            if (cVar == null) {
                ab.e("MicroMsg.JsApiStartBluetoothDevicesDiscovery", "OnBluetoothAdapterStateChangeEvent dispatch fail, service is null");
                AppMethodBeat.o(94210);
            } else {
                JSONArray jSONArray = new JSONArray();
                for (d aCq : list) {
                    try {
                        jSONArray.put(aCq.aCq());
                    } catch (JSONException e) {
                        ab.e("MicroMsg.JsApiStartBluetoothDevicesDiscovery", "put JSON data error : %s", new Object[]{e});
                    }
                }
                try {
                    hDD.remove("devices");
                    hDD.put("devices", jSONArray);
                } catch (JSONException e2) {
                    ab.e("MicroMsg.JsApiStartBluetoothDevicesDiscovery", "put JSON data error : %s", new Object[]{e2});
                }
                if (cVar == null) {
                    ab.w("MicroMsg.JsApiStartBluetoothDevicesDiscovery", "service is null, fail");
                    AppMethodBeat.o(94210);
                } else {
                    hDI.b(cVar, cVar.aBw()).AM(hDD.toString()).aCj();
                    ab.i("MicroMsg.JsApiStartBluetoothDevicesDiscovery", "OnBluetoothDeviceFoundEvent %s", new Object[]{hDD.toString()});
                    AppMethodBeat.o(94210);
                }
            }
        }
    }
}
