mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-09-06 06:25:20 +02:00
Port to UriHelper
This commit is contained in:
parent
aadde7d1ca
commit
df1fe7c5b8
@ -15,6 +15,7 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.UriHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Also see Mi1SFirmwareInfo.
|
* Also see Mi1SFirmwareInfo.
|
||||||
@ -26,12 +27,13 @@ public abstract class AbstractMiBandFWHelper {
|
|||||||
private final byte[] fw;
|
private final byte[] fw;
|
||||||
|
|
||||||
public AbstractMiBandFWHelper(Uri uri, Context context) throws IOException {
|
public AbstractMiBandFWHelper(Uri uri, Context context) throws IOException {
|
||||||
|
UriHelper uriHelper = UriHelper.get(uri, context);
|
||||||
String pebblePattern = ".*\\.(pbw|pbz|pbl)";
|
String pebblePattern = ".*\\.(pbw|pbz|pbl)";
|
||||||
if (uri.getPath().matches(pebblePattern)) {
|
if (uriHelper.getFileName().matches(pebblePattern)) {
|
||||||
throw new IOException("Firmware has a filename that looks like a Pebble app/firmware.");
|
throw new IOException("Firmware has a filename that looks like a Pebble app/firmware.");
|
||||||
}
|
}
|
||||||
|
|
||||||
try (InputStream in = new BufferedInputStream(context.getContentResolver().openInputStream(uri))) {
|
try (InputStream in = new BufferedInputStream(uriHelper.openInputStream())) {
|
||||||
this.fw = FileUtils.readAll(in, 1024 * 1024); // 1 MB
|
this.fw = FileUtils.readAll(in, 1024 * 1024); // 1 MB
|
||||||
determineFirmwareInfo(fw);
|
determineFirmwareInfo(fw);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
|
Loading…
Reference in New Issue
Block a user