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:
parent
0a28ce92a9
commit
a5a3e57a34
@ -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
|
||||
}
|
@ -23,7 +23,18 @@ import android.net.Uri;
|
||||
import androidx.annotation.NonNull;
|
||||
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.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsCustomizer;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator;
|
||||
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.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig;
|
||||
|
||||
public abstract class SonyHeadphonesCoordinator extends AbstractDeviceCoordinator {
|
||||
@Override
|
||||
@ -123,4 +135,113 @@ public abstract class SonyHeadphonesCoordinator extends AbstractDeviceCoordinato
|
||||
public boolean supportsFindDevice() {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,9 +18,12 @@ package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.coordinator
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
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.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||
@ -41,16 +44,6 @@ public class SonyWFSP800NCoordinator extends SonyHeadphonesCoordinator {
|
||||
return DeviceType.SONY_WF_SP800N;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBatteryCount() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsPowerOff() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BatteryConfig[] getBatteryConfig() {
|
||||
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
|
||||
public int[] getSupportedDeviceSpecificSettings(final GBDevice device) {
|
||||
return new int[]{
|
||||
R.xml.devicesettings_sony_headphones_ambient_sound_control,
|
||||
R.xml.devicesettings_header_other,
|
||||
R.xml.devicesettings_sony_headphones_equalizer,
|
||||
R.xml.devicesettings_header_system,
|
||||
R.xml.devicesettings_sony_headphones_button_modes_left_right,
|
||||
R.xml.devicesettings_sony_headphones_pause_when_taken_off,
|
||||
R.xml.devicesettings_automatic_power_off_when_taken_off,
|
||||
R.xml.devicesettings_sony_headphones_notifications_voice_guide,
|
||||
R.xml.devicesettings_sony_headphones_device_info
|
||||
};
|
||||
public List<SonyHeadphonesCapabilities> getCapabilities() {
|
||||
return Arrays.asList(
|
||||
SonyHeadphonesCapabilities.BatteryDual,
|
||||
SonyHeadphonesCapabilities.BatteryCase,
|
||||
SonyHeadphonesCapabilities.PowerOffFromPhone,
|
||||
SonyHeadphonesCapabilities.AmbientSoundControl,
|
||||
SonyHeadphonesCapabilities.Equalizer,
|
||||
SonyHeadphonesCapabilities.ButtonModesLeftRight,
|
||||
SonyHeadphonesCapabilities.PauseWhenTakenOff,
|
||||
SonyHeadphonesCapabilities.AutomaticPowerOffWhenTakenOff,
|
||||
SonyHeadphonesCapabilities.VoiceNotifications
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -18,9 +18,11 @@ package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.coordinator
|
||||
|
||||
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.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||
|
||||
@ -41,21 +43,20 @@ public class SonyWH1000XM3Coordinator extends SonyHeadphonesCoordinator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getSupportedDeviceSpecificSettings(final GBDevice device) {
|
||||
return new int[]{
|
||||
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_warning_wh1000xm3,
|
||||
R.xml.devicesettings_sony_headphones_equalizer,
|
||||
R.xml.devicesettings_sony_headphones_sound_position,
|
||||
R.xml.devicesettings_sony_headphones_surround_mode,
|
||||
R.xml.devicesettings_sony_headphones_audio_upsampling,
|
||||
R.xml.devicesettings_header_system,
|
||||
R.xml.devicesettings_sony_headphones_touch_sensor_single,
|
||||
R.xml.devicesettings_automatic_power_off_by_time,
|
||||
R.xml.devicesettings_sony_headphones_notifications_voice_guide,
|
||||
R.xml.devicesettings_sony_headphones_device_info
|
||||
};
|
||||
public List<SonyHeadphonesCapabilities> getCapabilities() {
|
||||
return Arrays.asList(
|
||||
SonyHeadphonesCapabilities.BatterySingle,
|
||||
SonyHeadphonesCapabilities.AmbientSoundControl,
|
||||
SonyHeadphonesCapabilities.WindNoiseReduction,
|
||||
SonyHeadphonesCapabilities.AncOptimizer,
|
||||
SonyHeadphonesCapabilities.AudioSettingsOnlyOnSbcCodec,
|
||||
SonyHeadphonesCapabilities.Equalizer,
|
||||
SonyHeadphonesCapabilities.SoundPosition,
|
||||
SonyHeadphonesCapabilities.SurroundMode,
|
||||
SonyHeadphonesCapabilities.AudioUpsampling,
|
||||
SonyHeadphonesCapabilities.TouchSensorSingle,
|
||||
SonyHeadphonesCapabilities.AutomaticPowerOffByTime,
|
||||
SonyHeadphonesCapabilities.VoiceNotifications
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -18,9 +18,11 @@ package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.coordinator
|
||||
|
||||
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.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||
|
||||
@ -41,22 +43,21 @@ public class SonyWH1000XM4Coordinator extends SonyHeadphonesCoordinator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getSupportedDeviceSpecificSettings(final GBDevice device) {
|
||||
return new int[]{
|
||||
public List<SonyHeadphonesCapabilities> getCapabilities() {
|
||||
return Arrays.asList(
|
||||
// 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_sony_headphones_speak_to_chat_with_settings,
|
||||
R.xml.devicesettings_sony_headphones_touch_sensor_single,
|
||||
R.xml.devicesettings_sony_headphones_pause_when_taken_off,
|
||||
R.xml.devicesettings_automatic_power_off_when_taken_off,
|
||||
R.xml.devicesettings_sony_headphones_notifications_voice_guide,
|
||||
R.xml.devicesettings_sony_headphones_device_info
|
||||
};
|
||||
SonyHeadphonesCapabilities.BatterySingle,
|
||||
SonyHeadphonesCapabilities.AmbientSoundControl,
|
||||
SonyHeadphonesCapabilities.WindNoiseReduction,
|
||||
SonyHeadphonesCapabilities.AncOptimizer,
|
||||
SonyHeadphonesCapabilities.Equalizer,
|
||||
SonyHeadphonesCapabilities.AudioUpsampling,
|
||||
SonyHeadphonesCapabilities.TouchSensorSingle,
|
||||
SonyHeadphonesCapabilities.PauseWhenTakenOff,
|
||||
SonyHeadphonesCapabilities.AutomaticPowerOffWhenTakenOff,
|
||||
SonyHeadphonesCapabilities.VoiceNotifications
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,8 @@
|
||||
|
||||
package nodomain.freeyourgadget.gadgetbridge.model;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class BatteryConfig {
|
||||
|
||||
private final int batteryIndex;
|
||||
@ -41,6 +43,16 @@ public class BatteryConfig {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,8 +26,10 @@ import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
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.GBDeviceEventUpdatePreferences;
|
||||
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.AudioUpsampling;
|
||||
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.impl.GBDevice;
|
||||
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.protocol.Request;
|
||||
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.NoiseCancellingOptimizerStatus;
|
||||
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;
|
||||
|
||||
public class SonyProtocolImplV1 extends AbstractSonyProtocolImpl {
|
||||
@ -494,55 +498,36 @@ public class SonyProtocolImplV1 extends AbstractSonyProtocolImpl {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
final DeviceType deviceType = getDevice().getType();
|
||||
|
||||
final List<Request> capabilityRequests = new ArrayList<>();
|
||||
final SonyHeadphonesCoordinator coordinator = (SonyHeadphonesCoordinator) DeviceHelper.getInstance().getCoordinator(getDevice());
|
||||
|
||||
// Populate the init requests
|
||||
// TODO: We should be determine which of these we need from the device...
|
||||
switch (deviceType) {
|
||||
case SONY_WH_1000XM3:
|
||||
capabilityRequests.add(getFirmwareVersion());
|
||||
capabilityRequests.add(getBattery(BatteryType.SINGLE));
|
||||
capabilityRequests.add(getAudioCodec());
|
||||
capabilityRequests.add(getAmbientSoundControl());
|
||||
capabilityRequests.add(getNoiseCancellingOptimizerState());
|
||||
capabilityRequests.add(getAudioUpsampling());
|
||||
capabilityRequests.add(getVoiceNotifications());
|
||||
capabilityRequests.add(getAutomaticPowerOff());
|
||||
capabilityRequests.add(getTouchSensor());
|
||||
capabilityRequests.add(getSurroundMode());
|
||||
capabilityRequests.add(getSoundPosition());
|
||||
capabilityRequests.add(getEqualizer());
|
||||
break;
|
||||
case SONY_WH_1000XM4:
|
||||
capabilityRequests.add(getFirmwareVersion());
|
||||
capabilityRequests.add(getBattery(BatteryType.SINGLE));
|
||||
capabilityRequests.add(getAudioCodec());
|
||||
capabilityRequests.add(getAmbientSoundControl());
|
||||
capabilityRequests.add(getNoiseCancellingOptimizerState());
|
||||
capabilityRequests.add(getAudioUpsampling());
|
||||
capabilityRequests.add(getVoiceNotifications());
|
||||
capabilityRequests.add(getAutomaticPowerOff());
|
||||
capabilityRequests.add(getTouchSensor());
|
||||
capabilityRequests.add(getEqualizer());
|
||||
capabilityRequests.add(getPauseWhenTakenOff());
|
||||
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;
|
||||
final List<Request> capabilityRequests = new ArrayList<>();
|
||||
|
||||
capabilityRequests.add(getFirmwareVersion());
|
||||
capabilityRequests.add(getAudioCodec());
|
||||
|
||||
final Map<SonyHeadphonesCapabilities, Request> capabilityRequestMap = new LinkedHashMap<SonyHeadphonesCapabilities, Request>() {{
|
||||
put(SonyHeadphonesCapabilities.BatterySingle, getBattery(BatteryType.SINGLE));
|
||||
put(SonyHeadphonesCapabilities.BatteryDual, getBattery(BatteryType.DUAL));
|
||||
put(SonyHeadphonesCapabilities.BatteryCase, getBattery(BatteryType.CASE));
|
||||
put(SonyHeadphonesCapabilities.AmbientSoundControl, getAmbientSoundControl());
|
||||
put(SonyHeadphonesCapabilities.AncOptimizer, getNoiseCancellingOptimizerState());
|
||||
put(SonyHeadphonesCapabilities.AudioUpsampling, getAudioUpsampling());
|
||||
put(SonyHeadphonesCapabilities.ButtonModesLeftRight, getButtonModes());
|
||||
put(SonyHeadphonesCapabilities.VoiceNotifications, getVoiceNotifications());
|
||||
put(SonyHeadphonesCapabilities.AutomaticPowerOffWhenTakenOff, getAutomaticPowerOff());
|
||||
put(SonyHeadphonesCapabilities.AutomaticPowerOffByTime, getAutomaticPowerOff());
|
||||
put(SonyHeadphonesCapabilities.TouchSensorSingle, getTouchSensor());
|
||||
put(SonyHeadphonesCapabilities.Equalizer, getEqualizer());
|
||||
put(SonyHeadphonesCapabilities.SoundPosition, getSoundPosition());
|
||||
put(SonyHeadphonesCapabilities.SurroundMode, getSurroundMode());
|
||||
put(SonyHeadphonesCapabilities.PauseWhenTakenOff, getPauseWhenTakenOff());
|
||||
}};
|
||||
|
||||
for (Map.Entry<SonyHeadphonesCapabilities, Request> capabilityEntry : capabilityRequestMap.entrySet()) {
|
||||
if (coordinator.supports(capabilityEntry.getKey())) {
|
||||
capabilityRequests.add(capabilityEntry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.singletonList(new SonyHeadphonesEnqueueRequestEvent(capabilityRequests));
|
||||
@ -644,7 +629,7 @@ public class SonyProtocolImplV1 extends AbstractSonyProtocolImpl {
|
||||
|
||||
final float pressure = payload[5] / 10.0f;
|
||||
|
||||
if (pressure <= 0 || pressure > 1.0f) {
|
||||
if (pressure <= 0 || pressure > 1.0f) {
|
||||
LOG.warn("Invalid Noise Cancelling Optimizer pressure: {} atm, ignoring", pressure);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@ -1076,19 +1061,8 @@ public class SonyProtocolImplV1 extends AbstractSonyProtocolImpl {
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
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;
|
||||
}
|
||||
return coordinator.supports(SonyHeadphonesCapabilities.WindNoiseReduction);
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.Reminder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.WorldClock;
|
||||
|
||||
class TestDeviceSupport extends AbstractDeviceSupport {
|
||||
|
||||
@ -70,6 +71,11 @@ class TestDeviceSupport extends AbstractDeviceSupport {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetWorldClocks(ArrayList<? extends WorldClock> clocks) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetCallState(CallSpec callSpec) {
|
||||
|
||||
@ -90,6 +96,11 @@ class TestDeviceSupport extends AbstractDeviceSupport {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetPhoneVolume(float volume) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInstallApp(Uri uri) {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user