From 6e5bedb365eed44227fea926a62c50e7785b7875 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Fri, 1 Dec 2023 07:52:08 +0100 Subject: [PATCH] Xiaomi: Implement Screen On on Notification setting Works on Redmi Watch 3 Active Does not work on Mi Watch Lite --- .../xiaomi/services/XiaomiSystemService.java | 22 +++++++++++++++++++ app/src/main/proto/xiaomi.proto | 1 + 2 files changed, 23 insertions(+) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiSystemService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiSystemService.java index 95028909e..1d7361936 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiSystemService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiSystemService.java @@ -63,6 +63,7 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi public static final int CMD_CLOCK = 3; public static final int CMD_FIRMWARE_INSTALL = 5; public static final int CMD_LANGUAGE = 6; + public static final int CMD_SCREEN_ON_ON_NOTIFICAIONS = 7; public static final int CMD_PASSWORD_GET = 9; public static final int CMD_FIND_PHONE = 17; public static final int CMD_FIND_WATCH = 18; @@ -145,9 +146,13 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi case PasswordCapabilityImpl.PREF_PASSWORD_ENABLED: case PasswordCapabilityImpl.PREF_PASSWORD: setPassword(); + return true; case HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE: setDisplayItems(); return true; + case DeviceSettingsPreferenceConst.PREF_SCREEN_ON_ON_NOTIFICATIONS: + setScreenOnOnNotifications(); + return true; } return super.onSendConfiguration(config, prefs); @@ -282,6 +287,23 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi ); } + private void setScreenOnOnNotifications() { + final Prefs prefs = getDevicePrefs(); + + final boolean screenOnOnNotificationsEnabled = prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_SCREEN_ON_ON_NOTIFICATIONS, true); + + LOG.info("Setting screen on on notification: {}", screenOnOnNotificationsEnabled); + + getSupport().sendCommand( + "set password", + XiaomiProto.Command.newBuilder() + .setType(CMD_SCREEN_ON_ON_NOTIFICAIONS) // Why? Would also expect COMMAND_TYPE here + .setSubtype(CMD_SCREEN_ON_ON_NOTIFICAIONS) + .setNotification(XiaomiProto.Notification.newBuilder().setScreenOnOnNotifications(screenOnOnNotificationsEnabled).build()) + .build() + ); + } + private void handlePassword(final XiaomiProto.Password password) { LOG.debug("Got device password"); final GBDeviceEventUpdatePreferences eventUpdatePreferences = new GBDeviceEventUpdatePreferences( diff --git a/app/src/main/proto/xiaomi.proto b/app/src/main/proto/xiaomi.proto index e1c854970..aa5f19f67 100644 --- a/app/src/main/proto/xiaomi.proto +++ b/app/src/main/proto/xiaomi.proto @@ -564,6 +564,7 @@ message Notification { optional Notification2 notification2 = 3; optional NotificationDismiss notification4 = 4; + optional bool screenOnOnNotifications = 7; optional uint32 unknown8 = 8; // 1 on canned replies request? // 7, 9 get | 7, 12 set optional CannedMessages cannedMessages = 9;