mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-02-04 05:57:33 +01:00
Xiaomi: Toggle phone silent mode from band
This commit is contained in:
parent
efc8752a66
commit
095b9e42d3
@ -443,6 +443,7 @@ public abstract class XiaomiCoordinator extends AbstractBLEDeviceCoordinator {
|
||||
if (supports(device, FEAT_DEVICE_ACTIONS)) {
|
||||
settings.add(R.xml.devicesettings_device_actions);
|
||||
}
|
||||
settings.add(R.xml.devicesettings_phone_silent_mode);
|
||||
|
||||
//
|
||||
// Developer
|
||||
|
@ -54,7 +54,8 @@ public class XiaomiSettingsCustomizer implements DeviceSpecificSettingsCustomize
|
||||
hidePrefIfNoneVisible(handler, "pref_header_other", Arrays.asList(
|
||||
"pref_contacts",
|
||||
"camera_remote",
|
||||
"screen_events_forwarding"
|
||||
"screen_events_forwarding",
|
||||
"phone_silent_mode"
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -56,6 +56,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.CheckSums;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.SilentMode;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
||||
|
||||
public class XiaomiSystemService extends AbstractXiaomiService implements XiaomiDataUploadService.Callback {
|
||||
@ -83,6 +84,9 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
|
||||
public static final int CMD_DISPLAY_ITEMS_GET = 29;
|
||||
public static final int CMD_DISPLAY_ITEMS_SET = 30;
|
||||
public static final int CMD_MISC_SETTING_SET_FROM_BAND = 42;
|
||||
public static final int CMD_SILENT_MODE_GET = 43;
|
||||
public static final int CMD_SILENT_MODE_SET_FROM_PHONE = 44;
|
||||
public static final int CMD_SILENT_MODE_SET_FROM_WATCH = 45;
|
||||
public static final int CMD_DEVICE_STATE_GET = 78;
|
||||
public static final int CMD_DEVICE_STATE = 79;
|
||||
|
||||
@ -158,6 +162,12 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
|
||||
case CMD_MISC_SETTING_SET_FROM_BAND:
|
||||
handleMiscSettingSet(cmd.getSystem().getMiscSettingSet());
|
||||
return;
|
||||
case CMD_SILENT_MODE_GET:
|
||||
handlePhoneSilentModeGet();
|
||||
return;
|
||||
case CMD_SILENT_MODE_SET_FROM_WATCH:
|
||||
handlePhoneSilentModeSet(cmd.getSystem().getPhoneSilentModeSet());
|
||||
return;
|
||||
case CMD_DEVICE_STATE_GET:
|
||||
handleBasicDeviceState(cmd.getSystem().hasBasicDeviceState()
|
||||
? cmd.getSystem().getBasicDeviceState()
|
||||
@ -634,6 +644,33 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
|
||||
currentSleepDetectionState = newState;
|
||||
}
|
||||
|
||||
public void handlePhoneSilentModeGet() {
|
||||
LOG.debug("Watch requested phone silent mode");
|
||||
sendPhoneSilentMode(SilentMode.isPhoneInSilenceMode(getSupport().getDevice().getAddress()));
|
||||
}
|
||||
|
||||
public void handlePhoneSilentModeSet(final XiaomiProto.PhoneSilentModeSet phoneSilentModeSet) {
|
||||
final boolean silent = phoneSilentModeSet.getPhoneSilentMode().getSilent();
|
||||
|
||||
LOG.debug("Set phone silent mode = {}", silent);
|
||||
SilentMode.setPhoneSilentMode(getSupport().getDevice().getAddress(), silent);
|
||||
}
|
||||
|
||||
private void sendPhoneSilentMode(final boolean enabled) {
|
||||
getSupport().sendCommand(
|
||||
"send phone silent mode = " + enabled,
|
||||
XiaomiProto.Command.newBuilder()
|
||||
.setType(COMMAND_TYPE)
|
||||
.setSubtype(CMD_SILENT_MODE_SET_FROM_PHONE)
|
||||
.setSystem(XiaomiProto.System.newBuilder().setPhoneSilentModeSet(
|
||||
XiaomiProto.PhoneSilentModeSet.newBuilder().setPhoneSilentMode(
|
||||
XiaomiProto.PhoneSilentMode.newBuilder().setSilent(enabled)
|
||||
)
|
||||
))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public void handleBasicDeviceState(XiaomiProto.BasicDeviceState deviceState) {
|
||||
LOG.debug("Got basic device state: {}", deviceState);
|
||||
|
||||
|
@ -117,6 +117,12 @@ message System {
|
||||
// 2, 15
|
||||
optional MiscSettingSet miscSettingSet = 35;
|
||||
|
||||
// 2, 43
|
||||
optional PhoneSilentModeGet phoneSilentModeGet = 36;
|
||||
|
||||
// 2, 44 returning to watch, 2, 45 setting from watch
|
||||
optional PhoneSilentModeSet phoneSilentModeSet = 37;
|
||||
|
||||
// 2, 46
|
||||
optional VibrationPatterns vibrationPatterns = 38;
|
||||
|
||||
@ -298,6 +304,18 @@ message Password {
|
||||
optional uint32 unknown3 = 3; // 0 when set on ret
|
||||
}
|
||||
|
||||
message PhoneSilentModeGet {
|
||||
optional uint32 unknown1 = 1; // 1
|
||||
}
|
||||
|
||||
message PhoneSilentModeSet {
|
||||
optional PhoneSilentMode phoneSilentMode = 1;
|
||||
}
|
||||
|
||||
message PhoneSilentMode {
|
||||
optional bool silent = 1;
|
||||
}
|
||||
|
||||
message VibrationPatterns {
|
||||
repeated VibrationNotificationType notificationType = 1;
|
||||
optional uint32 unknown2 = 2; // 50, max patterns?
|
||||
|
Loading…
x
Reference in New Issue
Block a user