Search in sources :

Example 91 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DeviceProfilesSettings method refreshProfilePreference.

private void refreshProfilePreference(CheckBox profilePref, LocalBluetoothProfile profile) {
    BluetoothDevice device = mCachedDevice.getDevice();
    // Gray out checkbox while connecting and disconnecting.
    profilePref.setEnabled(!mCachedDevice.isBusy());
    if (profile instanceof MapProfile) {
        profilePref.setChecked(mCachedDevice.getMessagePermissionChoice() == CachedBluetoothDevice.ACCESS_ALLOWED);
    } else if (profile instanceof PbapServerProfile) {
        profilePref.setChecked(mCachedDevice.getPhonebookPermissionChoice() == CachedBluetoothDevice.ACCESS_ALLOWED);
    } else if (profile instanceof PanProfile) {
        profilePref.setChecked(profile.getConnectionStatus(device) == BluetoothProfile.STATE_CONNECTED);
    } else {
        profilePref.setChecked(profile.isPreferred(device));
    }
}
Also used : MapProfile(com.android.settingslib.bluetooth.MapProfile) PbapServerProfile(com.android.settingslib.bluetooth.PbapServerProfile) BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) PanProfile(com.android.settingslib.bluetooth.PanProfile)

Example 92 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DockService method parseIntent.

private Message parseIntent(Intent intent) {
    BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
    int state = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, -1234);
    if (DEBUG) {
        Log.d(TAG, "Action: " + intent.getAction() + " State:" + state + " Device: " + (device == null ? "null" : device.getAliasName()));
    }
    int msgType;
    switch(state) {
        case Intent.EXTRA_DOCK_STATE_UNDOCKED:
            msgType = MSG_TYPE_UNDOCKED_TEMPORARY;
            break;
        case Intent.EXTRA_DOCK_STATE_DESK:
        case Intent.EXTRA_DOCK_STATE_HE_DESK:
        case Intent.EXTRA_DOCK_STATE_CAR:
            if (device == null) {
                Log.w(TAG, "device is null");
                return null;
            }
        /// Fall Through ///
        case Intent.EXTRA_DOCK_STATE_LE_DESK:
            if (DockEventReceiver.ACTION_DOCK_SHOW_UI.equals(intent.getAction())) {
                if (device == null) {
                    Log.w(TAG, "device is null");
                    return null;
                }
                msgType = MSG_TYPE_SHOW_UI;
            } else {
                msgType = MSG_TYPE_DOCKED;
            }
            break;
        default:
            return null;
    }
    return mServiceHandler.obtainMessage(msgType, state, 0, device);
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice)

Example 93 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DockService method processMessage.

// This method gets messages from both onStartCommand and mServiceHandler/mServiceLooper
private synchronized void processMessage(Message msg) {
    int msgType = msg.what;
    final int state = msg.arg1;
    final int startId = msg.arg2;
    BluetoothDevice device = null;
    if (msg.obj != null) {
        device = (BluetoothDevice) msg.obj;
    }
    if (DEBUG)
        Log.d(TAG, "processMessage: " + msgType + " state: " + state + " device = " + (device == null ? "null" : device.toString()));
    boolean deferFinishCall = false;
    switch(msgType) {
        case MSG_TYPE_SHOW_UI:
            if (device != null) {
                createDialog(device, state, startId);
            }
            break;
        case MSG_TYPE_DOCKED:
            deferFinishCall = msgTypeDocked(device, state, startId);
            break;
        case MSG_TYPE_UNDOCKED_PERMANENT:
            deferFinishCall = msgTypeUndockedPermanent(device, startId);
            break;
        case MSG_TYPE_UNDOCKED_TEMPORARY:
            msgTypeUndockedTemporary(device, state, startId);
            break;
        case MSG_TYPE_DISABLE_BT:
            deferFinishCall = msgTypeDisableBluetooth(startId);
            break;
    }
    if (mDialog == null && mPendingDevice == null && msgType != MSG_TYPE_UNDOCKED_TEMPORARY && !deferFinishCall) {
        // NOTE: We MUST not call stopSelf() directly, since we need to
        // make sure the wake lock acquired by the Receiver is released.
        DockEventReceiver.finishStartingService(this, startId);
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice)

Example 94 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DeviceProfilesSettings method onProfileClicked.

private void onProfileClicked(LocalBluetoothProfile profile, CheckBox profilePref) {
    BluetoothDevice device = mCachedDevice.getDevice();
    if (!profilePref.isChecked()) {
        // Recheck it, until the dialog is done.
        profilePref.setChecked(true);
        askDisconnect(mManager.getForegroundActivity(), profile);
    } else {
        if (profile instanceof MapProfile) {
            mCachedDevice.setMessagePermissionChoice(BluetoothDevice.ACCESS_ALLOWED);
        }
        if (profile instanceof PbapServerProfile) {
            mCachedDevice.setPhonebookPermissionChoice(BluetoothDevice.ACCESS_ALLOWED);
            refreshProfilePreference(profilePref, profile);
            return;
        }
        if (profile.isPreferred(device)) {
            // profile is preferred but not connected: disable auto-connect
            if (profile instanceof PanProfile) {
                mCachedDevice.connectProfile(profile);
            } else {
                profile.setPreferred(device, false);
            }
        } else {
            profile.setPreferred(device, true);
            mCachedDevice.connectProfile(profile);
        }
        refreshProfilePreference(profilePref, profile);
    }
}
Also used : MapProfile(com.android.settingslib.bluetooth.MapProfile) PbapServerProfile(com.android.settingslib.bluetooth.PbapServerProfile) BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) PanProfile(com.android.settingslib.bluetooth.PanProfile)

Example 95 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project android_frameworks_base by ResurrectionRemix.

the class PbapClientProfile method connect.

public boolean connect(BluetoothDevice device) {
    if (V) {
        Log.d(TAG, "PBAPClientProfile got connect request");
    }
    if (mService == null) {
        return false;
    }
    List<BluetoothDevice> srcs = getConnectedDevices();
    if (srcs != null) {
        for (BluetoothDevice src : srcs) {
            if (src.equals(device)) {
                // Connect to same device, Ignore it
                Log.d(TAG, "Ignoring Connect");
                return true;
            }
        }
        for (BluetoothDevice src : srcs) {
            mService.disconnect(device);
        }
    }
    Log.d(TAG, "PBAPClientProfile attempting to connect to " + device.getAddress());
    return mService.connect(device);
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Aggregations

BluetoothDevice (android.bluetooth.BluetoothDevice)101 Intent (android.content.Intent)13 BluetoothAdapter (android.bluetooth.BluetoothAdapter)12 CachedBluetoothDevice (com.android.settingslib.bluetooth.CachedBluetoothDevice)11 ParcelUuid (android.os.ParcelUuid)9 RemoteException (android.os.RemoteException)9 ScanFilter (android.bluetooth.le.ScanFilter)5 Parcel (android.os.Parcel)5 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 IOException (java.io.IOException)5 GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)5 IntentFilter (android.content.IntentFilter)4 MidiDeviceInfo (android.media.midi.MidiDeviceInfo)4 View (android.view.View)4 AdapterView (android.widget.AdapterView)3 ListView (android.widget.ListView)3 TextView (android.widget.TextView)3 Method (java.lang.reflect.Method)3 ArrayList (java.util.ArrayList)3 PendingIntent (android.app.PendingIntent)2