Search in sources :

Example 26 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project XobotOS by xamarin.

the class BluetoothHealthProfileHandler method onHealthDeviceChannelChanged.

/*package*/
void onHealthDeviceChannelChanged(String devicePath, String channelPath, boolean exists) {
    debugLog("onHealthDeviceChannelChanged: devicePath: " + devicePath + "ChannelPath: " + channelPath + "Exists: " + exists);
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    String address = mBluetoothService.getAddressFromObjectPath(devicePath);
    if (address == null)
        return;
    BluetoothDevice device = adapter.getRemoteDevice(address);
    BluetoothHealthAppConfiguration config;
    int state, prevState = BluetoothHealth.STATE_CHANNEL_DISCONNECTED;
    ParcelFileDescriptor fd;
    HealthChannel channel;
    config = findHealthApplication(device, channelPath);
    if (exists) {
        channel = findConnectingChannel(device, config);
        if (channel == null) {
            channel = new HealthChannel(device, config, null, false, channelPath);
            channel.mState = BluetoothHealth.STATE_CHANNEL_DISCONNECTED;
            mHealthChannels.add(channel);
        }
        channel.mChannelPath = channelPath;
        fd = mBluetoothService.getChannelFdNative(channelPath);
        if (fd == null) {
            errorLog("Error obtaining fd for channel:" + channelPath);
            disconnectChannel(device, config, channel.mId);
            return;
        }
        boolean mainChannel = getMainChannel(device, config) == null ? false : true;
        if (!mainChannel) {
            String mainChannelPath = mBluetoothService.getMainChannelNative(devicePath);
            if (mainChannelPath == null) {
                errorLog("Main Channel Path is null for devicePath:" + devicePath);
                return;
            }
            if (mainChannelPath.equals(channelPath))
                mainChannel = true;
        }
        channel.mChannelFd = fd;
        channel.mMainChannel = mainChannel;
        prevState = channel.mState;
        state = BluetoothHealth.STATE_CHANNEL_CONNECTED;
    } else {
        channel = findChannelByPath(device, channelPath);
        if (channel == null) {
            errorLog("Channel not found:" + config + ":" + channelPath);
            return;
        }
        mHealthChannels.remove(channel);
        channel.mChannelFd = null;
        prevState = channel.mState;
        state = BluetoothHealth.STATE_CHANNEL_DISCONNECTED;
    }
    channel.mState = state;
    callHealthChannelCallback(config, device, prevState, state, channel.mChannelFd, channel.mId);
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) ParcelFileDescriptor(android.os.ParcelFileDescriptor) BluetoothAdapter(android.bluetooth.BluetoothAdapter) BluetoothHealthAppConfiguration(android.bluetooth.BluetoothHealthAppConfiguration)

Example 27 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project XobotOS by xamarin.

the class BluetoothInputProfileHandler method handleInputDevicePropertyChange.

void handleInputDevicePropertyChange(String address, boolean connected) {
    int state = connected ? BluetoothInputDevice.STATE_CONNECTED : BluetoothInputDevice.STATE_DISCONNECTED;
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    BluetoothDevice device = adapter.getRemoteDevice(address);
    handleInputDeviceStateChange(device, state);
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 28 with BluetoothAdapter

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

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)

Example 29 with BluetoothAdapter

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

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 30 with BluetoothAdapter

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

the class ScoAudioTest method onCreate.

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.scoaudiotest);
    mScoStateTxt = (TextView) findViewById(R.id.scoStateTxt);
    mVdStateTxt = (TextView) findViewById(R.id.vdStateTxt);
    IntentFilter intentFilter = new IntentFilter(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED);
    intentFilter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED);
    intentFilter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
    registerReceiver(mReceiver, intentFilter);
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mAudioManager2 = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
    mHandler = new Handler();
    mMediaControllers[0] = new SimplePlayerController(this, R.id.playPause1, R.id.stop1, R.raw.sine440_mo_16b_16k, AudioManager.STREAM_BLUETOOTH_SCO);
    TextView name = (TextView) findViewById(R.id.playPause1Text);
    name.setText("VOICE_CALL stream");
    mScoButton = (ToggleButton) findViewById(R.id.ForceScoButton);
    mScoButton.setOnCheckedChangeListener(mForceScoChanged);
    mForceScoOn = false;
    mScoButton.setChecked(mForceScoOn);
    mVoiceDialerButton = (ToggleButton) findViewById(R.id.VoiceDialerButton);
    mVoiceDialerButton.setOnCheckedChangeListener(mVoiceDialerChanged);
    mVoiceDialerOn = false;
    mVoiceDialerButton.setChecked(mVoiceDialerOn);
    mMediaControllers[1] = new SimpleRecordController(this, R.id.recStop1, 0, "Sco_record_");
    mTtsInited = false;
    mTts = new TextToSpeech(this, new TtsInitListener());
    mTtsParams = new HashMap<String, String>();
    mTtsParams.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_BLUETOOTH_SCO));
    mTtsParams.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, UTTERANCE);
    mSpeakText = (EditText) findViewById(R.id.speakTextEdit);
    mSpeakText.setOnKeyListener(mSpeakKeyListener);
    mSpeakText.setText("sco audio test sentence");
    mTtsToFileButton = (ToggleButton) findViewById(R.id.TtsToFileButton);
    mTtsToFileButton.setOnCheckedChangeListener(mTtsToFileChanged);
    mTtsToFile = true;
    mTtsToFileButton.setChecked(mTtsToFile);
    mModeSpinner = (Spinner) findViewById(R.id.modeSpinner);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mModeStrings);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mModeSpinner.setAdapter(adapter);
    mModeSpinner.setOnItemSelectedListener(mModeChanged);
    mCurrentMode = mAudioManager.getMode();
    mModeSpinner.setSelection(mCurrentMode);
    mBluetoothHeadsetDevice = null;
    BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
    if (btAdapter != null) {
        btAdapter.getProfileProxy(this, mBluetoothProfileServiceListener, BluetoothProfile.HEADSET);
    }
    sVoiceCommandIntent = new Intent(Intent.ACTION_VOICE_COMMAND);
    sVoiceCommandIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
Also used : IntentFilter(android.content.IntentFilter) Handler(android.os.Handler) Intent(android.content.Intent) TextToSpeech(android.speech.tts.TextToSpeech) TextView(android.widget.TextView) BluetoothAdapter(android.bluetooth.BluetoothAdapter) ArrayAdapter(android.widget.ArrayAdapter)

Aggregations

BluetoothAdapter (android.bluetooth.BluetoothAdapter)184 Intent (android.content.Intent)27 BluetoothDevice (android.bluetooth.BluetoothDevice)22 BluetoothManager (android.bluetooth.BluetoothManager)16 BluetoothPan (android.bluetooth.BluetoothPan)15 IntentFilter (android.content.IntentFilter)15 LocationManager (android.location.LocationManager)15 BluetoothProfile (android.bluetooth.BluetoothProfile)13 Location (android.location.Location)12 LocationListener (android.location.LocationListener)12 Bundle (android.os.Bundle)12 TextView (android.widget.TextView)10 BluetoothLeScanner (android.bluetooth.le.BluetoothLeScanner)9 ScanSettings (android.bluetooth.le.ScanSettings)9 ScanCallback (android.bluetooth.le.ScanCallback)8 ScanResult (android.bluetooth.le.ScanResult)8 Method (java.lang.reflect.Method)8 List (java.util.List)8 Activity (android.app.Activity)7 ScanFilter (android.bluetooth.le.ScanFilter)7