Quick patch to fix operations not ready for HTTPS
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / CrashlogSendActivity.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19 package eu.alefzero.owncloud;
20
21 import java.io.File;
22 import java.io.IOException;
23
24 import org.apache.commons.httpclient.HttpClient;
25 import org.apache.commons.httpclient.HttpException;
26 import org.apache.commons.httpclient.methods.PostMethod;
27 import org.apache.commons.httpclient.methods.multipart.FilePart;
28 import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
29 import org.apache.commons.httpclient.methods.multipart.Part;
30
31 import android.app.AlertDialog;
32 import android.app.Dialog;
33 import android.content.DialogInterface;
34 import android.content.DialogInterface.OnCancelListener;
35 import android.content.DialogInterface.OnClickListener;
36 import android.os.Bundle;
37 import android.util.Log;
38
39 import com.actionbarsherlock.app.SherlockActivity;
40
41 import eu.alefzero.webdav.FileRequestEntity;
42
43 public class CrashlogSendActivity extends SherlockActivity implements OnClickListener, OnCancelListener {
44
45 private static final String TAG = "CrashlogSendActivity";
46 private static final String CRASHLOG_SUBMIT_URL = "http://alefzero.eu/a/crashlog/";
47 private static final int DIALOG_SUBMIT = 5;
48
49 private String mLogFilename;
50
51 @Override
52 protected void onCreate(Bundle savedInstanceState) {
53 super.onCreate(savedInstanceState);
54 mLogFilename = getIntent().getStringExtra(CrashHandler.KEY_CRASH_FILENAME);
55 if (mLogFilename == null) {
56 Log.wtf(TAG, "No file crashlog path given!");
57 finish();
58 return;
59 }
60 Log.i(TAG, "crashlog file path " + mLogFilename);
61
62 showDialog(DIALOG_SUBMIT);
63 }
64
65
66 @Override
67 protected Dialog onCreateDialog(int id) {
68 if (id == DIALOG_SUBMIT) {
69 AlertDialog.Builder builder = new AlertDialog.Builder(this);
70 builder.setMessage(R.string.crashlog_message);
71 builder.setNegativeButton(R.string.crashlog_dont_send_report, this);
72 builder.setPositiveButton(R.string.crashlog_send_report, this);
73 builder.setCancelable(true);
74 builder.setOnCancelListener(this);
75 return builder.create();
76 }
77 return super.onCreateDialog(id);
78 }
79
80
81 @Override
82 public void onClick(DialogInterface dialog, final int which) {
83 new Thread(new Runnable() {
84
85 @Override
86 public void run() {
87 // TODO Auto-generated method stub
88 File file = new File(mLogFilename);
89 if (which == Dialog.BUTTON_POSITIVE) {
90 try {
91 HttpClient client = new HttpClient();
92 PostMethod post = new PostMethod(CRASHLOG_SUBMIT_URL);
93 Part[] parts = {new FilePart("crashfile", file)};
94 post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
95 client.executeMethod(post);
96 post.releaseConnection();
97 } catch (Exception e) {
98 e.printStackTrace();
99 }
100 }
101 file.delete();
102 finish();
103 }
104 }).start();
105 }
106
107
108 @Override
109 public void onCancel(DialogInterface dialog) {
110 new File(mLogFilename).delete();
111 finish();
112 }
113
114 }