package com.epson.mobilephone.common.ble.util;

import android.bluetooth.BluetoothManager;
import android.content.Context;

public class BLEUtility {
    public static final int GATT_BUSY = 132;
    public static final int GATT_DB_FULL = 131;
    public static final int GATT_INTERNAL_ERROR = 129;
    public static final int GATT_WRONG_STATE = 130;

    public interface BleWorkCallback {
        void call(Object obj);
    }

    private BLEUtility() {
    }

    public static boolean isBLESupported(Context context) {
        return context.getPackageManager().hasSystemFeature("android.hardware.bluetooth_le");
    }

    public static BluetoothManager getManager(Context context) {
        return (BluetoothManager) context.getSystemService("bluetooth");
    }

    @NonNull
    public static String IntToHex2(int i) {
        return new String(new char[]{Character.forDigit((i >> 4) & 15, 16), Character.forDigit(i & 15, 16)}).toUpperCase();
    }

    public static boolean isThreadAliveParentGroup(String str) {
        if (str == null) {
            return false;
        }
        ThreadGroup parent = Thread.currentThread().getThreadGroup().getParent();
        Thread[] threadArr = new Thread[parent.activeCount()];
        parent.enumerate(threadArr, true);
        int length = threadArr.length;
        int i = 0;
        while (i < length) {
            Thread thread = threadArr[i];
            if (thread == null || !thread.getName().equals(str) || !thread.isAlive()) {
                i++;
            } else {
                EpLog.d("" + thread);
                return true;
            }
        }
        return false;
    }

    @Nullable
    public static Thread getThread(String str) {
        if (str == null) {
            return null;
        }
        Thread.currentThread();
        Thread[] threadArr = new Thread[Thread.activeCount()];
        Thread.enumerate(threadArr);
        int length = threadArr.length;
        int i = 0;
        while (i < length) {
            Thread thread = threadArr[i];
            if (thread == null || !thread.getName().equals(str)) {
                i++;
            } else {
                EpLog.m77i("find thread : " + str);
                return thread;
            }
        }
        return null;
    }

    public static boolean isThreadAlive(String str) {
        Thread thread = getThread(str);
        return thread != null && thread.isAlive();
    }
}
