Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ac415954 authored by Jaikumar Ganesh's avatar Jaikumar Ganesh Committed by Android (Google) Code Review
Browse files

Merge "Incoming connection dialog tweaks."

parents d578be27 d3728cb3
Loading
Loading
Loading
Loading
+32 −14
Original line number Diff line number Diff line
@@ -120,6 +120,7 @@ public final class BluetoothDeviceProfileState extends StateMachine {
    private Pair<Integer, String> mIncomingConnections;
    private PowerManager.WakeLock mWakeLock;
    private PowerManager mPowerManager;
    private boolean mPairingRequestRcvd = false;

    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
@@ -187,6 +188,17 @@ public final class BluetoothDeviceProfileState extends StateMachine {
                Message msg = obtainMessage(CONNECTION_ACCESS_REQUEST_REPLY);
                msg.arg1 = val;
                sendMessage(msg);
            } else if (action.equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) {
                mPairingRequestRcvd = true;
            } else if (action.equals(BluetoothDevice.ACTION_BOND_STATE_CHANGED)) {
                int state = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE,
                        BluetoothDevice.ERROR);
                if (state == BluetoothDevice.BOND_BONDED && mPairingRequestRcvd) {
                    setTrust(BluetoothDevice.CONNECTION_ACCESS_YES);
                    mPairingRequestRcvd = false;
                } else if (state == BluetoothDevice.BOND_NONE) {
                    mPairingRequestRcvd = false;
                }
            }
        }
    };
@@ -207,7 +219,7 @@ public final class BluetoothDeviceProfileState extends StateMachine {
    }

    public BluetoothDeviceProfileState(Context context, String address,
          BluetoothService service, BluetoothA2dpService a2dpService) {
          BluetoothService service, BluetoothA2dpService a2dpService, boolean setTrust) {
        super(address);
        mContext = context;
        mDevice = new BluetoothDevice(address);
@@ -231,6 +243,8 @@ public final class BluetoothDeviceProfileState extends StateMachine {
        filter.addAction(BluetoothInputDevice.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
        filter.addAction(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY);
        filter.addAction(BluetoothDevice.ACTION_PAIRING_REQUEST);
        filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);

        mContext.registerReceiver(mBroadcastReceiver, filter);

@@ -247,6 +261,10 @@ public final class BluetoothDeviceProfileState extends StateMachine {
                                              PowerManager.ACQUIRE_CAUSES_WAKEUP |
                                              PowerManager.ON_AFTER_RELEASE, TAG);
        mWakeLock.setReferenceCounted(false);

        if (setTrust) {
            setTrust(BluetoothDevice.CONNECTION_ACCESS_YES);
        }
    }

    private BluetoothProfile.ServiceListener mBluetoothProfileServiceListener =
+32 −1
Original line number Diff line number Diff line
@@ -21,8 +21,13 @@ import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothHeadset;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.provider.Settings;
import android.util.Log;

import java.io.BufferedReader;
@@ -74,11 +79,17 @@ class BluetoothBondState {
    private BluetoothA2dp mA2dpProxy;
    private BluetoothHeadset mHeadsetProxy;

    private ArrayList<String> mPairingRequestRcvd = new ArrayList<String>();

    BluetoothBondState(Context context, BluetoothService service) {
        mContext = context;
        mService = service;
        mBluetoothInputProfileHandler =
            BluetoothInputProfileHandler.getInstance(mContext, mService);

        IntentFilter filter = new IntentFilter();
        filter.addAction(BluetoothDevice.ACTION_PAIRING_REQUEST);
        mContext.registerReceiver(mReceiver, filter);
    }

    synchronized void setPendingOutgoingBonding(String address) {
@@ -137,11 +148,18 @@ class BluetoothBondState {
        }

        if (state == BluetoothDevice.BOND_BONDED) {
            mService.addProfileState(address);
            boolean setTrust = false;
            if (mPairingRequestRcvd.contains(address)) setTrust = true;

            mService.addProfileState(address, setTrust);
            mPairingRequestRcvd.remove(address);

        } else if (state == BluetoothDevice.BOND_BONDING) {
            if (mA2dpProxy == null || mHeadsetProxy == null) {
                getProfileProxy();
            }
        } else if (state == BluetoothDevice.BOND_NONE) {
            mPairingRequestRcvd.remove(address);
        }

        setProfilePriorities(address, state);
@@ -452,4 +470,17 @@ class BluetoothBondState {
        }
    }

    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent == null) return;

            String action = intent.getAction();
            if (action.equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) {
                BluetoothDevice dev = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                String address = dev.getAddress();
                mPairingRequestRcvd.add(address);
            }
        }
    };
}
+3 −3
Original line number Diff line number Diff line
@@ -2277,11 +2277,11 @@ public class BluetoothService extends IBluetooth.Stub {
        return false;
    }

    BluetoothDeviceProfileState addProfileState(String address) {
    BluetoothDeviceProfileState addProfileState(String address, boolean setTrust) {
        BluetoothDeviceProfileState state = mDeviceProfileState.get(address);
        if (state != null) return state;

        state = new BluetoothDeviceProfileState(mContext, address, this, mA2dpService);
        state = new BluetoothDeviceProfileState(mContext, address, this, mA2dpService, setTrust);
        mDeviceProfileState.put(address, state);
        state.start();
        return state;
@@ -2311,7 +2311,7 @@ public class BluetoothService extends IBluetooth.Stub {
        }
        for (String path : bonds) {
            String address = getAddressFromObjectPath(path);
            BluetoothDeviceProfileState state = addProfileState(address);
            BluetoothDeviceProfileState state = addProfileState(address, false);
        }
    }