mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 21:06:50 +01:00
Pebble: prepend application start event to premature appmessage from a newly started app
This should fix some InvalidStateExceptions when using background javascript
This commit is contained in:
parent
296dfe2f17
commit
d9c012025d
@ -221,7 +221,7 @@ function gbPebble() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
GBjs.gbLog("sendAppMessage failed");
|
GBjs.gbLog("sendAppMessage failed" + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2238,18 +2238,23 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
switch (command) {
|
switch (command) {
|
||||||
case APPRUNSTATE_START:
|
case APPRUNSTATE_START:
|
||||||
LOG.info(ENDPOINT_NAME + ": started " + uuid);
|
LOG.info(ENDPOINT_NAME + ": started " + uuid);
|
||||||
currentRunningApp = uuid;
|
|
||||||
AppMessageHandler handler = mAppMessageHandlers.get(uuid);
|
AppMessageHandler handler = mAppMessageHandlers.get(uuid);
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
|
currentRunningApp = uuid;
|
||||||
return handler.onAppStart();
|
return handler.onAppStart();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
GBDeviceEventAppManagement gbDeviceEventAppManagement = new GBDeviceEventAppManagement();
|
if (!uuid.equals(currentRunningApp)) {
|
||||||
gbDeviceEventAppManagement.uuid = uuid;
|
currentRunningApp = uuid;
|
||||||
gbDeviceEventAppManagement.type = GBDeviceEventAppManagement.EventType.START;
|
GBDeviceEventAppManagement gbDeviceEventAppManagement = new GBDeviceEventAppManagement();
|
||||||
gbDeviceEventAppManagement.event = GBDeviceEventAppManagement.Event.SUCCESS;
|
gbDeviceEventAppManagement.uuid = uuid;
|
||||||
return new GBDeviceEvent[] {gbDeviceEventAppManagement};
|
gbDeviceEventAppManagement.type = GBDeviceEventAppManagement.EventType.START;
|
||||||
|
gbDeviceEventAppManagement.event = GBDeviceEventAppManagement.Event.SUCCESS;
|
||||||
|
return new GBDeviceEvent[]{gbDeviceEventAppManagement};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
case APPRUNSTATE_STOP:
|
case APPRUNSTATE_STOP:
|
||||||
LOG.info(ENDPOINT_NAME + ": stopped " + uuid);
|
LOG.info(ENDPOINT_NAME + ": stopped " + uuid);
|
||||||
break;
|
break;
|
||||||
@ -2603,13 +2608,13 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
LOG.info((endpoint == ENDPOINT_LAUNCHER ? "got LAUNCHER PUSH from UUID : " : "got APPLICATIONMESSAGE PUSH from UUID : ") + uuid);
|
LOG.info((endpoint == ENDPOINT_LAUNCHER ? "got LAUNCHER PUSH from UUID : " : "got APPLICATIONMESSAGE PUSH from UUID : ") + uuid);
|
||||||
AppMessageHandler handler = mAppMessageHandlers.get(uuid);
|
AppMessageHandler handler = mAppMessageHandlers.get(uuid);
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
|
currentRunningApp = uuid;
|
||||||
if (handler.isEnabled()) {
|
if (handler.isEnabled()) {
|
||||||
if (endpoint == ENDPOINT_APPLICATIONMESSAGE) {
|
if (endpoint == ENDPOINT_APPLICATIONMESSAGE) {
|
||||||
ArrayList<Pair<Integer, Object>> dict = decodeDict(buf);
|
ArrayList<Pair<Integer, Object>> dict = decodeDict(buf);
|
||||||
devEvts = handler.handleMessage(dict);
|
devEvts = handler.handleMessage(dict);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
currentRunningApp = uuid;
|
|
||||||
devEvts = handler.onAppStart();
|
devEvts = handler.onAppStart();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -2617,22 +2622,26 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
if (endpoint == ENDPOINT_APPLICATIONMESSAGE) {
|
devEvts = decodeDictToJSONAppMessage(uuid, buf);
|
||||||
devEvts = decodeDictToJSONAppMessage(uuid, buf);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
currentRunningApp = uuid;
|
|
||||||
GBDeviceEventAppManagement gbDeviceEventAppManagement = new GBDeviceEventAppManagement();
|
|
||||||
gbDeviceEventAppManagement.uuid = uuid;
|
|
||||||
gbDeviceEventAppManagement.type = GBDeviceEventAppManagement.EventType.START;
|
|
||||||
gbDeviceEventAppManagement.event = GBDeviceEventAppManagement.Event.SUCCESS;
|
|
||||||
devEvts = new GBDeviceEvent[] {gbDeviceEventAppManagement};
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
LOG.error(e.getMessage());
|
LOG.error(e.getMessage());
|
||||||
return null;
|
}
|
||||||
|
if (!uuid.equals(currentRunningApp)) {
|
||||||
|
GBDeviceEventAppManagement gbDeviceEventAppManagement = new GBDeviceEventAppManagement();
|
||||||
|
gbDeviceEventAppManagement.uuid = uuid;
|
||||||
|
gbDeviceEventAppManagement.type = GBDeviceEventAppManagement.EventType.START;
|
||||||
|
gbDeviceEventAppManagement.event = GBDeviceEventAppManagement.Event.SUCCESS;
|
||||||
|
|
||||||
|
// prepend the
|
||||||
|
GBDeviceEvent concatEvents[] = new GBDeviceEvent[(devEvts != null ? devEvts.length : 0) + 1];
|
||||||
|
concatEvents[0] = gbDeviceEventAppManagement;
|
||||||
|
if (devEvts != null) {
|
||||||
|
System.arraycopy(devEvts, 0, concatEvents, 1, devEvts.length);
|
||||||
|
}
|
||||||
|
devEvts = concatEvents;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
currentRunningApp = uuid;
|
||||||
break;
|
break;
|
||||||
case APPLICATIONMESSAGE_ACK:
|
case APPLICATIONMESSAGE_ACK:
|
||||||
case APPLICATIONMESSAGE_NACK:
|
case APPLICATIONMESSAGE_NACK:
|
||||||
|
Loading…
Reference in New Issue
Block a user