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:
commit
19be1121c9
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -27,6 +27,7 @@ import android.os.ParcelUuid;
|
|||||||
import android.webkit.ValueCallback;
|
import android.webkit.ValueCallback;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -75,6 +76,7 @@ class PebbleIoThread extends GBDeviceIoThread {
|
|||||||
private final PebbleProtocol mPebbleProtocol;
|
private final PebbleProtocol mPebbleProtocol;
|
||||||
private final PebbleSupport mPebbleSupport;
|
private final PebbleSupport mPebbleSupport;
|
||||||
private PebbleKitSupport mPebbleKitSupport;
|
private PebbleKitSupport mPebbleKitSupport;
|
||||||
|
private final PebbleActiveAppTracker mPebbleActiveAppTracker;
|
||||||
private final boolean mEnablePebblekit;
|
private final boolean mEnablePebblekit;
|
||||||
|
|
||||||
private boolean mIsTCP = false;
|
private boolean mIsTCP = false;
|
||||||
@ -149,6 +151,8 @@ class PebbleIoThread extends GBDeviceIoThread {
|
|||||||
mEnablePebblekit = prefs.getBoolean("pebble_enable_pebblekit", false);
|
mEnablePebblekit = prefs.getBoolean("pebble_enable_pebblekit", false);
|
||||||
mPebbleProtocol.setAlwaysACKPebbleKit(prefs.getBoolean("pebble_always_ack_pebblekit", false));
|
mPebbleProtocol.setAlwaysACKPebbleKit(prefs.getBoolean("pebble_always_ack_pebblekit", false));
|
||||||
mPebbleProtocol.setEnablePebbleKit(mEnablePebblekit);
|
mPebbleProtocol.setEnablePebbleKit(mEnablePebblekit);
|
||||||
|
|
||||||
|
mPebbleActiveAppTracker = new PebbleActiveAppTracker();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int readWithException(InputStream inputStream, byte[] buffer, int byteOffset, int byteCount) throws IOException {
|
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);
|
WebViewSingleton.getInstance().runJavascriptInterface(gbDevice, appMgmt.uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mPebbleActiveAppTracker.markAppOpened(appMgmt.uuid);
|
||||||
|
break;
|
||||||
|
case STOP:
|
||||||
|
mPebbleActiveAppTracker.markAppClosed(appMgmt.uuid);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
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) {
|
private void finishInstall(boolean hadError) {
|
||||||
if (!mIsInstalling) {
|
if (!mIsInstalling) {
|
||||||
return;
|
return;
|
||||||
|
@ -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_START = "com.getpebble.action.app.START";
|
||||||
private static final String PEBBLEKIT_ACTION_APP_STOP = "com.getpebble.action.app.STOP";
|
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_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_RECEIVE_DATA = "com.getpebble.action.dl.RECEIVE_DATA";
|
||||||
private static final String PEBBLEKIT_ACTION_DL_ACK_DATA = "com.getpebble.action.dl.ACK_DATA";
|
private static final String PEBBLEKIT_ACTION_DL_ACK_DATA = "com.getpebble.action.dl.ACK_DATA";
|
||||||
@ -73,8 +75,13 @@ class PebbleKitSupport {
|
|||||||
case PEBBLEKIT_ACTION_APP_STOP:
|
case PEBBLEKIT_ACTION_APP_STOP:
|
||||||
uuid = (UUID) intent.getSerializableExtra("uuid");
|
uuid = (UUID) intent.getSerializableExtra("uuid");
|
||||||
if (uuid != null) {
|
if (uuid != null) {
|
||||||
|
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)));
|
mPebbleIoThread.write(mPebbleProtocol.encodeAppStart(uuid, action.equals(PEBBLEKIT_ACTION_APP_START)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case PEBBLEKIT_ACTION_APP_SEND:
|
case PEBBLEKIT_ACTION_APP_SEND:
|
||||||
int transaction_id = intent.getIntExtra("transaction_id", -1);
|
int transaction_id = intent.getIntExtra("transaction_id", -1);
|
||||||
|
@ -2156,7 +2156,12 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
break;
|
break;
|
||||||
case APPRUNSTATE_STOP:
|
case APPRUNSTATE_STOP:
|
||||||
LOG.info(ENDPOINT_NAME + ": stopped " + uuid);
|
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:
|
default:
|
||||||
LOG.info(ENDPOINT_NAME + ": (cmd:" + command + ")" + uuid);
|
LOG.info(ENDPOINT_NAME + ": (cmd:" + command + ")" + uuid);
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user