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.Collections;
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.appmanager.AppManagerActivity;
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator;
@ -139,11 +140,11 @@ public class BangleJSCoordinator extends AbstractDeviceCoordinator {
}
@Override
public boolean supportsAppsManagement() { return true; }
public boolean supportsAppsManagement() { return BuildConfig.INTERNET_ACCESS; }
@Override
public Class<? extends Activity> getAppsManagementActivity() {
return AppsManagementActivity.class;
return BuildConfig.INTERNET_ACCESS ? AppsManagementActivity.class : null;
}
@Override

View File

@ -59,6 +59,7 @@ import java.util.SimpleTimeZone;
import java.util.UUID;
import java.lang.reflect.Field;
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
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) {
try {
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) {
LOG.info("UART RX LINE: " + line);
@ -322,52 +336,50 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
} break;
case "http": {
// FIXME: This should be behind a default-off option in Gadgetbridge settings
RequestQueue queue = Volley.newRequestQueue(getContext());
String url = json.getString("url");
String _xmlPath = "";
try { _xmlPath = json.getString("xpath"); } catch (JSONException e) {}
final String xmlPath = _xmlPath;
// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
JSONObject o = new JSONObject();
if (xmlPath.length()!=0) {
try {
InputSource inputXML = new InputSource( new StringReader( response ) );
XPath xPath = XPathFactory.newInstance().newXPath();
response = xPath.evaluate(xmlPath, inputXML);
} catch (Exception error) {
if (BuildConfig.INTERNET_ACCESS) {
RequestQueue queue = Volley.newRequestQueue(getContext());
String url = json.getString("url");
String _xmlPath = "";
try {
_xmlPath = json.getString("xpath");
} catch (JSONException e) {
}
final String xmlPath = _xmlPath;
// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
JSONObject o = new JSONObject();
if (xmlPath.length() != 0) {
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 {
o.put("err", error.toString());
o.put("t", "http");
o.put("resp", response);
} catch (JSONException e) {
GB.toast(getContext(), "HTTP: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
}
}
uartTxJSON("http", o);
}
try {
o.put("t", "http");
o.put("resp", response);
} catch (JSONException e) {
GB.toast(getContext(), "HTTP: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
}
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);
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
JSONObject o = new JSONObject();
uartTxJSONError("http", error.toString());
}
uartTxJSON("http", o);
}
});
queue.add(stringRequest);
});
queue.add(stringRequest);
} else {
uartTxJSONError("http", "Internet access not enabled");
}
} break;
default : {
LOG.info("UART RX JSON packet type '"+packetType+"' not understood.");