1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-08-03 04:21:52 +02:00

Adding internet connectivity with 'http' Gadgetbridge event

FIXME - still needs a setting to enable that is off by default
This commit is contained in:
Gordon Williams 2022-02-10 16:49:17 +00:00
parent 2a53219a14
commit c597adf27f
4 changed files with 53 additions and 0 deletions

View File

@ -213,6 +213,7 @@ dependencies {
implementation 'com.github.wax911:android-emojify:0.1.7'
implementation 'com.google.protobuf:protobuf-lite:3.0.1'
implementation "androidx.multidex:multidex:2.0.1"
implementation 'com.android.volley:volley:1.2.1'
}
preBuild.dependsOn(":GBDaoGenerator:genSources")

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>

View File

@ -65,6 +65,7 @@ import java.util.Set;
import de.cketti.library.changelog.ChangeLog;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAdapterv2;
import nodomain.freeyourgadget.gadgetbridge.database.DBAccess;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
@ -438,6 +439,12 @@ public class ControlCenterv2 extends AppCompatActivity
}
}
if (BuildConfig.INTERNET_ACCESS) {
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.INTERNET) == PackageManager.PERMISSION_DENIED) {
wantedPermissions.add(Manifest.permission.INTERNET);
}
}
if (!wantedPermissions.isEmpty()) {
Prefs prefs = GBApplication.getPrefs();
// If this is not the first run, we can rely on

View File

@ -31,6 +31,13 @@ import android.widget.Toast;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.RequestQueue;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@ -267,6 +274,39 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
}
} 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");
// 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();
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);
}
uartTxJSON("http", o);
}
});
queue.add(stringRequest);
} break;
}
}