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

Commit 61345026 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Fix formatting issue on Headset State Machine"

parents e4406bcc c303b43b
Loading
Loading
Loading
Loading
+54 −61
Original line number Original line Diff line number Diff line
@@ -97,11 +97,10 @@ public class HeadsetService extends ProfileService {
            } else if (action.equals(AudioManager.VOLUME_CHANGED_ACTION)) {
            } else if (action.equals(AudioManager.VOLUME_CHANGED_ACTION)) {
                int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1);
                int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1);
                if (streamType == AudioManager.STREAM_BLUETOOTH_SCO) {
                if (streamType == AudioManager.STREAM_BLUETOOTH_SCO) {
                    mStateMachine.sendMessage(HeadsetStateMachine.INTENT_SCO_VOLUME_CHANGED,
                    mStateMachine.sendMessage(
                                              intent);
                            HeadsetStateMachine.INTENT_SCO_VOLUME_CHANGED, intent);
                }
                }
            }
            } else if (action.equals(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY)) {
            else if (action.equals(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY)) {
                int requestType = intent.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
                int requestType = intent.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
                        BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS);
                        BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS);
                if (requestType == BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS) {
                if (requestType == BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS) {
@@ -115,7 +114,8 @@ public class HeadsetService extends ProfileService {
    /**
    /**
     * Handlers for incoming service calls
     * Handlers for incoming service calls
     */
     */
    private static class BluetoothHeadsetBinder extends IBluetoothHeadset.Stub implements IProfileServiceBinder {
    private static class BluetoothHeadsetBinder
            extends IBluetoothHeadset.Stub implements IProfileServiceBinder {
        private HeadsetService mService;
        private HeadsetService mService;


        public BluetoothHeadsetBinder(HeadsetService svc) {
        public BluetoothHeadsetBinder(HeadsetService svc) {
@@ -268,8 +268,8 @@ public class HeadsetService extends ProfileService {
            return service.stopScoUsingVirtualVoiceCall(device);
            return service.stopScoUsingVirtualVoiceCall(device);
        }
        }


        public void phoneStateChanged(int numActive, int numHeld, int callState,
        public void phoneStateChanged(
                                      String number, int type) {
                int numActive, int numHeld, int callState, String number, int type) {
            HeadsetService service = getService();
            HeadsetService service = getService();
            if (service == null) return;
            if (service == null) return;
            service.phoneStateChanged(numActive, numHeld, callState, number, type);
            service.phoneStateChanged(numActive, numHeld, callState, number, type);
@@ -282,9 +282,8 @@ public class HeadsetService extends ProfileService {
            service.clccResponse(index, direction, status, mode, mpty, number, type);
            service.clccResponse(index, direction, status, mode, mpty, number, type);
        }
        }


        public boolean sendVendorSpecificResultCode(BluetoothDevice device,
        public boolean sendVendorSpecificResultCode(
                                                    String command,
                BluetoothDevice device, String command, String arg) {
                                                    String arg) {
            HeadsetService service = getService();
            HeadsetService service = getService();
            if (service == null) {
            if (service == null) {
                return false;
                return false;
@@ -347,8 +346,7 @@ public class HeadsetService extends ProfileService {
    }
    }


    public boolean connect(BluetoothDevice device) {
    public boolean connect(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH ADMIN permission");
                                       "Need BLUETOOTH ADMIN permission");


        if (getPriority(device) == BluetoothProfile.PRIORITY_OFF) {
        if (getPriority(device) == BluetoothProfile.PRIORITY_OFF) {
            return false;
            return false;
@@ -356,8 +354,8 @@ public class HeadsetService extends ProfileService {


        int connectionState = mStateMachine.getConnectionState(device);
        int connectionState = mStateMachine.getConnectionState(device);
        Log.d(TAG, "connectionState = " + connectionState);
        Log.d(TAG, "connectionState = " + connectionState);
        if (connectionState == BluetoothProfile.STATE_CONNECTED ||
        if (connectionState == BluetoothProfile.STATE_CONNECTED
            connectionState == BluetoothProfile.STATE_CONNECTING) {
                || connectionState == BluetoothProfile.STATE_CONNECTING) {
            return false;
            return false;
        }
        }


@@ -366,11 +364,10 @@ public class HeadsetService extends ProfileService {
    }
    }


    boolean disconnect(BluetoothDevice device) {
    boolean disconnect(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH ADMIN permission");
                                       "Need BLUETOOTH ADMIN permission");
        int connectionState = mStateMachine.getConnectionState(device);
        int connectionState = mStateMachine.getConnectionState(device);
        if (connectionState != BluetoothProfile.STATE_CONNECTED &&
        if (connectionState != BluetoothProfile.STATE_CONNECTED
            connectionState != BluetoothProfile.STATE_CONNECTING) {
                && connectionState != BluetoothProfile.STATE_CONNECTING) {
            return false;
            return false;
        }
        }


@@ -394,18 +391,15 @@ public class HeadsetService extends ProfileService {
    }
    }


    public boolean setPriority(BluetoothDevice device, int priority) {
    public boolean setPriority(BluetoothDevice device, int priority) {
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");
                                       "Need BLUETOOTH_ADMIN permission");
        Settings.Global.putInt(getContentResolver(),
        Settings.Global.putInt(getContentResolver(),
            Settings.Global.getBluetoothHeadsetPriorityKey(device.getAddress()),
                Settings.Global.getBluetoothHeadsetPriorityKey(device.getAddress()), priority);
            priority);
        if (DBG) Log.d(TAG, "Saved priority " + device + " = " + priority);
        if (DBG) Log.d(TAG, "Saved priority " + device + " = " + priority);
        return true;
        return true;
    }
    }


    public int getPriority(BluetoothDevice device) {
    public int getPriority(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");
                                       "Need BLUETOOTH_ADMIN permission");
        int priority = Settings.Global.getInt(getContentResolver(),
        int priority = Settings.Global.getInt(getContentResolver(),
                Settings.Global.getBluetoothHeadsetPriorityKey(device.getAddress()),
                Settings.Global.getBluetoothHeadsetPriorityKey(device.getAddress()),
                BluetoothProfile.PRIORITY_UNDEFINED);
                BluetoothProfile.PRIORITY_UNDEFINED);
@@ -415,8 +409,8 @@ public class HeadsetService extends ProfileService {
    boolean startVoiceRecognition(BluetoothDevice device) {
    boolean startVoiceRecognition(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        int connectionState = mStateMachine.getConnectionState(device);
        int connectionState = mStateMachine.getConnectionState(device);
        if (connectionState != BluetoothProfile.STATE_CONNECTED &&
        if (connectionState != BluetoothProfile.STATE_CONNECTED
            connectionState != BluetoothProfile.STATE_CONNECTING) {
                && connectionState != BluetoothProfile.STATE_CONNECTING) {
            return false;
            return false;
        }
        }
        mStateMachine.sendMessage(HeadsetStateMachine.VOICE_RECOGNITION_START);
        mStateMachine.sendMessage(HeadsetStateMachine.VOICE_RECOGNITION_START);
@@ -429,8 +423,8 @@ public class HeadsetService extends ProfileService {
        // But since we allow startVoiceRecognition in STATE_CONNECTED and
        // But since we allow startVoiceRecognition in STATE_CONNECTED and
        // STATE_CONNECTING state, we do these 2 in this method
        // STATE_CONNECTING state, we do these 2 in this method
        int connectionState = mStateMachine.getConnectionState(device);
        int connectionState = mStateMachine.getConnectionState(device);
        if (connectionState != BluetoothProfile.STATE_CONNECTED &&
        if (connectionState != BluetoothProfile.STATE_CONNECTED
            connectionState != BluetoothProfile.STATE_CONNECTING) {
                && connectionState != BluetoothProfile.STATE_CONNECTING) {
            return false;
            return false;
        }
        }
        mStateMachine.sendMessage(HeadsetStateMachine.VOICE_RECOGNITION_STOP);
        mStateMachine.sendMessage(HeadsetStateMachine.VOICE_RECOGNITION_STOP);
@@ -507,16 +501,16 @@ public class HeadsetService extends ProfileService {


    boolean stopScoUsingVirtualVoiceCall(BluetoothDevice device) {
    boolean stopScoUsingVirtualVoiceCall(BluetoothDevice device) {
        int connectionState = mStateMachine.getConnectionState(device);
        int connectionState = mStateMachine.getConnectionState(device);
        if (connectionState != BluetoothProfile.STATE_CONNECTED &&
        if (connectionState != BluetoothProfile.STATE_CONNECTED
            connectionState != BluetoothProfile.STATE_CONNECTING) {
                && connectionState != BluetoothProfile.STATE_CONNECTING) {
            return false;
            return false;
        }
        }
        mStateMachine.sendMessage(HeadsetStateMachine.VIRTUAL_CALL_STOP, device);
        mStateMachine.sendMessage(HeadsetStateMachine.VIRTUAL_CALL_STOP, device);
        return true;
        return true;
    }
    }


    private void phoneStateChanged(int numActive, int numHeld, int callState,
    private void phoneStateChanged(
                                  String number, int type) {
            int numActive, int numHeld, int callState, String number, int type) {
        enforceCallingOrSelfPermission(MODIFY_PHONE_STATE, null);
        enforceCallingOrSelfPermission(MODIFY_PHONE_STATE, null);
        Message msg = mStateMachine.obtainMessage(HeadsetStateMachine.CALL_STATE_CHANGED);
        Message msg = mStateMachine.obtainMessage(HeadsetStateMachine.CALL_STATE_CHANGED);
        msg.obj = new HeadsetCallState(numActive, numHeld, callState, number, type);
        msg.obj = new HeadsetCallState(numActive, numHeld, callState, number, type);
@@ -524,16 +518,15 @@ public class HeadsetService extends ProfileService {
        mStateMachine.sendMessage(msg);
        mStateMachine.sendMessage(msg);
    }
    }


    private void clccResponse(int index, int direction, int status, int mode, boolean mpty,
    private void clccResponse(
                             String number, int type) {
            int index, int direction, int status, int mode, boolean mpty, String number, int type) {
        enforceCallingOrSelfPermission(MODIFY_PHONE_STATE, null);
        enforceCallingOrSelfPermission(MODIFY_PHONE_STATE, null);
        mStateMachine.sendMessage(HeadsetStateMachine.SEND_CCLC_RESPONSE,
        mStateMachine.sendMessage(HeadsetStateMachine.SEND_CCLC_RESPONSE,
                new HeadsetClccResponse(index, direction, status, mode, mpty, number, type));
                new HeadsetClccResponse(index, direction, status, mode, mpty, number, type));
    }
    }


    private boolean sendVendorSpecificResultCode(BluetoothDevice device,
    private boolean sendVendorSpecificResultCode(
                                                 String command,
            BluetoothDevice device, String command, String arg) {
                                                 String arg) {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        int connectionState = mStateMachine.getConnectionState(device);
        int connectionState = mStateMachine.getConnectionState(device);
        if (connectionState != BluetoothProfile.STATE_CONNECTED) {
        if (connectionState != BluetoothProfile.STATE_CONNECTED) {
@@ -584,15 +577,15 @@ public class HeadsetService extends ProfileService {
    private boolean bindResponse(int ind_id, boolean ind_status) {
    private boolean bindResponse(int ind_id, boolean ind_status) {
        for (BluetoothDevice device : getConnectedDevices()) {
        for (BluetoothDevice device : getConnectedDevices()) {
            int connectionState = mStateMachine.getConnectionState(device);
            int connectionState = mStateMachine.getConnectionState(device);
            if (connectionState != BluetoothProfile.STATE_CONNECTED &&
            if (connectionState != BluetoothProfile.STATE_CONNECTED
                connectionState != BluetoothProfile.STATE_CONNECTING) {
                    && connectionState != BluetoothProfile.STATE_CONNECTING) {
                continue;
                continue;
            }
            }
            if (DBG) Log.d("Bind Response sent for", device.getAddress());
            if (DBG) Log.d("Bind Response sent for", device.getAddress());
            Message msg = mStateMachine.obtainMessage(HeadsetStateMachine.BIND_RESPONSE);
            Message msg = mStateMachine.obtainMessage(HeadsetStateMachine.BIND_RESPONSE);
            msg.obj = device;
            msg.obj = device;
            msg.arg1 = ind_id;
            msg.arg1 = ind_id;
            msg.arg2 = (ind_status == true) ? 1 : 0;
            msg.arg2 = ind_status ? 1 : 0;
            mStateMachine.sendMessage(msg);
            mStateMachine.sendMessage(msg);
            return true;
            return true;
        }
        }
+684 −815

File changed.

Preview size limit exceeded, changes collapsed.