use of android.bluetooth.BluetoothDevice in project android_frameworks_base by AOSPA.
the class BluetoothEventManager method readPairedDevices.
boolean readPairedDevices() {
Set<BluetoothDevice> bondedDevices = mLocalAdapter.getBondedDevices();
if (bondedDevices == null) {
return false;
}
boolean deviceAdded = false;
for (BluetoothDevice device : bondedDevices) {
CachedBluetoothDevice cachedDevice = mDeviceManager.findDevice(device);
if (cachedDevice == null) {
cachedDevice = mDeviceManager.addDevice(mLocalAdapter, mProfileManager, device);
dispatchDeviceAdded(cachedDevice);
deviceAdded = true;
}
}
return deviceAdded;
}
use of android.bluetooth.BluetoothDevice in project BleLiteLib4android by afunx.
the class BleConnectOperation method run.
@Override
public void run() {
BluetoothDevice bluetoothDevice = BleUtils.getRemoteDevice(mBleAddr);
// bluetoothDevice.fetchUuidsWithSdp();
BleConnector connector = getConnector();
if (connector == null) {
connector = new BleConnector.Builder().build(mAppContext, bluetoothDevice).setGattCallback(mBluetoothGattCallback).create();
setConnector(connector);
}
connector.connect();
}
use of android.bluetooth.BluetoothDevice in project android_frameworks_base by ResurrectionRemix.
the class ScanFilterTest method setUp.
@Override
protected void setUp() throws Exception {
byte[] scanRecord = new byte[] { // advertising flags
0x02, // advertising flags
0x01, // advertising flags
0x1a, // 16 bit service uuids
0x05, // 16 bit service uuids
0x02, // 16 bit service uuids
0x0b, // 16 bit service uuids
0x11, // 16 bit service uuids
0x0a, // 16 bit service uuids
0x11, // setName
0x04, // setName
0x09, // setName
0x50, // setName
0x65, // setName
0x64, // tx power level
0x02, // tx power level
0x0A, // tx power level
(byte) 0xec, // service data
0x05, // service data
0x16, // service data
0x0b, // service data
0x11, // service data
0x50, // service data
0x64, // manufacturer specific data
0x05, // manufacturer specific data
(byte) 0xff, // manufacturer specific data
(byte) 0xe0, // manufacturer specific data
0x00, // manufacturer specific data
0x02, // manufacturer specific data
0x15, // an unknown data type won't cause trouble
0x03, // an unknown data type won't cause trouble
0x50, // an unknown data type won't cause trouble
0x01, // an unknown data type won't cause trouble
0x02 };
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
BluetoothDevice device = adapter.getRemoteDevice(DEVICE_MAC);
mScanResult = new ScanResult(device, ScanRecord.parseFromBytes(scanRecord), -10, 1397545200000000L);
mFilterBuilder = new ScanFilter.Builder();
}
use of android.bluetooth.BluetoothDevice in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class DockEventReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
if (intent == null)
return;
int state = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, EXTRA_INVALID));
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (DEBUG) {
Log.d(TAG, "Action: " + intent.getAction() + " State:" + state + " Device: " + (device == null ? "null" : device.getAliasName()));
}
if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction()) || ACTION_DOCK_SHOW_UI.endsWith(intent.getAction())) {
if ((device == null) && (ACTION_DOCK_SHOW_UI.endsWith(intent.getAction()) || ((state != Intent.EXTRA_DOCK_STATE_UNDOCKED) && (state != Intent.EXTRA_DOCK_STATE_LE_DESK)))) {
if (DEBUG)
Log.d(TAG, "Wrong state: " + state + " or intent: " + intent.toString() + " with null device");
return;
}
switch(state) {
case Intent.EXTRA_DOCK_STATE_UNDOCKED:
case Intent.EXTRA_DOCK_STATE_CAR:
case Intent.EXTRA_DOCK_STATE_DESK:
case Intent.EXTRA_DOCK_STATE_LE_DESK:
case Intent.EXTRA_DOCK_STATE_HE_DESK:
Intent i = new Intent(intent);
i.setClass(context, DockService.class);
beginStartingService(context, i);
break;
default:
Log.e(TAG, "Unknown state: " + state);
break;
}
} else if (BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED.equals(intent.getAction()) || BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED.equals(intent.getAction())) {
int newState = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, BluetoothProfile.STATE_CONNECTED);
int oldState = intent.getIntExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, 0);
/*
* Reconnect to the dock if:
* 1) it is a dock
* 2) it is disconnected
* 3) the disconnect is initiated remotely
* 4) the dock is still docked (check can only be done in the Service)
*/
if (device == null) {
if (DEBUG)
Log.d(TAG, "Device is missing");
return;
}
if (newState == BluetoothProfile.STATE_DISCONNECTED && oldState != BluetoothProfile.STATE_DISCONNECTING) {
// Too bad, the dock state can't be checked from a BroadcastReceiver.
Intent i = new Intent(intent);
i.setClass(context, DockService.class);
beginStartingService(context, i);
}
} else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(intent.getAction())) {
int btState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
if (btState != BluetoothAdapter.STATE_TURNING_ON) {
Intent i = new Intent(intent);
i.setClass(context, DockService.class);
beginStartingService(context, i);
}
}
}
use of android.bluetooth.BluetoothDevice in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class DeviceProfilesSettings method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mManager = Utils.getLocalBtManager(getActivity());
CachedBluetoothDeviceManager deviceManager = mManager.getCachedDeviceManager();
String address = getArguments().getString(ARG_DEVICE_ADDRESS);
BluetoothDevice remoteDevice = mManager.getBluetoothAdapter().getRemoteDevice(address);
mCachedDevice = deviceManager.findDevice(remoteDevice);
if (mCachedDevice == null) {
mCachedDevice = deviceManager.addDevice(mManager.getBluetoothAdapter(), mManager.getProfileManager(), remoteDevice);
}
mProfileManager = mManager.getProfileManager();
}
Aggregations