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 24 matching lines...) Expand all Loading... |
35 import android.os.Bundle; | 35 import android.os.Bundle; |
36 import android.text.TextUtils; | 36 import android.text.TextUtils; |
37 import android.util.Log; | 37 import android.util.Log; |
38 import android.util.Xml; | 38 import android.util.Xml; |
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 |
| 46 * comments. |
46 */ | 47 */ |
47 public final class CrashReportDialog extends Activity | 48 public final class CrashReportDialog extends Activity |
48 { | 49 { |
49 private final static String TAG = "CrashReportDialog"; | 50 private final static String TAG = Utils.getTag(CrashReportDialog.class); |
| 51 |
50 private String report; | 52 private String report; |
51 | 53 |
52 @Override | 54 @Override |
53 protected void onCreate(Bundle savedInstanceState) | 55 protected void onCreate(final Bundle savedInstanceState) |
54 { | 56 { |
55 super.onCreate(savedInstanceState); | 57 super.onCreate(savedInstanceState); |
56 requestWindowFeature(Window.FEATURE_LEFT_ICON); | 58 this.requestWindowFeature(Window.FEATURE_LEFT_ICON); |
57 setContentView(R.layout.crashreport); | 59 this.setContentView(R.layout.crashreport); |
58 | 60 |
59 Bundle extras = getIntent().getExtras(); | 61 final Bundle extras = this.getIntent().getExtras(); |
60 if (extras == null) | 62 if (extras == null) |
61 { | 63 { |
62 finish(); | 64 this.finish(); |
63 return; | 65 return; |
64 } | 66 } |
65 report = extras.getString("report"); | 67 this.report = extras.getString("report"); |
66 | 68 |
67 getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, android.R.d
rawable.ic_dialog_alert); | 69 this.getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, androi
d.R.drawable.ic_dialog_alert); |
68 } | 70 } |
69 | 71 |
70 public void onOk(View v) | 72 public void onOk(final View v) |
71 { | 73 { |
72 String comment = ((EditText) findViewById(R.id.comments)).getText().toString
(); | 74 final String comment = ((EditText)this.findViewById(R.id.comments)).getText(
).toString(); |
73 | 75 |
74 try | 76 try |
75 { | 77 { |
76 String[] reportLines = report.split(System.getProperty("line.separator")); | 78 final String[] reportLines = this.report.split(System.getProperty("line.se
parator")); |
77 int api = Integer.parseInt(reportLines[0]); | 79 final int api = Integer.parseInt(reportLines[0]); |
78 int build = Integer.parseInt(reportLines[1]); | 80 final int build = Integer.parseInt(reportLines[1]); |
79 | 81 |
80 XmlSerializer xmlSerializer = Xml.newSerializer(); | 82 final XmlSerializer xmlSerializer = Xml.newSerializer(); |
81 StringWriter writer = new StringWriter(); | 83 final StringWriter writer = new StringWriter(); |
82 | 84 |
83 xmlSerializer.setOutput(writer); | 85 xmlSerializer.setOutput(writer); |
84 xmlSerializer.startDocument("UTF-8", true); | 86 xmlSerializer.startDocument("UTF-8", true); |
85 xmlSerializer.startTag("", "crashreport"); | 87 xmlSerializer.startTag("", "crashreport"); |
86 xmlSerializer.attribute("", "version", "1"); | 88 xmlSerializer.attribute("", "version", "1"); |
87 xmlSerializer.attribute("", "api", String.valueOf(api)); | 89 xmlSerializer.attribute("", "api", String.valueOf(api)); |
88 xmlSerializer.attribute("", "build", String.valueOf(build)); | 90 xmlSerializer.attribute("", "build", String.valueOf(build)); |
89 xmlSerializer.startTag("", "error"); | 91 xmlSerializer.startTag("", "error"); |
90 xmlSerializer.attribute("", "type", reportLines[2]); | 92 xmlSerializer.attribute("", "type", reportLines[2]); |
91 xmlSerializer.startTag("", "message"); | 93 xmlSerializer.startTag("", "message"); |
92 xmlSerializer.text(reportLines[3]); | 94 xmlSerializer.text(reportLines[3]); |
93 xmlSerializer.endTag("", "message"); | 95 xmlSerializer.endTag("", "message"); |
94 xmlSerializer.startTag("", "stacktrace"); | 96 xmlSerializer.startTag("", "stacktrace"); |
95 Pattern p = Pattern.compile("\\|"); | 97 final Pattern p = Pattern.compile("\\|"); |
96 boolean hasCause = false; | 98 boolean hasCause = false; |
97 int i = 4; | 99 int i = 4; |
98 while (i < reportLines.length) | 100 while (i < reportLines.length) |
99 { | 101 { |
100 if ("cause".equals(reportLines[i])) | 102 if ("cause".equals(reportLines[i])) |
101 { | 103 { |
102 xmlSerializer.endTag("", "stacktrace"); | 104 xmlSerializer.endTag("", "stacktrace"); |
103 xmlSerializer.startTag("", "cause"); | 105 xmlSerializer.startTag("", "cause"); |
104 hasCause = true; | 106 hasCause = true; |
105 i++; | 107 i++; |
106 xmlSerializer.attribute("", "type", reportLines[i]); | 108 xmlSerializer.attribute("", "type", reportLines[i]); |
107 i++; | 109 i++; |
108 xmlSerializer.startTag("", "message"); | 110 xmlSerializer.startTag("", "message"); |
109 xmlSerializer.text(reportLines[i]); | 111 xmlSerializer.text(reportLines[i]); |
110 i++; | 112 i++; |
111 xmlSerializer.endTag("", "message"); | 113 xmlSerializer.endTag("", "message"); |
112 xmlSerializer.startTag("", "stacktrace"); | 114 xmlSerializer.startTag("", "stacktrace"); |
113 continue; | 115 continue; |
114 } | 116 } |
115 Log.e(TAG, "Line: " + reportLines[i]); | 117 Log.e(TAG, "Line: " + reportLines[i]); |
116 String[] element = TextUtils.split(reportLines[i], p); | 118 final String[] element = TextUtils.split(reportLines[i], p); |
117 xmlSerializer.startTag("", "frame"); | 119 xmlSerializer.startTag("", "frame"); |
118 xmlSerializer.attribute("", "class", element[0]); | 120 xmlSerializer.attribute("", "class", element[0]); |
119 xmlSerializer.attribute("", "method", element[1]); | 121 xmlSerializer.attribute("", "method", element[1]); |
120 xmlSerializer.attribute("", "isnative", element[2]); | 122 xmlSerializer.attribute("", "isnative", element[2]); |
121 xmlSerializer.attribute("", "file", element[3]); | 123 xmlSerializer.attribute("", "file", element[3]); |
122 xmlSerializer.attribute("", "line", element[4]); | 124 xmlSerializer.attribute("", "line", element[4]); |
123 xmlSerializer.endTag("", "frame"); | 125 xmlSerializer.endTag("", "frame"); |
124 i++; | 126 i++; |
125 } | 127 } |
126 xmlSerializer.endTag("", "stacktrace"); | 128 xmlSerializer.endTag("", "stacktrace"); |
127 if (hasCause) | 129 if (hasCause) |
| 130 { |
128 xmlSerializer.endTag("", "cause"); | 131 xmlSerializer.endTag("", "cause"); |
| 132 } |
129 xmlSerializer.endTag("", "error"); | 133 xmlSerializer.endTag("", "error"); |
130 xmlSerializer.startTag("", "comment"); | 134 xmlSerializer.startTag("", "comment"); |
131 xmlSerializer.text(comment); | 135 xmlSerializer.text(comment); |
132 xmlSerializer.endTag("", "comment"); | 136 xmlSerializer.endTag("", "comment"); |
133 xmlSerializer.endTag("", "crashreport"); | 137 xmlSerializer.endTag("", "crashreport"); |
134 xmlSerializer.endDocument(); | 138 xmlSerializer.endDocument(); |
135 | 139 |
136 String xml = writer.toString(); | 140 final String xml = writer.toString(); |
137 HttpClient httpclient = new DefaultHttpClient(); | 141 final HttpClient httpclient = new DefaultHttpClient(); |
138 HttpPost httppost = new HttpPost(getString(R.string.crash_report_url)); | 142 final HttpPost httppost = new HttpPost(this.getString(R.string.crash_repor
t_url)); |
139 httppost.setHeader("Content-Type", "text/xml; charset=UTF-8"); | 143 httppost.setHeader("Content-Type", "text/xml; charset=UTF-8"); |
140 httppost.addHeader("X-Adblock-Plus", "yes"); | 144 httppost.addHeader("X-Adblock-Plus", "yes"); |
141 httppost.setEntity(new StringEntity(xml)); | 145 httppost.setEntity(new StringEntity(xml)); |
142 HttpResponse httpresponse = httpclient.execute(httppost); | 146 final HttpResponse httpresponse = httpclient.execute(httppost); |
143 StatusLine statusLine = httpresponse.getStatusLine(); | 147 final StatusLine statusLine = httpresponse.getStatusLine(); |
144 Log.e(TAG, statusLine.getStatusCode() + " " + statusLine.getReasonPhrase()
); | 148 Log.e(TAG, statusLine.getStatusCode() + " " + statusLine.getReasonPhrase()
); |
145 Log.e(TAG, EntityUtils.toString(httpresponse.getEntity())); | 149 Log.e(TAG, EntityUtils.toString(httpresponse.getEntity())); |
146 if (statusLine.getStatusCode() != 200) | 150 if (statusLine.getStatusCode() != 200) |
| 151 { |
147 throw new ClientProtocolException(); | 152 throw new ClientProtocolException(); |
148 String response = EntityUtils.toString(httpresponse.getEntity()); | 153 } |
| 154 final String response = EntityUtils.toString(httpresponse.getEntity()); |
149 if (!"saved".equals(response)) | 155 if (!"saved".equals(response)) |
| 156 { |
150 throw new ClientProtocolException(); | 157 throw new ClientProtocolException(); |
151 deleteFile(CrashHandler.REPORT_FILE); | 158 } |
| 159 this.deleteFile(CrashHandler.REPORT_FILE); |
152 } | 160 } |
153 catch (ClientProtocolException e) | 161 catch (final ClientProtocolException e) |
154 { | 162 { |
155 Log.e(TAG, "Failed to submit a crash", e); | 163 Log.e(TAG, "Failed to submit a crash", e); |
156 Toast.makeText(this, R.string.msg_crash_submission_failure, Toast.LENGTH_L
ONG).show(); | 164 Toast.makeText(this, R.string.msg_crash_submission_failure, Toast.LENGTH_L
ONG).show(); |
157 } | 165 } |
158 catch (IOException e) | 166 catch (final IOException e) |
159 { | 167 { |
160 Log.e(TAG, "Failed to submit a crash", e); | 168 Log.e(TAG, "Failed to submit a crash", e); |
161 Toast.makeText(this, R.string.msg_crash_submission_failure, Toast.LENGTH_L
ONG).show(); | 169 Toast.makeText(this, R.string.msg_crash_submission_failure, Toast.LENGTH_L
ONG).show(); |
162 } | 170 } |
163 catch (Exception e) | 171 catch (final Exception e) |
164 { | 172 { |
165 Log.e(TAG, "Failed to create report", e); | 173 Log.e(TAG, "Failed to create report", e); |
166 // Assuming corrupted report file, just silently deleting it | 174 // Assuming corrupted report file, just silently deleting it |
167 deleteFile(CrashHandler.REPORT_FILE); | 175 this.deleteFile(CrashHandler.REPORT_FILE); |
168 } | 176 } |
169 finish(); | 177 this.finish(); |
170 } | 178 } |
171 | 179 |
172 public void onCancel(View v) | 180 public void onCancel(final View v) |
173 { | 181 { |
174 deleteFile(CrashHandler.REPORT_FILE); | 182 this.deleteFile(CrashHandler.REPORT_FILE); |
175 finish(); | 183 this.finish(); |
176 } | 184 } |
177 } | 185 } |
OLD | NEW |