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

Commit 97283b9f authored by sravan voleti's avatar sravan voleti
Browse files

MAP: Fix MAP disconnect

Use case:
1) connect to remote
2) uncheck MAP from the settings app.

Expected result:
Profile should initiate a disconnect.

Observed Result:
Profile not initiated disconnect.

Root cause:
setConnectionPolicy of MAP service only
updating device profile connection policy.

Fix:
Add extra check with connection policy to initiate
disconnect if received connection policy is FORBIDDEN.

Bug: 158546058
Test: performed above use case, issue not seen.
Change-Id: I173de5bc5ecd3379b526bd642d9e2cfaacf7cf65
parent 02d5e3db
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -588,6 +588,20 @@ public class BluetoothMapService extends ProfileService {
        }
    }

    /**
     * Set connection policy of the profile and tries to disconnect it if connectionPolicy is
     * {@link BluetoothProfile#CONNECTION_POLICY_FORBIDDEN}
     *
     * <p> The device should already be paired.
     * Connection policy can be one of:
     * {@link BluetoothProfile#CONNECTION_POLICY_ALLOWED},
     * {@link BluetoothProfile#CONNECTION_POLICY_FORBIDDEN},
     * {@link BluetoothProfile#CONNECTION_POLICY_UNKNOWN}
     *
     * @param device Paired bluetooth device
     * @param connectionPolicy is the connection policy to set to for this profile
     * @return true if connectionPolicy is set, false on error
     */
    boolean setConnectionPolicy(BluetoothDevice device, int connectionPolicy) {
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED,
                "Need BLUETOOTH_PRIVILEGED permission");
@@ -596,6 +610,9 @@ public class BluetoothMapService extends ProfileService {
        }
        AdapterService.getAdapterService().getDatabase()
                .setProfileConnectionPolicy(device, BluetoothProfile.MAP, connectionPolicy);
        if (connectionPolicy == BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
            disconnect(device);
        }
        return true;
    }