1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 05:16:51 +01:00

Xiaomi: Refuse delete of active watchface

This commit is contained in:
José Rebelo 2023-10-22 11:58:55 +01:00
parent 1b645f44d7
commit e2d7798e36

View File

@ -46,6 +46,7 @@ public class XiaomiWatchfaceService extends AbstractXiaomiService {
private final Set<UUID> allWatchfaces = new HashSet<>(); private final Set<UUID> allWatchfaces = new HashSet<>();
private final Set<UUID> userWatchfaces = new HashSet<>(); private final Set<UUID> userWatchfaces = new HashSet<>();
private UUID activeWatchface = null;
public XiaomiWatchfaceService(final XiaomiSupport support) { public XiaomiWatchfaceService(final XiaomiSupport support) {
super(support); super(support);
@ -89,6 +90,7 @@ public class XiaomiWatchfaceService extends AbstractXiaomiService {
allWatchfaces.clear(); allWatchfaces.clear();
userWatchfaces.clear(); userWatchfaces.clear();
activeWatchface = null;
final List<GBDeviceApp> gbDeviceApps = new ArrayList<>(); final List<GBDeviceApp> gbDeviceApps = new ArrayList<>();
@ -98,6 +100,9 @@ public class XiaomiWatchfaceService extends AbstractXiaomiService {
if (watchface.getCanDelete()) { if (watchface.getCanDelete()) {
userWatchfaces.add(uuid); userWatchfaces.add(uuid);
} }
if (watchface.getActive()) {
activeWatchface = uuid;
}
GBDeviceApp gbDeviceApp = new GBDeviceApp( GBDeviceApp gbDeviceApp = new GBDeviceApp(
uuid, uuid,
@ -120,6 +125,8 @@ public class XiaomiWatchfaceService extends AbstractXiaomiService {
return; return;
} }
activeWatchface = uuid;
LOG.debug("Set watchface to {}", uuid); LOG.debug("Set watchface to {}", uuid);
getSupport().sendCommand( getSupport().sendCommand(
@ -147,6 +154,11 @@ public class XiaomiWatchfaceService extends AbstractXiaomiService {
return; return;
} }
if (uuid.equals(activeWatchface)) {
LOG.warn("Refusing to delete active watchface {}", uuid);
return;
}
LOG.debug("Delete watchface {}", uuid); LOG.debug("Delete watchface {}", uuid);
allWatchfaces.remove(uuid); allWatchfaces.remove(uuid);