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:
parent
86f738d947
commit
2413f07741
@ -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
|
||||
|
@ -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,10 +336,14 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
} break;
|
||||
case "http": {
|
||||
// FIXME: This should be behind a default-off option in Gadgetbridge settings
|
||||
if (BuildConfig.INTERNET_ACCESS) {
|
||||
RequestQueue queue = Volley.newRequestQueue(getContext());
|
||||
String url = json.getString("url");
|
||||
String _xmlPath = "";
|
||||
try { _xmlPath = json.getString("xpath"); } catch (JSONException e) {}
|
||||
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,
|
||||
@ -333,17 +351,14 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
@Override
|
||||
public void onResponse(String response) {
|
||||
JSONObject o = new JSONObject();
|
||||
if (xmlPath.length()!=0) {
|
||||
if (xmlPath.length() != 0) {
|
||||
try {
|
||||
InputSource inputXML = new InputSource( new StringReader( response ) );
|
||||
InputSource inputXML = new InputSource(new StringReader(response));
|
||||
XPath xPath = XPathFactory.newInstance().newXPath();
|
||||
response = xPath.evaluate(xmlPath, inputXML);
|
||||
} catch (Exception error) {
|
||||
try {
|
||||
o.put("err", error.toString());
|
||||
} catch (JSONException e) {
|
||||
GB.toast(getContext(), "HTTP: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
||||
}
|
||||
uartTxJSONError("http", error.toString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
try {
|
||||
@ -358,16 +373,13 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
@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);
|
||||
uartTxJSONError("http", error.toString());
|
||||
}
|
||||
});
|
||||
queue.add(stringRequest);
|
||||
} else {
|
||||
uartTxJSONError("http", "Internet access not enabled");
|
||||
}
|
||||
} break;
|
||||
default : {
|
||||
LOG.info("UART RX JSON packet type '"+packetType+"' not understood.");
|
||||
|
Loading…
Reference in New Issue
Block a user