mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Garmin: add BUNDLE_EXTRA_INSTALL_TASK_NAME and BUNDLE_EXTRA_INSTALL_BYTES for onInstallApp
This commit is contained in:
+16
@@ -16,6 +16,8 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.devices.garmin;
|
||||
|
||||
import static nodomain.freeyourgadget.gadgetbridge.service.AbstractDeviceSupport.BUNDLE_EXTRA_INSTALL_BYTES;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
@@ -62,6 +64,20 @@ public class GarminFitFileInstallHandler implements InstallHandler {
|
||||
public GarminFitFileInstallHandler(final Uri uri, final Bundle options, final Context context) {
|
||||
this.mContext = context;
|
||||
|
||||
if (options != null && options.containsKey(BUNDLE_EXTRA_INSTALL_BYTES)) {
|
||||
try {
|
||||
rawBytes = options.getByteArray(BUNDLE_EXTRA_INSTALL_BYTES);
|
||||
fitFile = FitFile.parseIncoming(rawBytes);
|
||||
fileType = fitFile.getFileType();
|
||||
return;
|
||||
} catch (final FitParseException e) {
|
||||
LOG.error("bundle fit bytes are corrupted", e);
|
||||
fitParseException = e;
|
||||
} catch (final Exception e) {
|
||||
LOG.error("failed to read bundle fit bytes", e);
|
||||
}
|
||||
}
|
||||
|
||||
final UriHelper uriHelper;
|
||||
try {
|
||||
uriHelper = UriHelper.get(uri, context);
|
||||
|
||||
+10
-2
@@ -1,7 +1,7 @@
|
||||
/* Copyright (C) 2015-2024 Alicia Hormann, Andreas Böhler, Andreas Shimokawa,
|
||||
/* Copyright (C) 2015-2026 Alicia Hormann, Andreas Böhler, Andreas Shimokawa,
|
||||
Arjan Schrijver, Carsten Pfeiffer, Daniele Gobbetti, Davis Mosenkovs,
|
||||
Dmitriy Bogdanov, foxstidious, Ganblejs, José Rebelo, Pauli Salmenrinne,
|
||||
Petr Vaněk, Taavi Eomäe, Yoran Vulker
|
||||
Petr Vaněk, Taavi Eomäe, Yoran Vulker, Thomas Kuehne
|
||||
|
||||
This file is part of Gadgetbridge.
|
||||
|
||||
@@ -71,7 +71,13 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
||||
private Context context;
|
||||
private boolean autoReconnect, scanReconnect;
|
||||
|
||||
/// an optional {@link Bundle} extra of type {@code byte[]} used to pass
|
||||
/// <u>small</u> transient data to {@link #onInstallApp(Uri, Bundle)}
|
||||
public static final String BUNDLE_EXTRA_INSTALL_BYTES = "install_handler_bytes";
|
||||
|
||||
/// an optional {@link Bundle} extra of type {@code String} used to pass
|
||||
/// a task name for logging to {@link #onInstallApp(Uri, Bundle)}
|
||||
public static final String BUNDLE_EXTRA_INSTALL_TASK_NAME = "install_handler_task_name";
|
||||
|
||||
@Override
|
||||
public void setContext(GBDevice gbDevice, BluetoothAdapter btAdapter, Context context) {
|
||||
@@ -368,6 +374,8 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
||||
*
|
||||
* @param uri reference to a watch app file
|
||||
* @param options a bundle of custom options
|
||||
* @see #BUNDLE_EXTRA_INSTALL_BYTES
|
||||
* @see #BUNDLE_EXTRA_INSTALL_TASK_NAME
|
||||
*/
|
||||
@Override
|
||||
public void onInstallApp(Uri uri, @NonNull final Bundle options) {
|
||||
|
||||
+18
-5
@@ -1328,13 +1328,15 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
||||
public void onInstallApp(Uri uri, @NonNull final Bundle options) {
|
||||
final GarminFitFileInstallHandler fitFileInstallHandler = new GarminFitFileInstallHandler(uri, options, getContext());
|
||||
if (fitFileInstallHandler.isValid()) {
|
||||
final FileType.FILETYPE fileType = fitFileInstallHandler.getFileType();
|
||||
communicator.sendMessage(
|
||||
"upload fit file",
|
||||
options.getString(BUNDLE_EXTRA_INSTALL_TASK_NAME, "upload " + fileType + " file"),
|
||||
fileTransferHandler.initiateUpload(
|
||||
fitFileInstallHandler.getRawBytes(),
|
||||
fitFileInstallHandler.getFileType()
|
||||
fileType
|
||||
).getOutgoingMessage()
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final GarminGpxRouteInstallHandler garminGpxRouteInstallHandler = new GarminGpxRouteInstallHandler(uri, getContext());
|
||||
@@ -1346,19 +1348,30 @@ public class GarminSupport extends AbstractBTLESingleDeviceSupport implements IC
|
||||
);
|
||||
final FitFile convertedFile = gpxRouteFileConverter.getConvertedFile();
|
||||
final FileType.FILETYPE fileType = convertedFile.getFileType();
|
||||
communicator.sendMessage("upload " + fileType + " file", fileTransferHandler.initiateUpload(convertedFile.getOutgoingMessage(), fileType).getOutgoingMessage());
|
||||
communicator.sendMessage(
|
||||
options.getString(BUNDLE_EXTRA_INSTALL_TASK_NAME, "upload " + fileType + " file"),
|
||||
fileTransferHandler.initiateUpload(
|
||||
convertedFile.getOutgoingMessage(),
|
||||
fileType
|
||||
).getOutgoingMessage()
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final GarminPrgFileInstallHandler prgFileInstallHandler = new GarminPrgFileInstallHandler(uri, getContext());
|
||||
if (prgFileInstallHandler.isValid()) {
|
||||
final FileType.FILETYPE fileType = FileType.FILETYPE.PRG;
|
||||
communicator.sendMessage(
|
||||
"upload prg file",
|
||||
options.getString(BUNDLE_EXTRA_INSTALL_TASK_NAME, "upload " + fileType + " file"),
|
||||
fileTransferHandler.initiateUpload(
|
||||
prgFileInstallHandler.getRawBytes(),
|
||||
FileType.FILETYPE.PRG
|
||||
fileType
|
||||
).getOutgoingMessage()
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
LOG.warn("no install handler found for {} {}", uri, options.getString(BUNDLE_EXTRA_INSTALL_TASK_NAME));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user