diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e792e65b9..8cb2c48be 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -211,6 +211,11 @@ android:name=".activities.FwAppInstallerActivity" android:label="@string/title_activity_fw_app_insaller" android:parentActivityName=".activities.ControlCenterv2" + android:exported="true" /> + diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FileInstallerActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FileInstallerActivity.java new file mode 100644 index 000000000..e0757c564 --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FileInstallerActivity.java @@ -0,0 +1,129 @@ +/* Copyright (C) 2015-2024 Andreas Shimokawa, Carsten Pfeiffer, Daniel + Dakhno, Daniele Gobbetti, José Rebelo, Lem Dulfo, Petr Vaněk, Taavi Eomäe + + This file is part of Gadgetbridge. + + Gadgetbridge is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Gadgetbridge is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . */ +package nodomain.freeyourgadget.gadgetbridge.activities; + +import android.content.Intent; +import android.net.Uri; +import android.os.AsyncTask; +import android.os.Bundle; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import nodomain.freeyourgadget.gadgetbridge.GBApplication; +import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator; +import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; +import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; +import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; + +/** + * An entrypoint activity to install a file to a device. This activity will find the compatible + * {@link InstallHandler} and pass the corresponding {@link DeviceType} to the corresponding install + * activity. + */ +public class FileInstallerActivity extends AbstractGBActivity { + private static final Logger LOG = LoggerFactory.getLogger(FileInstallerActivity.class); + + private Uri uri; + + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_file_installer); + + uri = getIntent().getData(); + if (uri == null) { // For "share" intent + uri = getIntent().getParcelableExtra(Intent.EXTRA_STREAM); + } + + new FindInstallHandlerTask().execute(uri); + } + + private List getAllDeviceTypesConnectedFirst() { + final Set connectedCoordinators = GBApplication.app().getDeviceManager() + .getSelectedDevices().stream() + .filter(GBDevice::isConnected) + .map(GBDevice::getDeviceCoordinator) + .collect(Collectors.toSet()); + + return Arrays.stream(DeviceType.values()) + .sorted((d1, d2) -> { + final DeviceCoordinator c1 = d1.getDeviceCoordinator(); + final DeviceCoordinator c2 = d2.getDeviceCoordinator(); + if (connectedCoordinators.contains(c1)) { + return -1; + } else if (connectedCoordinators.contains(c2)) { + return 1; + } else { + return 0; + } + }).collect(Collectors.toList()); + } + + private class FindInstallHandlerTask extends AsyncTask { + @Override + protected Result doInBackground(final Uri... uris) { + for (final DeviceType deviceType : getAllDeviceTypesConnectedFirst()) { + final DeviceCoordinator coordinator = deviceType.getDeviceCoordinator(); + final InstallHandler handler = coordinator.findInstallHandler(uris[0], FileInstallerActivity.this); + if (handler != null) { + LOG.info("Found install handler {} from {}", handler.getClass(), coordinator.getClass()); + return new Result(deviceType, handler); + } + } + + return null; + } + + @Override + protected void onPostExecute(final Result result) { + final Intent intent; + if (result != null) { + if (result.installHandler.getInstallActivity() != null) { + intent = new Intent(FileInstallerActivity.this, result.installHandler.getInstallActivity()); + } else { + intent = new Intent(FileInstallerActivity.this, FwAppInstallerActivity.class); + } + intent.putExtra(FwAppInstallerActivity.EXTRA_DEVICE_TYPE_NAME, result.deviceType.name()); + } else { + intent = new Intent(FileInstallerActivity.this, FwAppInstallerActivity.class); + } + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_TASK_ON_HOME); + intent.setAction(Intent.ACTION_VIEW); + intent.setDataAndType(uri, null); + startActivity(intent); + finish(); + } + + private class Result { + private final DeviceType deviceType; + private final InstallHandler installHandler; + + private Result(final DeviceType deviceType, final InstallHandler installHandler) { + this.deviceType = deviceType; + this.installHandler = installHandler; + } + } + } +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java index 530c281f8..fb0522146 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java @@ -33,6 +33,7 @@ import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.app.NavUtils; import androidx.localbroadcastmanager.content.LocalBroadcastManager; @@ -53,7 +54,6 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; import nodomain.freeyourgadget.gadgetbridge.model.GenericItem; import nodomain.freeyourgadget.gadgetbridge.model.ItemWithDetails; -import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper; import nodomain.freeyourgadget.gadgetbridge.util.GB; @@ -62,6 +62,8 @@ public class FwAppInstallerActivity extends AbstractGBActivity implements Instal private static final Logger LOG = LoggerFactory.getLogger(FwAppInstallerActivity.class); private static final String ITEM_DETAILS = "details"; + public static final String EXTRA_DEVICE_TYPE_NAME = "deviceTypeName"; + private TextView fwAppInstallTextView; private ImageView previewImage; private Button installButton; @@ -214,14 +216,24 @@ public class FwAppInstallerActivity extends AbstractGBActivity implements Instal if (uri == null) { // For "share" intent uri = getIntent().getParcelableExtra(Intent.EXTRA_STREAM); } - installHandler = findInstallHandlerFor(uri); + if (device != null) { + installHandler = device.getDeviceCoordinator().findInstallHandler(uri, this); + } else { + String deviceTypeName = getIntent().getStringExtra(EXTRA_DEVICE_TYPE_NAME); + if (deviceTypeName != null) { + installHandler = DeviceType.fromName(deviceTypeName).getDeviceCoordinator().findInstallHandler(uri, this); + } else { + installHandler = findInstallHandlerFor(uri); + } + } + if (installHandler == null) { setInfoText(getString(R.string.installer_activity_unable_to_find_handler)); } else { setInfoText(getString(R.string.installer_activity_wait_while_determining_status)); List selectedDevices = GBApplication.app().getDeviceManager().getSelectedDevices(); - if(selectedDevices.size() == 0){ + if(selectedDevices.isEmpty()){ GB.toast(getString(R.string.open_fw_installer_connect_minimum_one_device), Toast.LENGTH_LONG, GB.ERROR); finish(); return; @@ -243,7 +255,7 @@ public class FwAppInstallerActivity extends AbstractGBActivity implements Instal } @Override - protected void onSaveInstanceState(Bundle outState) { + protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); outState.putParcelableArrayList(ITEM_DETAILS, details); } @@ -271,14 +283,10 @@ public class FwAppInstallerActivity extends AbstractGBActivity implements Instal List devices = deviceManager.getSelectedDevices(); for(GBDevice connectedDevice : devices){ if (connectedDevice.isConnected()) { - DeviceCoordinator coordinator = connectedDevice.getDeviceCoordinator(); - if (coordinator != null) { - connectedCoordinators.add(coordinator); - } + connectedCoordinators.add(connectedDevice.getDeviceCoordinator()); } } - sortedCoordinators.addAll(connectedCoordinators); for (DeviceCoordinator coordinator : allCoordinators) { if (!connectedCoordinators.contains(coordinator)) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AppManagerActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AppManagerActivity.java index 2398e9168..d69cdd014 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AppManagerActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AppManagerActivity.java @@ -209,6 +209,7 @@ public class AppManagerActivity extends AbstractGBFragmentActivity { super.onActivityResult(requestCode, resultCode, resultData); if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK) { Intent startIntent = new Intent(AppManagerActivity.this, FwAppInstallerActivity.class); + startIntent.putExtra(GBDevice.EXTRA_DEVICE, mGBDevice); startIntent.setAction(Intent.ACTION_VIEW); startIntent.setDataAndType(resultData.getData(), null); startActivity(startIntent); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/InstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/InstallHandler.java index 87556b8fa..91339edb2 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/InstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/InstallHandler.java @@ -16,6 +16,8 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices; +import android.app.Activity; + import nodomain.freeyourgadget.gadgetbridge.activities.InstallActivity; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; @@ -25,6 +27,8 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; */ public interface InstallHandler { + Class getInstallActivity(); + /** * Returns true if this handler is able to install the element. * #validateInstallation may only be called if this method returned true. diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/divoom/PixooInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/divoom/PixooInstallHandler.java index beee43ef1..651d8bedb 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/divoom/PixooInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/divoom/PixooInstallHandler.java @@ -17,9 +17,11 @@ package nodomain.freeyourgadget.gadgetbridge.devices.divoom; +import android.app.Activity; import android.content.Context; import android.net.Uri; +import nodomain.freeyourgadget.gadgetbridge.activities.FwAppInstallerActivity; import nodomain.freeyourgadget.gadgetbridge.activities.InstallActivity; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; @@ -33,6 +35,11 @@ public class PixooInstallHandler implements InstallHandler { mUri = uri; } + @Override + public Class getInstallActivity() { + return FwAppInstallerActivity.class; + } + @Override public boolean isValid() { return true; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/garmin/GarminGpxRouteInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/garmin/GarminGpxRouteInstallHandler.java index 5afb29ef8..5846420b1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/garmin/GarminGpxRouteInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/garmin/GarminGpxRouteInstallHandler.java @@ -16,6 +16,9 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.garmin; +import static nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.GarminCapability.COURSE_DOWNLOAD; + +import android.app.Activity; import android.content.Context; import android.net.Uri; @@ -27,6 +30,7 @@ import java.io.IOException; import java.io.InputStream; import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.activities.FwAppInstallerActivity; import nodomain.freeyourgadget.gadgetbridge.activities.InstallActivity; import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; @@ -36,8 +40,6 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.GpxRouteF import nodomain.freeyourgadget.gadgetbridge.util.FileUtils; import nodomain.freeyourgadget.gadgetbridge.util.UriHelper; -import static nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.GarminCapability.COURSE_DOWNLOAD; - public class GarminGpxRouteInstallHandler implements InstallHandler { private static final Logger LOG = LoggerFactory.getLogger(GarminGpxRouteInstallHandler.class); @@ -67,6 +69,11 @@ public class GarminGpxRouteInstallHandler implements InstallHandler { } } + @Override + public Class getInstallActivity() { + return FwAppInstallerActivity.class; + } + @Override public boolean isValid() { return gpxRouteFileConverter != null; @@ -88,7 +95,7 @@ public class GarminGpxRouteInstallHandler implements InstallHandler { return; } final GarminCoordinator garminCoordinator = (GarminCoordinator) coordinator; - if (!garminCoordinator.supports(device, COURSE_DOWNLOAD)) { + if (garminCoordinator.supports(device, COURSE_DOWNLOAD)) { installActivity.setInfoText(mContext.getString(R.string.fwapp_install_device_not_supported)); installActivity.setInstallEnabled(false); return; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/zeppos/ZeppOsAgpsInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/zeppos/ZeppOsAgpsInstallHandler.java index 6349f6cb7..08a044f8e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/zeppos/ZeppOsAgpsInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/zeppos/ZeppOsAgpsInstallHandler.java @@ -16,6 +16,7 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.huami.zeppos; +import android.app.Activity; import android.content.Context; import android.net.Uri; @@ -27,6 +28,7 @@ import java.io.IOException; import java.io.InputStream; import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.activities.FwAppInstallerActivity; import nodomain.freeyourgadget.gadgetbridge.activities.InstallActivity; import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; @@ -65,6 +67,11 @@ public class ZeppOsAgpsInstallHandler implements InstallHandler { } @Override + public Class getInstallActivity() { + return FwAppInstallerActivity.class; + } + +@Override public boolean isValid() { return file != null; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/zeppos/ZeppOsGpxRouteInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/zeppos/ZeppOsGpxRouteInstallHandler.java index a17215631..05dc3b7ff 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/zeppos/ZeppOsGpxRouteInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/zeppos/ZeppOsGpxRouteInstallHandler.java @@ -16,6 +16,7 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.huami.zeppos; +import android.app.Activity; import android.content.Context; import android.net.Uri; @@ -27,6 +28,7 @@ import java.io.IOException; import java.io.InputStream; import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.activities.FwAppInstallerActivity; import nodomain.freeyourgadget.gadgetbridge.activities.InstallActivity; import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; @@ -63,6 +65,11 @@ public class ZeppOsGpxRouteInstallHandler implements InstallHandler { } } + @Override + public Class getInstallActivity() { + return FwAppInstallerActivity.class; + } + @Override public boolean isValid() { return file != null; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiInstallHandler.java index 3aafb654f..cd898a3c3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiInstallHandler.java @@ -17,16 +17,18 @@ package nodomain.freeyourgadget.gadgetbridge.devices.huawei; +import android.app.Activity; import android.content.Context; import android.net.Uri; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.activities.FwAppInstallerActivity; import nodomain.freeyourgadget.gadgetbridge.activities.InstallActivity; import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; - import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.GenericItem; import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiAppManager; @@ -154,6 +156,11 @@ public class HuaweiInstallHandler implements InstallHandler { } + @Override + public Class getInstallActivity() { + return FwAppInstallerActivity.class; + } + @Override public boolean isValid() { return helper.isValid(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/AbstractMiBandFWInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/AbstractMiBandFWInstallHandler.java index d27b4f8dd..421568636 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/AbstractMiBandFWInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/AbstractMiBandFWInstallHandler.java @@ -17,6 +17,7 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.miband; +import android.app.Activity; import android.content.Context; import android.net.Uri; @@ -26,15 +27,14 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.activities.FwAppInstallerActivity; import nodomain.freeyourgadget.gadgetbridge.activities.InstallActivity; import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.GenericItem; -import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper; import static nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareType.AGPS_UIHH; -import static nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareType.WATCHFACE; public abstract class AbstractMiBandFWInstallHandler implements InstallHandler { private static final Logger LOG = LoggerFactory.getLogger(AbstractMiBandFWInstallHandler.class); @@ -151,6 +151,11 @@ public abstract class AbstractMiBandFWInstallHandler implements InstallHandler { } + @Override + public Class getInstallActivity() { + return FwAppInstallerActivity.class; + } + @Override public boolean isValid() { return helper != null; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWInstallHandler.java index 9fa65d9d3..9858c4b1f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWInstallHandler.java @@ -17,6 +17,7 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.pebble; +import android.app.Activity; import android.content.Context; import android.net.Uri; @@ -34,6 +35,7 @@ import java.io.InputStream; import java.io.Writer; import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.activities.FwAppInstallerActivity; import nodomain.freeyourgadget.gadgetbridge.activities.InstallActivity; import nodomain.freeyourgadget.gadgetbridge.activities.appmanager.AppManagerActivity; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; @@ -203,6 +205,10 @@ public class PBWInstallHandler implements InstallHandler { } } } + @Override + public Class getInstallActivity() { + return FwAppInstallerActivity.class; + } @Override public boolean isValid() { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pinetime/PineTimeInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pinetime/PineTimeInstallHandler.java index 5bbfcdc20..dc4e115a1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pinetime/PineTimeInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pinetime/PineTimeInstallHandler.java @@ -16,6 +16,7 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.pinetime; +import android.app.Activity; import android.content.Context; import android.net.Uri; @@ -30,13 +31,14 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.activities.FwAppInstallerActivity; import nodomain.freeyourgadget.gadgetbridge.activities.InstallActivity; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; import nodomain.freeyourgadget.gadgetbridge.model.GenericItem; -import nodomain.freeyourgadget.gadgetbridge.util.UriHelper; import nodomain.freeyourgadget.gadgetbridge.util.GBZipFile; +import nodomain.freeyourgadget.gadgetbridge.util.UriHelper; import nodomain.freeyourgadget.gadgetbridge.util.ZipFileException; public class PineTimeInstallHandler implements InstallHandler { @@ -112,6 +114,11 @@ public class PineTimeInstallHandler implements InstallHandler { public void onStartInstall(GBDevice device) { } + @Override + public Class getInstallActivity() { + return FwAppInstallerActivity.class; + } + @Override public boolean isValid() { return dfuPackageManifest != null && diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/FossilHRInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/FossilHRInstallHandler.java index 50589f2e7..e49281574 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/FossilHRInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/FossilHRInstallHandler.java @@ -17,6 +17,7 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.qhybrid; +import android.app.Activity; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; @@ -37,6 +38,7 @@ import java.io.IOException; import java.io.Writer; import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.activities.FwAppInstallerActivity; import nodomain.freeyourgadget.gadgetbridge.activities.InstallActivity; import nodomain.freeyourgadget.gadgetbridge.activities.appmanager.AbstractAppManagerFragment; import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator; @@ -45,7 +47,6 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; import nodomain.freeyourgadget.gadgetbridge.model.GenericItem; -import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper; import nodomain.freeyourgadget.gadgetbridge.util.FileUtils; import nodomain.freeyourgadget.gadgetbridge.util.GB; @@ -182,6 +183,11 @@ public class FossilHRInstallHandler implements InstallHandler { return true; } + @Override + public Class getInstallActivity() { + return FwAppInstallerActivity.class; + } + @Override public boolean isValid() { return fossilFile.isValid(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/FossilInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/FossilInstallHandler.java index e1dcceb6a..645f56db0 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/FossilInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/FossilInstallHandler.java @@ -16,6 +16,7 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.qhybrid; +import android.app.Activity; import android.content.Context; import android.net.Uri; @@ -26,6 +27,7 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.activities.FwAppInstallerActivity; import nodomain.freeyourgadget.gadgetbridge.activities.InstallActivity; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; @@ -104,6 +106,11 @@ public class FossilInstallHandler implements InstallHandler { public void onStartInstall(GBDevice device) { } + @Override + public Class getInstallActivity() { + return FwAppInstallerActivity.class; + } + @Override public boolean isValid() { return mIsValid; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/xiaomi/XiaomiInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/xiaomi/XiaomiInstallHandler.java index eab30fabe..0593aafcc 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/xiaomi/XiaomiInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/xiaomi/XiaomiInstallHandler.java @@ -16,10 +16,12 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.xiaomi; +import android.app.Activity; import android.content.Context; import android.net.Uri; import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.activities.FwAppInstallerActivity; import nodomain.freeyourgadget.gadgetbridge.activities.InstallActivity; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; @@ -36,6 +38,11 @@ public class XiaomiInstallHandler implements InstallHandler { this.helper = new XiaomiFWHelper(uri, context); } + @Override + public Class getInstallActivity() { + return FwAppInstallerActivity.class; + } + @Override public boolean isValid() { return helper.isValid(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/cmfwatchpro/CmfInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/cmfwatchpro/CmfInstallHandler.java index 0c9c12475..e7af14c11 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/cmfwatchpro/CmfInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/cmfwatchpro/CmfInstallHandler.java @@ -16,10 +16,12 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.service.devices.cmfwatchpro; +import android.app.Activity; import android.content.Context; import android.net.Uri; import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.activities.FwAppInstallerActivity; import nodomain.freeyourgadget.gadgetbridge.activities.InstallActivity; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; @@ -36,6 +38,11 @@ public class CmfInstallHandler implements InstallHandler { this.helper = new CmfFwHelper(uri, context); } + @Override + public Class getInstallActivity() { + return FwAppInstallerActivity.class; + } + @Override public boolean isValid() { return helper.isValid(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/zeppos/ZeppOsFwInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/zeppos/ZeppOsFwInstallHandler.java index 3a7fa6521..6c59b7721 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/zeppos/ZeppOsFwInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/zeppos/ZeppOsFwInstallHandler.java @@ -18,10 +18,13 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos; import static nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareType.AGPS_UIHH; +import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; import android.net.Uri; +import androidx.annotation.Nullable; + import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,6 +61,12 @@ public class ZeppOsFwInstallHandler implements InstallHandler { mHelper = new ZeppOsFwHelper(uri, context, deviceName, deviceSources); } + @Nullable + @Override + public Class getInstallActivity() { + return null; + } + @Override public boolean isValid() { return mHelper.isValid(); diff --git a/app/src/main/res/layout/activity_file_installer.xml b/app/src/main/res/layout/activity_file_installer.xml new file mode 100644 index 000000000..64f9fcbd0 --- /dev/null +++ b/app/src/main/res/layout/activity_file_installer.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c56ac7e43..460f81ce6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -134,6 +134,7 @@ Blacklisted Calendars + File installer FW/App installer You are about to install the %s. You are about to install the %s firmware on your Amazfit Bip.\n\nPlease make sure to install the .fw file, then the .res file, and finally the .gps file. Your watch will reboot after installing the .fw file.\n\nNote: You do not have to install .res and .gps if these files are exactly the same as the ones previously installed.\n\nPROCEED AT YOUR OWN RISK!