package com.ifpdos.factorytest;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.util.Log;

/* JADX INFO: loaded from: classes.dex */
public class LocalBluetoothAdapter {
    private static final String TAG = "LocalBluetoothAdapter";
    private static LocalBluetoothAdapter sInstance;
    private final BluetoothAdapter mAdapter;
    private int mState = Integer.MIN_VALUE;

    private LocalBluetoothAdapter(BluetoothAdapter bluetoothAdapter) {
        this.mAdapter = bluetoothAdapter;
    }

    public static synchronized LocalBluetoothAdapter getInstance() {
        BluetoothAdapter defaultAdapter;
        if (sInstance == null && (defaultAdapter = BluetoothAdapter.getDefaultAdapter()) != null) {
            sInstance = new LocalBluetoothAdapter(defaultAdapter);
        }
        return sInstance;
    }

    void cancelDiscovery() {
        this.mAdapter.cancelDiscovery();
    }

    boolean enable() {
        return this.mAdapter.enable();
    }

    boolean disable() {
        return this.mAdapter.disable();
    }

    void getProfileProxy(Context context, BluetoothProfile.ServiceListener serviceListener, int i) {
        this.mAdapter.getProfileProxy(context, serviceListener, i);
    }

    String getName() {
        return this.mAdapter.getName();
    }

    int getScanMode() {
        return this.mAdapter.getScanMode();
    }

    int getState() {
        return this.mAdapter.getState();
    }

    public boolean isDiscovering() {
        return this.mAdapter.isDiscovering();
    }

    boolean isEnabled() {
        return this.mAdapter.isEnabled();
    }

    void setName(String str) {
        this.mAdapter.setName(str);
    }

    public boolean startScanning() {
        return !this.mAdapter.isDiscovering() && this.mAdapter.startDiscovery();
    }

    public void stopScanning() {
        if (this.mAdapter.isDiscovering()) {
            this.mAdapter.cancelDiscovery();
        }
    }

    public synchronized int getBluetoothState() {
        syncBluetoothState();
        return this.mState;
    }

    boolean syncBluetoothState() {
        int state = this.mAdapter.getState();
        if (state == this.mState) {
            return false;
        }
        this.mState = state;
        return true;
    }

    public void setBluetoothEnabled(boolean z) {
        BluetoothAdapter bluetoothAdapter = this.mAdapter;
        Log.d(TAG, "enable : " + z + " success=" + (z ? bluetoothAdapter.enable() : bluetoothAdapter.disable()));
    }
}
