1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-21 04:20:27 +02:00
Gadgetbridge/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/galaxy_buds/GalaxyBudsIOThread.java
narektor 84e452bd6b Galaxy Buds2 Pro support (this time proper) (#3049)
Mostly copied from the Buds Pro as those earbuds have a similar feature set and mostly the same protocol.

Working:
- Pairing
- Earbud and case battery level
- Finding lost device
- Settings:
	- Noise control:
    	- ANC/ambient/off
        - With one earbud
        - Voice detect and timeouts
    	- Ambient sound during calls
    - Touch options:
    	- Touch lock
        - Switch noise control, voice assistant, Spotify and volume actions
    	- Double tap edge
    - Equalizer
    - Sound balance
	- Seamless earbud connection

Can be improved:
- ~~ANC level and ambient sound volume do nothing, and don't seem to be supported on this model as there is no toggle for either in the official app.~~ (fixed: 26a9d274ae)
- Ambient sound customization has more options than on previous models, but I can't implement it properly as I can't really hear any difference between the options (my buds might be the issue though).
- ~~The touch lock toggle is once again inverted, like on the [Buds2](d2c4990c48)~~ (fixed: 21db5390c1).

Untested:
- Settings:
    - In-ear detection for calls
    - Ambient sound customization
    - Game mode

This PR also makes some visual changes to the settings of various Galaxy Buds models.

I'd also like to be added to the wiki's allow list. I want to add the Buds2 and Buds2 Pro to the list of supported devices.

---

And sorry for creating this many pull requests. This is mostly due to Codeberg breaking the reference to the branch.

Co-authored-by: Narek <narek.email@gmail.com>
Reviewed-on: https://codeberg.org/Freeyourgadget/Gadgetbridge/pulls/3049
Reviewed-by: José Rebelo <joserebelo@noreply.codeberg.org>
Reviewed-by: Andreas Shimokawa <ashimokawa@noreply.codeberg.org>
Co-authored-by: narektor <narektor@noreply.codeberg.org>
Co-committed-by: narektor <narektor@noreply.codeberg.org>
2023-02-21 14:50:24 +00:00

53 lines
1.9 KiB
Java

package nodomain.freeyourgadget.gadgetbridge.service.devices.galaxy_buds;
import static nodomain.freeyourgadget.gadgetbridge.util.GB.hexdump;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.os.ParcelUuid;
import androidx.annotation.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.service.btclassic.BtClassicIoThread;
public class GalaxyBudsIOThread extends BtClassicIoThread {
private static final Logger LOG = LoggerFactory.getLogger(GalaxyBudsIOThread.class);
private final GalaxyBudsProtocol galaxyBudsProtocol;
private final GBDevice gbDevice;
@NonNull
protected UUID getUuidToConnect(@NonNull ParcelUuid[] uuids) {
if (gbDevice.getType().equals(DeviceType.GALAXY_BUDS)) {
return galaxyBudsProtocol.UUID_GALAXY_BUDS_DEVICE_CTRL;
}
return galaxyBudsProtocol.UUID_GALAXY_BUDS_LIVE_DEVICE_CTRL;
}
public GalaxyBudsIOThread(GBDevice device, Context context, GalaxyBudsProtocol deviceProtocol,
GalaxyBudsDeviceSupport galaxyBudsDeviceSupport, BluetoothAdapter bluetoothAdapter) {
super(device, context, deviceProtocol, galaxyBudsDeviceSupport, bluetoothAdapter);
galaxyBudsProtocol = deviceProtocol;
gbDevice = device;
}
@Override
protected byte[] parseIncoming(InputStream inStream) throws IOException {
byte[] buffer = new byte[1048576]; //HUGE read
int bytes = inStream.read(buffer);
LOG.debug("read " + bytes + " bytes. " + hexdump(buffer, 0, bytes));
return Arrays.copyOf(buffer, bytes);
}
}