Search in sources :

Example 11 with BluetoothClass

use of android.bluetooth.BluetoothClass in project XobotOS by xamarin.

the class BluetoothEventLoop method onRequestPinCode.

/**
     * Called by native code on a RequestPinCode method call to
     * org.bluez.Agent.
     *
     * @param objectPath the path of the device requesting a PIN code
     * @param nativeData a native pointer to the original D-Bus message
     */
private void onRequestPinCode(String objectPath, int nativeData) {
    String address = checkPairingRequestAndGetAddress(objectPath, nativeData);
    if (address == null)
        return;
    String pendingOutgoingAddress = mBluetoothService.getPendingOutgoingBonding();
    BluetoothClass btClass = new BluetoothClass(mBluetoothService.getRemoteClass(address));
    int btDeviceClass = btClass.getDeviceClass();
    if (address.equals(pendingOutgoingAddress)) {
        // Check if its a dock
        if (mBluetoothService.isBluetoothDock(address)) {
            String pin = mBluetoothService.getDockPin();
            mBluetoothService.setPin(address, BluetoothDevice.convertPinToBytes(pin));
            return;
        }
        // try 0000 once if the device looks dumb
        switch(btDeviceClass) {
            case BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET:
            case BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE:
            case BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES:
            case BluetoothClass.Device.AUDIO_VIDEO_PORTABLE_AUDIO:
            case BluetoothClass.Device.AUDIO_VIDEO_HIFI_AUDIO:
                if (mBluetoothService.attemptAutoPair(address))
                    return;
        }
    }
    if (btDeviceClass == BluetoothClass.Device.PERIPHERAL_KEYBOARD || btDeviceClass == BluetoothClass.Device.PERIPHERAL_KEYBOARD_POINTING) {
        // and pair.
        if (mBluetoothService.isFixedPinZerosAutoPairKeyboard(address)) {
            mBluetoothService.setPin(address, BluetoothDevice.convertPinToBytes("0000"));
            return;
        }
        // Generate a variable PIN. This is not truly random but good enough.
        int pin = (int) Math.floor(Math.random() * 10000);
        sendDisplayPinIntent(address, pin);
        return;
    }
    // Acquire wakelock during PIN code request to bring up LCD display
    mWakeLock.acquire();
    Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_REQUEST);
    intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mAdapter.getRemoteDevice(address));
    intent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, BluetoothDevice.PAIRING_VARIANT_PIN);
    mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM);
    // Release wakelock to allow the LCD to go off after the PIN popup notification.
    mWakeLock.release();
    return;
}
Also used : BluetoothClass(android.bluetooth.BluetoothClass) Intent(android.content.Intent)

Example 12 with BluetoothClass

use of android.bluetooth.BluetoothClass in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BluetoothDevicePreference method getBtClassDrawableWithDescription.

private Pair<Integer, String> getBtClassDrawableWithDescription() {
    BluetoothClass btClass = mCachedDevice.getBtClass();
    if (btClass != null) {
        switch(btClass.getMajorDeviceClass()) {
            case BluetoothClass.Device.Major.COMPUTER:
                return new Pair<Integer, String>(R.drawable.ic_bt_laptop, COMPUTER);
            case BluetoothClass.Device.Major.PHONE:
                return new Pair<Integer, String>(R.drawable.ic_bt_cellphone, PHONE);
            case BluetoothClass.Device.Major.PERIPHERAL:
                return new Pair<Integer, String>(HidProfile.getHidClassDrawable(btClass), INPUT_PERIPHERAL);
            case BluetoothClass.Device.Major.IMAGING:
                return new Pair<Integer, String>(R.drawable.ic_bt_imaging, IMAGING);
            default:
        }
    } else {
        Log.w(TAG, "mBtClass is null");
    }
    List<LocalBluetoothProfile> profiles = mCachedDevice.getProfiles();
    for (LocalBluetoothProfile profile : profiles) {
        int resId = profile.getDrawableResource(btClass);
        if (resId != 0) {
            return new Pair<Integer, String>(resId, null);
        }
    }
    if (btClass != null) {
        if (btClass.doesClassMatch(BluetoothClass.PROFILE_A2DP)) {
            return new Pair<Integer, String>(R.drawable.ic_bt_headphones_a2dp, HEADPHONE);
        }
        if (btClass.doesClassMatch(BluetoothClass.PROFILE_HEADSET)) {
            return new Pair<Integer, String>(R.drawable.ic_bt_headset_hfp, HEADSET);
        }
    }
    return new Pair<Integer, String>(R.drawable.ic_settings_bluetooth, BLUETOOTH);
}
Also used : LocalBluetoothProfile(com.android.settingslib.bluetooth.LocalBluetoothProfile) BluetoothClass(android.bluetooth.BluetoothClass) Pair(android.util.Pair)

Example 13 with BluetoothClass

use of android.bluetooth.BluetoothClass in project android_frameworks_base by ResurrectionRemix.

the class CachedBluetoothDevice method updateProfiles.

private boolean updateProfiles() {
    ParcelUuid[] uuids = mDevice.getUuids();
    if (uuids == null)
        return false;
    ParcelUuid[] localUuids = mLocalAdapter.getUuids();
    if (localUuids == null)
        return false;
    /**
         * Now we know if the device supports PBAP, update permissions...
         */
    processPhonebookAccess();
    mProfileManager.updateProfiles(uuids, localUuids, mProfiles, mRemovedProfiles, mLocalNapRoleConnected, mDevice);
    if (DEBUG) {
        Log.e(TAG, "updating profiles for " + mDevice.getAliasName());
        BluetoothClass bluetoothClass = mDevice.getBluetoothClass();
        if (bluetoothClass != null)
            Log.v(TAG, "Class: " + bluetoothClass.toString());
        Log.v(TAG, "UUID:");
        for (ParcelUuid uuid : uuids) {
            Log.v(TAG, "  " + uuid);
        }
    }
    return true;
}
Also used : ParcelUuid(android.os.ParcelUuid) BluetoothClass(android.bluetooth.BluetoothClass)

Example 14 with BluetoothClass

use of android.bluetooth.BluetoothClass in project android_frameworks_base by DirtyUnicorns.

the class CachedBluetoothDevice method updateProfiles.

private boolean updateProfiles() {
    ParcelUuid[] uuids = mDevice.getUuids();
    if (uuids == null)
        return false;
    ParcelUuid[] localUuids = mLocalAdapter.getUuids();
    if (localUuids == null)
        return false;
    /**
         * Now we know if the device supports PBAP, update permissions...
         */
    processPhonebookAccess();
    mProfileManager.updateProfiles(uuids, localUuids, mProfiles, mRemovedProfiles, mLocalNapRoleConnected, mDevice);
    if (DEBUG) {
        Log.e(TAG, "updating profiles for " + mDevice.getAliasName());
        BluetoothClass bluetoothClass = mDevice.getBluetoothClass();
        if (bluetoothClass != null)
            Log.v(TAG, "Class: " + bluetoothClass.toString());
        Log.v(TAG, "UUID:");
        for (ParcelUuid uuid : uuids) {
            Log.v(TAG, "  " + uuid);
        }
    }
    return true;
}
Also used : ParcelUuid(android.os.ParcelUuid) BluetoothClass(android.bluetooth.BluetoothClass)

Aggregations

BluetoothClass (android.bluetooth.BluetoothClass)14 ParcelUuid (android.os.ParcelUuid)5 Intent (android.content.Intent)3 BluetoothDevice (android.bluetooth.BluetoothDevice)1 Pair (android.util.Pair)1 LocalBluetoothProfile (com.android.settingslib.bluetooth.LocalBluetoothProfile)1