Search in sources :

Example 81 with BluetoothAdapter

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

the class Tethering method setBluetoothTethering.

private void setBluetoothTethering(final boolean enable, final ResultReceiver receiver) {
    final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter == null || !adapter.isEnabled()) {
        Log.w(TAG, "Tried to enable bluetooth tethering with null or disabled adapter. null: " + (adapter == null));
        sendTetherResult(receiver, ConnectivityManager.TETHER_ERROR_SERVICE_UNAVAIL);
        return;
    }
    adapter.getProfileProxy(mContext, new ServiceListener() {

        @Override
        public void onServiceDisconnected(int profile) {
        }

        @Override
        public void onServiceConnected(int profile, BluetoothProfile proxy) {
            ((BluetoothPan) proxy).setBluetoothTethering(enable);
            // TODO: Enabling bluetooth tethering can fail asynchronously here.
            // We should figure out a way to bubble up that failure instead of sending success.
            int result = ((BluetoothPan) proxy).isTetheringOn() == enable ? ConnectivityManager.TETHER_ERROR_NO_ERROR : ConnectivityManager.TETHER_ERROR_MASTER_ERROR;
            sendTetherResult(receiver, result);
            if (enable && isTetherProvisioningRequired()) {
                scheduleProvisioningRechecks(ConnectivityManager.TETHERING_BLUETOOTH);
            }
            adapter.closeProfileProxy(BluetoothProfile.PAN, proxy);
        }
    }, BluetoothProfile.PAN);
}
Also used : ServiceListener(android.bluetooth.BluetoothProfile.ServiceListener) BluetoothProfile(android.bluetooth.BluetoothProfile) BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 82 with BluetoothAdapter

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

the class AudioService method getBluetoothHeadset.

private boolean getBluetoothHeadset() {
    boolean result = false;
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter != null) {
        result = adapter.getProfileProxy(mContext, mBluetoothProfileServiceListener, BluetoothProfile.HEADSET);
    }
    // If we could not get a bluetooth headset proxy, send a failure message
    // without delay to reset the SCO audio state and clear SCO clients.
    // If we could get a proxy, send a delayed failure message that will reset our state
    // in case we don't receive onServiceConnected().
    sendMsg(mAudioHandler, MSG_BT_HEADSET_CNCT_FAILED, SENDMSG_REPLACE, 0, 0, null, result ? BT_HEADSET_CNCT_TIMEOUT_MS : 0);
    return result;
}
Also used : BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 83 with BluetoothAdapter

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

the class AudioService method onSystemReady.

public void onSystemReady() {
    mSystemReady = true;
    sendMsg(mAudioHandler, MSG_LOAD_SOUND_EFFECTS, SENDMSG_QUEUE, 0, 0, null, 0);
    mScoConnectionState = AudioManager.SCO_AUDIO_STATE_ERROR;
    resetBluetoothSco();
    getBluetoothHeadset();
    //FIXME: this is to maintain compatibility with deprecated intent
    // AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED. Remove when appropriate.
    Intent newIntent = new Intent(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED);
    newIntent.putExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, AudioManager.SCO_AUDIO_STATE_DISCONNECTED);
    sendStickyBroadcastToAll(newIntent);
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter != null) {
        adapter.getProfileProxy(mContext, mBluetoothProfileServiceListener, BluetoothProfile.A2DP);
    }
    mHdmiManager = (HdmiControlManager) mContext.getSystemService(Context.HDMI_CONTROL_SERVICE);
    if (mHdmiManager != null) {
        synchronized (mHdmiManager) {
            mHdmiTvClient = mHdmiManager.getTvClient();
            if (mHdmiTvClient != null) {
                mFixedVolumeDevices &= ~AudioSystem.DEVICE_ALL_HDMI_SYSTEM_AUDIO_AND_SPEAKER;
            }
            mHdmiPlaybackClient = mHdmiManager.getPlaybackClient();
            mHdmiCecSink = false;
        }
    }
    mNm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    sendMsg(mAudioHandler, MSG_CONFIGURE_SAFE_MEDIA_VOLUME_FORCED, SENDMSG_REPLACE, 0, 0, TAG, SAFE_VOLUME_CONFIGURE_TIMEOUT_MS);
    StreamOverride.init(mContext);
    mControllerService.init();
    onIndicateSystemReady();
}
Also used : Intent(android.content.Intent) BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Aggregations

BluetoothAdapter (android.bluetooth.BluetoothAdapter)83 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)6 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