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

Commit fe290e86 authored by AnubhavGupta's avatar AnubhavGupta Committed by Linux Build Service Account
Browse files

Bluetooth: Add interface for A2DP Sink

 - add new constants
 - add new interfaces

Change-Id: I1b9c9544f186d819a40396b7ebaf512f2c76cfb7
parent 0886f8e2
Loading
Loading
Loading
Loading
+83 −0
Original line number Original line Diff line number Diff line
@@ -370,6 +370,89 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
        return null;
        return null;
    }
    }


    /**
     * Set priority of the profile
     *
     * <p> The device should already be paired.
     *  Priority can be one of {@link #PRIORITY_ON} orgetBluetoothManager
     * {@link #PRIORITY_OFF},
     *
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
     * permission.
     *
     * @param device Paired bluetooth device
     * @param priority
     * @return true if priority is set, false on error
     * @hide
     */
    public boolean setPriority(BluetoothDevice device, int priority) {
        if (DBG) log("setPriority(" + device + ", " + priority + ")");
        if (mService != null && isEnabled()
            && isValidDevice(device)) {
            if (priority != BluetoothProfile.PRIORITY_OFF &&
                priority != BluetoothProfile.PRIORITY_ON){
                return false;
            }
            try {
                return mService.setPriority(device, priority);
            } catch (RemoteException e) {
                   Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                   return false;
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
            return false;
    }

    /**
     * Get the priority of the profile.
     *
     * <p> The priority can be any of:
     * {@link #PRIORITY_AUTO_CONNECT}, {@link #PRIORITY_OFF},
     * {@link #PRIORITY_ON}, {@link #PRIORITY_UNDEFINED}
     *
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
     *
     * @param device Bluetooth device
     * @return priority of the device
     * @hide
     */
    public int getPriority(BluetoothDevice device) {
        if (VDBG) log("getPriority(" + device + ")");
        if (mService != null && isEnabled()
            && isValidDevice(device)) {
            try {
                return mService.getPriority(device);
            } catch (RemoteException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                return BluetoothProfile.PRIORITY_OFF;
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return BluetoothProfile.PRIORITY_OFF;
    }

    /**
     * Check if A2DP profile is streaming music.
     *
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
     *
     * @param device BluetoothDevice device
     */
    public boolean isA2dpPlaying(BluetoothDevice device) {
        if (mService != null && isEnabled()
            && isValidDevice(device)) {
            try {
                return mService.isA2dpPlaying(device);
            } catch (RemoteException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                return false;
            }
        }
        if (mService == null) Log.w(TAG, "Proxy not attached to service");
        return false;
    }

    /**
    /**
     * Helper for converting a state to a string.
     * Helper for converting a state to a string.
     *
     *
+17 −0
Original line number Original line Diff line number Diff line
@@ -283,6 +283,8 @@ public final class BluetoothClass implements Parcelable {
    public static final int PROFILE_PANU = 4;
    public static final int PROFILE_PANU = 4;
    /** @hide */
    /** @hide */
    public static final int PROFILE_NAP = 5;
    public static final int PROFILE_NAP = 5;
    /** @hide */
    public static final int PROFILE_A2DP_SINK = 6;


    /**
    /**
     * Check class bits for possible bluetooth profile support.
     * Check class bits for possible bluetooth profile support.
@@ -310,6 +312,21 @@ public final class BluetoothClass implements Parcelable {
                default:
                default:
                    return false;
                    return false;
            }
            }
        } else if (profile == PROFILE_A2DP_SINK) {
            if (hasService(Service.CAPTURE)) {
                return true;
            }
            // By the A2DP spec, srcs must indicate the CAPTURE service.
            // However if some device that do not, we try to
            // match on some other class bits.
            switch (getDeviceClass()) {
                case Device.AUDIO_VIDEO_HIFI_AUDIO:
                case Device.AUDIO_VIDEO_SET_TOP_BOX:
                case Device.AUDIO_VIDEO_VCR :
                    return true;
                default:
                    return false;
            }
        } else if (profile == PROFILE_HEADSET) {
        } else if (profile == PROFILE_HEADSET) {
            // The render service class is required by the spec for HFP, so is a
            // The render service class is required by the spec for HFP, so is a
            // pretty good signal
            // pretty good signal
+3 −0
Original line number Original line Diff line number Diff line
@@ -30,5 +30,8 @@ interface IBluetoothA2dpSink {
    List<BluetoothDevice> getConnectedDevices();
    List<BluetoothDevice> getConnectedDevices();
    List<BluetoothDevice> getDevicesMatchingConnectionStates(in int[] states);
    List<BluetoothDevice> getDevicesMatchingConnectionStates(in int[] states);
    int getConnectionState(in BluetoothDevice device);
    int getConnectionState(in BluetoothDevice device);
    boolean setPriority(in BluetoothDevice device, int priority);
    int getPriority(in BluetoothDevice device);
    boolean isA2dpPlaying(in BluetoothDevice device);
    BluetoothAudioConfig getAudioConfig(in BluetoothDevice device);
    BluetoothAudioConfig getAudioConfig(in BluetoothDevice device);
}
}
+11 −0
Original line number Original line Diff line number Diff line
@@ -6260,6 +6260,9 @@ public final class Settings {
        public static final String
        public static final String
                BLUETOOTH_A2DP_SINK_PRIORITY_PREFIX = "bluetooth_a2dp_sink_priority_";
                BLUETOOTH_A2DP_SINK_PRIORITY_PREFIX = "bluetooth_a2dp_sink_priority_";
        /** {@hide} */
        /** {@hide} */
        public static final String
                BLUETOOTH_A2DP_SRC_PRIORITY_PREFIX = "bluetooth_a2dp_src_priority_";
        /** {@hide} */
        public static final String
        public static final String
                BLUETOOTH_INPUT_DEVICE_PRIORITY_PREFIX = "bluetooth_input_device_priority_";
                BLUETOOTH_INPUT_DEVICE_PRIORITY_PREFIX = "bluetooth_input_device_priority_";
        /** {@hide} */
        /** {@hide} */
@@ -6282,6 +6285,14 @@ public final class Settings {
            return BLUETOOTH_A2DP_SINK_PRIORITY_PREFIX + address.toUpperCase(Locale.ROOT);
            return BLUETOOTH_A2DP_SINK_PRIORITY_PREFIX + address.toUpperCase(Locale.ROOT);
        }
        }


        /**
         * Get the key that retrieves a bluetooth a2dp src's priority.
         * @hide
         */
        public static final String getBluetoothA2dpSrcPriorityKey(String address) {
            return BLUETOOTH_A2DP_SRC_PRIORITY_PREFIX + address.toUpperCase(Locale.ROOT);
        }

        /**
        /**
         * Get the key that retrieves a bluetooth Input Device's priority.
         * Get the key that retrieves a bluetooth Input Device's priority.
         * @hide
         * @hide