Search in sources :

Example 96 with CachedBluetoothDevice

use of com.android.settingslib.bluetooth.CachedBluetoothDevice in project android_packages_apps_Settings by omnirom.

the class DevicePickerFragment method onDeviceBondStateChanged.

public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
    BluetoothDevice device = cachedDevice.getDevice();
    if (!device.equals(mSelectedDevice)) {
        return;
    }
    if (bondState == BluetoothDevice.BOND_BONDED) {
        sendDevicePickedIntent(device);
        finish();
    } else if (bondState == BluetoothDevice.BOND_NONE) {
        enableScanning();
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice)

Example 97 with CachedBluetoothDevice

use of com.android.settingslib.bluetooth.CachedBluetoothDevice in project android_packages_apps_Settings by omnirom.

the class BluetoothDeviceUpdater method addPreference.

/**
 * Add the {@link Preference} with {@link BluetoothDevicePreference.SortType} that
 * represents the {@code cachedDevice}
 */
protected void addPreference(CachedBluetoothDevice cachedDevice, @BluetoothDevicePreference.SortType int type) {
    final BluetoothDevice device = cachedDevice.getDevice();
    if (!mPreferenceMap.containsKey(device)) {
        BluetoothDevicePreference btPreference = new BluetoothDevicePreference(mPrefContext, cachedDevice, true, /* showDeviceWithoutNames */
        type);
        btPreference.setKey(getPreferenceKey());
        btPreference.setOnGearClickListener(mDeviceProfilesListener);
        if (this instanceof Preference.OnPreferenceClickListener) {
            btPreference.setOnPreferenceClickListener((Preference.OnPreferenceClickListener) this);
        }
        mPreferenceMap.put(device, btPreference);
        mDevicePreferenceCallback.onDeviceAdded(btPreference);
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) GearPreference(com.android.settings.widget.GearPreference) Preference(androidx.preference.Preference)

Example 98 with CachedBluetoothDevice

use of com.android.settingslib.bluetooth.CachedBluetoothDevice in project android_packages_apps_Settings by omnirom.

the class BluetoothDeviceUpdater method launchDeviceDetails.

/**
 * Get {@link CachedBluetoothDevice} from {@link Preference} and it is used to init
 * {@link SubSettingLauncher} to launch {@link BluetoothDeviceDetailsFragment}
 */
protected void launchDeviceDetails(Preference preference) {
    mMetricsFeatureProvider.logClickedPreference(preference, mFragment.getMetricsCategory());
    final CachedBluetoothDevice device = ((BluetoothDevicePreference) preference).getBluetoothDevice();
    if (device == null) {
        return;
    }
    final Bundle args = new Bundle();
    args.putString(BluetoothDeviceDetailsFragment.KEY_DEVICE_ADDRESS, device.getDevice().getAddress());
    new SubSettingLauncher(mFragment.getContext()).setDestination(BluetoothDeviceDetailsFragment.class.getName()).setArguments(args).setTitleRes(R.string.device_details_title).setSourceMetricsCategory(mFragment.getMetricsCategory()).launch();
}
Also used : CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) SubSettingLauncher(com.android.settings.core.SubSettingLauncher) Bundle(android.os.Bundle)

Example 99 with CachedBluetoothDevice

use of com.android.settingslib.bluetooth.CachedBluetoothDevice in project android_packages_apps_Settings by omnirom.

the class NotificationBackend method getDeviceList.

public static CharSequence getDeviceList(ICompanionDeviceManager cdm, LocalBluetoothManager lbm, String pkg, int userId) {
    boolean multiple = false;
    StringBuilder sb = new StringBuilder();
    try {
        List<String> associatedMacAddrs = cdm.getAssociations(pkg, userId);
        if (associatedMacAddrs != null) {
            for (String assocMac : associatedMacAddrs) {
                final Collection<CachedBluetoothDevice> cachedDevices = lbm.getCachedDeviceManager().getCachedDevicesCopy();
                for (CachedBluetoothDevice cachedBluetoothDevice : cachedDevices) {
                    if (Objects.equals(assocMac, cachedBluetoothDevice.getAddress())) {
                        if (multiple) {
                            sb.append(", ");
                        } else {
                            multiple = true;
                        }
                        sb.append(cachedBluetoothDevice.getName());
                    }
                }
            }
        }
    } catch (RemoteException e) {
        Log.w(TAG, "Error calling CDM", e);
    }
    return sb.toString();
}
Also used : CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) RemoteException(android.os.RemoteException)

Example 100 with CachedBluetoothDevice

use of com.android.settingslib.bluetooth.CachedBluetoothDevice in project android_packages_apps_Settings by omnirom.

the class BluetoothDevicesSlice method getPairedBluetoothDevices.

@VisibleForTesting
List<CachedBluetoothDevice> getPairedBluetoothDevices() {
    final List<CachedBluetoothDevice> bluetoothDeviceList = new ArrayList<>();
    // If Bluetooth is disable, skip getting the Bluetooth devices.
    if (!BluetoothAdapter.getDefaultAdapter().isEnabled()) {
        Log.i(TAG, "Cannot get Bluetooth devices, Bluetooth is disabled.");
        return bluetoothDeviceList;
    }
    final LocalBluetoothManager localBtManager = BluetoothUpdateWorker.getLocalBtManager();
    if (localBtManager == null) {
        Log.i(TAG, "Cannot get Bluetooth devices, Bluetooth is not ready.");
        return bluetoothDeviceList;
    }
    final Collection<CachedBluetoothDevice> cachedDevices = localBtManager.getCachedDeviceManager().getCachedDevicesCopy();
    // Get all paired devices and sort them.
    return cachedDevices.stream().filter(device -> device.getDevice().getBondState() == BluetoothDevice.BOND_BONDED).sorted(COMPARATOR).collect(Collectors.toList());
}
Also used : CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) ArrayList(java.util.ArrayList) LocalBluetoothManager(com.android.settingslib.bluetooth.LocalBluetoothManager) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Aggregations

CachedBluetoothDevice (com.android.settingslib.bluetooth.CachedBluetoothDevice)104 BluetoothDevice (android.bluetooth.BluetoothDevice)38 LocalBluetoothManager (com.android.settingslib.bluetooth.LocalBluetoothManager)30 CachedBluetoothDeviceManager (com.android.settingslib.bluetooth.CachedBluetoothDeviceManager)15 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)12 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 DialogInterface (android.content.DialogInterface)7 OnClickListener (android.view.View.OnClickListener)7 MapProfile (com.android.settingslib.bluetooth.MapProfile)7 VisibleForTesting (androidx.annotation.VisibleForTesting)6 Intent (android.content.Intent)5 Preference (androidx.preference.Preference)4 Bundle (android.os.Bundle)2 ListBuilder (androidx.slice.builders.ListBuilder)2 SubSettingLauncher (com.android.settings.core.SubSettingLauncher)2 GearPreference (com.android.settings.widget.GearPreference)2 LocalBluetoothProfile (com.android.settingslib.bluetooth.LocalBluetoothProfile)2 Iterator (java.util.Iterator)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2