package com.example.bbqtemperature.service;

import android.app.Service;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothAdapter.LeScanCallback;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCallback;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService;
import android.bluetooth.BluetoothManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;
import com.example.bbqtemperature.p029a.C0359b;
import com.example.bbqtemperature.p032d.C0458a;
import com.example.bbqtemperature.p032d.C0459b;
import com.example.bbqtemperature.p033e.C0461b;
import com.example.bbqtemperature.p033e.C0463d;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import p000a.p001a.p002a.C0001a.C0000a;
import qlnet.com.easybbq.R;

public class MyBbqBleService extends Service {
    /* renamed from: A */
    private BluetoothGatt f1292A;
    /* renamed from: B */
    private BluetoothGattService f1293B;
    /* renamed from: C */
    private BluetoothGattCharacteristic f1294C;
    /* renamed from: D */
    private BluetoothGattCharacteristic f1295D;
    /* renamed from: E */
    private BluetoothGattCharacteristic f1296E;
    /* renamed from: F */
    private BluetoothGattCharacteristic f1297F;
    /* renamed from: G */
    private boolean f1298G = true;
    /* renamed from: H */
    private final int f1299H = 24;
    /* renamed from: I */
    private final int f1300I = 23;
    /* renamed from: J */
    private final int f1301J = 22;
    /* renamed from: K */
    private final int f1302K = 21;
    /* renamed from: L */
    private final int f1303L = 20;
    /* renamed from: M */
    private final int f1304M = 30000;
    /* renamed from: N */
    private boolean f1305N = true;
    /* renamed from: O */
    private BbqThermometer f1306O;
    /* renamed from: P */
    private C0485a f1307P;
    /* renamed from: Q */
    private boolean f1308Q = true;
    /* renamed from: R */
    private int f1309R;
    /* renamed from: S */
    private final String f1310S = "iBBQ";
    /* renamed from: T */
    private final String f1311T = "GrillEye";
    /* renamed from: U */
    private int f1312U = -1;
    /* renamed from: V */
    private int f1313V = 0;
    /* renamed from: W */
    private int f1314W = 0;
    /* renamed from: X */
    private Queue<Runnable> f1315X = new ArrayBlockingQueue(20);
    /* renamed from: Y */
    private List<Integer> f1316Y = new ArrayList();
    /* renamed from: Z */
    private SharedPreferences f1317Z;
    /* renamed from: a */
    private String f1318a = getClass().getSimpleName();
    private Editor aa;
    private boolean ab = true;
    private C0359b ac;
    private ExecutorService ad = Executors.newSingleThreadScheduledExecutor();
    private Handler ae = new C04641(this);
    private BluetoothGattCallback af = new C04748(this);
    private LeScanCallback ag = new C04769(this);
    private Runnable ah = new C04717(this);
    private C0486b ai;
    private int aj = 0;
    /* renamed from: b */
    private Timer f1319b;
    /* renamed from: c */
    private C0458a f1320c;
    /* renamed from: d */
    private C0459b f1321d;
    /* renamed from: e */
    private final byte[] f1322e = new byte[]{(byte) 32, (byte) 7, (byte) 6, (byte) 5, (byte) 4, (byte) 3, (byte) 2, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 0};
    /* renamed from: f */
    private final byte[] f1323f = new byte[]{(byte) 33, (byte) 7, (byte) 6, (byte) 5, (byte) 4, (byte) 3, (byte) 2, (byte) 1, (byte) -72, (byte) 34, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0};
    /* renamed from: g */
    private final byte[] f1324g = new byte[]{(byte) 8, (byte) 36, (byte) 0, (byte) 0, (byte) 0, (byte) 0};
    /* renamed from: h */
    private final byte[] f1325h = new byte[]{(byte) 8, (byte) 35, (byte) 0, (byte) 0, (byte) 0, (byte) 0};
    /* renamed from: i */
    private final byte[] f1326i = new byte[]{(byte) 2, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 0};
    /* renamed from: j */
    private final byte[] f1327j = new byte[]{(byte) 2, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0};
    /* renamed from: k */
    private final byte[] f1328k = new byte[]{(byte) -3, (byte) 1, (byte) 1, (byte) 1, (byte) 0, (byte) 0};
    /* renamed from: l */
    private final byte[] f1329l = new byte[]{(byte) -3, (byte) 1, (byte) 0, (byte) 1, (byte) 0, (byte) 0};
    /* renamed from: m */
    private final byte[] f1330m = new byte[]{(byte) 11, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 0};
    /* renamed from: n */
    private final byte[] f1331n = new byte[]{(byte) 4, (byte) -1, (byte) 0, (byte) 0, (byte) 0, (byte) 0};
    /* renamed from: o */
    private final byte[] f1332o = new byte[]{(byte) -1, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 0};
    /* renamed from: p */
    private final String[] f1333p = new String[]{"com.example.bbqtemperature.SERVICE_CH0", "com.example.bbqtemperature.SERVICE_CH1", "com.example.bbqtemperature.SERVICE_CH2", "com.example.bbqtemperature.SERVICE_CH3", "com.example.bbqtemperature.SERVICE_CH4", "com.example.bbqtemperature.SERVICE_CH5"};
    /* renamed from: q */
    private final String[] f1334q = new String[]{"com.example.bbqtemperature.CH0_NODATA", "com.example.bbqtemperature.CH1_NODATA", "com.example.bbqtemperature.CH2_NODATA", "com.example.bbqtemperature.CH3_NODATA", "com.example.bbqtemperature.CH4_NODATA", "com.example.bbqtemperature.CH5_NODATA"};
    /* renamed from: r */
    private final int f1335r = -90;
    /* renamed from: s */
    private final int f1336s = -100;
    /* renamed from: t */
    private int f1337t = 300;
    /* renamed from: u */
    private int f1338u = 1;
    /* renamed from: v */
    private int f1339v = 1;
    /* renamed from: w */
    private int f1340w = 0;
    /* renamed from: x */
    private BluetoothManager f1341x;
    /* renamed from: y */
    private BluetoothAdapter f1342y;
    /* renamed from: z */
    private String f1343z;

    /* renamed from: com.example.bbqtemperature.service.MyBbqBleService$1 */
    class C04641 extends Handler {
        /* renamed from: a */
        final /* synthetic */ MyBbqBleService f1262a;

        C04641(MyBbqBleService myBbqBleService) {
            this.f1262a = myBbqBleService;
        }

        public void handleMessage(Message message) {
            switch (message.what) {
                case 20:
                    this.f1262a.m1762e();
                    return;
                case 22:
                    this.f1262a.f1342y.startLeScan(this.f1262a.ag);
                    return;
                case 24:
                    this.f1262a.m1758d();
                    return;
                default:
                    return;
            }
        }
    }

    /* renamed from: com.example.bbqtemperature.service.MyBbqBleService$2 */
    class C04652 implements Runnable {
        /* renamed from: a */
        final /* synthetic */ MyBbqBleService f1263a;

        C04652(MyBbqBleService myBbqBleService) {
            this.f1263a = myBbqBleService;
        }

        public void run() {
            this.f1263a.m1781n();
        }
    }

    /* renamed from: com.example.bbqtemperature.service.MyBbqBleService$3 */
    class C04663 implements Runnable {
        /* renamed from: a */
        final /* synthetic */ MyBbqBleService f1264a;

        C04663(MyBbqBleService myBbqBleService) {
            this.f1264a = myBbqBleService;
        }

        public void run() {
            this.f1264a.m1786p();
        }
    }

    /* renamed from: com.example.bbqtemperature.service.MyBbqBleService$4 */
    class C04674 implements Runnable {
        /* renamed from: a */
        final /* synthetic */ MyBbqBleService f1265a;

        C04674(MyBbqBleService myBbqBleService) {
            this.f1265a = myBbqBleService;
        }

        public void run() {
            this.f1265a.m1772i();
        }
    }

    /* renamed from: com.example.bbqtemperature.service.MyBbqBleService$5 */
    class C04685 implements Runnable {
        /* renamed from: a */
        final /* synthetic */ MyBbqBleService f1266a;

        C04685(MyBbqBleService myBbqBleService) {
            this.f1266a = myBbqBleService;
        }

        public void run() {
            this.f1266a.m1770h();
        }
    }

    /* renamed from: com.example.bbqtemperature.service.MyBbqBleService$6 */
    class C04696 implements Runnable {
        /* renamed from: a */
        final /* synthetic */ MyBbqBleService f1267a;

        C04696(MyBbqBleService myBbqBleService) {
            this.f1267a = myBbqBleService;
        }

        public void run() {
            this.f1267a.m1772i();
        }
    }

    /* renamed from: com.example.bbqtemperature.service.MyBbqBleService$7 */
    class C04717 implements Runnable {
        /* renamed from: a */
        final /* synthetic */ MyBbqBleService f1269a;

        /* renamed from: com.example.bbqtemperature.service.MyBbqBleService$7$1 */
        class C04701 implements Runnable {
            /* renamed from: a */
            final /* synthetic */ C04717 f1268a;

            C04701(C04717 c04717) {
                this.f1268a = c04717;
            }

            public void run() {
                this.f1268a.f1269a.m1773j();
            }
        }

        C04717(MyBbqBleService myBbqBleService) {
            this.f1269a = myBbqBleService;
        }

        public void run() {
            if (this.f1269a.f1292A != null && this.f1269a.f1297F != null && this.f1269a.f1308Q && this.f1269a.f1306O.m1698e()) {
                try {
                    this.f1269a.f1315X.add(new C04701(this));
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (this.f1269a.f1315X.size() == 1) {
                    this.f1269a.m1773j();
                }
                this.f1269a.ae.postDelayed(this, 300000);
            }
        }
    }

    /* renamed from: com.example.bbqtemperature.service.MyBbqBleService$8 */
    class C04748 extends BluetoothGattCallback {
        /* renamed from: a */
        final /* synthetic */ MyBbqBleService f1272a;

        /* renamed from: com.example.bbqtemperature.service.MyBbqBleService$8$1 */
        class C04721 implements Runnable {
            /* renamed from: a */
            final /* synthetic */ C04748 f1270a;

            C04721(C04748 c04748) {
                this.f1270a = c04748;
            }

            public void run() {
                this.f1270a.f1272a.m1758d();
            }
        }

        /* renamed from: com.example.bbqtemperature.service.MyBbqBleService$8$2 */
        class C04732 implements Runnable {
            /* renamed from: a */
            final /* synthetic */ C04748 f1271a;

            C04732(C04748 c04748) {
                this.f1271a = c04748;
            }

            public void run() {
                this.f1271a.f1272a.m1772i();
            }
        }

        C04748(MyBbqBleService myBbqBleService) {
            this.f1272a = myBbqBleService;
        }

        public void onCharacteristicChanged(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic) {
            int i = 0;
            String str = bluetoothGattCharacteristic.getUuid() + ":";
            String str2 = str;
            for (byte toHexString : bluetoothGattCharacteristic.getValue()) {
                str2 = str2 + Integer.toHexString(toHexString) + ", ";
            }
            byte[] value;
            short a;
            if (bluetoothGattCharacteristic.getUuid().equals(this.f1272a.f1294C.getUuid())) {
                value = bluetoothGattCharacteristic.getValue();
                if (value[0] == (byte) 32) {
                    Log.i("value[0]", "0x20   配对密钥");
                    this.f1272a.f1309R = C0463d.m1682a(value, 1);
                    this.f1272a.aa.putInt("MIYAO", this.f1272a.f1309R).apply();
                    this.f1272a.f1315X.add(new C04732(this));
                    if (this.f1272a.f1315X.size() == 1) {
                        this.f1272a.m1772i();
                    }
                } else if (value[0] == (byte) 33) {
                    Log.i("TAG", "0x21");
                    if (value[1] == (byte) 0) {
                        this.f1272a.sendBroadcast(new Intent("com.example.bbqtemperature.SERVICE_PAIR_MIYAO"));
                        Log.e("value[1]", "0x00");
                        if (!this.f1272a.f1343z.equals(this.f1272a.f1306O.m1695c())) {
                            this.f1272a.f1306O.m1690a(this.f1272a.f1343z);
                        }
                        this.f1272a.m1742a("com.example.bbqtemperature.SERVICE_YANZHENG");
                        this.f1272a.aa.putInt("MIYAO", C0463d.m1682a(new byte[]{(byte) -72, (byte) 34, (byte) 0, (byte) 0}, 0));
                        this.f1272a.aa.commit();
                        this.f1272a.m1789r();
                        this.f1272a.f1320c.m1660b(0);
                        this.f1272a.f1306O.m1696c(true);
                        this.f1272a.f1306O.m1691a(false);
                        Log.e(this.f1272a.f1318a, "connect success!");
                        this.f1272a.ae.sendEmptyMessageDelayed(20, 1500);
                        this.f1272a.f1305N = true;
                    } else if (value[1] == (byte) 1) {
                        Log.i(this.f1272a.f1318a, "connect fail");
                    } else {
                        Log.i(this.f1272a.f1318a, "what's this");
                        this.f1272a.m1742a("com.example.bbqtemperature.SERVICE_CONNECT_FAILED");
                    }
                } else if (value[0] == (byte) 35) {
                    this.f1272a.f1339v = value[1];
                    this.f1272a.f1340w = value[2];
                    if (this.f1272a.f1339v > 3 || (this.f1272a.f1339v == 3 && this.f1272a.f1340w >= 2)) {
                        this.f1272a.f1338u = 0;
                    } else {
                        this.f1272a.f1338u = 1;
                    }
                    if (this.f1272a.f1339v >= 3 && "easybbq".equals("newbbqtest")) {
                        this.f1272a.f1338u = -20;
                    }
                    this.f1272a.aa.putInt("mainVersions", value[1]);
                    this.f1272a.aa.putInt("secondVersions", value[2]);
                    this.f1272a.aa.commit();
                } else if (value[0] == (byte) 36) {
                    a = MyBbqBleService.m1730a(value, 1);
                    short a2 = MyBbqBleService.m1730a(value, 3);
                    Log.i(this.f1272a.f1318a, "onCharacteristicChanged: fullBattery: " + a2);
                    if (a2 == (short) 0) {
                        a2 = (short) 6550;
                    }
                    this.f1272a.aa.putInt("FULL_DIAN", a2).commit();
                    Intent intent = new Intent("com.example.bbqtemperature.SERVICE_DIANYA");
                    intent.putExtra("INTENT_DIANYA", a);
                    intent.putExtra("INTENT_FULL_DIANYA", a2);
                    this.f1272a.sendBroadcast(intent);
                } else if (value[0] != (byte) -1 && value[0] == (byte) 4 && value[1] == (byte) -1) {
                    this.f1272a.f1320c.m1657a();
                }
            } else if (bluetoothGattCharacteristic.getUuid().equals(this.f1272a.f1296E.getUuid())) {
                value = bluetoothGattCharacteristic.getValue();
                if (this.f1272a.f1298G) {
                    this.f1272a.aa.putInt("PROBE_COUNT", value.length / 2);
                    this.f1272a.aa.commit();
                    this.f1272a.f1298G = false;
                    this.f1272a.sendBroadcast(new Intent("INTENT_GET_TEMP"));
                }
                while (i < value.length) {
                    a = (short) ((int) Math.round(((double) MyBbqBleService.m1730a(value, i)) / 10.0d));
                    Log.i(this.f1272a.f1318a, "onCharacteristicChanged: t: " + a);
                    if (a < this.f1272a.f1338u || a > this.f1272a.f1337t) {
                        this.f1272a.m1742a(this.f1272a.f1334q[i / 2]);
                    } else {
                        this.f1272a.m1743a(this.f1272a.f1333p[i / 2], a);
                        this.f1272a.f1321d.m1666a((i / 2) + 1, a);
                    }
                    i += 2;
                }
            }
        }

        public void onCharacteristicWrite(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, int i) {
            Log.e(this.f1272a.f1318a, "characteristic:status: " + i + ">>>UUid: " + bluetoothGattCharacteristic.getUuid());
            if (bluetoothGattCharacteristic.getUuid().equals(this.f1272a.f1297F.getUuid())) {
                if (i == 0) {
                    this.f1272a.f1315X.remove();
                }
                Log.e(this.f1272a.f1318a, "ff5 queue size: " + this.f1272a.f1315X.size());
                if (this.f1272a.f1315X.size() > 0) {
                    this.f1272a.ad.submit((Runnable) this.f1272a.f1315X.element());
                } else {
                    Log.i(this.f1272a.f1318a, "onReceive: forceconnect false");
                }
            } else if (i == 0) {
                this.f1272a.f1315X.remove();
                Log.e(this.f1272a.f1318a, "!ff5 queue size: " + this.f1272a.f1315X.size());
            } else {
                this.f1272a.ad.submit((Runnable) this.f1272a.f1315X.element());
            }
        }

        public void onConnectionStateChange(BluetoothGatt bluetoothGatt, int i, int i2) {
            Log.e(this.f1272a.f1318a, "status: " + i + ",new status: " + i2);
            if (i == 0 && i2 == 2) {
                Log.e("tag", "has connected");
                this.f1272a.f1315X.clear();
                this.f1272a.f1313V = 0;
                this.f1272a.f1314W = 0;
                if (this.f1272a.f1292A != null) {
                    Log.e("TAG", "开始发现服务");
                    bluetoothGatt.discoverServices();
                    return;
                }
                return;
            }
            this.f1272a.m1802a();
            this.f1272a.ae.removeCallbacks(this.f1272a.ah);
            this.f1272a.f1315X.clear();
            Intent intent = new Intent("com.example.bbqtemperature.SERVICE_RSSI");
            intent.putExtra("INTENT_RSSI", -100);
            this.f1272a.sendBroadcast(intent);
            Log.e("TAG", "connected fail");
            if (this.f1272a.f1308Q) {
                if (!this.f1272a.f1306O.m1699f()) {
                    Log.i(this.f1272a.f1318a, "onConnectionStateChange: delayed 30s send connect fail");
                    this.f1272a.m1788q();
                }
                if (!this.f1272a.f1317Z.getBoolean("scan_have_data", false) || C0463d.m1683a(this.f1272a) || this.f1272a.f1306O.m1692a()) {
                    Log.i(this.f1272a.f1318a, "onConnectionStateChange: nothavedata or background or isfirstconnect");
                    this.f1272a.f1306O.m1696c(false);
                    this.f1272a.ae.post(new C04721(this));
                    return;
                }
                Log.i(this.f1272a.f1318a, "onConnectionStateChange: have data and forground");
                this.f1272a.m1791s();
                if (this.f1272a.f1306O.m1698e()) {
                    Log.i(this.f1272a.f1318a, "onConnectionStateChange: send broadcast mode action");
                    this.f1272a.sendBroadcast(new Intent("com.example.bbqtemperature.SERVICE_CONNECT_BROADCAST"));
                    this.f1272a.f1306O.m1701h();
                    return;
                }
                return;
            }
            this.f1272a.f1306O.m1696c(false);
        }

        public void onDescriptorWrite(BluetoothGatt bluetoothGatt, BluetoothGattDescriptor bluetoothGattDescriptor, int i) {
            Log.e(this.f1272a.f1318a, "onDescriptorWrite: " + i + " >>> UUID: " + bluetoothGattDescriptor.getUuid());
            if (i == 0) {
                this.f1272a.f1314W = this.f1272a.f1314W + 1;
            }
            Log.e(this.f1272a.f1318a, "notifyCount: " + this.f1272a.f1314W);
            switch (this.f1272a.f1314W) {
                case C0000a.WheelView_selectTextColor /*1*/:
                    this.f1272a.m1768g();
                    return;
                case C0000a.WheelView_otherTextColor /*2*/:
                    this.f1272a.m1776k();
                    return;
                default:
                    return;
            }
        }

        public void onReadRemoteRssi(BluetoothGatt bluetoothGatt, int i, int i2) {
            if (this.f1272a.f1316Y.size() == 5) {
                this.f1272a.f1316Y.remove(0);
                this.f1272a.f1316Y.add(Integer.valueOf(i));
            } else if (this.f1272a.f1316Y.size() < 5) {
                this.f1272a.f1316Y.add(Integer.valueOf(i));
            }
            int i3 = 0;
            for (int i4 = 0; i4 < this.f1272a.f1316Y.size(); i4++) {
                i3 += ((Integer) this.f1272a.f1316Y.get(i4)).intValue();
            }
            int size = i3 / this.f1272a.f1316Y.size();
            Intent intent = new Intent("com.example.bbqtemperature.SERVICE_RSSI");
            intent.putExtra("INTENT_RSSI", size);
            this.f1272a.sendBroadcast(intent);
        }

        public void onServicesDiscovered(BluetoothGatt bluetoothGatt, int i) {
            Log.i(this.f1272a.f1318a, "onServicesDiscovered: ");
            if (i != 0) {
                return;
            }
            if (bluetoothGatt == null || this.f1272a.f1292A == null) {
                Log.e(this.f1272a.f1318a, "gatt or mbluetoothgatt is null");
                return;
            }
            this.f1272a.f1293B = bluetoothGatt.getService(C0461b.f1211c);
            if (this.f1272a.f1293B == null) {
                Log.e(this.f1272a.f1318a, "not found this uuid: " + C0461b.f1211c);
                return;
            }
            this.f1272a.f1294C = this.f1272a.f1293B.getCharacteristic(C0461b.f1212d);
            this.f1272a.f1295D = this.f1272a.f1293B.getCharacteristic(C0461b.f1213e);
            this.f1272a.f1296E = this.f1272a.f1293B.getCharacteristic(C0461b.f1214f);
            this.f1272a.f1297F = this.f1272a.f1293B.getCharacteristic(C0461b.f1215g);
            this.f1272a.m1734a(this.f1272a.f1294C, true);
        }
    }

    /* renamed from: com.example.bbqtemperature.service.MyBbqBleService$9 */
    class C04769 implements LeScanCallback {
        /* renamed from: a */
        final /* synthetic */ MyBbqBleService f1275a;

        C04769(MyBbqBleService myBbqBleService) {
            this.f1275a = myBbqBleService;
        }

        /* renamed from: a */
        private int m1702a(byte[] bArr) {
            int i = 0;
            while (i < bArr.length - 1) {
                if (bArr[i + 1] == (byte) -1) {
                    return i;
                }
                i += bArr[i] + 1;
            }
            return -1;
        }

        /* renamed from: a */
        private void m1703a(final BluetoothDevice bluetoothDevice) {
            Log.e(this.f1275a.f1318a, "stopLeScanAndConnect: ");
            this.f1275a.m1794t();
            this.f1275a.ae.post(new Runnable(this) {
                /* renamed from: b */
                final /* synthetic */ C04769 f1274b;

                public void run() {
                    this.f1274b.f1275a.m1733a(bluetoothDevice);
                }
            });
            this.f1275a.f1343z = bluetoothDevice.getAddress();
        }

        public void onLeScan(BluetoothDevice bluetoothDevice, int i, byte[] bArr) {
            boolean z = false;
            if (bluetoothDevice.getName() != null) {
                String name = bluetoothDevice.getName();
                Log.i(this.f1275a.f1318a, "onLeScan: " + name + ", addr: " + bluetoothDevice.getAddress());
                int parseInt;
                int a;
                int i2;
                if (this.f1275a.f1306O.m1697d()) {
                    Log.i(this.f1275a.f1318a, "handleMessage: noaddress");
                    if (this.f1275a.f1305N) {
                        String string = this.f1275a.f1317Z.getString("bbq_name", "");
                        try {
                            parseInt = Integer.parseInt(string);
                        } catch (NumberFormatException e) {
                            parseInt = 0;
                        }
                        int i3;
                        if (name.startsWith("iBBQ")) {
                            if (name.equals("iBBQ")) {
                                a = m1702a(bArr);
                                if (a >= 0) {
                                    i2 = 0;
                                    for (i3 = 1; i3 <= 4; i3++) {
                                        i2 += bArr[(a + i3) + 1] & (255 << (i3 * 8));
                                    }
                                    Log.i(this.f1275a.f1318a, "onLeScan: deviceID: " + i2);
                                    i3 = (bArr[a] - 11) / 2;
                                    if (parseInt == i2 && i3 == this.f1275a.f1317Z.getInt("PROBE_COUNT", -1)) {
                                        Log.i(this.f1275a.f1318a, "onLeScan:have data 准备执行这个方法connect(device)");
                                        this.f1275a.aa.putBoolean("scan_have_data", true).apply();
                                        m1703a(bluetoothDevice);
                                        return;
                                    }
                                    return;
                                }
                                return;
                            } else if (name.equals("iBBQ" + string)) {
                                Log.i(this.f1275a.f1318a, "onLeScan:not have data 准备执行这个方法connect(device)");
                                this.f1275a.aa.putBoolean("scan_have_data", false).apply();
                                m1703a(bluetoothDevice);
                                return;
                            } else {
                                return;
                            }
                        } else if ("easybbq".equals("grilleye") && name.equals("GrillEye")) {
                            a = m1702a(bArr);
                            if (a >= 0) {
                                i2 = 0;
                                for (i3 = 1; i3 <= 4; i3++) {
                                    i2 += bArr[(a + i3) + 1] & (255 << (i3 * 8));
                                }
                                Log.i(this.f1275a.f1318a, "onLeScan: deviceID: " + i2);
                                i3 = (bArr[a] - 11) / 2;
                                if (parseInt == i2 && i3 == this.f1275a.f1317Z.getInt("PROBE_COUNT", -1)) {
                                    Log.i(this.f1275a.f1318a, "onLeScan:have data 准备执行这个方法connect(device)");
                                    this.f1275a.aa.putBoolean("scan_have_data", true).apply();
                                    m1703a(bluetoothDevice);
                                    return;
                                }
                                return;
                            }
                            return;
                        } else {
                            return;
                        }
                    }
                    Log.i(this.f1275a.f1318a, "onLeScan: isnotmatch");
                    if ("easybbq".equals("qtech")) {
                        Log.i(this.f1275a.f1318a, "onLeScan: isqtech");
                        if (name.equals("iBBQ")) {
                            parseInt = m1702a(bArr);
                            if (parseInt >= 0) {
                                Log.e(this.f1275a.f1318a, "onLeScan: " + parseInt + " " + bArr[parseInt + 5]);
                                if (bArr[parseInt + 5] == Byte.MIN_VALUE) {
                                    this.f1275a.aa.putBoolean("scan_have_data", true).apply();
                                    m1703a(bluetoothDevice);
                                    return;
                                }
                                return;
                            }
                            return;
                        }
                        return;
                    }
                    Log.i(this.f1275a.f1318a, "onLeScan: isnotqtech");
                    if (name.startsWith("iBBQ")) {
                        Log.i(this.f1275a.f1318a, "onLeScan: found bbq not exactmatch 准备执行这个方法connect(device)");
                        if (name.equals("iBBQ")) {
                            Log.i(this.f1275a.f1318a, "onLeScan: equalbbq");
                            parseInt = m1702a(bArr);
                            Log.i(this.f1275a.f1318a, "onLeScan: startIndex: " + parseInt);
                            if (parseInt >= 0) {
                                this.f1275a.aa.putBoolean("scan_have_data", true).apply();
                                Log.i(this.f1275a.f1318a, "onLeScan: putCount: " + this.f1275a.f1298G);
                                if (this.f1275a.f1298G) {
                                    this.f1275a.aa.putInt("PROBE_COUNT", (bArr[parseInt] - 11) / 2).commit();
                                    if (!"easybbq".equals("grilleye")) {
                                        Log.i(this.f1275a.f1318a, "onLeScan: send intentgettemp");
                                        this.f1275a.sendBroadcast(new Intent("INTENT_GET_TEMP"));
                                    }
                                }
                            } else {
                                Log.i(this.f1275a.f1318a, "onLeScan: notequalbbq");
                                this.f1275a.aa.putBoolean("scan_have_data", false).apply();
                            }
                        } else {
                            this.f1275a.aa.putBoolean("scan_have_data", false).apply();
                        }
                        m1703a(bluetoothDevice);
                        return;
                    } else if ("easybbq".equals("grilleye")) {
                        Log.i(this.f1275a.f1318a, "onLeScan: found bbq not exactmatch 准备执行这个方法connect(device)");
                        if (name.equals("GrillEye")) {
                            if (m1702a(bArr) >= 0) {
                                this.f1275a.aa.putBoolean("scan_have_data", true).apply();
                            } else {
                                this.f1275a.aa.putBoolean("scan_have_data", false).apply();
                            }
                            m1703a(bluetoothDevice);
                            return;
                        }
                        return;
                    } else {
                        return;
                    }
                }
                Log.e("tag", "has address");
                if (!bluetoothDevice.getAddress().equals(this.f1275a.f1306O.m1695c())) {
                    return;
                }
                if (this.f1275a.f1317Z.getBoolean("scan_have_data", false)) {
                    this.f1275a.m1789r();
                    this.f1275a.f1320c.m1660b(0);
                    this.f1275a.sendBroadcast(new Intent("com.example.bbqtemperature.SERVICE_CONNECT_BROADCAST"));
                    Intent intent = new Intent("com.example.bbqtemperature.SERVICE_RSSI");
                    intent.putExtra("INTENT_RSSI", i);
                    this.f1275a.sendBroadcast(intent);
                    Log.i(this.f1275a.f1318a, "onLeScan: isdisconnect: " + this.f1275a.f1306O.m1699f());
                    if (!this.f1275a.f1306O.m1699f()) {
                        this.f1275a.m1788q();
                    }
                    this.f1275a.f1306O.m1701h();
                    i2 = m1702a(bArr);
                    a = bArr[i2] - 11;
                    Log.i(this.f1275a.f1318a, "handleMessage: scanrecord: " + bArr[i2] + ", length: " + a);
                    for (parseInt = 0; parseInt < a; parseInt += 2) {
                        short round = (short) ((int) Math.round(((double) MyBbqBleService.m1730a(bArr, ((i2 + 11) + 1) + parseInt)) / 10.0d));
                        Log.i(this.f1275a.f1318a, "handleMessage: t: " + round);
                        if (round < this.f1275a.f1338u || round > this.f1275a.f1337t) {
                            this.f1275a.m1742a(this.f1275a.f1334q[parseInt / 2]);
                        } else {
                            this.f1275a.m1743a(this.f1275a.f1333p[parseInt / 2], round);
                            this.f1275a.f1321d.m1666a((parseInt / 2) + 1, round);
                        }
                    }
                    if (i > -90) {
                        String e2 = this.f1275a.f1318a;
                        StringBuilder append = new StringBuilder().append("handleMessage: rssi > CONNECT_RSSI?: ");
                        if (i > -90) {
                            z = true;
                        }
                        Log.i(e2, append.append(z).toString());
                        m1703a(bluetoothDevice);
                        return;
                    }
                    return;
                }
                Log.e("connect", "fanfu 连接");
                m1703a(bluetoothDevice);
            }
        }
    }

    /* renamed from: com.example.bbqtemperature.service.MyBbqBleService$a */
    class C0485a extends BroadcastReceiver {
        /* renamed from: a */
        final /* synthetic */ MyBbqBleService f1289a;

        /* renamed from: com.example.bbqtemperature.service.MyBbqBleService$a$2 */
        class C04782 implements Runnable {
            /* renamed from: a */
            final /* synthetic */ C0485a f1280a;

            C04782(C0485a c0485a) {
                this.f1280a = c0485a;
            }

            public void run() {
                this.f1280a.f1289a.m1773j();
            }
        }

        /* renamed from: com.example.bbqtemperature.service.MyBbqBleService$a$3 */
        class C04793 implements Runnable {
            /* renamed from: a */
            final /* synthetic */ C0485a f1281a;

            C04793(C0485a c0485a) {
                this.f1281a = c0485a;
            }

            public void run() {
                this.f1281a.f1289a.m1780m();
            }
        }

        /* renamed from: com.example.bbqtemperature.service.MyBbqBleService$a$4 */
        class C04804 implements Runnable {
            /* renamed from: a */
            final /* synthetic */ C0485a f1282a;

            C04804(C0485a c0485a) {
                this.f1282a = c0485a;
            }

            public void run() {
                this.f1282a.f1289a.m1781n();
            }
        }

        /* renamed from: com.example.bbqtemperature.service.MyBbqBleService$a$5 */
        class C04815 implements Runnable {
            /* renamed from: a */
            final /* synthetic */ C0485a f1283a;

            C04815(C0485a c0485a) {
                this.f1283a = c0485a;
            }

            public void run() {
                this.f1283a.f1289a.m1784o();
            }
        }

        /* renamed from: com.example.bbqtemperature.service.MyBbqBleService$a$8 */
        class C04848 implements Runnable {
            /* renamed from: a */
            final /* synthetic */ C0485a f1288a;

            C04848(C0485a c0485a) {
                this.f1288a = c0485a;
            }

            public void run() {
                this.f1288a.f1289a.m1786p();
            }
        }

        C0485a(MyBbqBleService myBbqBleService) {
            this.f1289a = myBbqBleService;
        }

        /* renamed from: a */
        private void m1704a() {
            if (this.f1289a.f1306O.m1700g()) {
                Toast.makeText(this.f1289a.getApplicationContext(), R.string.device_is_oneway_connected, 1).show();
            }
        }

        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals("android.bluetooth.adapter.action.STATE_CHANGED")) {
                switch (intent.getIntExtra("android.bluetooth.adapter.extra.STATE", -1)) {
                    case 12:
                        this.f1289a.f1308Q = true;
                        this.f1289a.m1791s();
                        return;
                    case 13:
                        this.f1289a.f1308Q = false;
                        this.f1289a.m1802a();
                        return;
                    default:
                        return;
                }
            } else if (action.equals("com.example.bbqtemperature.SERVICE_TARGETTEMP")) {
                final byte byteExtra = intent.getByteExtra("INTENT_DATA_ID", (byte) 1);
                final short shortExtra = intent.getShortExtra("INTENT_DATA_COUNT", (short) -3000);
                final short shortExtra2 = intent.getShortExtra("INTENT_DATA_HINT", (short) 3020);
                Log.i(this.f1289a.f1318a, "temp>>>low: " + shortExtra + ", temp: " + shortExtra2);
                if (this.f1289a.f1306O.m1698e()) {
                    this.f1289a.f1315X.add(new Runnable(this) {
                        /* renamed from: d */
                        final /* synthetic */ C0485a f1279d;

                        public void run() {
                            this.f1279d.f1289a.m1732a(byteExtra, shortExtra, shortExtra2);
                        }
                    });
                    if (this.f1289a.f1315X.size() == 1) {
                        this.f1289a.m1732a(byteExtra, shortExtra, shortExtra2);
                        return;
                    }
                    return;
                }
                Log.i(this.f1289a.f1318a, "onReceive: forceconnect settargettemp");
                m1704a();
            } else if (action.equals("com.example.bbqtemperature.SERVICE_READDY")) {
                if (this.f1289a.f1292A != null && this.f1289a.f1297F != null && this.f1289a.f1308Q && this.f1289a.f1306O.m1698e()) {
                    try {
                        this.f1289a.f1315X.add(new C04782(this));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    if (this.f1289a.f1315X.size() == 1) {
                        this.f1289a.m1773j();
                    }
                }
            } else if (action.equals("com.example.bbqtemperature.SERVICE_SETUNIT")) {
                if (this.f1289a.f1306O.m1698e()) {
                    this.f1289a.f1315X.add(new C04793(this));
                    if (this.f1289a.f1315X.size() == 1) {
                        this.f1289a.m1780m();
                        return;
                    }
                    return;
                }
                Log.i(this.f1289a.f1318a, "onReceive: forceconnect setunit");
                m1704a();
            } else if (action.equals("com.example.bbqtemperature.action_device_alarm")) {
                if (this.f1289a.f1306O.m1698e()) {
                    this.f1289a.f1315X.add(new C04804(this));
                    if (this.f1289a.f1315X.size() == 1) {
                        this.f1289a.m1781n();
                        return;
                    }
                    return;
                }
                Log.i(this.f1289a.f1318a, "onReceive: forceconnect setunit");
                m1704a();
            } else if (action.equals("com.example.bbqtemperature.REFRESH_SER")) {
                if (this.f1289a.f1306O.m1698e()) {
                    this.f1289a.f1315X.add(new C04815(this));
                    if (this.f1289a.f1315X.size() == 1) {
                        this.f1289a.m1784o();
                        return;
                    }
                    return;
                }
                Log.i(this.f1289a.f1318a, "onReceive: forceconnect setfuwei");
                m1704a();
            } else if (action.equals("com.example.bbqtemperature.REFRESH_PROBE")) {
                Log.i(this.f1289a.f1318a, "onReceive: getaction: refresh_probe");
                if (this.f1289a.f1306O.m1698e()) {
                    final Byte valueOf = Byte.valueOf((byte) (intent.getByteExtra("INTENT_DATA_ID", (byte) 1) - 1));
                    this.f1289a.f1315X.add(new Runnable(this) {
                        /* renamed from: b */
                        final /* synthetic */ C0485a f1285b;

                        public void run() {
                            this.f1285b.f1289a.m1732a(valueOf.byteValue(), (short) -3000, (short) 3020);
                        }
                    });
                    if (this.f1289a.f1315X.size() == 1) {
                        this.f1289a.m1732a(valueOf.byteValue(), (short) -3000, (short) 3020);
                    }
                    this.f1289a.f1315X.add(new Runnable(this) {
                        /* renamed from: b */
                        final /* synthetic */ C0485a f1287b;

                        public void run() {
                            this.f1287b.f1289a.m1731a(valueOf.byteValue());
                        }
                    });
                    if (this.f1289a.f1315X.size() == 1) {
                        this.f1289a.m1731a(valueOf.byteValue());
                        return;
                    }
                    return;
                }
                Log.i(this.f1289a.f1318a, "onReceive: forceconnect settargettemp 0");
                m1704a();
            } else if (!action.equals("com.example.bbqtemperature.LENG_QUE")) {
            } else {
                if (this.f1289a.f1306O.m1698e()) {
                    this.f1289a.f1315X.add(new C04848(this));
                    if (this.f1289a.f1315X.size() == 1) {
                        this.f1289a.m1786p();
                        return;
                    }
                    return;
                }
                Log.i(this.f1289a.f1318a, "onReceive: forceconnect setcoolingtime");
                m1704a();
            }
        }
    }

    /* renamed from: com.example.bbqtemperature.service.MyBbqBleService$b */
    class C0486b implements Runnable {
        /* renamed from: a */
        final /* synthetic */ MyBbqBleService f1290a;

        C0486b(MyBbqBleService myBbqBleService) {
            this.f1290a = myBbqBleService;
        }

        public void run() {
            Log.i(this.f1290a.f1318a, "run: disconnect isbackground");
            C0463d.m1683a(this.f1290a);
            this.f1290a.f1306O.m1696c(false);
            this.f1290a.f1306O.sendBroadcast(new Intent("com.example.bbqtemperature.SERVICE_CONNECT_FAILED"));
        }
    }

    /* renamed from: com.example.bbqtemperature.service.MyBbqBleService$c */
    class C0487c extends TimerTask {
        /* renamed from: a */
        final /* synthetic */ MyBbqBleService f1291a;

        C0487c(MyBbqBleService myBbqBleService) {
            this.f1291a = myBbqBleService;
        }

        public void run() {
            Log.w(this.f1291a.f1318a, "times is " + this.f1291a.aj);
            switch (this.f1291a.aj) {
                case C0000a.WheelView_lineColor /*0*/:
                    if (!C0463d.m1683a(this.f1291a)) {
                        this.f1291a.ae.sendEmptyMessage(22);
                        Log.i(this.f1291a.f1318a, "run: start scan");
                        break;
                    }
                    this.f1291a.m1758d();
                    this.f1291a.m1794t();
                    break;
                case C0000a.WheelView_selectTextColor /*1*/:
                case C0000a.WheelView_otherTextColor /*2*/:
                case 3:
                case 4:
                    break;
                case 5:
                    this.f1291a.f1342y.stopLeScan(this.f1291a.ag);
                    Log.i(this.f1291a.f1318a, "run: stop scan");
                    this.f1291a.aj = -1;
                    break;
                default:
                    this.f1291a.aj = -1;
                    break;
            }
            this.f1291a.aj = this.f1291a.aj + 1;
        }
    }

    /* renamed from: a */
    public static short m1730a(byte[] bArr, int i) {
        return bArr.length <= i ? (short) 0 : (short) ((bArr[i + 1] << 8) | (bArr[i + 0] & 255));
    }

    /* renamed from: a */
    private void m1731a(byte b) {
        Log.i(this.f1318a, "fuwei 1");
        byte[] bArr = new byte[]{(byte) 4, b, (byte) 0, (byte) 0, (byte) 0, (byte) 0};
        if (this.f1292A != null && this.f1297F != null && this.f1308Q) {
            this.f1297F.setValue(bArr);
            this.f1292A.writeCharacteristic(this.f1297F);
        }
    }

    /* renamed from: a */
    private void m1732a(byte b, short s, short s2) {
        Log.i(this.f1318a, "set targetTemp");
        byte[] bArr = new byte[]{(byte) 1, b, (byte) (s & 255), (byte) (s >> 8), (byte) (s2 & 255), (byte) (s2 >> 8)};
        Log.e(this.f1318a, "low: " + s + ",temp: " + s2);
        if (this.f1292A != null && this.f1297F != null && this.f1308Q) {
            this.f1297F.setValue(bArr);
            this.f1292A.writeCharacteristic(this.f1297F);
        }
    }

    /* renamed from: a */
    private void m1733a(BluetoothDevice bluetoothDevice) {
        m1802a();
        Log.e("connect", "准备连接了");
        this.f1292A = bluetoothDevice.connectGatt(this, false, this.af);
    }

    /* renamed from: a */
    private void m1734a(BluetoothGattCharacteristic bluetoothGattCharacteristic, boolean z) {
        if (this.f1342y == null || this.f1292A == null) {
            Log.e(this.f1318a, "setNotification is not done");
            return;
        }
        Log.e(this.f1318a, "mBluetoothGatt: " + this.f1292A);
        Log.e(this.f1318a, "characteristic: " + bluetoothGattCharacteristic);
        this.f1292A.setCharacteristicNotification(bluetoothGattCharacteristic, z);
        BluetoothGattDescriptor descriptor = bluetoothGattCharacteristic.getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"));
        if (z) {
            descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        } else {
            descriptor.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
        }
        this.f1292A.writeDescriptor(descriptor);
        Log.e(this.f1318a, "setNotification done");
    }

    /* renamed from: a */
    private void m1742a(String str) {
        sendBroadcast(new Intent(str));
    }

    /* renamed from: a */
    private void m1743a(String str, short s) {
        Intent intent = new Intent(str);
        intent.putExtra("INTENT_DIANYA", s);
        sendBroadcast(intent);
    }

    /* renamed from: b */
    private boolean m1749b() {
        if (this.f1341x == null) {
            this.f1341x = (BluetoothManager) getSystemService("bluetooth");
            if (this.f1341x == null) {
                return false;
            }
        }
        this.f1342y = this.f1341x.getAdapter();
        return this.f1342y != null;
    }

    /* renamed from: c */
    private void m1754c() {
        if (this.f1292A != null) {
            this.f1292A.disconnect();
        }
    }

    /* renamed from: d */
    private void m1758d() {
        m1802a();
        BluetoothDevice remoteDevice = this.f1342y.getRemoteDevice(this.f1343z);
        Log.i(this.f1318a, this.f1343z);
        if (remoteDevice != null) {
            Log.e("连接", "connectToDevice()执行了连接");
            this.f1292A = remoteDevice.connectGatt(this, false, this.af);
            Log.e(this.f1318a, "mBluetoothGatt: " + this.f1292A);
            return;
        }
        Log.e(this.f1318a, "getRemoteDevice is null");
    }

    /* renamed from: e */
    private void m1762e() {
        m1765f();
        this.ae.post(new Runnable(this) {
            /* renamed from: a */
            final /* synthetic */ MyBbqBleService f1256a;

            {
                this.f1256a = r1;
            }

            public void run() {
                if (this.f1256a.f1308Q) {
                    this.f1256a.m1734a(this.f1256a.f1296E, true);
                    Log.e("tag", "open ff4 notification");
                }
            }
        });
        this.ae.postDelayed(new Runnable(this) {
            /* renamed from: a */
            final /* synthetic */ MyBbqBleService f1257a;

            {
                this.f1257a = r1;
            }

            public void run() {
                if (this.f1257a.f1292A != null && this.f1257a.f1297F != null && this.f1257a.f1308Q && this.f1257a.f1306O.m1698e()) {
                    this.f1257a.f1292A.readRemoteRssi();
                    this.f1257a.ae.postDelayed(this, 2000);
                }
            }
        }, 1000);
        this.ae.postDelayed(this.ah, 10000);
    }

    /* renamed from: f */
    private void m1765f() {
        this.f1315X.add(new Runnable(this) {
            /* renamed from: a */
            final /* synthetic */ MyBbqBleService f1258a;

            {
                this.f1258a = r1;
            }

            public void run() {
                this.f1258a.m1776k();
            }
        });
        this.f1315X.add(new Runnable(this) {
            /* renamed from: a */
            final /* synthetic */ MyBbqBleService f1259a;

            {
                this.f1259a = r1;
            }

            public void run() {
                this.f1259a.m1777l();
            }
        });
        this.f1315X.add(new Runnable(this) {
            /* renamed from: a */
            final /* synthetic */ MyBbqBleService f1260a;

            {
                this.f1260a = r1;
            }

            public void run() {
                this.f1260a.m1773j();
            }
        });
        this.f1315X.add(new Runnable(this) {
            /* renamed from: a */
            final /* synthetic */ MyBbqBleService f1261a;

            {
                this.f1261a = r1;
            }

            public void run() {
                this.f1261a.m1780m();
            }
        });
        this.f1315X.add(new C04652(this));
        this.f1315X.add(new C04663(this));
        Log.e(this.f1318a, "init queue size: " + this.f1315X.size());
    }

    /* renamed from: g */
    private void m1768g() {
        this.f1315X.clear();
        Log.i(this.f1318a, "yanZheng: isExactMatch: " + this.f1305N);
        if ("easybbq".equals("qtech")) {
            this.f1315X.add(new C04674(this));
            if (this.f1315X.size() == 1) {
                m1772i();
            }
        } else if (this.f1305N) {
            this.f1315X.add(new C04696(this));
            if (this.f1315X.size() == 1) {
                m1772i();
            }
        } else {
            this.f1315X.add(new C04685(this));
            if (this.f1315X.size() == 1) {
                m1770h();
            }
        }
    }

    /* renamed from: h */
    private void m1770h() {
        Log.i(this.f1318a, "handPair: ");
        if (this.f1292A != null && this.f1295D != null && this.f1308Q) {
            this.f1295D.setValue(this.f1322e);
            this.f1292A.writeCharacteristic(this.f1295D);
            m1742a("com.example.bbqtemperature.PAIR_WAIT");
        }
    }

    /* renamed from: i */
    private void m1772i() {
        Log.i(this.f1318a, "autoPair: ");
        if (this.f1292A != null && this.f1295D != null && this.f1308Q) {
            this.f1295D.setValue(this.f1323f);
            this.f1292A.writeCharacteristic(this.f1295D);
        }
    }

    /* renamed from: j */
    private void m1773j() {
        Log.i(this.f1318a, "read dianya");
        if (this.f1292A != null && this.f1297F != null && this.f1308Q) {
            this.f1297F.setValue(this.f1324g);
            this.f1292A.writeCharacteristic(this.f1297F);
        }
    }

    /* renamed from: k */
    private void m1776k() {
        Log.i(this.f1318a, "read versions");
        if (this.f1292A != null && this.f1297F != null && this.f1308Q) {
            this.f1297F.setValue(this.f1325h);
            this.f1292A.writeCharacteristic(this.f1297F);
        }
    }

    /* renamed from: l */
    private void m1777l() {
        if (this.f1292A != null && this.f1297F != null && this.f1308Q) {
            this.f1297F.setValue(this.f1330m);
            this.f1292A.writeCharacteristic(this.f1297F);
            Log.i("tag", "open ff5 temp");
        }
    }

    /* renamed from: m */
    private void m1780m() {
        Log.i(this.f1318a, "set unit");
        boolean z = this.f1317Z.getBoolean("UNIT_FLAG", m1796u());
        if (this.f1292A != null && this.f1297F != null && this.f1308Q) {
            if (z) {
                this.f1297F.setValue(this.f1326i);
            } else {
                this.f1297F.setValue(this.f1327j);
            }
            this.f1292A.writeCharacteristic(this.f1297F);
        }
    }

    /* renamed from: n */
    private void m1781n() {
        Log.i(this.f1318a, "set unit");
        boolean z = this.f1317Z.getBoolean("IS_DEVICE_ALARM", true);
        if (this.f1292A != null && this.f1297F != null && this.f1308Q) {
            if (z) {
                this.f1297F.setValue(this.f1328k);
            } else {
                this.f1297F.setValue(this.f1329l);
            }
            this.f1292A.writeCharacteristic(this.f1297F);
        }
    }

    /* renamed from: o */
    private void m1784o() {
        Log.i(this.f1318a, "fuwei");
        if (this.f1292A != null && this.f1297F != null) {
            this.f1297F.setValue(this.f1331n);
            this.f1292A.writeCharacteristic(this.f1297F);
        }
    }

    /* renamed from: p */
    private void m1786p() {
        int i = "easybbq".equals("grilleye") ? (short) this.f1317Z.getInt("AUTO_MINUTE", 1) : (short) this.f1317Z.getInt("AUTO_MINUTE", 10);
        Log.i(this.f1318a, "setCoolingTime: " + i);
        short s = (short) (i * 60);
        byte[] bArr = new byte[]{(byte) 3, (byte) -1, (byte) (s & 255), (byte) (s >>> 8), (byte) 0, (byte) 0};
        if (this.f1292A != null && this.f1297F != null && this.f1308Q) {
            this.f1297F.setValue(bArr);
            this.f1292A.writeCharacteristic(this.f1297F);
        }
    }

    /* renamed from: q */
    private void m1788q() {
        Log.i(this.f1318a, "startDisconnectTimeDown: ");
        if (this.ai != null) {
            this.ae.removeCallbacks(this.ai);
            this.ai = null;
        }
        this.ai = new C0486b(this);
        this.ae.postDelayed(this.ai, 30000);
    }

    /* renamed from: r */
    private void m1789r() {
        Log.i(this.f1318a, "stopDisconnectTimeDown: ");
        if (this.ai != null) {
            this.ae.removeCallbacks(this.ai);
        }
        this.ai = null;
    }

    /* renamed from: s */
    private void m1791s() {
        m1794t();
        this.f1319b = new Timer();
        this.f1319b.schedule(new C0487c(this), 200, 1500);
    }

    /* renamed from: t */
    private void m1794t() {
        if (this.f1319b != null) {
            Log.e(this.f1318a, "stopTimeScan: ");
            this.f1319b.cancel();
            this.f1319b = null;
            this.aj = 0;
        }
        this.f1342y.stopLeScan(this.ag);
    }

    /* renamed from: u */
    private boolean m1796u() {
        return !"easybbq".equals("grilleye");
    }

    /* renamed from: a */
    public void m1802a() {
        m1754c();
        if (this.f1292A != null) {
            this.f1292A.close();
            this.f1292A = null;
            Log.e("TAG", "close执行！！！");
        }
    }

    public IBinder onBind(Intent intent) {
        return null;
    }

    public void onCreate() {
        this.f1306O = BbqThermometer.m1687i();
        this.f1320c = C0458a.m1653a((Context) this);
        this.f1321d = C0459b.m1664a();
        Log.i(this.f1318a, "onCreate: ");
        this.f1292A = null;
        this.f1317Z = getSharedPreferences("SHAR_DATA_BBQ_120", 0);
        this.f1309R = this.f1317Z.getInt("MIYAO", -1);
        this.f1312U = this.f1317Z.getInt("PROBE_COUNT", -1);
        boolean z = this.f1312U == -1 || this.f1306O.m1697d();
        this.f1298G = z;
        Log.i(this.f1318a, "onCreate: putCount: " + this.f1298G);
        this.ab = this.f1317Z.getBoolean("FIRST_UNIT", true);
        this.f1339v = this.f1317Z.getInt("mainVersions", 1);
        this.f1340w = this.f1317Z.getInt("secondVersions", 0);
        if (this.f1339v > 3 || (this.f1339v == 3 && this.f1340w >= 2)) {
            this.f1338u = 0;
        } else {
            this.f1338u = 1;
        }
        this.aa = this.f1317Z.edit();
        m1749b();
        this.f1307P = new C0485a(this);
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.example.bbqtemperature.SERVICE_TARGETTEMP");
        intentFilter.addAction("com.example.bbqtemperature.SERVICE_READDY");
        intentFilter.addAction("com.example.bbqtemperature.SERVICE_SETUNIT");
        intentFilter.addAction("com.example.bbqtemperature.action_device_alarm");
        intentFilter.addAction("com.example.bbqtemperature.SERVICE_OPEN_DATA");
        intentFilter.addAction("com.example.bbqtemperature.SERVICE_CONNECT_FAILED");
        intentFilter.addAction("com.example.bbqtemperature.REFRESH_SER");
        intentFilter.addAction("com.example.bbqtemperature.REFRESH_PROBE");
        intentFilter.addAction("com.example.bbqtemperature.REFRESH_ALARM_TIME");
        intentFilter.addAction("com.example.bbqtemperature.LENG_QUE");
        intentFilter.addAction("android.bluetooth.adapter.action.STATE_CHANGED");
        registerReceiver(this.f1307P, intentFilter);
        super.onCreate();
    }

    public void onDestroy() {
        Log.e(this.f1318a, "service onDestroy");
        this.f1315X.clear();
        this.f1308Q = false;
        this.f1306O.m1696c(false);
        if (this.f1342y != null) {
            m1794t();
        }
        m1789r();
        this.ai = null;
        m1802a();
        unregisterReceiver(this.f1307P);
        super.onDestroy();
    }

    public int onStartCommand(Intent intent, int i, int i2) {
        Log.e("TAG", "开始服务onStratCommand");
        this.ac = new C0359b(this);
        if (intent != null) {
            this.f1305N = intent.getBooleanExtra("isExactMatch", true);
        }
        this.f1343z = this.f1306O.m1695c();
        if (this.f1343z.equals("NO_ADDRESS")) {
            Log.e("TAG", "准备打开扫描Starts a scan for Bluetooth LE devices");
            this.f1342y.startLeScan(this.ag);
        } else {
            m1758d();
        }
        return super.onStartCommand(intent, i, i2);
    }
}
