1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-15 21:27:51 +01:00

Sony Headphones: Simplify capability definition

This commit is contained in:
José Rebelo 2022-05-15 17:22:55 +01:00
parent 0a28ce92a9
commit a5a3e57a34
8 changed files with 272 additions and 121 deletions

View File

@ -0,0 +1,38 @@
/* Copyright (C) 2022 José Rebelo
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones;
public enum SonyHeadphonesCapabilities {
BatterySingle,
BatteryDual,
BatteryCase,
PowerOffFromPhone,
AmbientSoundControl,
WindNoiseReduction,
AncOptimizer,
AudioSettingsOnlyOnSbcCodec,
AudioUpsampling,
ButtonModesLeftRight,
VoiceNotifications,
AutomaticPowerOffWhenTakenOff,
AutomaticPowerOffByTime,
TouchSensorSingle,
Equalizer,
SoundPosition,
SurroundMode,
PauseWhenTakenOff
}

View File

@ -23,7 +23,18 @@ import android.net.Uri;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.apache.commons.lang3.ArrayUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsCustomizer; import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsCustomizer;
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
@ -32,6 +43,7 @@ import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.Device; import nodomain.freeyourgadget.gadgetbridge.entities.Device;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample; import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig;
public abstract class SonyHeadphonesCoordinator extends AbstractDeviceCoordinator { public abstract class SonyHeadphonesCoordinator extends AbstractDeviceCoordinator {
@Override @Override
@ -123,4 +135,113 @@ public abstract class SonyHeadphonesCoordinator extends AbstractDeviceCoordinato
public boolean supportsFindDevice() { public boolean supportsFindDevice() {
return false; return false;
} }
@Override
public boolean supportsPowerOff() {
return supports(SonyHeadphonesCapabilities.PowerOffFromPhone);
}
@Override
public int getBatteryCount() {
if (supports(SonyHeadphonesCapabilities.BatterySingle)) {
if (supports(SonyHeadphonesCapabilities.BatteryDual)) {
throw new IllegalStateException("A device can't have both single and dual battery");
} else if(supports(SonyHeadphonesCapabilities.BatteryCase)) {
throw new IllegalStateException("Devices with single battery + case are not supported by the protocol");
}
}
int batteryCount = 0;
if (supports(SonyHeadphonesCapabilities.BatterySingle)) {
batteryCount += 1;
}
if (supports(SonyHeadphonesCapabilities.BatteryCase)) {
batteryCount += 1;
}
if (supports(SonyHeadphonesCapabilities.BatteryDual)) {
batteryCount += 2;
}
return batteryCount;
}
@Override
public int[] getSupportedDeviceSpecificSettings(final GBDevice device) {
final List<Integer> settings = new ArrayList<>();
if (supports(SonyHeadphonesCapabilities.AmbientSoundControl)) {
if (supports(SonyHeadphonesCapabilities.WindNoiseReduction)) {
settings.add(R.xml.devicesettings_sony_headphones_ambient_sound_control_wind_noise_reduction);
} else {
settings.add(R.xml.devicesettings_sony_headphones_ambient_sound_control);
}
if (supports(SonyHeadphonesCapabilities.AncOptimizer)) {
settings.add(R.xml.devicesettings_sony_headphones_anc_optimizer);
}
}
addSettingsUnderHeader(settings, R.xml.devicesettings_header_other, new LinkedHashMap<SonyHeadphonesCapabilities, Integer>() {{
put(SonyHeadphonesCapabilities.AudioSettingsOnlyOnSbcCodec, R.xml.devicesettings_sony_warning_wh1000xm3);
put(SonyHeadphonesCapabilities.Equalizer, R.xml.devicesettings_sony_headphones_equalizer);
put(SonyHeadphonesCapabilities.SoundPosition, R.xml.devicesettings_sony_headphones_sound_position);
put(SonyHeadphonesCapabilities.SurroundMode, R.xml.devicesettings_sony_headphones_surround_mode);
put(SonyHeadphonesCapabilities.AudioUpsampling, R.xml.devicesettings_sony_headphones_audio_upsampling);
}});
addSettingsUnderHeader(settings, R.xml.devicesettings_header_system, new LinkedHashMap<SonyHeadphonesCapabilities, Integer>() {{
put(SonyHeadphonesCapabilities.ButtonModesLeftRight, R.xml.devicesettings_sony_headphones_button_modes_left_right);
put(SonyHeadphonesCapabilities.TouchSensorSingle, R.xml.devicesettings_sony_headphones_touch_sensor_single);
put(SonyHeadphonesCapabilities.PauseWhenTakenOff, R.xml.devicesettings_sony_headphones_pause_when_taken_off);
put(SonyHeadphonesCapabilities.AutomaticPowerOffWhenTakenOff, R.xml.devicesettings_automatic_power_off_when_taken_off);
put(SonyHeadphonesCapabilities.AutomaticPowerOffByTime, R.xml.devicesettings_automatic_power_off_by_time);
put(SonyHeadphonesCapabilities.VoiceNotifications, R.xml.devicesettings_sony_headphones_notifications_voice_guide);
}});
settings.add(R.xml.devicesettings_sony_headphones_device_info);
return ArrayUtils.toPrimitive(settings.toArray(new Integer[0]));
}
public List<SonyHeadphonesCapabilities> getCapabilities() {
return Collections.emptyList();
}
public boolean supports(final SonyHeadphonesCapabilities capability) {
return getCapabilities().contains(capability);
}
/**
* Add the preference screens for capabilities under a header. The header is also only added if at least one capability is supported by the device.
*
* @param settings the list of settings to update
* @param header the header to add, if any capability supported
* @param capabilities the map of capability to preference screen
*/
private void addSettingsUnderHeader(final List<Integer> settings,
final int header,
final Map<SonyHeadphonesCapabilities, Integer> capabilities) {
final Set<SonyHeadphonesCapabilities> supportedCapabilities = new HashSet<>(capabilities.keySet());
for (SonyHeadphonesCapabilities capability : capabilities.keySet()) {
if (!supports(capability)) {
supportedCapabilities.remove(capability);
}
}
if (supportedCapabilities.isEmpty()) {
// None of the capabilities in the map are supported
return;
}
settings.add(header);
for (Map.Entry<SonyHeadphonesCapabilities, Integer> capabilitiesSetting : capabilities.entrySet()) {
if (supports(capabilitiesSetting.getKey())) {
settings.add(capabilitiesSetting.getValue());
}
}
}
} }

View File

@ -18,9 +18,12 @@ package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.coordinator
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import java.util.Arrays;
import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.SonyHeadphonesCapabilities;
import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.SonyHeadphonesCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.SonyHeadphonesCoordinator;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
import nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig; import nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
@ -41,16 +44,6 @@ public class SonyWFSP800NCoordinator extends SonyHeadphonesCoordinator {
return DeviceType.SONY_WF_SP800N; return DeviceType.SONY_WF_SP800N;
} }
@Override
public int getBatteryCount() {
return 3;
}
@Override
public boolean supportsPowerOff() {
return true;
}
@Override @Override
public BatteryConfig[] getBatteryConfig() { public BatteryConfig[] getBatteryConfig() {
final BatteryConfig battery1 = new BatteryConfig(0, R.drawable.ic_sony_wf_800n_case, R.string.battery_case); final BatteryConfig battery1 = new BatteryConfig(0, R.drawable.ic_sony_wf_800n_case, R.string.battery_case);
@ -61,17 +54,17 @@ public class SonyWFSP800NCoordinator extends SonyHeadphonesCoordinator {
} }
@Override @Override
public int[] getSupportedDeviceSpecificSettings(final GBDevice device) { public List<SonyHeadphonesCapabilities> getCapabilities() {
return new int[]{ return Arrays.asList(
R.xml.devicesettings_sony_headphones_ambient_sound_control, SonyHeadphonesCapabilities.BatteryDual,
R.xml.devicesettings_header_other, SonyHeadphonesCapabilities.BatteryCase,
R.xml.devicesettings_sony_headphones_equalizer, SonyHeadphonesCapabilities.PowerOffFromPhone,
R.xml.devicesettings_header_system, SonyHeadphonesCapabilities.AmbientSoundControl,
R.xml.devicesettings_sony_headphones_button_modes_left_right, SonyHeadphonesCapabilities.Equalizer,
R.xml.devicesettings_sony_headphones_pause_when_taken_off, SonyHeadphonesCapabilities.ButtonModesLeftRight,
R.xml.devicesettings_automatic_power_off_when_taken_off, SonyHeadphonesCapabilities.PauseWhenTakenOff,
R.xml.devicesettings_sony_headphones_notifications_voice_guide, SonyHeadphonesCapabilities.AutomaticPowerOffWhenTakenOff,
R.xml.devicesettings_sony_headphones_device_info SonyHeadphonesCapabilities.VoiceNotifications
}; );
} }
} }

View File

@ -18,9 +18,11 @@ package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.coordinator
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import nodomain.freeyourgadget.gadgetbridge.R; import java.util.Arrays;
import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.SonyHeadphonesCapabilities;
import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.SonyHeadphonesCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.SonyHeadphonesCoordinator;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
@ -41,21 +43,20 @@ public class SonyWH1000XM3Coordinator extends SonyHeadphonesCoordinator {
} }
@Override @Override
public int[] getSupportedDeviceSpecificSettings(final GBDevice device) { public List<SonyHeadphonesCapabilities> getCapabilities() {
return new int[]{ return Arrays.asList(
R.xml.devicesettings_sony_headphones_ambient_sound_control_wind_noise_reduction, SonyHeadphonesCapabilities.BatterySingle,
R.xml.devicesettings_sony_headphones_anc_optimizer, SonyHeadphonesCapabilities.AmbientSoundControl,
R.xml.devicesettings_header_other, SonyHeadphonesCapabilities.WindNoiseReduction,
R.xml.devicesettings_sony_warning_wh1000xm3, SonyHeadphonesCapabilities.AncOptimizer,
R.xml.devicesettings_sony_headphones_equalizer, SonyHeadphonesCapabilities.AudioSettingsOnlyOnSbcCodec,
R.xml.devicesettings_sony_headphones_sound_position, SonyHeadphonesCapabilities.Equalizer,
R.xml.devicesettings_sony_headphones_surround_mode, SonyHeadphonesCapabilities.SoundPosition,
R.xml.devicesettings_sony_headphones_audio_upsampling, SonyHeadphonesCapabilities.SurroundMode,
R.xml.devicesettings_header_system, SonyHeadphonesCapabilities.AudioUpsampling,
R.xml.devicesettings_sony_headphones_touch_sensor_single, SonyHeadphonesCapabilities.TouchSensorSingle,
R.xml.devicesettings_automatic_power_off_by_time, SonyHeadphonesCapabilities.AutomaticPowerOffByTime,
R.xml.devicesettings_sony_headphones_notifications_voice_guide, SonyHeadphonesCapabilities.VoiceNotifications
R.xml.devicesettings_sony_headphones_device_info );
};
} }
} }

View File

@ -18,9 +18,11 @@ package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.coordinator
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import nodomain.freeyourgadget.gadgetbridge.R; import java.util.Arrays;
import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.SonyHeadphonesCapabilities;
import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.SonyHeadphonesCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.SonyHeadphonesCoordinator;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
@ -41,22 +43,21 @@ public class SonyWH1000XM4Coordinator extends SonyHeadphonesCoordinator {
} }
@Override @Override
public int[] getSupportedDeviceSpecificSettings(final GBDevice device) { public List<SonyHeadphonesCapabilities> getCapabilities() {
return new int[]{ return Arrays.asList(
// TODO: Function of [CUSTOM] button // TODO: Function of [CUSTOM] button
R.xml.devicesettings_sony_headphones_ambient_sound_control_wind_noise_reduction,
R.xml.devicesettings_sony_headphones_anc_optimizer,
R.xml.devicesettings_header_other,
R.xml.devicesettings_sony_headphones_equalizer,
R.xml.devicesettings_sony_headphones_audio_upsampling,
R.xml.devicesettings_header_system,
// TODO R.xml.devicesettings_connect_two_devices, // TODO R.xml.devicesettings_connect_two_devices,
// TODO R.xml.devicesettings_sony_headphones_speak_to_chat_with_settings, // TODO R.xml.devicesettings_sony_headphones_speak_to_chat_with_settings,
R.xml.devicesettings_sony_headphones_touch_sensor_single, SonyHeadphonesCapabilities.BatterySingle,
R.xml.devicesettings_sony_headphones_pause_when_taken_off, SonyHeadphonesCapabilities.AmbientSoundControl,
R.xml.devicesettings_automatic_power_off_when_taken_off, SonyHeadphonesCapabilities.WindNoiseReduction,
R.xml.devicesettings_sony_headphones_notifications_voice_guide, SonyHeadphonesCapabilities.AncOptimizer,
R.xml.devicesettings_sony_headphones_device_info SonyHeadphonesCapabilities.Equalizer,
}; SonyHeadphonesCapabilities.AudioUpsampling,
SonyHeadphonesCapabilities.TouchSensorSingle,
SonyHeadphonesCapabilities.PauseWhenTakenOff,
SonyHeadphonesCapabilities.AutomaticPowerOffWhenTakenOff,
SonyHeadphonesCapabilities.VoiceNotifications
);
} }
} }

View File

@ -17,6 +17,8 @@
package nodomain.freeyourgadget.gadgetbridge.model; package nodomain.freeyourgadget.gadgetbridge.model;
import java.util.Objects;
public class BatteryConfig { public class BatteryConfig {
private final int batteryIndex; private final int batteryIndex;
@ -41,6 +43,16 @@ public class BatteryConfig {
return batteryLabel; return batteryLabel;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof BatteryConfig)) return false;
BatteryConfig that = (BatteryConfig) o;
return getBatteryIndex() == that.getBatteryIndex() && getBatteryIcon() == that.getBatteryIcon() && getBatteryLabel() == that.getBatteryLabel();
} }
@Override
public int hashCode() {
return Objects.hash(getBatteryIndex(), getBatteryIcon(), getBatteryLabel());
}
}

View File

@ -26,8 +26,10 @@ import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst; import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
@ -36,6 +38,8 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInf
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdateDeviceInfo; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdateDeviceInfo;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo;
import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.SonyHeadphonesCapabilities;
import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.SonyHeadphonesCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.AmbientSoundControl; import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.AmbientSoundControl;
import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.AudioUpsampling; import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.AudioUpsampling;
import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.AutomaticPowerOff; import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.AutomaticPowerOff;
@ -49,7 +53,6 @@ import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.TouchS
import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.VoiceNotifications; import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.VoiceNotifications;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState; import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.deviceevents.SonyHeadphonesEnqueueRequestEvent; import nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.deviceevents.SonyHeadphonesEnqueueRequestEvent;
import nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.Request; import nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.Request;
import nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.MessageType; import nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.MessageType;
@ -58,6 +61,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.prot
import nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.impl.v1.params.BatteryType; import nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.impl.v1.params.BatteryType;
import nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.impl.v1.params.NoiseCancellingOptimizerStatus; import nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.impl.v1.params.NoiseCancellingOptimizerStatus;
import nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.impl.v1.params.VirtualSoundParam; import nodomain.freeyourgadget.gadgetbridge.service.devices.sony.headphones.protocol.impl.v1.params.VirtualSoundParam;
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class SonyProtocolImplV1 extends AbstractSonyProtocolImpl { public class SonyProtocolImplV1 extends AbstractSonyProtocolImpl {
@ -494,55 +498,36 @@ public class SonyProtocolImplV1 extends AbstractSonyProtocolImpl {
return Collections.emptyList(); return Collections.emptyList();
} }
final DeviceType deviceType = getDevice().getType(); final SonyHeadphonesCoordinator coordinator = (SonyHeadphonesCoordinator) DeviceHelper.getInstance().getCoordinator(getDevice());
final List<Request> capabilityRequests = new ArrayList<>();
// Populate the init requests // Populate the init requests
// TODO: We should be determine which of these we need from the device... final List<Request> capabilityRequests = new ArrayList<>();
switch (deviceType) {
case SONY_WH_1000XM3:
capabilityRequests.add(getFirmwareVersion()); capabilityRequests.add(getFirmwareVersion());
capabilityRequests.add(getBattery(BatteryType.SINGLE));
capabilityRequests.add(getAudioCodec()); capabilityRequests.add(getAudioCodec());
capabilityRequests.add(getAmbientSoundControl());
capabilityRequests.add(getNoiseCancellingOptimizerState()); final Map<SonyHeadphonesCapabilities, Request> capabilityRequestMap = new LinkedHashMap<SonyHeadphonesCapabilities, Request>() {{
capabilityRequests.add(getAudioUpsampling()); put(SonyHeadphonesCapabilities.BatterySingle, getBattery(BatteryType.SINGLE));
capabilityRequests.add(getVoiceNotifications()); put(SonyHeadphonesCapabilities.BatteryDual, getBattery(BatteryType.DUAL));
capabilityRequests.add(getAutomaticPowerOff()); put(SonyHeadphonesCapabilities.BatteryCase, getBattery(BatteryType.CASE));
capabilityRequests.add(getTouchSensor()); put(SonyHeadphonesCapabilities.AmbientSoundControl, getAmbientSoundControl());
capabilityRequests.add(getSurroundMode()); put(SonyHeadphonesCapabilities.AncOptimizer, getNoiseCancellingOptimizerState());
capabilityRequests.add(getSoundPosition()); put(SonyHeadphonesCapabilities.AudioUpsampling, getAudioUpsampling());
capabilityRequests.add(getEqualizer()); put(SonyHeadphonesCapabilities.ButtonModesLeftRight, getButtonModes());
break; put(SonyHeadphonesCapabilities.VoiceNotifications, getVoiceNotifications());
case SONY_WH_1000XM4: put(SonyHeadphonesCapabilities.AutomaticPowerOffWhenTakenOff, getAutomaticPowerOff());
capabilityRequests.add(getFirmwareVersion()); put(SonyHeadphonesCapabilities.AutomaticPowerOffByTime, getAutomaticPowerOff());
capabilityRequests.add(getBattery(BatteryType.SINGLE)); put(SonyHeadphonesCapabilities.TouchSensorSingle, getTouchSensor());
capabilityRequests.add(getAudioCodec()); put(SonyHeadphonesCapabilities.Equalizer, getEqualizer());
capabilityRequests.add(getAmbientSoundControl()); put(SonyHeadphonesCapabilities.SoundPosition, getSoundPosition());
capabilityRequests.add(getNoiseCancellingOptimizerState()); put(SonyHeadphonesCapabilities.SurroundMode, getSurroundMode());
capabilityRequests.add(getAudioUpsampling()); put(SonyHeadphonesCapabilities.PauseWhenTakenOff, getPauseWhenTakenOff());
capabilityRequests.add(getVoiceNotifications()); }};
capabilityRequests.add(getAutomaticPowerOff());
capabilityRequests.add(getTouchSensor()); for (Map.Entry<SonyHeadphonesCapabilities, Request> capabilityEntry : capabilityRequestMap.entrySet()) {
capabilityRequests.add(getEqualizer()); if (coordinator.supports(capabilityEntry.getKey())) {
capabilityRequests.add(getPauseWhenTakenOff()); capabilityRequests.add(capabilityEntry.getValue());
break; }
case SONY_WF_SP800N:
capabilityRequests.add(getFirmwareVersion());
capabilityRequests.add(getBattery(BatteryType.DUAL));
capabilityRequests.add(getBattery(BatteryType.CASE));
capabilityRequests.add(getAudioCodec());
capabilityRequests.add(getAmbientSoundControl());
capabilityRequests.add(getVoiceNotifications());
capabilityRequests.add(getAutomaticPowerOff());
capabilityRequests.add(getEqualizer());
capabilityRequests.add(getButtonModes());
capabilityRequests.add(getPauseWhenTakenOff());
break;
default:
LOG.error("Unsupported Sony device type '{}' with key '{}'", deviceType, deviceType.getKey());
return null;
} }
return Collections.singletonList(new SonyHeadphonesEnqueueRequestEvent(capabilityRequests)); return Collections.singletonList(new SonyHeadphonesEnqueueRequestEvent(capabilityRequests));
@ -1076,19 +1061,8 @@ public class SonyProtocolImplV1 extends AbstractSonyProtocolImpl {
} }
private boolean supportsWindNoiseCancelling() { private boolean supportsWindNoiseCancelling() {
// TODO: We should be able to determine this dynamically... final SonyHeadphonesCoordinator coordinator = (SonyHeadphonesCoordinator) DeviceHelper.getInstance().getCoordinator(getDevice());
final DeviceType deviceType = getDevice().getType(); return coordinator.supports(SonyHeadphonesCapabilities.WindNoiseReduction);
switch (deviceType) {
case SONY_WH_1000XM3:
case SONY_WH_1000XM4:
return true;
case SONY_WF_SP800N:
return false;
default:
LOG.error("Unknown Sony device type '{}' with key '{}'", deviceType, deviceType.getKey());
return false;
}
} }
} }

View File

@ -17,6 +17,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.model.Reminder; import nodomain.freeyourgadget.gadgetbridge.model.Reminder;
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec; import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
import nodomain.freeyourgadget.gadgetbridge.model.WorldClock;
class TestDeviceSupport extends AbstractDeviceSupport { class TestDeviceSupport extends AbstractDeviceSupport {
@ -70,6 +71,11 @@ class TestDeviceSupport extends AbstractDeviceSupport {
} }
@Override
public void onSetWorldClocks(ArrayList<? extends WorldClock> clocks) {
}
@Override @Override
public void onSetCallState(CallSpec callSpec) { public void onSetCallState(CallSpec callSpec) {
@ -90,6 +96,11 @@ class TestDeviceSupport extends AbstractDeviceSupport {
} }
@Override
public void onSetPhoneVolume(float volume) {
}
@Override @Override
public void onInstallApp(Uri uri) { public void onInstallApp(Uri uri) {