Search in sources :

Example 56 with CachedBluetoothDevice

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

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

use of com.android.settingslib.bluetooth.CachedBluetoothDevice in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DeviceProfilesSettings method askDisconnect.

private void askDisconnect(Context context, final LocalBluetoothProfile profile) {
    // local reference for callback
    final CachedBluetoothDevice device = mCachedDevice;
    String name = device.getName();
    if (TextUtils.isEmpty(name)) {
        name = context.getString(R.string.bluetooth_device);
    }
    String profileName = context.getString(profile.getNameResource(device.getDevice()));
    String title = context.getString(R.string.bluetooth_disable_profile_title);
    String message = context.getString(R.string.bluetooth_disable_profile_message, profileName, name);
    DialogInterface.OnClickListener disconnectListener = new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            // Disconnect only when user has selected OK
            if (which == OK_BUTTON) {
                device.disconnect(profile);
                profile.setPreferred(device.getDevice(), false);
                if (profile instanceof MapProfile) {
                    device.setMessagePermissionChoice(BluetoothDevice.ACCESS_REJECTED);
                }
                if (profile instanceof PbapServerProfile) {
                    device.setPhonebookPermissionChoice(BluetoothDevice.ACCESS_REJECTED);
                }
            }
            refreshProfilePreference(findProfile(profile.toString()), profile);
        }
    };
    mDisconnectDialog = Utils.showDisconnectDialog(context, mDisconnectDialog, disconnectListener, title, Html.fromHtml(message));
}
Also used : MapProfile(com.android.settingslib.bluetooth.MapProfile) PbapServerProfile(com.android.settingslib.bluetooth.PbapServerProfile) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) DialogInterface(android.content.DialogInterface) OnClickListener(android.view.View.OnClickListener)

Example 58 with CachedBluetoothDevice

use of com.android.settingslib.bluetooth.CachedBluetoothDevice in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DockService method connectIfEnabled.

private synchronized void connectIfEnabled(BluetoothDevice device) {
    CachedBluetoothDevice cachedDevice = getCachedBluetoothDevice(device);
    List<LocalBluetoothProfile> profiles = cachedDevice.getConnectableProfiles();
    for (LocalBluetoothProfile profile : profiles) {
        if (profile.getPreferred(device) == BluetoothProfile.PRIORITY_AUTO_CONNECT) {
            cachedDevice.connect(false);
            return;
        }
    }
}
Also used : LocalBluetoothProfile(com.android.settingslib.bluetooth.LocalBluetoothProfile) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice)

Example 59 with CachedBluetoothDevice

use of com.android.settingslib.bluetooth.CachedBluetoothDevice in project Resurrection_packages_apps_Settings by ResurrectionRemix.

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

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

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)

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