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

Fossil Hybrid: file handle can be passed to service as string

This commit is contained in:
Daniel Dakhno 2021-01-28 11:34:43 +01:00
parent 3a4c5f6483
commit 614d711226
2 changed files with 28 additions and 2 deletions

View File

@ -284,7 +284,11 @@ public class QHybridSupport extends QHybridBaseSupport {
}
case QHYBRID_COMMAND_UPLOAD_FILE:{
Object handleObject = intent.getSerializableExtra("EXTRA_HANDLE");
if(handleObject == null || !(handleObject instanceof FileHandle)) return;
if(handleObject == null)return;
if(handleObject instanceof String){
handleObject = FileHandle.fromName((String)handleObject);
}
if(!(handleObject instanceof FileHandle)) return;
FileHandle handle = (FileHandle) handleObject;
String filePath = intent.getStringExtra("EXTRA_PATH");
watchAdapter.uploadFile(handle, filePath, intent.getBooleanExtra("EXTRA_ENCRYPTED", false));
@ -293,7 +297,7 @@ public class QHybridSupport extends QHybridBaseSupport {
}
}
};
LocalBroadcastManager.getInstance(getContext()).registerReceiver(commandReceiver, commandFilter);
LocalBroadcastManager.getInstance(GBApplication.getContext()).registerReceiver(commandReceiver, commandFilter);
helper = new PackageConfigHelper(GBApplication.getContext());
@ -301,6 +305,7 @@ public class QHybridSupport extends QHybridBaseSupport {
globalFilter.addAction(QHYBRID_ACTION_SET_ACTIVITY_HAND);
globalFilter.addAction(QHYBRID_COMMAND_SET_MENU_MESSAGE);
globalFilter.addAction(QHYBRID_COMMAND_SET_WIDGET_CONTENT);
globalFilter.addAction(QHYBRID_COMMAND_UPLOAD_FILE);
globalCommandReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@ -363,6 +368,18 @@ public class QHybridSupport extends QHybridBaseSupport {
}
break;
}
case QHYBRID_COMMAND_UPLOAD_FILE:{
Object handleObject = intent.getSerializableExtra("EXTRA_HANDLE");
if(handleObject == null)return;
if(handleObject instanceof String){
handleObject = FileHandle.fromName((String)handleObject);
}
if(!(handleObject instanceof FileHandle)) return;
FileHandle handle = (FileHandle) handleObject;
String filePath = intent.getStringExtra("EXTRA_PATH");
watchAdapter.uploadFile(handle, filePath, intent.getBooleanExtra("EXTRA_ENCRYPTED", false));
break;
}
}
}
};

View File

@ -48,6 +48,15 @@ public enum FileHandle {
this.subHandle = subHandle;
}
public static FileHandle fromName(String name){
for(FileHandle handle : FileHandle.values()){
if(handle.toString().equals(name)){
return handle;
}
}
return null;
}
public short getHandle(){
return (short)((handle << 8) | (subHandle));
}