Search in sources :

Example 71 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project robolectric by robolectric.

the class ShadowBluetoothAdapterTest method canGetAndSetAddress.

@Test
public void canGetAndSetAddress() throws Exception {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    shadowOf(adapter).setAddress("expected");
    assertThat(adapter.getAddress()).isEqualTo("expected");
}
Also used : BluetoothAdapter(android.bluetooth.BluetoothAdapter) Test(org.junit.Test)

Example 72 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter 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();
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) ScanFilter(android.bluetooth.le.ScanFilter) BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 73 with BluetoothAdapter

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

the class DevelopmentSettings method writeBtHciSnoopLogOptions.

private void writeBtHciSnoopLogOptions() {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    adapter.configHciSnoopLog(mBtHciSnoopLog.isChecked());
    Settings.Secure.putInt(getActivity().getContentResolver(), Settings.Secure.BLUETOOTH_HCI_LOG, mBtHciSnoopLog.isChecked() ? 1 : 0);
}
Also used : BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 74 with BluetoothAdapter

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

the class TetherSettings method updateBluetoothState.

private void updateBluetoothState(String[] available, String[] tethered, String[] errored) {
    boolean bluetoothErrored = false;
    for (String s : errored) {
        for (String regex : mBluetoothRegexs) {
            if (s.matches(regex))
                bluetoothErrored = true;
        }
    }
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter == null) {
        return;
    }
    int btState = adapter.getState();
    if (btState == BluetoothAdapter.STATE_TURNING_OFF) {
        mBluetoothTether.setEnabled(false);
        mBluetoothTether.setSummary(R.string.bluetooth_turning_off);
    } else if (btState == BluetoothAdapter.STATE_TURNING_ON) {
        mBluetoothTether.setEnabled(false);
        mBluetoothTether.setSummary(R.string.bluetooth_turning_on);
    } else {
        BluetoothPan bluetoothPan = mBluetoothPan.get();
        if (btState == BluetoothAdapter.STATE_ON && bluetoothPan != null && bluetoothPan.isTetheringOn()) {
            mBluetoothTether.setChecked(true);
            mBluetoothTether.setEnabled(!mDataSaverEnabled);
            int bluetoothTethered = bluetoothPan.getConnectedDevices().size();
            if (bluetoothTethered > 1) {
                String summary = getString(R.string.bluetooth_tethering_devices_connected_subtext, bluetoothTethered);
                mBluetoothTether.setSummary(summary);
            } else if (bluetoothTethered == 1) {
                mBluetoothTether.setSummary(R.string.bluetooth_tethering_device_connected_subtext);
            } else if (bluetoothErrored) {
                mBluetoothTether.setSummary(R.string.bluetooth_tethering_errored_subtext);
            } else {
                mBluetoothTether.setSummary(R.string.bluetooth_tethering_available_subtext);
            }
        } else {
            mBluetoothTether.setEnabled(!mDataSaverEnabled);
            mBluetoothTether.setChecked(false);
            mBluetoothTether.setSummary(R.string.bluetooth_tethering_off_subtext);
        }
    }
}
Also used : BluetoothAdapter(android.bluetooth.BluetoothAdapter) BluetoothPan(android.bluetooth.BluetoothPan)

Example 75 with BluetoothAdapter

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

the class BatteryStatsService method updateExternalStatsSync.

/**
     * Fetches data from external sources (WiFi controller, bluetooth chipset) and updates
     * batterystats with that information.
     *
     * We first grab a lock specific to this method, then once all the data has been collected,
     * we grab the mStats lock and update the data.
     *
     * @param reason The reason why this collection was requested. Useful for debugging.
     * @param updateFlags Which external stats to update. Can be a combination of
     *                    {@link BatteryStatsImpl.ExternalStatsSync#UPDATE_CPU},
     *                    {@link BatteryStatsImpl.ExternalStatsSync#UPDATE_RADIO},
     *                    {@link BatteryStatsImpl.ExternalStatsSync#UPDATE_WIFI},
     *                    and {@link BatteryStatsImpl.ExternalStatsSync#UPDATE_BT}.
     */
void updateExternalStatsSync(final String reason, int updateFlags) {
    SynchronousResultReceiver wifiReceiver = null;
    SynchronousResultReceiver bluetoothReceiver = null;
    SynchronousResultReceiver modemReceiver = null;
    synchronized (mExternalStatsLock) {
        if (mContext == null) {
            // Don't do any work yet.
            return;
        }
        if ((updateFlags & BatteryStatsImpl.ExternalStatsSync.UPDATE_WIFI) != 0) {
            if (mWifiManager == null) {
                mWifiManager = IWifiManager.Stub.asInterface(ServiceManager.getService(Context.WIFI_SERVICE));
            }
            if (mWifiManager != null) {
                try {
                    wifiReceiver = new SynchronousResultReceiver();
                    mWifiManager.requestActivityInfo(wifiReceiver);
                } catch (RemoteException e) {
                // Oh well.
                }
            }
        }
        if ((updateFlags & BatteryStatsImpl.ExternalStatsSync.UPDATE_BT) != 0) {
            final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
            if (adapter != null) {
                bluetoothReceiver = new SynchronousResultReceiver();
                adapter.requestControllerActivityEnergyInfo(bluetoothReceiver);
            }
        }
        if ((updateFlags & BatteryStatsImpl.ExternalStatsSync.UPDATE_RADIO) != 0) {
            if (mTelephony == null) {
                mTelephony = TelephonyManager.from(mContext);
            }
            if (mTelephony != null) {
                modemReceiver = new SynchronousResultReceiver();
                mTelephony.requestModemActivityInfo(modemReceiver);
            }
        }
        WifiActivityEnergyInfo wifiInfo = null;
        BluetoothActivityEnergyInfo bluetoothInfo = null;
        ModemActivityInfo modemInfo = null;
        try {
            wifiInfo = awaitControllerInfo(wifiReceiver);
        } catch (TimeoutException e) {
            Slog.w(TAG, "Timeout reading wifi stats");
        }
        try {
            bluetoothInfo = awaitControllerInfo(bluetoothReceiver);
        } catch (TimeoutException e) {
            Slog.w(TAG, "Timeout reading bt stats");
        }
        try {
            modemInfo = awaitControllerInfo(modemReceiver);
        } catch (TimeoutException e) {
            Slog.w(TAG, "Timeout reading modem stats");
        }
        synchronized (mStats) {
            mStats.addHistoryEventLocked(SystemClock.elapsedRealtime(), SystemClock.uptimeMillis(), BatteryStats.HistoryItem.EVENT_COLLECT_EXTERNAL_STATS, reason, 0);
            mStats.updateCpuTimeLocked();
            mStats.updateKernelWakelocksLocked();
            if (wifiInfo != null) {
                if (wifiInfo.isValid()) {
                    mStats.updateWifiStateLocked(extractDelta(wifiInfo));
                } else {
                    Slog.e(TAG, "wifi info is invalid: " + wifiInfo);
                }
            }
            if (bluetoothInfo != null) {
                if (bluetoothInfo.isValid()) {
                    mStats.updateBluetoothStateLocked(bluetoothInfo);
                } else {
                    Slog.e(TAG, "bluetooth info is invalid: " + bluetoothInfo);
                }
            }
            if (modemInfo != null) {
                if (modemInfo.isValid()) {
                    mStats.updateMobileRadioStateLocked(SystemClock.elapsedRealtime(), modemInfo);
                } else {
                    Slog.e(TAG, "modem info is invalid: " + modemInfo);
                }
            }
        }
    }
}
Also used : SynchronousResultReceiver(android.os.SynchronousResultReceiver) WifiActivityEnergyInfo(android.net.wifi.WifiActivityEnergyInfo) ModemActivityInfo(android.telephony.ModemActivityInfo) RemoteException(android.os.RemoteException) BluetoothAdapter(android.bluetooth.BluetoothAdapter) BluetoothActivityEnergyInfo(android.bluetooth.BluetoothActivityEnergyInfo) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

BluetoothAdapter (android.bluetooth.BluetoothAdapter)87 Intent (android.content.Intent)15 Location (android.location.Location)12 LocationListener (android.location.LocationListener)12 LocationManager (android.location.LocationManager)12 Bundle (android.os.Bundle)12 BluetoothDevice (android.bluetooth.BluetoothDevice)11 IntentFilter (android.content.IntentFilter)7 Handler (android.os.Handler)6 TextToSpeech (android.speech.tts.TextToSpeech)6 ArrayAdapter (android.widget.ArrayAdapter)6 TextView (android.widget.TextView)6 BluetoothActivityEnergyInfo (android.bluetooth.BluetoothActivityEnergyInfo)5 BluetoothProfile (android.bluetooth.BluetoothProfile)5 ServiceListener (android.bluetooth.BluetoothProfile.ServiceListener)5 ScanFilter (android.bluetooth.le.ScanFilter)5 WifiActivityEnergyInfo (android.net.wifi.WifiActivityEnergyInfo)5 RemoteException (android.os.RemoteException)5 SynchronousResultReceiver (android.os.SynchronousResultReceiver)5 ModemActivityInfo (android.telephony.ModemActivityInfo)5