1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-15 05:07:54 +01:00

Merge remote-tracking branch 'github/pr/1492/previous_app_management'

This commit is contained in:
Andreas Shimokawa 2019-05-09 11:34:56 +02:00
commit 19be1121c9
4 changed files with 74 additions and 2 deletions

View File

@ -0,0 +1,40 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.UUID;
public class PebbleActiveAppTracker {
private @Nullable UUID mPreviousRunningApp = null;
private @Nullable UUID mCurrentRunningApp = null;
@Nullable
public UUID getPreviousRunningApp() {
return mPreviousRunningApp;
}
@Nullable
public UUID getCurrentRunningApp() {
return mCurrentRunningApp;
}
public void markAppClosed(@NonNull UUID app) {
if (mCurrentRunningApp == app) {
if (mPreviousRunningApp != null) {
markAppOpened(mPreviousRunningApp);
} else {
mCurrentRunningApp = null;
}
}
}
public void markAppOpened(@NonNull UUID openedApp) {
if (openedApp.equals(mCurrentRunningApp)) {
return;
}
mPreviousRunningApp = mCurrentRunningApp;
mCurrentRunningApp = openedApp;
}
}

View File

@ -27,6 +27,7 @@ import android.os.ParcelUuid;
import android.webkit.ValueCallback;
import android.webkit.WebView;
import androidx.annotation.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -75,6 +76,7 @@ class PebbleIoThread extends GBDeviceIoThread {
private final PebbleProtocol mPebbleProtocol;
private final PebbleSupport mPebbleSupport;
private PebbleKitSupport mPebbleKitSupport;
private final PebbleActiveAppTracker mPebbleActiveAppTracker;
private final boolean mEnablePebblekit;
private boolean mIsTCP = false;
@ -149,6 +151,8 @@ class PebbleIoThread extends GBDeviceIoThread {
mEnablePebblekit = prefs.getBoolean("pebble_enable_pebblekit", false);
mPebbleProtocol.setAlwaysACKPebbleKit(prefs.getBoolean("pebble_always_ack_pebblekit", false));
mPebbleProtocol.setEnablePebbleKit(mEnablePebblekit);
mPebbleActiveAppTracker = new PebbleActiveAppTracker();
}
private int readWithException(InputStream inputStream, byte[] buffer, int byteOffset, int byteCount) throws IOException {
@ -563,6 +567,11 @@ class PebbleIoThread extends GBDeviceIoThread {
WebViewSingleton.getInstance().runJavascriptInterface(gbDevice, appMgmt.uuid);
}
}
mPebbleActiveAppTracker.markAppOpened(appMgmt.uuid);
break;
case STOP:
mPebbleActiveAppTracker.markAppClosed(appMgmt.uuid);
break;
default:
break;
@ -681,6 +690,17 @@ class PebbleIoThread extends GBDeviceIoThread {
}
}
void reopenLastApp(@NonNull UUID assumedCurrentApp) {
UUID currentApp = mPebbleActiveAppTracker.getCurrentRunningApp();
UUID previousApp = mPebbleActiveAppTracker.getPreviousRunningApp();
if (previousApp == null || !assumedCurrentApp.equals(currentApp)) {
write(mPebbleProtocol.encodeAppStart(assumedCurrentApp, false));
} else {
write(mPebbleProtocol.encodeAppStart(previousApp, true));
}
}
private void finishInstall(boolean hadError) {
if (!mIsInstalling) {
return;

View File

@ -44,6 +44,8 @@ class PebbleKitSupport {
private static final String PEBBLEKIT_ACTION_APP_START = "com.getpebble.action.app.START";
private static final String PEBBLEKIT_ACTION_APP_STOP = "com.getpebble.action.app.STOP";
private static final String PEBBLEKIT_EXTRA_REOPEN_LAST_APP = "com.getpebble.action.app.REOPEN_LAST_APP";
private static final String PEBBLEKIT_ACTION_DL_RECEIVE_DATA_NEW = "com.getpebble.action.dl.RECEIVE_DATA_NEW";
//private static final String PEBBLEKIT_ACTION_DL_RECEIVE_DATA = "com.getpebble.action.dl.RECEIVE_DATA";
private static final String PEBBLEKIT_ACTION_DL_ACK_DATA = "com.getpebble.action.dl.ACK_DATA";
@ -73,7 +75,12 @@ class PebbleKitSupport {
case PEBBLEKIT_ACTION_APP_STOP:
uuid = (UUID) intent.getSerializableExtra("uuid");
if (uuid != null) {
mPebbleIoThread.write(mPebbleProtocol.encodeAppStart(uuid, action.equals(PEBBLEKIT_ACTION_APP_START)));
if (action.equals(PEBBLEKIT_ACTION_APP_STOP) &&
intent.getBooleanExtra(PEBBLEKIT_EXTRA_REOPEN_LAST_APP, false)) {
mPebbleIoThread.reopenLastApp(uuid);
} else {
mPebbleIoThread.write(mPebbleProtocol.encodeAppStart(uuid, action.equals(PEBBLEKIT_ACTION_APP_START)));
}
}
break;
case PEBBLEKIT_ACTION_APP_SEND:

View File

@ -2156,7 +2156,12 @@ public class PebbleProtocol extends GBDeviceProtocol {
break;
case APPRUNSTATE_STOP:
LOG.info(ENDPOINT_NAME + ": stopped " + uuid);
break;
GBDeviceEventAppManagement gbDeviceEventAppManagement = new GBDeviceEventAppManagement();
gbDeviceEventAppManagement.uuid = uuid;
gbDeviceEventAppManagement.type = GBDeviceEventAppManagement.EventType.STOP;
gbDeviceEventAppManagement.event = GBDeviceEventAppManagement.Event.SUCCESS;
return new GBDeviceEvent[]{gbDeviceEventAppManagement};
default:
LOG.info(ENDPOINT_NAME + ": (cmd:" + command + ")" + uuid);
break;