1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-11 04:29:29 +01:00

Pebble: Fix firmware installation when all 8 app slots are in use

We were trying to get a free slot when installing a firmware which is not neccessary.
This should also fix firmware installation in recovery (#54)
This commit is contained in:
Andreas Shimokawa 2015-05-25 01:26:27 +02:00
parent 6fb6b5c164
commit 8366af736c

View File

@ -143,25 +143,15 @@ public class PebbleIoThread extends GBDeviceIoThread {
try { try {
if (mIsInstalling) { if (mIsInstalling) {
switch (mInstallState) { switch (mInstallState) {
case APP_WAIT_SLOT: case WAIT_SLOT:
if (mInstallSlot == -1) { if (mInstallSlot == -1) {
finishInstall(true); // no slots available finishInstall(true); // no slots available
} else if (mInstallSlot >= 0) { } else if (mInstallSlot >= 0) {
mInstallState = PebbleAppInstallState.APP_START_INSTALL; mInstallState = PebbleAppInstallState.START_INSTALL;
continue; continue;
} }
break; break;
case APP_START_INSTALL: case START_INSTALL:
if (mPBWReader == null) {
mPBWReader = new PBWReader(mInstallURI, getContext());
mPebbleInstallables = mPBWReader.getPebbleInstallables();
mCurrentInstallableIndex = 0;
if (mPBWReader.isFirmware()) {
writeInstallApp(mPebbleProtocol.encodeInstallFirmwareStart());
mInstallSlot = 0;
LOG.info("starting firmware installation");
}
}
LOG.info("start installing app binary"); LOG.info("start installing app binary");
PebbleInstallable pi = mPebbleInstallables[mCurrentInstallableIndex]; PebbleInstallable pi = mPebbleInstallables[mCurrentInstallableIndex];
mZis = mPBWReader.getInputStreamFile(pi.getFileName()); mZis = mPBWReader.getInputStreamFile(pi.getFileName());
@ -169,16 +159,16 @@ public class PebbleIoThread extends GBDeviceIoThread {
mBinarySize = pi.getFileSize(); mBinarySize = pi.getFileSize();
mBytesWritten = 0; mBytesWritten = 0;
writeInstallApp(mPebbleProtocol.encodeUploadStart(pi.getType(), (byte) mInstallSlot, mBinarySize)); writeInstallApp(mPebbleProtocol.encodeUploadStart(pi.getType(), (byte) mInstallSlot, mBinarySize));
mInstallState = PebbleAppInstallState.APP_WAIT_TOKEN; mInstallState = PebbleAppInstallState.WAIT_TOKEN;
break; break;
case APP_WAIT_TOKEN: case WAIT_TOKEN:
if (mAppInstallToken != -1) { if (mAppInstallToken != -1) {
LOG.info("got token " + mAppInstallToken); LOG.info("got token " + mAppInstallToken);
mInstallState = PebbleAppInstallState.APP_UPLOAD_CHUNK; mInstallState = PebbleAppInstallState.UPLOAD_CHUNK;
continue; continue;
} }
break; break;
case APP_UPLOAD_CHUNK: case UPLOAD_CHUNK:
int bytes = 0; int bytes = 0;
do { do {
int read = mZis.read(buffer, bytes, 2000 - bytes); int read = mZis.read(buffer, bytes, 2000 - bytes);
@ -192,28 +182,28 @@ public class PebbleIoThread extends GBDeviceIoThread {
writeInstallApp(mPebbleProtocol.encodeUploadChunk(mAppInstallToken, buffer, bytes)); writeInstallApp(mPebbleProtocol.encodeUploadChunk(mAppInstallToken, buffer, bytes));
mBytesWritten += bytes; mBytesWritten += bytes;
mAppInstallToken = -1; mAppInstallToken = -1;
mInstallState = PebbleAppInstallState.APP_WAIT_TOKEN; mInstallState = PebbleAppInstallState.WAIT_TOKEN;
} else { } else {
mInstallState = PebbleAppInstallState.APP_UPLOAD_COMMIT; mInstallState = PebbleAppInstallState.UPLOAD_COMMIT;
continue; continue;
} }
break; break;
case APP_UPLOAD_COMMIT: case UPLOAD_COMMIT:
writeInstallApp(mPebbleProtocol.encodeUploadCommit(mAppInstallToken, mCRC)); writeInstallApp(mPebbleProtocol.encodeUploadCommit(mAppInstallToken, mCRC));
mAppInstallToken = -1; mAppInstallToken = -1;
mInstallState = PebbleAppInstallState.APP_WAIT_COMMIT; mInstallState = PebbleAppInstallState.WAIT_COMMIT;
break; break;
case APP_WAIT_COMMIT: case WAIT_COMMIT:
if (mAppInstallToken != -1) { if (mAppInstallToken != -1) {
LOG.info("got token " + mAppInstallToken); LOG.info("got token " + mAppInstallToken);
mInstallState = PebbleAppInstallState.APP_UPLOAD_COMPLETE; mInstallState = PebbleAppInstallState.UPLOAD_COMPLETE;
continue; continue;
} }
break; break;
case APP_UPLOAD_COMPLETE: case UPLOAD_COMPLETE:
writeInstallApp(mPebbleProtocol.encodeUploadComplete(mAppInstallToken)); writeInstallApp(mPebbleProtocol.encodeUploadComplete(mAppInstallToken));
if (++mCurrentInstallableIndex < mPebbleInstallables.length) { if (++mCurrentInstallableIndex < mPebbleInstallables.length) {
mInstallState = PebbleAppInstallState.APP_START_INSTALL; mInstallState = PebbleAppInstallState.START_INSTALL;
} else { } else {
mInstallState = PebbleAppInstallState.APP_REFRESH; mInstallState = PebbleAppInstallState.APP_REFRESH;
} }
@ -307,7 +297,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
@Override @Override
synchronized public void write(byte[] bytes) { synchronized public void write(byte[] bytes) {
// block writes if app installation in in progress // block writes if app installation in in progress
if (mIsConnected && (!mIsInstalling || mInstallState == PebbleAppInstallState.APP_WAIT_SLOT)) { if (mIsConnected && (!mIsInstalling || mInstallState == PebbleAppInstallState.WAIT_SLOT)) {
try { try {
mOutStream.write(bytes); mOutStream.write(bytes);
mOutStream.flush(); mOutStream.flush();
@ -394,10 +384,22 @@ public class PebbleIoThread extends GBDeviceIoThread {
if (mIsInstalling) { if (mIsInstalling) {
return; return;
} }
write(mPebbleProtocol.encodeAppInfoReq()); // do this here to get run() out of its blocking read
mInstallState = PebbleAppInstallState.APP_WAIT_SLOT;
mInstallURI = uri;
mIsInstalling = true; mIsInstalling = true;
mInstallURI = uri;
mPBWReader = new PBWReader(mInstallURI, getContext());
mPebbleInstallables = mPBWReader.getPebbleInstallables();
mCurrentInstallableIndex = 0;
if (mPBWReader.isFirmware()) {
writeInstallApp(mPebbleProtocol.encodeInstallFirmwareStart());
LOG.info("starting firmware installation");
mInstallSlot = 0;
mInstallState = PebbleAppInstallState.START_INSTALL;
} else {
writeInstallApp(mPebbleProtocol.encodeAppInfoReq());
mInstallState = PebbleAppInstallState.WAIT_SLOT;
}
} }
public void finishInstall(boolean hadError) { public void finishInstall(boolean hadError) {
@ -436,13 +438,13 @@ public class PebbleIoThread extends GBDeviceIoThread {
private enum PebbleAppInstallState { private enum PebbleAppInstallState {
UNKNOWN, UNKNOWN,
APP_WAIT_SLOT, WAIT_SLOT,
APP_START_INSTALL, START_INSTALL,
APP_WAIT_TOKEN, WAIT_TOKEN,
APP_UPLOAD_CHUNK, UPLOAD_CHUNK,
APP_UPLOAD_COMMIT, UPLOAD_COMMIT,
APP_WAIT_COMMIT, WAIT_COMMIT,
APP_UPLOAD_COMPLETE, UPLOAD_COMPLETE,
APP_REFRESH, APP_REFRESH,
} }
} }