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();
}
}
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);
}
}
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();
}
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();
}
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());
}
Aggregations