@@ -0,0 +1,3698 @@
+package com.google.heartrate.wearos.app.bluetooth;%0A%0Aimport android.bluetooth.BluetoothAdapter;%0Aimport android.bluetooth.BluetoothGattServer;%0Aimport android.bluetooth.BluetoothGattServerCallback;%0Aimport android.bluetooth.BluetoothManager;%0Aimport android.bluetooth.le.BluetoothLeAdvertiser;%0Aimport android.content.Context;%0Aimport android.content.pm.PackageManager;%0A%0Aimport com.google.heartrate.wearos.app.gatt.GattException;%0A%0Aimport static android.content.Context.BLUETOOTH_SERVICE;%0A%0A/**%0A * Provides bluetooth related objects and checks.%0A */%0Apublic class BluetoothUtils %7B%0A    private static final String TAG = BluetoothUtils.class.getSimpleName();%0A%0A    /**%0A     * Check if bluetooth is supported on current device.%0A     * @param context context of application%0A     */%0A    public static void assertBluetoothIsSupported(Context context) throws GattException %7B%0A        BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService(BLUETOOTH_SERVICE);%0A        if (bluetoothManager == null) %7B%0A            throw new GattException(%22Bluetooth is not supported. No BluetoothManager found.%22);%0A        %7D%0A%0A        BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();%0A        if (bluetoothAdapter == null) %7B%0A            throw new GattException(%22Bluetooth is not supported. No BluetoothAdapter found.%22);%0A        %7D%0A%0A        if (!bluetoothAdapter.isEnabled()) %7B%0A            throw new GattException(%22Bluetooth adapter is currently disabled%22);%0A        %7D%0A%0A        if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) %7B%0A            throw new GattException(%22Bluetooth LE  is not supported. No FEATURE_BLUETOOTH_LE found.%22);%0A        %7D%0A    %7D%0A%0A    /**%0A     * Get bluetooth manager.%0A     * @param context context of application%0A     * @return bluetooth manager%0A     */%0A    public static BluetoothManager getBluetoothManager(Context context) throws GattException %7B%0A        BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);%0A        if (bluetoothManager == null) %7B%0A            throw new GattException(%22Bluetooth is not supported. No BluetoothManager found.%22);%0A        %7D%0A        return bluetoothManager;%0A    %7D%0A%0A    /**%0A     * Get bluetooth adapter.%0A     * @param context context of application%0A     * @return bluetooth adapter%0A     */%0A    public static BluetoothAdapter getBluetoothAdapter(Context context) throws GattException %7B%0A        BluetoothManager bluetoothManager = getBluetoothManager(context);%0A        BluetoothAdapter adapter = bluetoothManager.getAdapter();%0A        if (adapter == null) %7B%0A            throw new GattException(%22Bluetooth is not supported. No BluetoothAdapter found.%22);%0A        %7D%0A%0A        return adapter;%0A    %7D%0A%0A    /**%0A     * Get bluetooth adapter.%0A     * @param context context of application%0A     * @return bluetooth adapter%0A     */%0A    public static BluetoothLeAdvertiser getBluetoothLeAdvertiser(Context context) throws GattException %7B%0A        BluetoothAdapter adapter = getBluetoothAdapter(context);%0A        BluetoothLeAdvertiser advertiser = adapter.getBluetoothLeAdvertiser();%0A        if (advertiser == null) %7B%0A            throw new GattException(%22Bluetooth advertising is not supported. Can not get BluetoothLeAdvertiser.%22);%0A        %7D%0A%0A        return advertiser;%0A    %7D%0A%0A    public static BluetoothGattServer getBluetoothGattServer(Context context, BluetoothGattServerCallback callback) throws GattException %7B%0A        BluetoothGattServer server = getBluetoothManager(context)%0A                .openGattServer(context, callback);%0A%0A        if (server == null) %7B%0A            throw new GattException(%22Unable to create GATT server%22);%0A        %7D%0A%0A        return server;%0A    %7D%0A%7D%0A

Add bluetooth utils class