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

Commit b8670987 authored by Henri Chataing's avatar Henri Chataing
Browse files

VolumeControlService: Push registerCallback and unregisterCallback to the handler thread

Resolves two issues:
- registerCallback invokes an aconfig flag which _can_
  require READ_DEVICE_CONFIG permission, this prevents
  the caller implicitely requiring the permission
- mCallbacks is not otherwise protected against
  concurrent access from the handler thread

Test: atest CtsBluetoothTestCases
Bug: 307408418
Change-Id: I4fd8e84e44bac8f272bbfff28377473d689a9979
parent 579d20b1
Loading
Loading
Loading
Loading
+19 −7
Original line number Diff line number Diff line
@@ -85,8 +85,7 @@ public class VolumeControlService extends ProfileService {
    private Handler mHandler = null;
    private FeatureFlags mFeatureFlags;

    @VisibleForTesting
    RemoteCallbackList<IBluetoothVolumeControlCallback> mCallbacks;
    @VisibleForTesting RemoteCallbackList<IBluetoothVolumeControlCallback> mCallbacks;

    @VisibleForTesting
    static class VolumeControlOffsetDescriptor {
@@ -1775,11 +1774,18 @@ public class VolumeControlService extends ProfileService {
                }

                enforceBluetoothPrivilegedPermission(service);
                service.mHandler.post(
                        () -> {
                            try {
                                service.registerCallback(callback);
                                receiver.send(null);
                            } catch (RuntimeException e) {
                                receiver.propagateException(e);
                            }
                        });
            } catch (RuntimeException e) {
                receiver.propagateException(e);
            }
        }

        @Override
@@ -1796,12 +1802,18 @@ public class VolumeControlService extends ProfileService {
                }

                enforceBluetoothPrivilegedPermission(service);

                service.mHandler.post(
                        () -> {
                            try {
                                service.mCallbacks.unregister(callback);
                                receiver.send(null);
                            } catch (RuntimeException e) {
                                receiver.propagateException(e);
                            }
                        });
            } catch (RuntimeException e) {
                receiver.propagateException(e);
            }
        }
    }