Search in sources :

Example 1 with CachedBluetoothDevice

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

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

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

the class DockService method handleUndocked.

private synchronized void handleUndocked(BluetoothDevice device) {
    mRunnable = null;
    mProfileManager.removeServiceListener(this);
    if (mDialog != null) {
        mDialog.dismiss();
        mDialog = null;
    }
    mDevice = null;
    mPendingDevice = null;
    if (device != null) {
        CachedBluetoothDevice cachedDevice = getCachedBluetoothDevice(device);
        cachedDevice.disconnect();
    }
}
Also used : CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice)

Example 3 with CachedBluetoothDevice

use of com.android.settingslib.bluetooth.CachedBluetoothDevice 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);
    }
}
Also used : LocalBluetoothProfile(com.android.settingslib.bluetooth.LocalBluetoothProfile) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice)

Example 4 with CachedBluetoothDevice

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

the class DockService method handleUnexpectedDisconnect.

private synchronized void handleUnexpectedDisconnect(BluetoothDevice disconnectedDevice, LocalBluetoothProfile profile, int startId) {
    if (DEBUG) {
        Log.d(TAG, "handling failed connect for " + disconnectedDevice);
    }
    // Reconnect if docked.
    if (disconnectedDevice != null) {
        // registerReceiver can't be called from a BroadcastReceiver
        Intent intent = registerReceiver(null, new IntentFilter(Intent.ACTION_DOCK_EVENT));
        if (intent != null) {
            int state = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, Intent.EXTRA_DOCK_STATE_UNDOCKED);
            if (state != Intent.EXTRA_DOCK_STATE_UNDOCKED) {
                BluetoothDevice dockedDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                if (dockedDevice != null && dockedDevice.equals(disconnectedDevice)) {
                    CachedBluetoothDevice cachedDevice = getCachedBluetoothDevice(dockedDevice);
                    cachedDevice.connectProfile(profile);
                }
            }
        }
    }
    DockEventReceiver.finishStartingService(this, startId);
}
Also used : IntentFilter(android.content.IntentFilter) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) Intent(android.content.Intent)

Example 5 with CachedBluetoothDevice

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

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)

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