mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-09-08 07:28:32 +02:00
Add option for enabling/disabling internet access, and add ability to send Intents direct from Bangle.js
This commit is contained in:
parent
573e704040
commit
e786354c8d
@ -41,6 +41,9 @@ public class DeviceSettingsPreferenceConst {
|
||||
public static final String PREF_VIBRATION_STRENGH_PERCENTAGE = "vibration_strength";
|
||||
public static final String PREF_RELAX_FIRMWARE_CHECKS = "relax_firmware_checks";
|
||||
|
||||
public static final String PREF_DEVICE_INTERNET_ACCESS = "device_internet_access";
|
||||
public static final String PREF_DEVICE_INTENTS = "device_intents";
|
||||
|
||||
public static final String PREF_DISCONNECT_NOTIFICATION = "disconnect_notification";
|
||||
public static final String PREF_DISCONNECT_NOTIFICATION_START = "disconnect_notification_start";
|
||||
public static final String PREF_DISCONNECT_NOTIFICATION_END = "disconnect_notification_end";
|
||||
|
@ -29,6 +29,7 @@ import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Vector;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
@ -167,9 +168,16 @@ public class BangleJSCoordinator extends AbstractDeviceCoordinator {
|
||||
}
|
||||
|
||||
public int[] getSupportedDeviceSpecificSettings(GBDevice device) {
|
||||
return new int[]{
|
||||
R.xml.devicesettings_transliteration
|
||||
};
|
||||
Vector<Integer> settings = new Vector<Integer>();
|
||||
settings.add(R.xml.devicesettings_transliteration);
|
||||
settings.add(R.xml.devicesettings_high_mtu);
|
||||
if (BuildConfig.INTERNET_ACCESS)
|
||||
settings.add(R.xml.devicesettings_device_internet_access);
|
||||
settings.add(R.xml.devicesettings_device_intents);
|
||||
// must be a better way of doing this?
|
||||
int[] settingsInt = new int[settings.size()];
|
||||
for (int i=0; i<settings.size(); i++) settingsInt[i] = settings.get(i);
|
||||
return settingsInt;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -62,6 +62,7 @@ import java.lang.reflect.Field;
|
||||
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
|
||||
@ -92,6 +93,9 @@ import nodomain.freeyourgadget.gadgetbridge.util.AlarmUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||
|
||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_ALLOW_HIGH_MTU;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DEVICE_INTERNET_ACCESS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DEVICE_INTENTS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.database.DBHelper.*;
|
||||
|
||||
import javax.xml.xpath.XPath;
|
||||
@ -103,6 +107,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
private BluetoothGattCharacteristic rxCharacteristic = null;
|
||||
private BluetoothGattCharacteristic txCharacteristic = null;
|
||||
private boolean allowHighMTU = false;
|
||||
private int mtuSize = 20;
|
||||
|
||||
private String receivedLine = "";
|
||||
@ -153,6 +158,9 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
builder.setGattCallback(this);
|
||||
builder.notify(rxCharacteristic, true);
|
||||
|
||||
Prefs devicePrefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()));
|
||||
allowHighMTU = devicePrefs.getBoolean(PREF_ALLOW_HIGH_MTU, false);
|
||||
|
||||
uartTx(builder, " \u0003"); // clear active line
|
||||
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
@ -205,7 +213,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
o.put("t", taskName);
|
||||
o.put("err", message);
|
||||
} catch (JSONException e) {
|
||||
GB.toast(getContext(), "HTTP: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
||||
GB.toast(getContext(), "uartTxJSONError: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
||||
}
|
||||
uartTxJSON(taskName, o);
|
||||
}
|
||||
@ -335,8 +343,8 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
} break;
|
||||
case "http": {
|
||||
// FIXME: This should be behind a default-off option in Gadgetbridge settings
|
||||
if (BuildConfig.INTERNET_ACCESS) {
|
||||
Prefs devicePrefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()));
|
||||
if (BuildConfig.INTERNET_ACCESS && devicePrefs.getBoolean(PREF_DEVICE_INTERNET_ACCESS, false)) {
|
||||
RequestQueue queue = Volley.newRequestQueue(getContext());
|
||||
String url = json.getString("url");
|
||||
String _xmlPath = "";
|
||||
@ -378,9 +386,32 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
});
|
||||
queue.add(stringRequest);
|
||||
} else {
|
||||
uartTxJSONError("http", "Internet access not enabled");
|
||||
if (BuildConfig.INTERNET_ACCESS)
|
||||
uartTxJSONError("http", "Internet access not enabled, check Gadgetbridge Device Settings");
|
||||
else
|
||||
uartTxJSONError("http", "Internet access not enabled in this Gadgetbridge build");
|
||||
}
|
||||
} break;
|
||||
case "intent": {
|
||||
Prefs devicePrefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()));
|
||||
if (devicePrefs.getBoolean(PREF_DEVICE_INTENTS, false)) {
|
||||
String action = json.getString("action");
|
||||
JSONObject extra = json.getJSONObject("extra");
|
||||
Intent in = new Intent();
|
||||
in.setAction(action);
|
||||
if (extra != null) {
|
||||
Iterator<String> iter = extra.keys();
|
||||
while (iter.hasNext()) {
|
||||
String key = iter.next();
|
||||
in.putExtra(key, extra.getString(key));
|
||||
}
|
||||
}
|
||||
LOG.info("Sending intent " + action);
|
||||
this.getContext().getApplicationContext().sendBroadcast(in);
|
||||
} else {
|
||||
uartTxJSONError("intent", "Android Intents not enabled, check Gadgetbridge Device Settings");
|
||||
}
|
||||
}
|
||||
default : {
|
||||
LOG.info("UART RX JSON packet type '"+packetType+"' not understood.");
|
||||
}
|
||||
@ -396,7 +427,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
if (BangleJSConstants.UUID_CHARACTERISTIC_NORDIC_UART_RX.equals(characteristic.getUuid())) {
|
||||
byte[] chars = characteristic.getValue();
|
||||
// check to see if we get more data - if so, increase out MTU for sending
|
||||
if (chars.length > mtuSize)
|
||||
if (allowHighMTU && chars.length > mtuSize)
|
||||
mtuSize = chars.length;
|
||||
String packetStr = new String(chars);
|
||||
LOG.info("RX: " + packetStr);
|
||||
|
@ -264,6 +264,10 @@
|
||||
<string name="pref_summary_use_custom_font">Enable this if your device has a custom font firmware for emoji support</string>
|
||||
<string name="pref_title_allow_high_mtu">Allow high MTU</string>
|
||||
<string name="pref_summary_allow_high_mtu">Increases transfer speed, but might not work on some Android devices.</string>
|
||||
<string name="pref_title_device_internet_access">Allow Internet Access</string>
|
||||
<string name="pref_summary_device_internet_access">Allow apps on this device to access the internet</string>
|
||||
<string name="pref_title_device_intents">Allow Intents</string>
|
||||
<string name="pref_summary_device_intents">Allow apps on this device to send Android Intents</string>
|
||||
<string name="pref_summary_sync_calendar">Enables calendar alerts, even when disconnected</string>
|
||||
<string name="pref_title_sync_caldendar">Sync calendar events</string>
|
||||
<string name="pref_summary_relax_firmware_checks">Relax firmware checks</string>
|
||||
|
9
app/src/main/res/xml/devicesettings_device_intents.xml
Normal file
9
app/src/main/res/xml/devicesettings_device_intents.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:icon="@drawable/ic_language"
|
||||
android:key="device_intents"
|
||||
android:summary="@string/pref_summary_device_intents"
|
||||
android:title="@string/pref_title_device_intents" />
|
||||
</androidx.preference.PreferenceScreen>
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:icon="@drawable/ic_language"
|
||||
android:key="device_internet_access"
|
||||
android:summary="@string/pref_summary_device_internet_access"
|
||||
android:title="@string/pref_title_device_internet_access" />
|
||||
</androidx.preference.PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user