From b85c1a803be1bc6f2336d43423227aa8351d6563 Mon Sep 17 00:00:00 2001 From: Daniel Dakhno Date: Sat, 30 Jan 2021 22:20:07 +0100 Subject: [PATCH] Fossil HR: enumerate apps on watch on every connect --- .../fossil_hr/FossilHRWatchAdapter.java | 11 ++--- .../application/ApplicationInformation.java | 18 +++++++ .../application/ApplicationsListRequest.java | 49 +++++++++++++++++++ 3 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/application/ApplicationInformation.java create mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/application/ApplicationsListRequest.java diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java index 7c6c7e3cd..d51678745 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java @@ -182,12 +182,7 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { } private void listApplications(){ - queueWrite(new ApplicationsListRequest(this) { - @Override - public void handleApplicationsList(List applications) { - installedApplications = applications; - } - }); + queueWrite(new ApplicationsListRequest(this)); } private void initializeAfterAuthentication(boolean authenticated) { @@ -390,6 +385,10 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { uploadWidgets(); } + public void setInstalledApplications(List installedApplications) { + this.installedApplications = installedApplications; + } + private void uploadWidgets() { ArrayList systemWidgets = new ArrayList<>(widgets.size()); for (Widget widget : widgets) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/application/ApplicationInformation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/application/ApplicationInformation.java new file mode 100644 index 000000000..73f3a261a --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/application/ApplicationInformation.java @@ -0,0 +1,18 @@ +package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.application; + +public class ApplicationInformation { + String appName, version; + int hash; + byte fileHandle; + + public ApplicationInformation(String appName, String version, int hash, byte fileHandle) { + this.appName = appName; + this.version = version; + this.hash = hash; + this.fileHandle = fileHandle; + } + + public String getAppName() { + return appName; + } +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/application/ApplicationsListRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/application/ApplicationsListRequest.java new file mode 100644 index 000000000..05f9e162a --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/application/ApplicationsListRequest.java @@ -0,0 +1,49 @@ +package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.application; + +import android.content.pm.ApplicationInfo; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.ArrayList; + +import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil_hr.FossilHRWatchAdapter; +import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileLookupAndGetRequest; +import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.file.FileHandle; +import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileLookupRequest.FILE_LOOKUP_ERROR; + +public class ApplicationsListRequest extends FileLookupAndGetRequest{ + public ApplicationsListRequest(FossilHRWatchAdapter adapter) { + super(FileHandle.APP_CODE, adapter); + } + + public void handleFileData(byte[] fileData){ + ArrayList applicationInfos = new ArrayList<>(); + ByteBuffer buffer = ByteBuffer.wrap(fileData); + buffer.order(ByteOrder.LITTLE_ENDIAN); + buffer.position(12); + while(buffer.remaining() > 4){ + short packetLength = buffer.getShort(); + buffer.get(); + int nameLength = buffer.get() - 1; // cutting off null byte + byte[] nameBuffer = new byte[nameLength]; + buffer.get(nameBuffer); + buffer.get(); // null byte + byte handle = buffer.get(); + int hash = buffer.getInt(); + String version = String.format( + "%d.%d.%d.%d", + buffer.get(), buffer.get(), buffer.get(), buffer.get() + ); + applicationInfos.add(new ApplicationInformation( + new String(nameBuffer), + version, + hash, + handle + )); + } + ((FossilHRWatchAdapter) getAdapter()).setInstalledApplications(applicationInfos); + } + public void handleFileLookupError(FILE_LOOKUP_ERROR error){ + + } +}