Search in sources :

Example 61 with CachedBluetoothDevice

use of com.android.settingslib.bluetooth.CachedBluetoothDevice in project android_frameworks_base by crdroidandroid.

the class BluetoothControllerImpl method dump.

public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    pw.println("BluetoothController state:");
    pw.print("  mLocalBluetoothManager=");
    pw.println(mLocalBluetoothManager);
    if (mLocalBluetoothManager == null) {
        return;
    }
    pw.print("  mEnabled=");
    pw.println(mEnabled);
    pw.print("  mConnectionState=");
    pw.println(stateToString(mConnectionState));
    pw.print("  mLastDevice=");
    pw.println(mLastDevice);
    pw.print("  mCallbacks.size=");
    pw.println(mHandler.mCallbacks.size());
    pw.println("  Bluetooth Devices:");
    for (CachedBluetoothDevice device : mLocalBluetoothManager.getCachedDeviceManager().getCachedDevicesCopy()) {
        pw.println("    " + getDeviceString(device));
    }
}
Also used : CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice)

Example 62 with CachedBluetoothDevice

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

the class BluetoothPermissionActivity method onNegative.

private void onNegative() {
    if (DEBUG)
        Log.d(TAG, "onNegative");
    boolean always = true;
    if (mRequestType == BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS) {
        LocalBluetoothManager bluetoothManager = Utils.getLocalBtManager(this);
        CachedBluetoothDeviceManager cachedDeviceManager = bluetoothManager.getCachedDeviceManager();
        CachedBluetoothDevice cachedDevice = cachedDeviceManager.findDevice(mDevice);
        if (cachedDevice == null) {
            cachedDevice = cachedDeviceManager.addDevice(bluetoothManager.getBluetoothAdapter(), bluetoothManager.getProfileManager(), mDevice);
        }
        always = cachedDevice.checkAndIncreaseMessageRejectionCount();
    }
    sendReplyIntentToReceiver(false, always);
}
Also used : CachedBluetoothDeviceManager(com.android.settingslib.bluetooth.CachedBluetoothDeviceManager) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) LocalBluetoothManager(com.android.settingslib.bluetooth.LocalBluetoothManager)

Example 63 with CachedBluetoothDevice

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

the class BluetoothPermissionRequest method checkUserChoice.

/**
 * @return true user had made a choice, this method replies to the request according
 *              to user's previous decision
 *         false user hadnot made any choice on this device
 */
private boolean checkUserChoice() {
    boolean processed = false;
    // ignore if it is something else than phonebook/message settings it wants us to remember
    if (mRequestType != BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS && mRequestType != BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS && mRequestType != BluetoothDevice.REQUEST_TYPE_SIM_ACCESS) {
        if (DEBUG)
            Log.d(TAG, "checkUserChoice(): Unknown RequestType " + mRequestType);
        return processed;
    }
    LocalBluetoothManager bluetoothManager = Utils.getLocalBtManager(mContext);
    CachedBluetoothDeviceManager cachedDeviceManager = bluetoothManager.getCachedDeviceManager();
    CachedBluetoothDevice cachedDevice = cachedDeviceManager.findDevice(mDevice);
    if (cachedDevice == null) {
        cachedDevice = cachedDeviceManager.addDevice(bluetoothManager.getBluetoothAdapter(), bluetoothManager.getProfileManager(), mDevice);
    }
    String intentName = BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY;
    if (mRequestType == BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS) {
        int phonebookPermission = cachedDevice.getPhonebookPermissionChoice();
        if (phonebookPermission == CachedBluetoothDevice.ACCESS_UNKNOWN) {
        // Leave 'processed' as false.
        } else if (phonebookPermission == CachedBluetoothDevice.ACCESS_ALLOWED) {
            sendReplyIntentToReceiver(true);
            processed = true;
        } else if (phonebookPermission == CachedBluetoothDevice.ACCESS_REJECTED) {
            sendReplyIntentToReceiver(false);
            processed = true;
        } else {
            Log.e(TAG, "Bad phonebookPermission: " + phonebookPermission);
        }
    } else if (mRequestType == BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS) {
        int messagePermission = cachedDevice.getMessagePermissionChoice();
        if (messagePermission == CachedBluetoothDevice.ACCESS_UNKNOWN) {
        // Leave 'processed' as false.
        } else if (messagePermission == CachedBluetoothDevice.ACCESS_ALLOWED) {
            sendReplyIntentToReceiver(true);
            processed = true;
        } else if (messagePermission == CachedBluetoothDevice.ACCESS_REJECTED) {
            sendReplyIntentToReceiver(false);
            processed = true;
        } else {
            Log.e(TAG, "Bad messagePermission: " + messagePermission);
        }
    } else if (mRequestType == BluetoothDevice.REQUEST_TYPE_SIM_ACCESS) {
        int simPermission = cachedDevice.getSimPermissionChoice();
        if (simPermission == CachedBluetoothDevice.ACCESS_UNKNOWN) {
        // Leave 'processed' as false.
        } else if (simPermission == CachedBluetoothDevice.ACCESS_ALLOWED) {
            sendReplyIntentToReceiver(true);
            processed = true;
        } else if (simPermission == CachedBluetoothDevice.ACCESS_REJECTED) {
            sendReplyIntentToReceiver(false);
            processed = true;
        } else {
            Log.e(TAG, "Bad simPermission: " + simPermission);
        }
    }
    if (DEBUG)
        Log.d(TAG, "checkUserChoice(): returning " + processed);
    return processed;
}
Also used : CachedBluetoothDeviceManager(com.android.settingslib.bluetooth.CachedBluetoothDeviceManager) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) LocalBluetoothManager(com.android.settingslib.bluetooth.LocalBluetoothManager)

Example 64 with CachedBluetoothDevice

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

the class BluetoothSettings method initDevicePreference.

/**
 * Add a listener, which enables the advanced settings icon.
 *
 * @param preference the newly added preference
 */
@Override
void initDevicePreference(BluetoothDevicePreference preference) {
    preference.setOrder(PAIRED_DEVICE_ORDER);
    CachedBluetoothDevice cachedDevice = preference.getCachedDevice();
    if (cachedDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
        // Only paired device have an associated advanced settings screen
        preference.setOnGearClickListener(mDeviceProfilesListener);
    }
}
Also used : CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice)

Example 65 with CachedBluetoothDevice

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

the class DeviceListPreferenceFragment method onPreferenceTreeClick.

@Override
public boolean onPreferenceTreeClick(Preference preference) {
    if (KEY_BT_SCAN.equals(preference.getKey())) {
        mLocalAdapter.startScanning(true);
        return true;
    }
    if (preference instanceof BluetoothDevicePreference) {
        BluetoothDevicePreference btPreference = (BluetoothDevicePreference) preference;
        CachedBluetoothDevice device = btPreference.getCachedDevice();
        mSelectedDevice = device.getDevice();
        onDevicePreferenceClick(btPreference);
        return true;
    }
    return super.onPreferenceTreeClick(preference);
}
Also used : CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice)

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