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

Commit 778eccf4 authored by Matthew Xie's avatar Matthew Xie Committed by Android (Google) Code Review
Browse files

Merge "Check null of pidPair to skip the case the service record has been...

Merge "Check null of pidPair to skip the case the service record has been removed" into ics-factoryrom
parents aff24a52 dcbc97fc
Loading
Loading
Loading
Loading
+12 −14
Original line number Original line Diff line number Diff line
@@ -434,6 +434,10 @@ final class BluetoothAdapterStateMachine extends StateMachine {
                        if (mPublicState == BluetoothAdapter.STATE_TURNING_OFF) {
                        if (mPublicState == BluetoothAdapter.STATE_TURNING_OFF) {
                            transitionTo(mHotOff);
                            transitionTo(mHotOff);
                            finishSwitchingOff();
                            finishSwitchingOff();
                            if (!mContext.getResources().getBoolean
                            (com.android.internal.R.bool.config_bluetooth_adapter_quick_switch)) {
                                deferMessage(obtainMessage(TURN_COLD));
                            }
                        }
                        }
                    } else {
                    } else {
                        if (mPublicState != BluetoothAdapter.STATE_TURNING_ON) {
                        if (mPublicState != BluetoothAdapter.STATE_TURNING_ON) {
@@ -486,16 +490,6 @@ final class BluetoothAdapterStateMachine extends StateMachine {
            }
            }
            return retValue;
            return retValue;
        }
        }

        private void finishSwitchingOff() {
            mBluetoothService.finishDisable();
            if (mContext.getResources().getBoolean
                (com.android.internal.R.bool.config_bluetooth_adapter_quick_switch)) {
                broadcastState(BluetoothAdapter.STATE_OFF);
            } else {
                deferMessage(obtainMessage(TURN_COLD));
            }
        }
    }
    }


    private class BluetoothOn extends State {
    private class BluetoothOn extends State {
@@ -656,12 +650,10 @@ final class BluetoothAdapterStateMachine extends StateMachine {
                    //$FALL-THROUGH$ all devices are already disconnected
                    //$FALL-THROUGH$ all devices are already disconnected
                case ALL_DEVICES_DISCONNECTED:
                case ALL_DEVICES_DISCONNECTED:
                    removeMessages(DEVICES_DISCONNECT_TIMEOUT);
                    removeMessages(DEVICES_DISCONNECT_TIMEOUT);
                    mBluetoothService.finishDisable();
                    finishSwitchingOff();
                    broadcastState(BluetoothAdapter.STATE_OFF);
                    break;
                    break;
                case DEVICES_DISCONNECT_TIMEOUT:
                case DEVICES_DISCONNECT_TIMEOUT:
                    mBluetoothService.finishDisable();
                    finishSwitchingOff();
                    broadcastState(BluetoothAdapter.STATE_OFF);
                    Log.e(TAG, "Devices fail to disconnect, reseting...");
                    Log.e(TAG, "Devices fail to disconnect, reseting...");
                    transitionTo(mHotOff);
                    transitionTo(mHotOff);
                    deferMessage(obtainMessage(TURN_COLD));
                    deferMessage(obtainMessage(TURN_COLD));
@@ -695,6 +687,12 @@ final class BluetoothAdapterStateMachine extends StateMachine {
        }
        }
    }
    }


    private void finishSwitchingOff() {
        mBluetoothService.finishDisable();
        broadcastState(BluetoothAdapter.STATE_OFF);
        mBluetoothService.cleanupAfterFinishDisable();
    }

    private void shutoffBluetooth() {
    private void shutoffBluetooth() {
        mBluetoothService.shutoffBluetooth();
        mBluetoothService.shutoffBluetooth();
        mEventLoop.stop();
        mEventLoop.stop();
+13 −4
Original line number Original line Diff line number Diff line
@@ -390,8 +390,7 @@ public class BluetoothService extends IBluetooth.Stub {
    }
    }


    /**
    /**
     * The Bluetooth has been turned off, but hot. Do bonding, profile,
     * The Bluetooth has been turned off, but hot. Do bonding, profile cleanup
     * and internal cleanup
     */
     */
    synchronized void finishDisable() {
    synchronized void finishDisable() {
        // mark in progress bondings as cancelled
        // mark in progress bondings as cancelled
@@ -409,8 +408,17 @@ public class BluetoothService extends IBluetooth.Stub {
        Intent intent = new Intent(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
        Intent intent = new Intent(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
        intent.putExtra(BluetoothAdapter.EXTRA_SCAN_MODE, BluetoothAdapter.SCAN_MODE_NONE);
        intent.putExtra(BluetoothAdapter.EXTRA_SCAN_MODE, BluetoothAdapter.SCAN_MODE_NONE);
        mContext.sendBroadcast(intent, BLUETOOTH_PERM);
        mContext.sendBroadcast(intent, BLUETOOTH_PERM);
    }


    /**
     * Local clean up after broadcasting STATE_OFF intent
     */
    synchronized void cleanupAfterFinishDisable() {
        mAdapterProperties.clear();
        mAdapterProperties.clear();

        for (Integer srHandle : mServiceRecordToPid.keySet()) {
            removeServiceRecordNative(srHandle);
        }
        mServiceRecordToPid.clear();
        mServiceRecordToPid.clear();


        mProfilesConnected = 0;
        mProfilesConnected = 0;
@@ -1526,6 +1534,8 @@ public class BluetoothService extends IBluetooth.Stub {
    public void removeServiceRecord(int handle) {
    public void removeServiceRecord(int handle) {
        mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM,
        mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM,
                                                "Need BLUETOOTH permission");
                                                "Need BLUETOOTH permission");
        // Since this is a binder call check if Bluetooth is off
        if (getBluetoothStateInternal() == BluetoothAdapter.STATE_OFF) return;
        Message message = mHandler.obtainMessage(MESSAGE_REMOVE_SERVICE_RECORD);
        Message message = mHandler.obtainMessage(MESSAGE_REMOVE_SERVICE_RECORD);
        message.obj = new Pair<Integer, Integer>(handle, Binder.getCallingPid());
        message.obj = new Pair<Integer, Integer>(handle, Binder.getCallingPid());
        mHandler.sendMessage(message);
        mHandler.sendMessage(message);
@@ -1533,8 +1543,7 @@ public class BluetoothService extends IBluetooth.Stub {


    private synchronized void checkAndRemoveRecord(int handle, int pid) {
    private synchronized void checkAndRemoveRecord(int handle, int pid) {
        Pair<Integer, IBinder> pidPair = mServiceRecordToPid.get(handle);
        Pair<Integer, IBinder> pidPair = mServiceRecordToPid.get(handle);
        Integer owner = pidPair.first;
        if (pidPair != null && pid == pidPair.first) {
        if (owner != null && pid == owner.intValue()) {
            if (DBG) Log.d(TAG, "Removing service record " +
            if (DBG) Log.d(TAG, "Removing service record " +
                Integer.toHexString(handle) + " for pid " + pid);
                Integer.toHexString(handle) + " for pid " + pid);
            mServiceRecordToPid.remove(handle);
            mServiceRecordToPid.remove(handle);