diff --git a/clients/android/uploader/AndroidManifest.xml b/clients/android/uploader/AndroidManifest.xml
index 3a2adfc4a..9a4425057 100644
--- a/clients/android/uploader/AndroidManifest.xml
+++ b/clients/android/uploader/AndroidManifest.xml
@@ -3,10 +3,14 @@
package="com.danga.camli"
android:versionCode="1"
android:versionName="1.0">
-
-
-
-
+
+
+
+
+
+
+
@@ -37,31 +41,31 @@
-
-
+
+
-
-
-
-
-
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
\ No newline at end of file
+
diff --git a/clients/android/uploader/default.properties b/clients/android/uploader/default.properties
index 9d79b12c7..0b9250e02 100644
--- a/clients/android/uploader/default.properties
+++ b/clients/android/uploader/default.properties
@@ -8,4 +8,4 @@
# project structure.
# Project target.
-target=android-4
+target=android-8
diff --git a/clients/android/uploader/src/com/danga/camli/UploadThread.java b/clients/android/uploader/src/com/danga/camli/UploadThread.java
index 880e333fe..ae51e35c6 100644
--- a/clients/android/uploader/src/com/danga/camli/UploadThread.java
+++ b/clients/android/uploader/src/com/danga/camli/UploadThread.java
@@ -33,6 +33,7 @@ import org.json.JSONObject;
import android.os.ParcelFileDescriptor;
import android.os.SystemClock;
+import android.util.Base64;
import android.util.Log;
public class UploadThread extends Thread {
@@ -40,26 +41,42 @@ public class UploadThread extends Thread {
private final UploadService mService;
private final HostPort mHostPort;
+ private final String mPassword;
private LinkedList mQueue;
private final AtomicBoolean mStopRequested = new AtomicBoolean(false);
private final DefaultHttpClient mUA = new DefaultHttpClient();
+ private static final String USERNAME = "TODO-DUMMY-USER";
+
public UploadThread(UploadService uploadService, HostPort hp, String password) {
mService = uploadService;
mHostPort = hp;
+ mPassword = password;
- CredentialsProvider creds = new BasicCredentialsProvider();
- creds.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("TODO-DUMMY-USER",
- password));
- mUA.setCredentialsProvider(creds);
+ // TODO: this crap results in double HTTP requests on everything.
+ // And the setAuthenticationPreemptive method described at
+ // http://hc.apache.org/httpclient-3.x/authentication.html
+ // doesn't seem to be available on Android. So screw it, do it by hand instead
+ // below, manually setting the Authorization header.
+ //
+ //CredentialsProvider creds = new BasicCredentialsProvider();
+ //creds.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(USERNAME,
+ //password));
+ //mUA.setCredentialsProvider(creds);
+ Log.d(TAG, "Authorization: " + getBasicAuthHeaderValue());
}
public void stopPlease() {
mStopRequested.set(true);
}
+ private String getBasicAuthHeaderValue() {
+ return "Basic " + Base64.encodeToString((USERNAME + ":" + mPassword).getBytes(),
+ Base64.NO_WRAP | Base64.NO_PADDING);
+ }
+
@Override
public void run() {
if (!mHostPort.isValid()) {
@@ -104,6 +121,7 @@ public class UploadThread extends Thread {
// Do the pre-upload.
HttpPost preReq = new HttpPost("http://" + mHostPort
+ "/camli/preupload");
+ preReq.setHeader("Authorization", getBasicAuthHeaderValue());
List uploadKeys = new ArrayList();
uploadKeys.add(new BasicNameValuePair("camliversion", "1"));
@@ -155,6 +173,7 @@ public class UploadThread extends Thread {
}
HttpPost uploadReq = new HttpPost(uploadUrl);
+ uploadReq.setHeader("Authorization", getBasicAuthHeaderValue());
MultipartEntity entity = new MultipartEntity();
uploadReq.setEntity(entity);
HttpResponse uploadRes = null;