1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-11 12:39:26 +01:00

Xiaomi: Re-enable screen on on notifications preference

- Disabled by accident on 2063bc2df
- Move preference to XiaomiNotificationService
- Get preference value on connection
This commit is contained in:
José Rebelo 2023-12-08 20:55:58 +00:00
parent 2063bc2dfd
commit 2ff92c73f8
3 changed files with 42 additions and 22 deletions

View File

@ -388,7 +388,7 @@ public abstract class XiaomiCoordinator extends AbstractBLEDeviceCoordinator {
// TODO not implemented settings.add(R.xml.devicesettings_vibrationpatterns); // TODO not implemented settings.add(R.xml.devicesettings_vibrationpatterns);
// TODO not implemented settings.add(R.xml.devicesettings_donotdisturb_withauto_and_always); // TODO not implemented settings.add(R.xml.devicesettings_donotdisturb_withauto_and_always);
settings.add(R.xml.devicesettings_send_app_notifications); settings.add(R.xml.devicesettings_send_app_notifications);
// TODO not implemented settings.add(R.xml.devicesettings_screen_on_on_notifications); settings.add(R.xml.devicesettings_screen_on_on_notifications);
// TODO not implemented settings.add(R.xml.devicesettings_autoremove_notifications); // TODO not implemented settings.add(R.xml.devicesettings_autoremove_notifications);
if (getCannedRepliesSlotCount(device) > 0) { if (getCannedRepliesSlotCount(device) > 0) {
settings.add(R.xml.devicesettings_canned_dismisscall_16); settings.add(R.xml.devicesettings_canned_dismisscall_16);

View File

@ -47,6 +47,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiPrefere
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiSupport;
import nodomain.freeyourgadget.gadgetbridge.util.BitmapUtil; import nodomain.freeyourgadget.gadgetbridge.util.BitmapUtil;
import nodomain.freeyourgadget.gadgetbridge.util.NotificationUtils; import nodomain.freeyourgadget.gadgetbridge.util.NotificationUtils;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils; import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
public class XiaomiNotificationService extends AbstractXiaomiService implements XiaomiDataUploadService.Callback { public class XiaomiNotificationService extends AbstractXiaomiService implements XiaomiDataUploadService.Callback {
@ -60,6 +61,8 @@ public class XiaomiNotificationService extends AbstractXiaomiService implements
public static final int CMD_NOTIFICATION_DISMISS = 1; public static final int CMD_NOTIFICATION_DISMISS = 1;
public static final int CMD_CALL_REJECT = 2; public static final int CMD_CALL_REJECT = 2;
public static final int CMD_CALL_IGNORE = 5; public static final int CMD_CALL_IGNORE = 5;
public static final int CMD_SCREEN_ON_ON_NOTIFICATIONS_GET = 6;
public static final int CMD_SCREEN_ON_ON_NOTIFICATIONS_SET = 7;
public static final int CMD_OPEN_ON_PHONE = 8; public static final int CMD_OPEN_ON_PHONE = 8;
public static final int CMD_CANNED_MESSAGES_GET = 9; public static final int CMD_CANNED_MESSAGES_GET = 9;
public static final int CMD_CANNED_MESSAGES_SET = 12; // also canned message reply public static final int CMD_CANNED_MESSAGES_SET = 12; // also canned message reply
@ -78,6 +81,7 @@ public class XiaomiNotificationService extends AbstractXiaomiService implements
@Override @Override
public void initialize() { public void initialize() {
getSupport().sendCommand("get screen on on notifications", COMMAND_TYPE, CMD_SCREEN_ON_ON_NOTIFICATIONS_GET);
requestCannedMessages(); requestCannedMessages();
} }
@ -106,6 +110,15 @@ public class XiaomiNotificationService extends AbstractXiaomiService implements
deviceEvtCallControl.event = GBDeviceEventCallControl.Event.IGNORE; deviceEvtCallControl.event = GBDeviceEventCallControl.Event.IGNORE;
getSupport().evaluateGBDeviceEvent(deviceEvtCallControl); getSupport().evaluateGBDeviceEvent(deviceEvtCallControl);
return; return;
case CMD_SCREEN_ON_ON_NOTIFICATIONS_GET:
final boolean screenOnOnNotifications = cmd.getNotification().getScreenOnOnNotifications();
LOG.debug("Got screen on on notifications: {}", screenOnOnNotifications);
final GBDeviceEventUpdatePreferences eventUpdatePreferences = new GBDeviceEventUpdatePreferences(
DeviceSettingsPreferenceConst.PREF_SCREEN_ON_ON_NOTIFICATIONS,
screenOnOnNotifications
);
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
return;
case CMD_OPEN_ON_PHONE: case CMD_OPEN_ON_PHONE:
LOG.debug("Open on phone {}", cmd.getNotification().getOpenOnPhone().getId()); LOG.debug("Open on phone {}", cmd.getNotification().getOpenOnPhone().getId());
deviceEvtNotificationControl.handle = cmd.getNotification().getOpenOnPhone().getId(); deviceEvtNotificationControl.handle = cmd.getNotification().getOpenOnPhone().getId();
@ -125,6 +138,17 @@ public class XiaomiNotificationService extends AbstractXiaomiService implements
LOG.warn("Unhandled notification command {}", cmd.getSubtype()); LOG.warn("Unhandled notification command {}", cmd.getSubtype());
} }
@Override
public boolean onSendConfiguration(final String config, final Prefs prefs) {
switch (config) {
case DeviceSettingsPreferenceConst.PREF_SCREEN_ON_ON_NOTIFICATIONS:
setScreenOnOnNotifications();
return true;
}
return super.onSendConfiguration(config, prefs);
}
public void onNotification(final NotificationSpec notificationSpec) { public void onNotification(final NotificationSpec notificationSpec) {
if (!getDevicePrefs().getBoolean(DeviceSettingsPreferenceConst.PREF_SEND_APP_NOTIFICATIONS, true)) { if (!getDevicePrefs().getBoolean(DeviceSettingsPreferenceConst.PREF_SEND_APP_NOTIFICATIONS, true)) {
LOG.debug("App notifications disabled - ignoring"); LOG.debug("App notifications disabled - ignoring");
@ -257,6 +281,23 @@ public class XiaomiNotificationService extends AbstractXiaomiService implements
); );
} }
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 screen on on notification",
XiaomiProto.Command.newBuilder()
.setType(COMMAND_TYPE)
.setSubtype(CMD_SCREEN_ON_ON_NOTIFICATIONS_SET)
.setNotification(XiaomiProto.Notification.newBuilder().setScreenOnOnNotifications(screenOnOnNotificationsEnabled).build())
.build()
);
}
public void onSetCannedMessages(final CannedMessagesSpec cannedMessagesSpec) { public void onSetCannedMessages(final CannedMessagesSpec cannedMessagesSpec) {
if (cannedMessagesSpec.type != CannedMessagesSpec.TYPE_REJECTEDCALLS) { if (cannedMessagesSpec.type != CannedMessagesSpec.TYPE_REJECTEDCALLS) {
LOG.warn("Got unsupported canned messages type: {}", cannedMessagesSpec.type); LOG.warn("Got unsupported canned messages type: {}", cannedMessagesSpec.type);

View File

@ -67,7 +67,6 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
public static final int CMD_CLOCK = 3; public static final int CMD_CLOCK = 3;
public static final int CMD_FIRMWARE_INSTALL = 5; public static final int CMD_FIRMWARE_INSTALL = 5;
public static final int CMD_LANGUAGE = 6; 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_PASSWORD_GET = 9;
public static final int CMD_FIND_PHONE = 17; public static final int CMD_FIND_PHONE = 17;
public static final int CMD_FIND_WATCH = 18; public static final int CMD_FIND_WATCH = 18;
@ -160,9 +159,6 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
case HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE: case HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE:
setDisplayItems(); setDisplayItems();
return true; return true;
case DeviceSettingsPreferenceConst.PREF_SCREEN_ON_ON_NOTIFICATIONS:
setScreenOnOnNotifications();
return true;
} }
return super.onSendConfiguration(config, prefs); return super.onSendConfiguration(config, prefs);
@ -306,23 +302,6 @@ 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) { private void handlePassword(final XiaomiProto.Password password) {
LOG.debug("Got device password"); LOG.debug("Got device password");
final GBDeviceEventUpdatePreferences eventUpdatePreferences = new GBDeviceEventUpdatePreferences( final GBDeviceEventUpdatePreferences eventUpdatePreferences = new GBDeviceEventUpdatePreferences(