1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-02 06:52:55 +01:00

Ensure app manager is only available in Bangle.js builds (where internet access allowed)

This commit is contained in:
Gordon Williams 2022-03-24 14:09:47 +00:00
parent 86f738d947
commit 2413f07741
2 changed files with 56 additions and 43 deletions

View File

@ -30,6 +30,7 @@ import androidx.annotation.NonNull;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.appmanager.AppManagerActivity; import nodomain.freeyourgadget.gadgetbridge.activities.appmanager.AppManagerActivity;
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator;
@ -139,11 +140,11 @@ public class BangleJSCoordinator extends AbstractDeviceCoordinator {
} }
@Override @Override
public boolean supportsAppsManagement() { return true; } public boolean supportsAppsManagement() { return BuildConfig.INTERNET_ACCESS; }
@Override @Override
public Class<? extends Activity> getAppsManagementActivity() { public Class<? extends Activity> getAppsManagementActivity() {
return AppsManagementActivity.class; return BuildConfig.INTERNET_ACCESS ? AppsManagementActivity.class : null;
} }
@Override @Override

View File

@ -59,6 +59,7 @@ import java.util.SimpleTimeZone;
import java.util.UUID; import java.util.UUID;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
@ -186,7 +187,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
} }
} }
/// Write a string of data, and chunk it up /// Write a JSON object of data
private void uartTxJSON(String taskName, JSONObject json) { private void uartTxJSON(String taskName, JSONObject json) {
try { try {
TransactionBuilder builder = performInitialized(taskName); TransactionBuilder builder = performInitialized(taskName);
@ -197,6 +198,19 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
} }
} }
/// Write JSON object of the form {t:taskName, err:message}
private void uartTxJSONError(String taskName, String message) {
JSONObject o = new JSONObject();
try {
o.put("t", taskName);
o.put("err", message);
} catch (JSONException e) {
GB.toast(getContext(), "HTTP: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
}
uartTxJSON(taskName, o);
}
private void handleUartRxLine(String line) { private void handleUartRxLine(String line) {
LOG.info("UART RX LINE: " + line); LOG.info("UART RX LINE: " + line);
@ -322,10 +336,14 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
} break; } break;
case "http": { case "http": {
// FIXME: This should be behind a default-off option in Gadgetbridge settings // FIXME: This should be behind a default-off option in Gadgetbridge settings
if (BuildConfig.INTERNET_ACCESS) {
RequestQueue queue = Volley.newRequestQueue(getContext()); RequestQueue queue = Volley.newRequestQueue(getContext());
String url = json.getString("url"); String url = json.getString("url");
String _xmlPath = ""; String _xmlPath = "";
try { _xmlPath = json.getString("xpath"); } catch (JSONException e) {} try {
_xmlPath = json.getString("xpath");
} catch (JSONException e) {
}
final String xmlPath = _xmlPath; final String xmlPath = _xmlPath;
// Request a string response from the provided URL. // Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
@ -333,17 +351,14 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
@Override @Override
public void onResponse(String response) { public void onResponse(String response) {
JSONObject o = new JSONObject(); JSONObject o = new JSONObject();
if (xmlPath.length()!=0) { if (xmlPath.length() != 0) {
try { try {
InputSource inputXML = new InputSource( new StringReader( response ) ); InputSource inputXML = new InputSource(new StringReader(response));
XPath xPath = XPathFactory.newInstance().newXPath(); XPath xPath = XPathFactory.newInstance().newXPath();
response = xPath.evaluate(xmlPath, inputXML); response = xPath.evaluate(xmlPath, inputXML);
} catch (Exception error) { } catch (Exception error) {
try { uartTxJSONError("http", error.toString());
o.put("err", error.toString()); return;
} catch (JSONException e) {
GB.toast(getContext(), "HTTP: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
}
} }
} }
try { try {
@ -358,16 +373,13 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
@Override @Override
public void onErrorResponse(VolleyError error) { public void onErrorResponse(VolleyError error) {
JSONObject o = new JSONObject(); JSONObject o = new JSONObject();
try { uartTxJSONError("http", error.toString());
o.put("t", "http");
o.put("err", error.toString());
} catch (JSONException e) {
GB.toast(getContext(), "HTTP: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
}
uartTxJSON("http", o);
} }
}); });
queue.add(stringRequest); queue.add(stringRequest);
} else {
uartTxJSONError("http", "Internet access not enabled");
}
} break; } break;
default : { default : {
LOG.info("UART RX JSON packet type '"+packetType+"' not understood."); LOG.info("UART RX JSON packet type '"+packetType+"' not understood.");