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

Commit ef2bc3d4 authored by Jack He's avatar Jack He Committed by Gerrit Code Review
Browse files

Merge "VolumeControlService: Fixes for CTS run"

parents b9def0ef 901a0308
Loading
Loading
Loading
Loading
+59 −16
Original line number Diff line number Diff line
@@ -921,6 +921,10 @@ public class VolumeControlService extends ProfileService {
        public void connect(BluetoothDevice device, AttributionSource source,
                SynchronousResultReceiver receiver) {
            try {
                Objects.requireNonNull(device, "device cannot be null");
                Objects.requireNonNull(source, "source cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");

                VolumeControlService service = getService(source);
                boolean defaultValue = false;
                if (service != null) {
@@ -936,6 +940,10 @@ public class VolumeControlService extends ProfileService {
        public void disconnect(BluetoothDevice device, AttributionSource source,
                SynchronousResultReceiver receiver) {
            try {
                Objects.requireNonNull(device, "device cannot be null");
                Objects.requireNonNull(source, "source cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");

                VolumeControlService service = getService(source);
                boolean defaultValue = false;
                if (service != null) {
@@ -951,6 +959,9 @@ public class VolumeControlService extends ProfileService {
        public void getConnectedDevices(AttributionSource source,
                SynchronousResultReceiver receiver) {
            try {
                Objects.requireNonNull(source, "source cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");

                VolumeControlService service = getService(source);
                List<BluetoothDevice> defaultValue = new ArrayList<>();
                if (service != null) {
@@ -967,6 +978,9 @@ public class VolumeControlService extends ProfileService {
        public void getDevicesMatchingConnectionStates(int[] states,
                AttributionSource source, SynchronousResultReceiver receiver) {
            try {
                Objects.requireNonNull(source, "source cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");

                VolumeControlService service = getService(source);
                List<BluetoothDevice> defaultValue = new ArrayList<>();
                if (service != null) {
@@ -982,6 +996,10 @@ public class VolumeControlService extends ProfileService {
        public void getConnectionState(BluetoothDevice device, AttributionSource source,
                SynchronousResultReceiver receiver) {
            try {
                Objects.requireNonNull(device, "device cannot be null");
                Objects.requireNonNull(source, "source cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");

                VolumeControlService service = getService(source);
                int defaultValue = BluetoothProfile.STATE_DISCONNECTED;
                if (service != null) {
@@ -997,6 +1015,10 @@ public class VolumeControlService extends ProfileService {
        public void setConnectionPolicy(BluetoothDevice device, int connectionPolicy,
                AttributionSource source, SynchronousResultReceiver receiver) {
            try {
                Objects.requireNonNull(device, "device cannot be null");
                Objects.requireNonNull(source, "source cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");

                VolumeControlService service = getService(source);
                boolean defaultValue = false;
                if (service != null) {
@@ -1012,6 +1034,10 @@ public class VolumeControlService extends ProfileService {
        public void getConnectionPolicy(BluetoothDevice device, AttributionSource source,
                SynchronousResultReceiver receiver) {
            try {
                Objects.requireNonNull(device, "device cannot be null");
                Objects.requireNonNull(source, "source cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");

                VolumeControlService service = getService(source);
                int defaultValue = BluetoothProfile.CONNECTION_POLICY_UNKNOWN;
                if (service != null) {
@@ -1027,6 +1053,10 @@ public class VolumeControlService extends ProfileService {
        public void isVolumeOffsetAvailable(BluetoothDevice device,
                AttributionSource source, SynchronousResultReceiver receiver) {
            try {
                Objects.requireNonNull(device, "device cannot be null");
                Objects.requireNonNull(source, "source cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");

                boolean defaultValue = false;
                VolumeControlService service = getService(source);
                if (service != null) {
@@ -1042,6 +1072,10 @@ public class VolumeControlService extends ProfileService {
        public void setVolumeOffset(BluetoothDevice device, int volumeOffset,
                AttributionSource source, SynchronousResultReceiver receiver) {
            try {
                Objects.requireNonNull(device, "device cannot be null");
                Objects.requireNonNull(source, "source cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");

                VolumeControlService service = getService(source);
                if (service != null) {
                    service.setVolumeOffset(device, volumeOffset);
@@ -1056,6 +1090,9 @@ public class VolumeControlService extends ProfileService {
        public void setVolumeGroup(int groupId, int volume, AttributionSource source,
                SynchronousResultReceiver receiver) {
            try {
                Objects.requireNonNull(source, "source cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");

                VolumeControlService service = getService(source);
                if (service != null) {
                    service.setVolumeGroup(groupId, volume);
@@ -1069,6 +1106,11 @@ public class VolumeControlService extends ProfileService {
        @Override
        public void registerCallback(IBluetoothVolumeControlCallback callback,
                AttributionSource source, SynchronousResultReceiver receiver) {
            try {
                Objects.requireNonNull(callback, "callback cannot be null");
                Objects.requireNonNull(source, "source cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");

                VolumeControlService service = getService(source);
                if (service == null) {
                    throw new IllegalStateException("Service is unavailable");
@@ -1076,18 +1118,21 @@ public class VolumeControlService extends ProfileService {

                enforceBluetoothPrivilegedPermission(service);

            try {
                service.mCallbacks.register(callback);
                receiver.send(null);
            } catch (RuntimeException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
                throw new IllegalArgumentException(" Invalid callback");
                receiver.propagateException(e);
            }
        }

        @Override
        public void unregisterCallback(IBluetoothVolumeControlCallback callback,
                AttributionSource source, SynchronousResultReceiver receiver) {
            try {
                Objects.requireNonNull(callback, "callback cannot be null");
                Objects.requireNonNull(source, "source cannot be null");
                Objects.requireNonNull(receiver, "receiver cannot be null");

                VolumeControlService service = getService(source);
                if (service == null) {
                    throw new IllegalStateException("Service is unavailable");
@@ -1095,12 +1140,10 @@ public class VolumeControlService extends ProfileService {

                enforceBluetoothPrivilegedPermission(service);

            try {
                service.mCallbacks.unregister(callback);
                receiver.send(null);
            } catch (RuntimeException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
                throw new IllegalArgumentException(" Invalid callback ");
                receiver.propagateException(e);
            }
        }
    }