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

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

Merge "Remove allowBlocking from all BluetoothProfiles"

parents 062731bc b86023dd
Loading
Loading
Loading
Loading
+284 −227

File changed.

Preview size limit exceeded, changes collapsed.

+113 −70
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package android.bluetooth;
package android.bluetooth;


import static android.bluetooth.BluetoothUtils.getSyncTimeout;

import android.Manifest;
import android.Manifest;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.RequiresPermission;
import android.annotation.RequiresPermission;
@@ -29,14 +31,16 @@ import android.bluetooth.annotations.RequiresLegacyBluetoothPermission;
import android.compat.annotation.UnsupportedAppUsage;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.AttributionSource;
import android.content.AttributionSource;
import android.content.Context;
import android.content.Context;
import android.os.Binder;
import android.os.Build;
import android.os.Build;
import android.os.IBinder;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.RemoteException;
import android.util.Log;
import android.util.Log;


import com.android.modules.utils.SynchronousResultReceiver;

import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
import java.util.concurrent.TimeoutException;


/**
/**
 * This class provides the public APIs to control the Bluetooth A2DP Sink
 * This class provides the public APIs to control the Bluetooth A2DP Sink
@@ -86,7 +90,7 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
                    "BluetoothA2dpSink", IBluetoothA2dpSink.class.getName()) {
                    "BluetoothA2dpSink", IBluetoothA2dpSink.class.getName()) {
                @Override
                @Override
                public IBluetoothA2dpSink getServiceInterface(IBinder service) {
                public IBluetoothA2dpSink getServiceInterface(IBinder service) {
                    return IBluetoothA2dpSink.Stub.asInterface(Binder.allowBlocking(service));
                    return IBluetoothA2dpSink.Stub.asInterface(service);
                }
                }
    };
    };


@@ -140,16 +144,20 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
    public boolean connect(BluetoothDevice device) {
    public boolean connect(BluetoothDevice device) {
        if (DBG) log("connect(" + device + ")");
        if (DBG) log("connect(" + device + ")");
        final IBluetoothA2dpSink service = getService();
        final IBluetoothA2dpSink service = getService();
        if (service != null && isEnabled() && isValidDevice(device)) {
        final boolean defaultValue = false;
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) log(Log.getStackTraceString(new Throwable()));
        } else if (isEnabled() && isValidDevice(device)) {
            try {
            try {
                return service.connect(device, mAttributionSource);
                final SynchronousResultReceiver<Boolean> recv = new SynchronousResultReceiver();
            } catch (RemoteException e) {
                service.connect(device, mAttributionSource, recv);
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue);
                return false;
            } catch (RemoteException | TimeoutException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            }
            }
        }
        }
        if (service == null) Log.w(TAG, "Proxy not attached to service");
        return defaultValue;
        return false;
    }
    }


    /**
    /**
@@ -181,16 +189,20 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
    public boolean disconnect(BluetoothDevice device) {
    public boolean disconnect(BluetoothDevice device) {
        if (DBG) log("disconnect(" + device + ")");
        if (DBG) log("disconnect(" + device + ")");
        final IBluetoothA2dpSink service = getService();
        final IBluetoothA2dpSink service = getService();
        if (service != null && isEnabled() && isValidDevice(device)) {
        final boolean defaultValue = false;
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) log(Log.getStackTraceString(new Throwable()));
        } else if (isEnabled() && isValidDevice(device)) {
            try {
            try {
                return service.disconnect(device, mAttributionSource);
                final SynchronousResultReceiver<Boolean> recv = new SynchronousResultReceiver();
            } catch (RemoteException e) {
                service.disconnect(device, mAttributionSource, recv);
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue);
                return false;
            } catch (RemoteException | TimeoutException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            }
            }
        }
        }
        if (service == null) Log.w(TAG, "Proxy not attached to service");
        return defaultValue;
        return false;
    }
    }


    /**
    /**
@@ -204,17 +216,23 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
    public List<BluetoothDevice> getConnectedDevices() {
    public List<BluetoothDevice> getConnectedDevices() {
        if (VDBG) log("getConnectedDevices()");
        if (VDBG) log("getConnectedDevices()");
        final IBluetoothA2dpSink service = getService();
        final IBluetoothA2dpSink service = getService();
        if (service != null && isEnabled()) {
        final List<BluetoothDevice> defaultValue = new ArrayList<BluetoothDevice>();
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) log(Log.getStackTraceString(new Throwable()));
        } else if (isEnabled()) {
            try {
            try {
                final SynchronousResultReceiver<List<BluetoothDevice>> recv =
                        new SynchronousResultReceiver();
                service.getConnectedDevices(mAttributionSource, recv);
                return Attributable.setAttributionSource(
                return Attributable.setAttributionSource(
                        service.getConnectedDevices(mAttributionSource), mAttributionSource);
                        recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue),
            } catch (RemoteException e) {
                        mAttributionSource);
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
            } catch (RemoteException | TimeoutException e) {
                return new ArrayList<BluetoothDevice>();
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            }
            }
        }
        }
        if (service == null) Log.w(TAG, "Proxy not attached to service");
        return defaultValue;
        return new ArrayList<BluetoothDevice>();
    }
    }


    /**
    /**
@@ -228,18 +246,23 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
    public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
    public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
        if (VDBG) log("getDevicesMatchingStates()");
        if (VDBG) log("getDevicesMatchingStates()");
        final IBluetoothA2dpSink service = getService();
        final IBluetoothA2dpSink service = getService();
        if (service != null && isEnabled()) {
        final List<BluetoothDevice> defaultValue = new ArrayList<BluetoothDevice>();
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) log(Log.getStackTraceString(new Throwable()));
        } else if (isEnabled()) {
            try {
            try {
                final SynchronousResultReceiver<List<BluetoothDevice>> recv =
                        new SynchronousResultReceiver();
                service.getDevicesMatchingConnectionStates(states, mAttributionSource, recv);
                return Attributable.setAttributionSource(
                return Attributable.setAttributionSource(
                        service.getDevicesMatchingConnectionStates(states, mAttributionSource),
                        recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue),
                        mAttributionSource);
                        mAttributionSource);
            } catch (RemoteException e) {
            } catch (RemoteException | TimeoutException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
                return new ArrayList<BluetoothDevice>();
            }
            }
        }
        }
        if (service == null) Log.w(TAG, "Proxy not attached to service");
        return defaultValue;
        return new ArrayList<BluetoothDevice>();
    }
    }


    /**
    /**
@@ -251,18 +274,22 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
    @RequiresBluetoothConnectPermission
    @RequiresBluetoothConnectPermission
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    public int getConnectionState(BluetoothDevice device) {
    public int getConnectionState(BluetoothDevice device) {
        if (VDBG) log("getState(" + device + ")");
        if (VDBG) log("getConnectionState(" + device + ")");
        final IBluetoothA2dpSink service = getService();
        final IBluetoothA2dpSink service = getService();
        if (service != null && isEnabled() && isValidDevice(device)) {
        final int defaultValue = BluetoothProfile.STATE_DISCONNECTED;
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) log(Log.getStackTraceString(new Throwable()));
        } else if (isEnabled() && isValidDevice(device)) {
            try {
            try {
                return service.getConnectionState(device, mAttributionSource);
                final SynchronousResultReceiver<Integer> recv = new SynchronousResultReceiver();
            } catch (RemoteException e) {
                service.getConnectionState(device, mAttributionSource, recv);
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue);
                return BluetoothProfile.STATE_DISCONNECTED;
            } catch (RemoteException | TimeoutException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            }
            }
        }
        }
        if (service == null) Log.w(TAG, "Proxy not attached to service");
        return defaultValue;
        return BluetoothProfile.STATE_DISCONNECTED;
    }
    }


    /**
    /**
@@ -282,16 +309,21 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
    public BluetoothAudioConfig getAudioConfig(BluetoothDevice device) {
    public BluetoothAudioConfig getAudioConfig(BluetoothDevice device) {
        if (VDBG) log("getAudioConfig(" + device + ")");
        if (VDBG) log("getAudioConfig(" + device + ")");
        final IBluetoothA2dpSink service = getService();
        final IBluetoothA2dpSink service = getService();
        if (service != null && isEnabled() && isValidDevice(device)) {
        final BluetoothAudioConfig defaultValue = null;
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) log(Log.getStackTraceString(new Throwable()));
        } else if (isEnabled() && isValidDevice(device)) {
            try {
            try {
                return service.getAudioConfig(device, mAttributionSource);
                final SynchronousResultReceiver<BluetoothAudioConfig> recv =
            } catch (RemoteException e) {
                        new SynchronousResultReceiver();
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                service.getAudioConfig(device, mAttributionSource, recv);
                return null;
                return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue);
            } catch (RemoteException | TimeoutException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            }
            }
        }
        }
        if (service == null) Log.w(TAG, "Proxy not attached to service");
        return defaultValue;
        return null;
    }
    }


    /**
    /**
@@ -337,20 +369,22 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
            @ConnectionPolicy int connectionPolicy) {
            @ConnectionPolicy int connectionPolicy) {
        if (DBG) log("setConnectionPolicy(" + device + ", " + connectionPolicy + ")");
        if (DBG) log("setConnectionPolicy(" + device + ", " + connectionPolicy + ")");
        final IBluetoothA2dpSink service = getService();
        final IBluetoothA2dpSink service = getService();
        if (service != null && isEnabled() && isValidDevice(device)) {
        final boolean defaultValue = false;
            if (connectionPolicy != BluetoothProfile.CONNECTION_POLICY_FORBIDDEN
        if (service == null) {
                    && connectionPolicy != BluetoothProfile.CONNECTION_POLICY_ALLOWED) {
            Log.w(TAG, "Proxy not attached to service");
                return false;
            if (DBG) log(Log.getStackTraceString(new Throwable()));
            }
        } else if (isEnabled() && isValidDevice(device)
                && (connectionPolicy == BluetoothProfile.CONNECTION_POLICY_FORBIDDEN
                    || connectionPolicy == BluetoothProfile.CONNECTION_POLICY_ALLOWED)) {
            try {
            try {
                return service.setConnectionPolicy(device, connectionPolicy, mAttributionSource);
                final SynchronousResultReceiver<Boolean> recv = new SynchronousResultReceiver();
            } catch (RemoteException e) {
                service.setConnectionPolicy(device, connectionPolicy, mAttributionSource, recv);
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue);
                return false;
            } catch (RemoteException | TimeoutException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            }
            }
        }
        }
        if (service == null) Log.w(TAG, "Proxy not attached to service");
        return defaultValue;
        return false;
    }
    }


    /**
    /**
@@ -393,16 +427,20 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
    public @ConnectionPolicy int getConnectionPolicy(@NonNull BluetoothDevice device) {
    public @ConnectionPolicy int getConnectionPolicy(@NonNull BluetoothDevice device) {
        if (VDBG) log("getConnectionPolicy(" + device + ")");
        if (VDBG) log("getConnectionPolicy(" + device + ")");
        final IBluetoothA2dpSink service = getService();
        final IBluetoothA2dpSink service = getService();
        if (service != null && isEnabled() && isValidDevice(device)) {
        final int defaultValue = BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) log(Log.getStackTraceString(new Throwable()));
        } else if (isEnabled() && isValidDevice(device)) {
            try {
            try {
                return service.getConnectionPolicy(device, mAttributionSource);
                final SynchronousResultReceiver<Integer> recv = new SynchronousResultReceiver();
            } catch (RemoteException e) {
                service.getConnectionPolicy(device, mAttributionSource, recv);
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue);
                return BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
            } catch (RemoteException | TimeoutException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            }
            }
        }
        }
        if (service == null) Log.w(TAG, "Proxy not attached to service");
        return defaultValue;
        return BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
    }
    }


    /**
    /**
@@ -420,17 +458,22 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
            android.Manifest.permission.BLUETOOTH_PRIVILEGED,
            android.Manifest.permission.BLUETOOTH_PRIVILEGED,
    })
    })
    public boolean isAudioPlaying(@NonNull BluetoothDevice device) {
    public boolean isAudioPlaying(@NonNull BluetoothDevice device) {
        if (VDBG) log("isAudioPlaying(" + device + ")");
        final IBluetoothA2dpSink service = getService();
        final IBluetoothA2dpSink service = getService();
        if (service != null && isEnabled() && isValidDevice(device)) {
        final boolean defaultValue = false;
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) log(Log.getStackTraceString(new Throwable()));
        } else if (isEnabled() && isValidDevice(device)) {
            try {
            try {
                return service.isA2dpPlaying(device, mAttributionSource);
                final SynchronousResultReceiver<Boolean> recv = new SynchronousResultReceiver();
            } catch (RemoteException e) {
                service.isA2dpPlaying(device, mAttributionSource, recv);
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue);
                return false;
            } catch (RemoteException | TimeoutException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            }
            }
        }
        }
        if (service == null) Log.w(TAG, "Proxy not attached to service");
        return defaultValue;
        return false;
    }
    }


    /**
    /**
+80 −55
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package android.bluetooth;
package android.bluetooth;


import static android.bluetooth.BluetoothUtils.getSyncTimeout;

import android.annotation.RequiresPermission;
import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SdkConstant.SdkConstantType;
@@ -23,13 +25,15 @@ import android.bluetooth.annotations.RequiresBluetoothConnectPermission;
import android.bluetooth.annotations.RequiresLegacyBluetoothPermission;
import android.bluetooth.annotations.RequiresLegacyBluetoothPermission;
import android.content.AttributionSource;
import android.content.AttributionSource;
import android.content.Context;
import android.content.Context;
import android.os.Binder;
import android.os.IBinder;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.RemoteException;
import android.util.Log;
import android.util.Log;


import com.android.modules.utils.SynchronousResultReceiver;

import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
import java.util.concurrent.TimeoutException;


/**
/**
 * This class provides the public APIs to control the Bluetooth AVRCP Controller. It currently
 * This class provides the public APIs to control the Bluetooth AVRCP Controller. It currently
@@ -93,8 +97,7 @@ public final class BluetoothAvrcpController implements BluetoothProfile {
                    "BluetoothAvrcpController", IBluetoothAvrcpController.class.getName()) {
                    "BluetoothAvrcpController", IBluetoothAvrcpController.class.getName()) {
                @Override
                @Override
                public IBluetoothAvrcpController getServiceInterface(IBinder service) {
                public IBluetoothAvrcpController getServiceInterface(IBinder service) {
                    return IBluetoothAvrcpController.Stub.asInterface(
                    return IBluetoothAvrcpController.Stub.asInterface(service);
                            Binder.allowBlocking(service));
                }
                }
    };
    };


@@ -130,19 +133,24 @@ public final class BluetoothAvrcpController implements BluetoothProfile {
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    public List<BluetoothDevice> getConnectedDevices() {
    public List<BluetoothDevice> getConnectedDevices() {
        if (VDBG) log("getConnectedDevices()");
        if (VDBG) log("getConnectedDevices()");
        final IBluetoothAvrcpController service =
        final IBluetoothAvrcpController service = getService();
                getService();
        final List<BluetoothDevice> defaultValue = new ArrayList<BluetoothDevice>();
        if (service != null && isEnabled()) {
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) log(Log.getStackTraceString(new Throwable()));
        } else if (isEnabled()) {
            try {
            try {
                final SynchronousResultReceiver<List<BluetoothDevice>> recv =
                        new SynchronousResultReceiver();
                service.getConnectedDevices(mAttributionSource, recv);
                return Attributable.setAttributionSource(
                return Attributable.setAttributionSource(
                        service.getConnectedDevices(mAttributionSource), mAttributionSource);
                        recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue),
            } catch (RemoteException e) {
                        mAttributionSource);
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
            } catch (RemoteException | TimeoutException e) {
                return new ArrayList<BluetoothDevice>();
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            }
            }
        }
        }
        if (service == null) Log.w(TAG, "Proxy not attached to service");
        return defaultValue;
        return new ArrayList<BluetoothDevice>();
    }
    }


    /**
    /**
@@ -153,20 +161,24 @@ public final class BluetoothAvrcpController implements BluetoothProfile {
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
    public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
        if (VDBG) log("getDevicesMatchingStates()");
        if (VDBG) log("getDevicesMatchingStates()");
        final IBluetoothAvrcpController service =
        final IBluetoothAvrcpController service = getService();
                getService();
        final List<BluetoothDevice> defaultValue = new ArrayList<BluetoothDevice>();
        if (service != null && isEnabled()) {
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) log(Log.getStackTraceString(new Throwable()));
        } else if (isEnabled()) {
            try {
            try {
                final SynchronousResultReceiver<List<BluetoothDevice>> recv =
                        new SynchronousResultReceiver();
                service.getDevicesMatchingConnectionStates(states, mAttributionSource, recv);
                return Attributable.setAttributionSource(
                return Attributable.setAttributionSource(
                        service.getDevicesMatchingConnectionStates(states, mAttributionSource),
                        recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue),
                        mAttributionSource);
                        mAttributionSource);
            } catch (RemoteException e) {
            } catch (RemoteException | TimeoutException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
                return new ArrayList<BluetoothDevice>();
            }
            }
        }
        }
        if (service == null) Log.w(TAG, "Proxy not attached to service");
        return defaultValue;
        return new ArrayList<BluetoothDevice>();
    }
    }


    /**
    /**
@@ -177,18 +189,21 @@ public final class BluetoothAvrcpController implements BluetoothProfile {
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    public int getConnectionState(BluetoothDevice device) {
    public int getConnectionState(BluetoothDevice device) {
        if (VDBG) log("getState(" + device + ")");
        if (VDBG) log("getState(" + device + ")");
        final IBluetoothAvrcpController service =
        final IBluetoothAvrcpController service = getService();
                getService();
        final int defaultValue = BluetoothProfile.STATE_DISCONNECTED;
        if (service != null && isEnabled() && isValidDevice(device)) {
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) log(Log.getStackTraceString(new Throwable()));
        } else if (isEnabled() && isValidDevice(device)) {
            try {
            try {
                return service.getConnectionState(device, mAttributionSource);
                final SynchronousResultReceiver<Integer> recv = new SynchronousResultReceiver();
            } catch (RemoteException e) {
                service.getConnectionState(device, mAttributionSource, recv);
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue);
                return BluetoothProfile.STATE_DISCONNECTED;
            } catch (RemoteException | TimeoutException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            }
            }
        }
        }
        if (service == null) Log.w(TAG, "Proxy not attached to service");
        return defaultValue;
        return BluetoothProfile.STATE_DISCONNECTED;
    }
    }


    /**
    /**
@@ -201,17 +216,22 @@ public final class BluetoothAvrcpController implements BluetoothProfile {
    public BluetoothAvrcpPlayerSettings getPlayerSettings(BluetoothDevice device) {
    public BluetoothAvrcpPlayerSettings getPlayerSettings(BluetoothDevice device) {
        if (DBG) Log.d(TAG, "getPlayerSettings");
        if (DBG) Log.d(TAG, "getPlayerSettings");
        BluetoothAvrcpPlayerSettings settings = null;
        BluetoothAvrcpPlayerSettings settings = null;
        final IBluetoothAvrcpController service =
        final IBluetoothAvrcpController service = getService();
                getService();
        final BluetoothAvrcpPlayerSettings defaultValue = null;
        if (service != null && isEnabled()) {
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) log(Log.getStackTraceString(new Throwable()));
        } else if (isEnabled()) {
            try {
            try {
                settings = service.getPlayerSettings(device, mAttributionSource);
                final SynchronousResultReceiver<BluetoothAvrcpPlayerSettings> recv =
            } catch (RemoteException e) {
                        new SynchronousResultReceiver();
                Log.e(TAG, "Error talking to BT service in getMetadata() " + e);
                service.getPlayerSettings(device, mAttributionSource, recv);
                return null;
                settings = recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue);
            } catch (RemoteException | TimeoutException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            }
            }
        }
        }
        return settings;
        return defaultValue;
    }
    }


    /**
    /**
@@ -222,18 +242,21 @@ public final class BluetoothAvrcpController implements BluetoothProfile {
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    public boolean setPlayerApplicationSetting(BluetoothAvrcpPlayerSettings plAppSetting) {
    public boolean setPlayerApplicationSetting(BluetoothAvrcpPlayerSettings plAppSetting) {
        if (DBG) Log.d(TAG, "setPlayerApplicationSetting");
        if (DBG) Log.d(TAG, "setPlayerApplicationSetting");
        final IBluetoothAvrcpController service =
        final IBluetoothAvrcpController service = getService();
                getService();
        final boolean defaultValue = false;
        if (service != null && isEnabled()) {
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) log(Log.getStackTraceString(new Throwable()));
        } else if (isEnabled()) {
            try {
            try {
                return service.setPlayerApplicationSetting(plAppSetting, mAttributionSource);
                final SynchronousResultReceiver<Boolean> recv = new SynchronousResultReceiver();
            } catch (RemoteException e) {
                service.setPlayerApplicationSetting(plAppSetting, mAttributionSource, recv);
                Log.e(TAG, "Error talking to BT service in setPlayerApplicationSetting() " + e);
                return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue);
                return false;
            } catch (RemoteException | TimeoutException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            }
            }
        }
        }
        if (service == null) Log.w(TAG, "Proxy not attached to service");
        return defaultValue;
        return false;
    }
    }


    /**
    /**
@@ -245,18 +268,20 @@ public final class BluetoothAvrcpController implements BluetoothProfile {
    public void sendGroupNavigationCmd(BluetoothDevice device, int keyCode, int keyState) {
    public void sendGroupNavigationCmd(BluetoothDevice device, int keyCode, int keyState) {
        Log.d(TAG, "sendGroupNavigationCmd dev = " + device + " key " + keyCode + " State = "
        Log.d(TAG, "sendGroupNavigationCmd dev = " + device + " key " + keyCode + " State = "
                + keyState);
                + keyState);
        final IBluetoothAvrcpController service =
        final IBluetoothAvrcpController service = getService();
                getService();
        if (service == null) {
        if (service != null && isEnabled()) {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) log(Log.getStackTraceString(new Throwable()));
        } else if (isEnabled()) {
            try {
            try {
                service.sendGroupNavigationCmd(device, keyCode, keyState, mAttributionSource);
                final SynchronousResultReceiver recv = new SynchronousResultReceiver();
                return;
                service.sendGroupNavigationCmd(device, keyCode, keyState, mAttributionSource, recv);
            } catch (RemoteException e) {
                recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null);
                Log.e(TAG, "Error talking to BT service in sendGroupNavigationCmd()", e);
                return;
                return;
            } catch (RemoteException | TimeoutException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            }
            }
        }
        }
        if (service == null) Log.w(TAG, "Proxy not attached to service");
    }
    }


    private boolean isEnabled() {
    private boolean isEnabled() {
+131 −129

File changed.

Preview size limit exceeded, changes collapsed.

+305 −235

File changed.

Preview size limit exceeded, changes collapsed.

Loading