OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 28 matching lines...) Expand all Loading... |
39 import android.view.View; | 39 import android.view.View; |
40 import android.view.Window; | 40 import android.view.Window; |
41 import android.widget.EditText; | 41 import android.widget.EditText; |
42 import android.widget.Toast; | 42 import android.widget.Toast; |
43 | 43 |
44 /** | 44 /** |
45 * Shows crash report dialog asking user to submit crash report together with co
mments. | 45 * Shows crash report dialog asking user to submit crash report together with co
mments. |
46 */ | 46 */ |
47 public final class CrashReportDialog extends Activity | 47 public final class CrashReportDialog extends Activity |
48 { | 48 { |
49 private final static String TAG = "CrashReportDialog"; | 49 private static final String TAG = Utils.getTag(CrashReportDialog.class); |
| 50 |
50 private String report; | 51 private String report; |
51 | 52 |
52 @Override | 53 @Override |
53 protected void onCreate(Bundle savedInstanceState) | 54 protected void onCreate(final Bundle savedInstanceState) |
54 { | 55 { |
55 super.onCreate(savedInstanceState); | 56 super.onCreate(savedInstanceState); |
56 requestWindowFeature(Window.FEATURE_LEFT_ICON); | 57 requestWindowFeature(Window.FEATURE_LEFT_ICON); |
57 setContentView(R.layout.crashreport); | 58 setContentView(R.layout.crashreport); |
58 | 59 |
59 Bundle extras = getIntent().getExtras(); | 60 final Bundle extras = getIntent().getExtras(); |
60 if (extras == null) | 61 if (extras == null) |
61 { | 62 { |
62 finish(); | 63 finish(); |
63 return; | 64 return; |
64 } | 65 } |
65 report = extras.getString("report"); | 66 report = extras.getString("report"); |
66 | 67 |
67 getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, android.R.d
rawable.ic_dialog_alert); | 68 getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, android.R.d
rawable.ic_dialog_alert); |
68 } | 69 } |
69 | 70 |
70 public void onOk(View v) | 71 public void onOk(final View v) |
71 { | 72 { |
72 String comment = ((EditText) findViewById(R.id.comments)).getText().toString
(); | 73 final String comment = ((EditText) findViewById(R.id.comments)).getText().to
String(); |
73 | 74 |
74 try | 75 try |
75 { | 76 { |
76 String[] reportLines = report.split(System.getProperty("line.separator")); | 77 final String[] reportLines = report.split(System.getProperty("line.separat
or")); |
77 int api = Integer.parseInt(reportLines[0]); | 78 final int api = Integer.parseInt(reportLines[0]); |
78 int build = Integer.parseInt(reportLines[1]); | 79 final int build = Integer.parseInt(reportLines[1]); |
79 | 80 |
80 XmlSerializer xmlSerializer = Xml.newSerializer(); | 81 final XmlSerializer xmlSerializer = Xml.newSerializer(); |
81 StringWriter writer = new StringWriter(); | 82 final StringWriter writer = new StringWriter(); |
82 | 83 |
83 xmlSerializer.setOutput(writer); | 84 xmlSerializer.setOutput(writer); |
84 xmlSerializer.startDocument("UTF-8", true); | 85 xmlSerializer.startDocument("UTF-8", true); |
85 xmlSerializer.startTag("", "crashreport"); | 86 xmlSerializer.startTag("", "crashreport"); |
86 xmlSerializer.attribute("", "version", "1"); | 87 xmlSerializer.attribute("", "version", "1"); |
87 xmlSerializer.attribute("", "api", String.valueOf(api)); | 88 xmlSerializer.attribute("", "api", String.valueOf(api)); |
88 xmlSerializer.attribute("", "build", String.valueOf(build)); | 89 xmlSerializer.attribute("", "build", String.valueOf(build)); |
89 xmlSerializer.startTag("", "error"); | 90 xmlSerializer.startTag("", "error"); |
90 xmlSerializer.attribute("", "type", reportLines[2]); | 91 xmlSerializer.attribute("", "type", reportLines[2]); |
91 xmlSerializer.startTag("", "message"); | 92 xmlSerializer.startTag("", "message"); |
92 xmlSerializer.text(reportLines[3]); | 93 xmlSerializer.text(reportLines[3]); |
93 xmlSerializer.endTag("", "message"); | 94 xmlSerializer.endTag("", "message"); |
94 xmlSerializer.startTag("", "stacktrace"); | 95 xmlSerializer.startTag("", "stacktrace"); |
95 Pattern p = Pattern.compile("\\|"); | 96 final Pattern p = Pattern.compile("\\|"); |
96 boolean hasCause = false; | 97 boolean hasCause = false; |
97 int i = 4; | 98 int i = 4; |
98 while (i < reportLines.length) | 99 while (i < reportLines.length) |
99 { | 100 { |
100 if ("cause".equals(reportLines[i])) | 101 if ("cause".equals(reportLines[i])) |
101 { | 102 { |
102 xmlSerializer.endTag("", "stacktrace"); | 103 xmlSerializer.endTag("", "stacktrace"); |
103 xmlSerializer.startTag("", "cause"); | 104 xmlSerializer.startTag("", "cause"); |
104 hasCause = true; | 105 hasCause = true; |
105 i++; | 106 i++; |
106 xmlSerializer.attribute("", "type", reportLines[i]); | 107 xmlSerializer.attribute("", "type", reportLines[i]); |
107 i++; | 108 i++; |
108 xmlSerializer.startTag("", "message"); | 109 xmlSerializer.startTag("", "message"); |
109 xmlSerializer.text(reportLines[i]); | 110 xmlSerializer.text(reportLines[i]); |
110 i++; | 111 i++; |
111 xmlSerializer.endTag("", "message"); | 112 xmlSerializer.endTag("", "message"); |
112 xmlSerializer.startTag("", "stacktrace"); | 113 xmlSerializer.startTag("", "stacktrace"); |
113 continue; | 114 continue; |
114 } | 115 } |
115 Log.e(TAG, "Line: " + reportLines[i]); | 116 Log.e(TAG, "Line: " + reportLines[i]); |
116 String[] element = TextUtils.split(reportLines[i], p); | 117 final String[] element = TextUtils.split(reportLines[i], p); |
117 xmlSerializer.startTag("", "frame"); | 118 xmlSerializer.startTag("", "frame"); |
118 xmlSerializer.attribute("", "class", element[0]); | 119 xmlSerializer.attribute("", "class", element[0]); |
119 xmlSerializer.attribute("", "method", element[1]); | 120 xmlSerializer.attribute("", "method", element[1]); |
120 xmlSerializer.attribute("", "isnative", element[2]); | 121 xmlSerializer.attribute("", "isnative", element[2]); |
121 xmlSerializer.attribute("", "file", element[3]); | 122 xmlSerializer.attribute("", "file", element[3]); |
122 xmlSerializer.attribute("", "line", element[4]); | 123 xmlSerializer.attribute("", "line", element[4]); |
123 xmlSerializer.endTag("", "frame"); | 124 xmlSerializer.endTag("", "frame"); |
124 i++; | 125 i++; |
125 } | 126 } |
126 xmlSerializer.endTag("", "stacktrace"); | 127 xmlSerializer.endTag("", "stacktrace"); |
127 if (hasCause) | 128 if (hasCause) |
128 xmlSerializer.endTag("", "cause"); | 129 xmlSerializer.endTag("", "cause"); |
129 xmlSerializer.endTag("", "error"); | 130 xmlSerializer.endTag("", "error"); |
130 xmlSerializer.startTag("", "comment"); | 131 xmlSerializer.startTag("", "comment"); |
131 xmlSerializer.text(comment); | 132 xmlSerializer.text(comment); |
132 xmlSerializer.endTag("", "comment"); | 133 xmlSerializer.endTag("", "comment"); |
133 xmlSerializer.endTag("", "crashreport"); | 134 xmlSerializer.endTag("", "crashreport"); |
134 xmlSerializer.endDocument(); | 135 xmlSerializer.endDocument(); |
135 | 136 |
136 String xml = writer.toString(); | 137 final String xml = writer.toString(); |
137 HttpClient httpclient = new DefaultHttpClient(); | 138 final HttpClient httpclient = new DefaultHttpClient(); |
138 HttpPost httppost = new HttpPost(getString(R.string.crash_report_url)); | 139 final HttpPost httppost = new HttpPost(getString(R.string.crash_report_url
)); |
139 httppost.setHeader("Content-Type", "text/xml; charset=UTF-8"); | 140 httppost.setHeader("Content-Type", "text/xml; charset=UTF-8"); |
140 httppost.addHeader("X-Adblock-Plus", "yes"); | 141 httppost.addHeader("X-Adblock-Plus", "yes"); |
141 httppost.setEntity(new StringEntity(xml)); | 142 httppost.setEntity(new StringEntity(xml)); |
142 HttpResponse httpresponse = httpclient.execute(httppost); | 143 final HttpResponse httpresponse = httpclient.execute(httppost); |
143 StatusLine statusLine = httpresponse.getStatusLine(); | 144 final StatusLine statusLine = httpresponse.getStatusLine(); |
144 Log.e(TAG, statusLine.getStatusCode() + " " + statusLine.getReasonPhrase()
); | 145 Log.e(TAG, statusLine.getStatusCode() + " " + statusLine.getReasonPhrase()
); |
145 Log.e(TAG, EntityUtils.toString(httpresponse.getEntity())); | 146 Log.e(TAG, EntityUtils.toString(httpresponse.getEntity())); |
146 if (statusLine.getStatusCode() != 200) | 147 if (statusLine.getStatusCode() != 200) |
147 throw new ClientProtocolException(); | 148 throw new ClientProtocolException(); |
148 String response = EntityUtils.toString(httpresponse.getEntity()); | 149 final String response = EntityUtils.toString(httpresponse.getEntity()); |
149 if (!"saved".equals(response)) | 150 if (!"saved".equals(response)) |
150 throw new ClientProtocolException(); | 151 throw new ClientProtocolException(); |
151 deleteFile(CrashHandler.REPORT_FILE); | 152 deleteFile(CrashHandler.REPORT_FILE); |
152 } | 153 } |
153 catch (ClientProtocolException e) | 154 catch (final ClientProtocolException e) |
154 { | 155 { |
155 Log.e(TAG, "Failed to submit a crash", e); | 156 Log.e(TAG, "Failed to submit a crash", e); |
156 Toast.makeText(this, R.string.msg_crash_submission_failure, Toast.LENGTH_L
ONG).show(); | 157 Toast.makeText(this, R.string.msg_crash_submission_failure, Toast.LENGTH_L
ONG).show(); |
157 } | 158 } |
158 catch (IOException e) | 159 catch (final IOException e) |
159 { | 160 { |
160 Log.e(TAG, "Failed to submit a crash", e); | 161 Log.e(TAG, "Failed to submit a crash", e); |
161 Toast.makeText(this, R.string.msg_crash_submission_failure, Toast.LENGTH_L
ONG).show(); | 162 Toast.makeText(this, R.string.msg_crash_submission_failure, Toast.LENGTH_L
ONG).show(); |
162 } | 163 } |
163 catch (Exception e) | 164 catch (final Exception e) |
164 { | 165 { |
165 Log.e(TAG, "Failed to create report", e); | 166 Log.e(TAG, "Failed to create report", e); |
166 // Assuming corrupted report file, just silently deleting it | 167 // Assuming corrupted report file, just silently deleting it |
167 deleteFile(CrashHandler.REPORT_FILE); | 168 deleteFile(CrashHandler.REPORT_FILE); |
168 } | 169 } |
169 finish(); | 170 finish(); |
170 } | 171 } |
171 | 172 |
172 public void onCancel(View v) | 173 public void onCancel(final View v) |
173 { | 174 { |
174 deleteFile(CrashHandler.REPORT_FILE); | 175 deleteFile(CrashHandler.REPORT_FILE); |
175 finish(); | 176 finish(); |
176 } | 177 } |
177 } | 178 } |
OLD | NEW |