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

Commit c68ad73e authored by William Escande's avatar William Escande
Browse files

catch exception and return error in ManagerService

If a system exception occur, it will be lost in the binder. Instead we
can catch it and return an error

Fix: 268538823
Test: atest CtsBluetoothTestCases
subtest: BluetoothAdapterTest#test_getSetBluetoothHciSnoopLoggingMode'
Change-Id: I305c572489d72ef7b31ddf3dd7f5ff0d037e98d4
parent 088afbc3
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -3420,22 +3420,26 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
    public int setBtHciSnoopLogMode(int mode) {
        mContext.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED,
                "Need BLUETOOTH_PRIVILEGED permission");
        final BluetoothProperties.snoop_log_mode_values snoopMode;

        switch (mode) {
            case BluetoothAdapter.BT_SNOOP_LOG_MODE_DISABLED:
                BluetoothProperties.snoop_log_mode(
                        BluetoothProperties.snoop_log_mode_values.DISABLED);
                snoopMode = BluetoothProperties.snoop_log_mode_values.DISABLED;
                break;
            case BluetoothAdapter.BT_SNOOP_LOG_MODE_FILTERED:
                BluetoothProperties.snoop_log_mode(
                        BluetoothProperties.snoop_log_mode_values.FILTERED);
                snoopMode = BluetoothProperties.snoop_log_mode_values.FILTERED;
                break;
            case BluetoothAdapter.BT_SNOOP_LOG_MODE_FULL:
                BluetoothProperties.snoop_log_mode(
                        BluetoothProperties.snoop_log_mode_values.FULL);
                snoopMode = BluetoothProperties.snoop_log_mode_values.FULL;
                break;
            default:
                BluetoothProperties.snoop_log_mode(
                        BluetoothProperties.snoop_log_mode_values.EMPTY);
                Log.e(TAG, "setBtHciSnoopLogMode: Not a valid mode:" + mode);
                return BluetoothStatusCodes.ERROR_BAD_PARAMETERS;
        }
        try {
            BluetoothProperties.snoop_log_mode(snoopMode);
        } catch (RuntimeException e) {
            Log.e(TAG, "setBtHciSnoopLogMode: Failed to set mode to " + mode + ": " + e);
            return BluetoothStatusCodes.ERROR_UNKNOWN;
        }
        return BluetoothStatusCodes.SUCCESS;