Search in sources :

Example 11 with CachedBluetoothDevice

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

the class BluetoothControllerImpl method updateConnected.

private void updateConnected() {
    // Make sure our connection state is up to date.
    int state = mLocalBluetoothManager.getBluetoothAdapter().getConnectionState();
    if (state != mConnectionState) {
        mConnectionState = state;
        mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED);
    }
    if (mLastDevice != null && mLastDevice.isConnected()) {
        // Our current device is still valid.
        return;
    }
    mLastDevice = null;
    for (CachedBluetoothDevice device : getDevices()) {
        if (device.isConnected()) {
            mLastDevice = device;
        }
    }
    if (mLastDevice == null && mConnectionState == BluetoothAdapter.STATE_CONNECTED) {
        // If somehow we think we are connected, but have no connected devices, we aren't
        // connected.
        mConnectionState = BluetoothAdapter.STATE_DISCONNECTED;
        mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED);
    }
}
Also used : CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice)

Example 12 with CachedBluetoothDevice

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

the class KeyboardUI method processKeyboardState.

// Should only be called on the handler thread
private void processKeyboardState() {
    mHandler.removeMessages(MSG_PROCESS_KEYBOARD_STATE);
    if (!mEnabled) {
        mState = STATE_NOT_ENABLED;
        return;
    }
    if (!mBootCompleted) {
        mState = STATE_WAITING_FOR_BOOT_COMPLETED;
        return;
    }
    if (mInTabletMode != InputManager.SWITCH_STATE_OFF) {
        if (mState == STATE_WAITING_FOR_DEVICE_DISCOVERY) {
            stopScanning();
        } else if (mState == STATE_WAITING_FOR_BLUETOOTH) {
            mUIHandler.sendEmptyMessage(MSG_DISMISS_BLUETOOTH_DIALOG);
        }
        mState = STATE_WAITING_FOR_TABLET_MODE_EXIT;
        return;
    }
    final int btState = mLocalBluetoothAdapter.getState();
    if ((btState == BluetoothAdapter.STATE_TURNING_ON || btState == BluetoothAdapter.STATE_ON) && mState == STATE_WAITING_FOR_BLUETOOTH) {
        // If we're waiting for bluetooth but it has come on in the meantime, or is coming
        // on, just dismiss the dialog. This frequently happens during device startup.
        mUIHandler.sendEmptyMessage(MSG_DISMISS_BLUETOOTH_DIALOG);
    }
    if (btState == BluetoothAdapter.STATE_TURNING_ON) {
        mState = STATE_WAITING_FOR_BLUETOOTH;
        // Wait for bluetooth to fully come on.
        return;
    }
    if (btState != BluetoothAdapter.STATE_ON) {
        mState = STATE_WAITING_FOR_BLUETOOTH;
        showBluetoothDialog();
        return;
    }
    CachedBluetoothDevice device = getPairedKeyboard();
    if (mState == STATE_WAITING_FOR_TABLET_MODE_EXIT || mState == STATE_WAITING_FOR_BLUETOOTH) {
        if (device != null) {
            // If we're just coming out of tablet mode or BT just turned on,
            // then we want to go ahead and automatically connect to the
            // keyboard. We want to avoid this in other cases because we might
            // be spuriously called after the user has manually disconnected
            // the keyboard, meaning we shouldn't try to automtically connect
            // it again.
            mState = STATE_PAIRED;
            device.connect(false);
            return;
        }
        mCachedDeviceManager.clearNonBondedDevices();
    }
    device = getDiscoveredKeyboard();
    if (device != null) {
        mState = STATE_PAIRING;
        device.startPairing();
    } else {
        mState = STATE_WAITING_FOR_DEVICE_DISCOVERY;
        startScanning();
    }
}
Also used : CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice)

Example 13 with CachedBluetoothDevice

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

the class RemoteDeviceNameDialogFragment method getDevice.

@VisibleForTesting
CachedBluetoothDevice getDevice(Context context) {
    String deviceAddress = getArguments().getString(KEY_CACHED_DEVICE_ADDRESS);
    LocalBluetoothManager manager = Utils.getLocalBtManager(context);
    BluetoothDevice device = manager.getBluetoothAdapter().getRemoteDevice(deviceAddress);
    return manager.getCachedDeviceManager().findDevice(device);
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) LocalBluetoothManager(com.android.settingslib.bluetooth.LocalBluetoothManager) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 14 with CachedBluetoothDevice

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

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 15 with CachedBluetoothDevice

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

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)85 BluetoothDevice (android.bluetooth.BluetoothDevice)29 LocalBluetoothManager (com.android.settingslib.bluetooth.LocalBluetoothManager)29 CachedBluetoothDeviceManager (com.android.settingslib.bluetooth.CachedBluetoothDeviceManager)14 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)13 DialogInterface (android.content.DialogInterface)7 OnClickListener (android.view.View.OnClickListener)7 MapProfile (com.android.settingslib.bluetooth.MapProfile)7 Intent (android.content.Intent)3 VisibleForTesting (androidx.annotation.VisibleForTesting)3 Preference (androidx.preference.Preference)2 LocalBluetoothProfile (com.android.settingslib.bluetooth.LocalBluetoothProfile)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 IntentFilter (android.content.IntentFilter)1 Bundle (android.os.Bundle)1 ListBuilder (androidx.slice.builders.ListBuilder)1 SubSettingLauncher (com.android.settings.core.SubSettingLauncher)1 GearPreference (com.android.settings.widget.GearPreference)1 PbapServerProfile (com.android.settingslib.bluetooth.PbapServerProfile)1