parent
9cb53e93d0
commit
6b4b85d396
@ -181,7 +181,6 @@ def preDexEnabled = "true".equals(System.getProperty("pre-dex", "true"))
|
|||||||
android {
|
android {
|
||||||
compileSdkVersion 24
|
compileSdkVersion 24
|
||||||
buildToolsVersion '25.0.3'
|
buildToolsVersion '25.0.3'
|
||||||
useLibrary 'org.apache.http.legacy'
|
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
// use proguard on debug too since we have unknowingly broken
|
// use proguard on debug too since we have unknowingly broken
|
||||||
|
2
app/proguard-rules.pro
vendored
2
app/proguard-rules.pro
vendored
@ -7,6 +7,8 @@
|
|||||||
-dontwarn com.android.support.test.**
|
-dontwarn com.android.support.test.**
|
||||||
|
|
||||||
-dontwarn javax.naming.**
|
-dontwarn javax.naming.**
|
||||||
|
-dontnote org.apache.http.**
|
||||||
|
-dontnote android.net.http.**
|
||||||
-dontnote android.support.**
|
-dontnote android.support.**
|
||||||
-dontnote **ILicensingService
|
-dontnote **ILicensingService
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.fdroid.fdroid.localrepo;
|
package org.fdroid.fdroid.localrepo;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
@ -10,7 +11,6 @@ import android.content.Intent;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.net.http.AndroidHttpClient;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.support.annotation.IntDef;
|
import android.support.annotation.IntDef;
|
||||||
@ -20,11 +20,6 @@ import android.support.v4.app.NotificationCompat;
|
|||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import org.apache.http.HttpHost;
|
|
||||||
import org.apache.http.NameValuePair;
|
|
||||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
||||||
import org.apache.http.client.methods.HttpPost;
|
|
||||||
import org.apache.http.message.BasicNameValuePair;
|
|
||||||
import org.fdroid.fdroid.FDroidApp;
|
import org.fdroid.fdroid.FDroidApp;
|
||||||
import org.fdroid.fdroid.Preferences;
|
import org.fdroid.fdroid.Preferences;
|
||||||
import org.fdroid.fdroid.R;
|
import org.fdroid.fdroid.R;
|
||||||
@ -47,13 +42,14 @@ import rx.android.schedulers.AndroidSchedulers;
|
|||||||
import rx.schedulers.Schedulers;
|
import rx.schedulers.Schedulers;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.OutputStream;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.util.ArrayList;
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
@ -208,55 +204,37 @@ public class SwapService extends Service {
|
|||||||
UpdateService.updateRepoNow(this, peer.getRepoAddress());
|
UpdateService.updateRepoNow(this, peer.getRepoAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("StaticFieldLeak")
|
||||||
private void askServerToSwapWithUs(final Repo repo) {
|
private void askServerToSwapWithUs(final Repo repo) {
|
||||||
askServerToSwapWithUs(repo.address);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void askServerToSwapWithUs(final String address) {
|
|
||||||
new AsyncTask<Void, Void, Void>() {
|
new AsyncTask<Void, Void, Void>() {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... args) {
|
protected Void doInBackground(Void... args) {
|
||||||
Uri repoUri = Uri.parse(address);
|
|
||||||
String swapBackUri = Utils.getLocalRepoUri(FDroidApp.repo).toString();
|
String swapBackUri = Utils.getLocalRepoUri(FDroidApp.repo).toString();
|
||||||
|
HttpURLConnection conn = null;
|
||||||
AndroidHttpClient client = AndroidHttpClient.newInstance("F-Droid", SwapService.this);
|
|
||||||
HttpPost request = new HttpPost("/request-swap");
|
|
||||||
HttpHost host = new HttpHost(repoUri.getHost(), repoUri.getPort(), repoUri.getScheme());
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Utils.debugLog(TAG, "Asking server at " + address + " to swap with us in return (by POSTing to \"/request-swap\" with repo \"" + swapBackUri + "\")...");
|
URL url = new URL(repo.address.replace("/fdroid/repo", "/request-swap"));
|
||||||
populatePostParams(swapBackUri, request);
|
conn = (HttpURLConnection) url.openConnection();
|
||||||
client.execute(host, request);
|
conn.setRequestMethod("POST");
|
||||||
|
conn.setDoInput(true);
|
||||||
|
conn.setDoOutput(true);
|
||||||
|
|
||||||
|
OutputStream outputStream = conn.getOutputStream();
|
||||||
|
OutputStreamWriter writer = new OutputStreamWriter(outputStream);
|
||||||
|
writer.write("repo=" + swapBackUri);
|
||||||
|
writer.flush();
|
||||||
|
writer.close();
|
||||||
|
outputStream.close();
|
||||||
|
|
||||||
|
int responseCode = conn.getResponseCode();
|
||||||
|
Utils.debugLog(TAG, "Asking server at " + repo.address + " to swap with us in return (by " +
|
||||||
|
"POSTing to \"/request-swap\" with repo \"" + swapBackUri + "\"): " + responseCode);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
notifyOfErrorOnUiThread();
|
|
||||||
Log.e(TAG, "Error while asking server to swap with us", e);
|
Log.e(TAG, "Error while asking server to swap with us", e);
|
||||||
} finally {
|
} finally {
|
||||||
client.close();
|
conn.disconnect();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void populatePostParams(String swapBackUri, HttpPost request) throws UnsupportedEncodingException {
|
|
||||||
List<NameValuePair> params = new ArrayList<>();
|
|
||||||
params.add(new BasicNameValuePair("repo", swapBackUri));
|
|
||||||
UrlEncodedFormEntity encodedParams = new UrlEncodedFormEntity(params);
|
|
||||||
request.setEntity(encodedParams);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void notifyOfErrorOnUiThread() {
|
|
||||||
// TODO: Broadcast error message so that whoever wants to can display a relevant
|
|
||||||
// message in the UI. This service doesn't understand the concept of UI.
|
|
||||||
/*runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Toast.makeText(
|
|
||||||
SwapService.this,
|
|
||||||
R.string.swap_reciprocate_failed,
|
|
||||||
Toast.LENGTH_LONG
|
|
||||||
).show();
|
|
||||||
}
|
|
||||||
});*/
|
|
||||||
}
|
|
||||||
}.execute();
|
}.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import android.content.Intent;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.graphics.LightingColorFilter;
|
import android.graphics.LightingColorFilter;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
import android.support.annotation.ColorRes;
|
import android.support.annotation.ColorRes;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
@ -19,9 +20,6 @@ import android.widget.Button;
|
|||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ScrollView;
|
import android.widget.ScrollView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.apache.http.NameValuePair;
|
|
||||||
import org.apache.http.client.utils.URLEncodedUtils;
|
|
||||||
import org.fdroid.fdroid.FDroidApp;
|
import org.fdroid.fdroid.FDroidApp;
|
||||||
import org.fdroid.fdroid.Preferences;
|
import org.fdroid.fdroid.Preferences;
|
||||||
import org.fdroid.fdroid.QrGenAsyncTask;
|
import org.fdroid.fdroid.QrGenAsyncTask;
|
||||||
@ -31,9 +29,8 @@ import org.fdroid.fdroid.localrepo.SwapService;
|
|||||||
import org.fdroid.fdroid.net.WifiStateChangeService;
|
import org.fdroid.fdroid.net.WifiStateChangeService;
|
||||||
import org.fdroid.fdroid.views.swap.device.camera.CameraCharacteristicsChecker;
|
import org.fdroid.fdroid.views.swap.device.camera.CameraCharacteristicsChecker;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class WifiQrView extends ScrollView implements SwapWorkflowActivity.InnerView {
|
public class WifiQrView extends ScrollView implements SwapWorkflowActivity.InnerView {
|
||||||
|
|
||||||
@ -142,32 +139,34 @@ public class WifiQrView extends ScrollView implements SwapWorkflowActivity.Inner
|
|||||||
ipAddressView.setText(buttonLabel);
|
ipAddressView.setText(buttonLabel);
|
||||||
|
|
||||||
Uri sharingUri = Utils.getSharingUri(FDroidApp.repo);
|
Uri sharingUri = Utils.getSharingUri(FDroidApp.repo);
|
||||||
String qrUriString = scheme + sharingUri.getHost();
|
StringBuilder qrUrlBuilder = new StringBuilder(scheme);
|
||||||
|
qrUrlBuilder.append(sharingUri.getHost());
|
||||||
if (sharingUri.getPort() != 80) {
|
if (sharingUri.getPort() != 80) {
|
||||||
qrUriString += ":" + sharingUri.getPort();
|
qrUrlBuilder.append(':');
|
||||||
|
qrUrlBuilder.append(sharingUri.getPort());
|
||||||
}
|
}
|
||||||
qrUriString += sharingUri.getPath();
|
qrUrlBuilder.append(sharingUri.getPath());
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
|
|
||||||
// Andorid provides an API for getting the query parameters and iterating over them:
|
if (Build.VERSION.SDK_INT > 10) {
|
||||||
// Uri.getQueryParameterNames()
|
Set<String> names = sharingUri.getQueryParameterNames();
|
||||||
// But it is only available on later Android versions. As such we use URLEncodedUtils instead.
|
for (String name : names) {
|
||||||
List<NameValuePair> parameters = URLEncodedUtils.parse(URI.create(sharingUri.toString()), "UTF-8");
|
if (!"ssid".equals(name)) {
|
||||||
for (NameValuePair parameter : parameters) {
|
|
||||||
if (!"ssid".equals(parameter.getName())) {
|
|
||||||
if (first) {
|
if (first) {
|
||||||
qrUriString += "?";
|
qrUrlBuilder.append('?');
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
qrUriString += "&";
|
qrUrlBuilder.append('&');
|
||||||
|
}
|
||||||
|
qrUrlBuilder.append(name.toUpperCase(Locale.ENGLISH));
|
||||||
|
qrUrlBuilder.append('=');
|
||||||
|
qrUrlBuilder.append(sharingUri.getQueryParameter(name).toUpperCase(Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
qrUriString += parameter.getName().toUpperCase(Locale.ENGLISH) + "=" +
|
|
||||||
parameter.getValue().toUpperCase(Locale.ENGLISH);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String qrUriString = qrUrlBuilder.toString();
|
||||||
Utils.debugLog(TAG, "Encoded swap URI in QR Code: " + qrUriString);
|
Utils.debugLog(TAG, "Encoded swap URI in QR Code: " + qrUriString);
|
||||||
|
|
||||||
new QrGenAsyncTask(getActivity(), R.id.wifi_qr_code).execute(qrUriString);
|
new QrGenAsyncTask(getActivity(), R.id.wifi_qr_code).execute(qrUriString);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user