use of com.android.settingslib.bluetooth.LocalBluetoothProfile in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class DockService method applyBtSettings.
private synchronized void applyBtSettings(BluetoothDevice device, int startId) {
if (device == null || mProfiles == null || mCheckedItems == null || mLocalAdapter == null) {
return;
}
// Turn on BT if something is enabled
for (boolean enable : mCheckedItems) {
if (enable) {
int btState = mLocalAdapter.getBluetoothState();
if (DEBUG) {
Log.d(TAG, "BtState = " + btState);
}
// May have race condition as the phone comes in and out and in the dock.
// Always turn on BT
mLocalAdapter.enable();
// if adapter was previously OFF, TURNING_OFF, or TURNING_ON
if (btState != BluetoothAdapter.STATE_ON) {
if (mPendingDevice != null && mPendingDevice.equals(mDevice)) {
return;
}
mPendingDevice = device;
mPendingStartId = startId;
if (btState != BluetoothAdapter.STATE_TURNING_ON) {
getPrefs().edit().putBoolean(KEY_DISABLE_BT_WHEN_UNDOCKED, true).apply();
}
return;
}
}
}
mPendingDevice = null;
boolean callConnect = false;
CachedBluetoothDevice cachedDevice = getCachedBluetoothDevice(device);
for (int i = 0; i < mProfiles.length; i++) {
LocalBluetoothProfile profile = mProfiles[i];
if (DEBUG)
Log.d(TAG, profile.toString() + " = " + mCheckedItems[i]);
if (mCheckedItems[i]) {
// Checked but not connected
callConnect = true;
} else if (!mCheckedItems[i]) {
// Unchecked, may or may not be connected.
int status = profile.getConnectionStatus(cachedDevice.getDevice());
if (status == BluetoothProfile.STATE_CONNECTED) {
if (DEBUG)
Log.d(TAG, "applyBtSettings - Disconnecting");
cachedDevice.disconnect(mProfiles[i]);
}
}
profile.setPreferred(device, mCheckedItems[i]);
if (DEBUG) {
if (mCheckedItems[i] != profile.isPreferred(device)) {
Log.e(TAG, "Can't save preferred value");
}
}
}
if (callConnect) {
if (DEBUG)
Log.d(TAG, "applyBtSettings - Connecting");
cachedDevice.connect(false);
}
}
use of com.android.settingslib.bluetooth.LocalBluetoothProfile in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class DeviceProfilesSettings method refreshProfiles.
private void refreshProfiles() {
for (LocalBluetoothProfile profile : mCachedDevice.getConnectableProfiles()) {
CheckBox profilePref = findProfile(profile.toString());
if (profilePref == null) {
profilePref = createProfilePreference(profile);
mProfileContainer.addView(profilePref);
} else {
refreshProfilePreference(profilePref, profile);
}
}
for (LocalBluetoothProfile profile : mCachedDevice.getRemovedProfiles()) {
CheckBox profilePref = findProfile(profile.toString());
if (profilePref != null) {
if (profile instanceof PbapServerProfile) {
final int pbapPermission = mCachedDevice.getPhonebookPermissionChoice();
Log.d(TAG, "refreshProfiles: pbapPermission = " + pbapPermission);
if (pbapPermission != CachedBluetoothDevice.ACCESS_UNKNOWN)
continue;
}
if (profile instanceof MapProfile) {
final int mapPermission = mCachedDevice.getMessagePermissionChoice();
Log.d(TAG, "refreshProfiles: mapPermission = " + mapPermission);
if (mapPermission != CachedBluetoothDevice.ACCESS_UNKNOWN)
continue;
}
Log.d(TAG, "Removing " + profile.toString() + " from profile list");
mProfileContainer.removeView(profilePref);
}
}
showOrHideProfileGroup();
}
use of com.android.settingslib.bluetooth.LocalBluetoothProfile in project android_packages_apps_Settings by LineageOS.
the class BluetoothDetailsProfilesController method onPreferenceClick.
/**
* When the pref for a bluetooth profile is clicked on, we want to toggle the enabled/disabled
* state for that profile.
*/
@Override
public boolean onPreferenceClick(Preference preference) {
LocalBluetoothProfile profile = mProfileManager.getProfileByName(preference.getKey());
if (profile == null) {
// It might be the PbapServerProfile, which is not stored by name.
PbapServerProfile psp = mManager.getProfileManager().getPbapProfile();
if (TextUtils.equals(preference.getKey(), psp.toString())) {
profile = psp;
} else {
return false;
}
}
SwitchPreference profilePref = (SwitchPreference) preference;
BluetoothDevice device = mCachedDevice.getDevice();
if (profilePref.isChecked()) {
enableProfile(profile, device, profilePref);
} else {
disableProfile(profile, device, profilePref);
}
refreshProfilePreference(profilePref, profile);
return true;
}
use of com.android.settingslib.bluetooth.LocalBluetoothProfile in project android_packages_apps_Settings by LineageOS.
the class DeviceProfilesSettings method addPreferencesForProfiles.
private void addPreferencesForProfiles() {
mProfileContainer.removeAllViews();
for (LocalBluetoothProfile profile : mCachedDevice.getConnectableProfiles()) {
CheckBox pref = createProfilePreference(profile);
mProfileContainer.addView(pref);
if (profile instanceof A2dpProfile) {
BluetoothDevice device = mCachedDevice.getDevice();
A2dpProfile a2dpProfile = (A2dpProfile) profile;
if (a2dpProfile.supportsHighQualityAudio(device)) {
CheckBox highQualityPref = new CheckBox(getActivity());
highQualityPref.setTag(HIGH_QUALITY_AUDIO_PREF_TAG);
highQualityPref.setOnClickListener(v -> {
a2dpProfile.setHighQualityAudioEnabled(device, highQualityPref.isChecked());
});
highQualityPref.setVisibility(View.GONE);
mProfileContainer.addView(highQualityPref);
}
refreshProfilePreference(pref, profile);
}
}
final int pbapPermission = mCachedDevice.getPhonebookPermissionChoice();
// Only provide PBAP cabability if the client device has requested PBAP.
if (pbapPermission != CachedBluetoothDevice.ACCESS_UNKNOWN) {
final PbapServerProfile psp = mManager.getProfileManager().getPbapProfile();
CheckBox pbapPref = createProfilePreference(psp);
mProfileContainer.addView(pbapPref);
}
final MapProfile mapProfile = mManager.getProfileManager().getMapProfile();
final int mapPermission = mCachedDevice.getMessagePermissionChoice();
if (mapPermission != CachedBluetoothDevice.ACCESS_UNKNOWN) {
CheckBox mapPreference = createProfilePreference(mapProfile);
mProfileContainer.addView(mapPreference);
}
showOrHideProfileGroup();
}
use of com.android.settingslib.bluetooth.LocalBluetoothProfile in project android_packages_apps_Settings by LineageOS.
the class DeviceProfilesSettings method onClick.
@Override
public void onClick(View v) {
if (v instanceof CheckBox) {
LocalBluetoothProfile prof = getProfileOf(v);
onProfileClicked(prof, (CheckBox) v);
}
}
Aggregations