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,52 +336,50 @@ 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
RequestQueue queue = Volley.newRequestQueue(getContext()); if (BuildConfig.INTERNET_ACCESS) {
String url = json.getString("url"); RequestQueue queue = Volley.newRequestQueue(getContext());
String _xmlPath = ""; String url = json.getString("url");
try { _xmlPath = json.getString("xpath"); } catch (JSONException e) {} String _xmlPath = "";
final String xmlPath = _xmlPath; try {
// Request a string response from the provided URL. _xmlPath = json.getString("xpath");
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, } catch (JSONException e) {
new Response.Listener<String>() { }
@Override final String xmlPath = _xmlPath;
public void onResponse(String response) { // Request a string response from the provided URL.
JSONObject o = new JSONObject(); StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
if (xmlPath.length()!=0) { new Response.Listener<String>() {
try { @Override
InputSource inputXML = new InputSource( new StringReader( response ) ); public void onResponse(String response) {
XPath xPath = XPathFactory.newInstance().newXPath(); JSONObject o = new JSONObject();
response = xPath.evaluate(xmlPath, inputXML); if (xmlPath.length() != 0) {
} catch (Exception error) { try {
InputSource inputXML = new InputSource(new StringReader(response));
XPath xPath = XPathFactory.newInstance().newXPath();
response = xPath.evaluate(xmlPath, inputXML);
} catch (Exception error) {
uartTxJSONError("http", error.toString());
return;
}
}
try { try {
o.put("err", error.toString()); o.put("t", "http");
o.put("resp", response);
} catch (JSONException e) { } catch (JSONException e) {
GB.toast(getContext(), "HTTP: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); GB.toast(getContext(), "HTTP: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
} }
} uartTxJSON("http", o);
} }
try { }, new Response.ErrorListener() {
o.put("t", "http"); @Override
o.put("resp", response); public void onErrorResponse(VolleyError error) {
} catch (JSONException e) { JSONObject o = new JSONObject();
GB.toast(getContext(), "HTTP: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); uartTxJSONError("http", error.toString());
}
uartTxJSON("http", o);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
JSONObject o = new JSONObject();
try {
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);
}); } else {
queue.add(stringRequest); 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.");