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