1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-09-27 16:56:57 +02:00

Zepp OS: Ensure all communication respects service encryption flag

Not all communication was moved to services, and some might not be
respecting the encryption flag sent during initialization implemented
in 3a2b02df2. Some services are encrypted or not across different
watches - see #3308.
This commit is contained in:
José Rebelo 2024-01-17 20:43:17 +00:00
parent aa4c9c0877
commit 94c763ef99
2 changed files with 16 additions and 1 deletions

View File

@ -175,6 +175,8 @@ public abstract class Huami2021Support extends HuamiSupport implements ZeppOsFil
private final ZeppOsMusicService musicService = new ZeppOsMusicService(this);
private final Set<Short> mSupportedServices = new HashSet<>();
// FIXME: We need to keep track of which services are encrypted for now, since not all of them were yet migrated to a service
private final Set<Short> mIsEncrypted = new HashSet<>();
private final Map<Short, AbstractZeppOsService> mServiceMap = new LinkedHashMap<Short, AbstractZeppOsService>() {{
put(servicesService.getEndpoint(), servicesService);
put(fileTransferService.getEndpoint(), fileTransferService);
@ -923,6 +925,13 @@ public abstract class Huami2021Support extends HuamiSupport implements ZeppOsFil
LOG.warn("writeToChunkedOld is not supported");
}
@Override
public void writeToChunked2021(final TransactionBuilder builder, final short endpoint, final byte[] data, final boolean encryptIgnored) {
// Ensure communication for all services contains the encrypted flag reported by the service, since not all
// watches have the same services encrypted (eg. #3308).
huami2021ChunkedEncoder.write(builder, endpoint, data, force2021Protocol(), mIsEncrypted.contains(endpoint));
}
@Override
public void writeToConfiguration(final TransactionBuilder builder, final byte[] data) {
LOG.warn("writeToConfiguration is not supported");
@ -982,11 +991,15 @@ public abstract class Huami2021Support extends HuamiSupport implements ZeppOsFil
// In here, we only request the list of supported services - they will all be initialized in
// initializeServices below
mSupportedServices.clear();
mIsEncrypted.clear();
servicesService.requestServices(builder);
}
public void addSupportedService(final short endpoint) {
public void addSupportedService(final short endpoint, final boolean encrypted) {
mSupportedServices.add(endpoint);
if (encrypted) {
mIsEncrypted.add(endpoint);
}
}
public void initializeServices() {

View File

@ -77,6 +77,8 @@ public class ZeppOsServicesService extends AbstractZeppOsService {
if (service != null && encrypted != null) {
service.setEncrypted(encrypted);
}
getSupport().addSupportedService(endpoint, encrypted != null && encrypted);
}
getSupport().initializeServices();