Some cleanup
This commit is contained in:
parent
71461642f7
commit
9d9ef8a6f8
|
@ -24,8 +24,6 @@ import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||||
public class MiBandFWHelper {
|
public class MiBandFWHelper {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(MiBandFWHelper.class);
|
private static final Logger LOG = LoggerFactory.getLogger(MiBandFWHelper.class);
|
||||||
|
|
||||||
private final Uri uri;
|
|
||||||
private final ContentResolver cr;
|
|
||||||
/**
|
/**
|
||||||
* The backing firmware info instance, which in general supports the provided
|
* The backing firmware info instance, which in general supports the provided
|
||||||
* given firmware. You must call AbstractMiFirmwareInfo#checkValid() before
|
* given firmware. You must call AbstractMiFirmwareInfo#checkValid() before
|
||||||
|
@ -54,19 +52,12 @@ public class MiBandFWHelper {
|
||||||
};
|
};
|
||||||
|
|
||||||
public MiBandFWHelper(Uri uri, Context context) throws IOException {
|
public MiBandFWHelper(Uri uri, Context context) throws IOException {
|
||||||
this.uri = uri;
|
|
||||||
cr = context.getContentResolver();
|
|
||||||
if (cr == null) {
|
|
||||||
throw new IOException("No content resolver");
|
|
||||||
}
|
|
||||||
|
|
||||||
String pebblePattern = ".*\\.(pbw|pbz|pbl)";
|
String pebblePattern = ".*\\.(pbw|pbz|pbl)";
|
||||||
|
|
||||||
if (uri.getPath().matches(pebblePattern)) {
|
if (uri.getPath().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(cr.openInputStream(uri))) {
|
try (InputStream in = new BufferedInputStream(context.getContentResolver().openInputStream(uri))) {
|
||||||
this.fw = FileUtils.readAll(in, 1024 * 1024); // 1 MB
|
this.fw = FileUtils.readAll(in, 1024 * 1024); // 1 MB
|
||||||
this.firmwareInfo = determineFirmwareInfoFor(fw);
|
this.firmwareInfo = determineFirmwareInfoFor(fw);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
|
|
Loading…
Reference in New Issue