mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-09-01 20:15:52 +02:00
bangle fixes for latest internethelper
This commit is contained in:
parent
9f5a73be5e
commit
f7f4f4ba54
@ -14,6 +14,7 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Looper;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.RemoteException;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
@ -48,6 +49,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
@ -64,6 +66,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||
import nodomain.freeyourgadget.internethelper.aidl.http.HttpGetRequest;
|
||||
import nodomain.freeyourgadget.internethelper.aidl.http.HttpHeaders;
|
||||
import nodomain.freeyourgadget.internethelper.aidl.http.HttpResponse;
|
||||
import nodomain.freeyourgadget.internethelper.aidl.http.IHttpCallback;
|
||||
import nodomain.freeyourgadget.internethelper.aidl.http.IHttpService;
|
||||
@ -242,11 +245,18 @@ public class AppsManagementActivity extends AbstractGBActivity {
|
||||
|
||||
@Override
|
||||
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
|
||||
LOG.info("shouldIntercept {} {}", request.getUrl(), iHttpService != null);
|
||||
LOG.info("shouldIntercept {} {} {}", request.getMethod(), request.getUrl(), iHttpService != null);
|
||||
if (!request.getMethod().equalsIgnoreCase("get")) {
|
||||
return super.shouldInterceptRequest(view, request);
|
||||
}
|
||||
if (iHttpService == null) {
|
||||
return super.shouldInterceptRequest(view, request);
|
||||
}
|
||||
HttpGetRequest httpGetRequest = new HttpGetRequest(request.getUrl().toString(), new Bundle());
|
||||
final HttpHeaders httpHeaders = new HttpHeaders();
|
||||
for (Map.Entry<String, String> header : request.getRequestHeaders().entrySet()) {
|
||||
httpHeaders.addHeader(header.getKey(), header.getValue());
|
||||
}
|
||||
final HttpGetRequest httpGetRequest = new HttpGetRequest(request.getUrl().toString(), httpHeaders);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
final Capsule<WebResourceResponse> internetResponseCapsule = new Capsule<>();
|
||||
try {
|
||||
@ -254,11 +264,11 @@ public class AppsManagementActivity extends AbstractGBActivity {
|
||||
@Override
|
||||
public void onResponse(HttpResponse response) throws RemoteException {
|
||||
WebResourceResponse internetResponse = new WebResourceResponse(
|
||||
response.getHeaders().getString("content-type"),
|
||||
response.getHeaders().getString("content-encoding"),
|
||||
response.getHeaders().get("content-type"),
|
||||
response.getHeaders().get("content-encoding"),
|
||||
response.getStatus(), "OK",
|
||||
response.getHeadersMap(),
|
||||
new ByteArrayInputStream(response.getBody())
|
||||
response.getHeaders().toMap(),
|
||||
new ParcelFileDescriptor.AutoCloseInputStream(response.getBody())
|
||||
);
|
||||
internetResponseCapsule.set(internetResponse);
|
||||
latch.countDown();
|
||||
|
@ -1,6 +1,5 @@
|
||||
package nodomain.freeyourgadget.internethelper.aidl.http;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
@ -8,14 +7,14 @@ import androidx.annotation.NonNull;
|
||||
|
||||
public class HttpGetRequest implements Parcelable {
|
||||
private final String url;
|
||||
private final Bundle headers;
|
||||
private final HttpHeaders headers;
|
||||
|
||||
protected HttpGetRequest(final Parcel in) {
|
||||
url = in.readString();
|
||||
headers = in.readBundle(ClassLoader.getSystemClassLoader());
|
||||
headers = in.readParcelable(HttpGetRequest.class.getClassLoader());
|
||||
}
|
||||
|
||||
public HttpGetRequest(String url, Bundle headers) {
|
||||
public HttpGetRequest(String url, HttpHeaders headers) {
|
||||
this.url = url;
|
||||
this.headers = headers;
|
||||
}
|
||||
@ -40,14 +39,14 @@ public class HttpGetRequest implements Parcelable {
|
||||
@Override
|
||||
public void writeToParcel(@NonNull final Parcel dest, final int flags) {
|
||||
dest.writeString(url);
|
||||
dest.writeBundle(headers);
|
||||
dest.writeParcelable(headers, 0);
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public Bundle getHeaders() {
|
||||
public HttpHeaders getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,80 @@
|
||||
package nodomain.freeyourgadget.internethelper.aidl.http;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.util.Pair;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class HttpHeaders implements Parcelable {
|
||||
private final List<Pair<String, String>> headers = new ArrayList<>();
|
||||
|
||||
protected HttpHeaders(final Parcel in) {
|
||||
final int numHeaders = in.readInt();
|
||||
for (int i = 0; i < numHeaders; i++) {
|
||||
final String k = in.readString();
|
||||
final String v = in.readString();
|
||||
headers.add(Pair.create(k, v));
|
||||
}
|
||||
}
|
||||
|
||||
public HttpHeaders() {
|
||||
}
|
||||
|
||||
public static final Creator<HttpHeaders> CREATOR = new Creator<HttpHeaders>() {
|
||||
@Override
|
||||
public HttpHeaders createFromParcel(final Parcel in) {
|
||||
return new HttpHeaders(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpHeaders[] newArray(final int size) {
|
||||
return new HttpHeaders[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(@NonNull final Parcel dest, final int flags) {
|
||||
dest.writeInt(headers.size());
|
||||
for (final Pair<String, String> header : headers) {
|
||||
dest.writeString(header.first);
|
||||
dest.writeString(header.second);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Pair<String, String>> getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public void addHeader(final String key, final String value) {
|
||||
headers.add(Pair.create(key, value));
|
||||
}
|
||||
|
||||
public String get(final String key) {
|
||||
for (final Pair<String, String> header : headers) {
|
||||
if (header.first.equalsIgnoreCase(key)) {
|
||||
return header.second;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Map<String, String> toMap() {
|
||||
final Map<String, String> ret = new HashMap<>();
|
||||
for (final Pair<String, String> header : headers) {
|
||||
ret.put(header.first, header.second);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
@ -1,28 +1,23 @@
|
||||
package nodomain.freeyourgadget.internethelper.aidl.http;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class HttpResponse implements Parcelable {
|
||||
private final int status;
|
||||
private final Bundle headers;
|
||||
private final byte[] body;
|
||||
private final HttpHeaders headers;
|
||||
private final ParcelFileDescriptor body;
|
||||
|
||||
protected HttpResponse(final Parcel in) {
|
||||
status = in.readInt();
|
||||
headers = in.readBundle(ClassLoader.getSystemClassLoader());
|
||||
final int bodyLength = in.readInt();
|
||||
body = new byte[bodyLength];
|
||||
in.readByteArray(body);
|
||||
headers = in.readParcelable(HttpResponse.class.getClassLoader());
|
||||
body = in.readParcelable(HttpResponse.class.getClassLoader());
|
||||
}
|
||||
|
||||
public HttpResponse(final int status, final Bundle headers, final byte[] body) {
|
||||
public HttpResponse(final int status, final HttpHeaders headers, final ParcelFileDescriptor body) {
|
||||
this.status = status;
|
||||
this.headers = headers;
|
||||
this.body = body;
|
||||
@ -48,28 +43,19 @@ public class HttpResponse implements Parcelable {
|
||||
@Override
|
||||
public void writeToParcel(@NonNull final Parcel dest, final int flags) {
|
||||
dest.writeInt(status);
|
||||
dest.writeBundle(headers);
|
||||
dest.writeInt(body.length);
|
||||
dest.writeByteArray(body);
|
||||
dest.writeParcelable(headers, 0);
|
||||
dest.writeParcelable(body, 0);
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public Bundle getHeaders() {
|
||||
public HttpHeaders getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public Map<String, String> getHeadersMap() {
|
||||
final Map<String, String> ret = new HashMap<>();
|
||||
for (String k : headers.keySet()) {
|
||||
ret.put(k, headers.getString(k));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public byte[] getBody() {
|
||||
public ParcelFileDescriptor getBody() {
|
||||
return body;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user