mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-26 18:45:49 +01:00
Fossil HR: enumerate apps on watch on every connect
This commit is contained in:
parent
ec77345632
commit
b85c1a803b
@ -182,12 +182,7 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
||||
}
|
||||
|
||||
private void listApplications(){
|
||||
queueWrite(new ApplicationsListRequest(this) {
|
||||
@Override
|
||||
public void handleApplicationsList(List<ApplicationInformation> 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<ApplicationInformation> installedApplications) {
|
||||
this.installedApplications = installedApplications;
|
||||
}
|
||||
|
||||
private void uploadWidgets() {
|
||||
ArrayList<Widget> systemWidgets = new ArrayList<>(widgets.size());
|
||||
for (Widget widget : widgets) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<ApplicationInformation> 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){
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user