Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/org/adblockplus/android/CrashReportDialog.java

Issue 5697499218051072: Usage of new API, cleanups (reduced) (Closed)
Left Patch Set: Created April 11, 2014, 1:31 p.m.
Right Patch Set: Even more review issues fixed. Created April 28, 2014, 10:18 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/org/adblockplus/android/CrashHandler.java ('k') | src/org/adblockplus/android/HelpfulCheckBoxPreference.java » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
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 45 * Shows crash report dialog asking user to submit crash report together with co mments.
46 * comments.
47 */ 46 */
48 public final class CrashReportDialog extends Activity 47 public final class CrashReportDialog extends Activity
49 { 48 {
50 private final static String TAG = Utils.getTag(CrashReportDialog.class); 49 private static final String TAG = Utils.getTag(CrashReportDialog.class);
51
52 private String report; 50 private String report;
53 51
54 @Override 52 @Override
55 protected void onCreate(final Bundle savedInstanceState) 53 protected void onCreate(final Bundle savedInstanceState)
56 { 54 {
57 super.onCreate(savedInstanceState); 55 super.onCreate(savedInstanceState);
58 this.requestWindowFeature(Window.FEATURE_LEFT_ICON); 56 requestWindowFeature(Window.FEATURE_LEFT_ICON);
59 this.setContentView(R.layout.crashreport); 57 setContentView(R.layout.crashreport);
60 58
61 final Bundle extras = this.getIntent().getExtras(); 59 final Bundle extras = getIntent().getExtras();
62 if (extras == null) 60 if (extras == null)
63 { 61 {
64 this.finish(); 62 finish();
65 return; 63 return;
66 } 64 }
67 this.report = extras.getString("report"); 65 report = extras.getString("report");
68 66
69 this.getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, androi d.R.drawable.ic_dialog_alert); 67 getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, android.R.d rawable.ic_dialog_alert);
70 } 68 }
71 69
72 public void onOk(final View v) 70 public void onOk(final View v)
73 { 71 {
74 final String comment = ((EditText)this.findViewById(R.id.comments)).getText( ).toString(); 72 final String comment = ((EditText) findViewById(R.id.comments)).getText().to String();
75 73
76 try 74 try
77 { 75 {
78 final String[] reportLines = this.report.split(System.getProperty("line.se parator")); 76 final String[] reportLines = report.split(System.getProperty("line.separat or"));
79 final int api = Integer.parseInt(reportLines[0]); 77 final int api = Integer.parseInt(reportLines[0]);
80 final int build = Integer.parseInt(reportLines[1]); 78 final int build = Integer.parseInt(reportLines[1]);
81 79
82 final XmlSerializer xmlSerializer = Xml.newSerializer(); 80 final XmlSerializer xmlSerializer = Xml.newSerializer();
83 final StringWriter writer = new StringWriter(); 81 final StringWriter writer = new StringWriter();
84 82
85 xmlSerializer.setOutput(writer); 83 xmlSerializer.setOutput(writer);
86 xmlSerializer.startDocument("UTF-8", true); 84 xmlSerializer.startDocument("UTF-8", true);
87 xmlSerializer.startTag("", "crashreport"); 85 xmlSerializer.startTag("", "crashreport");
88 xmlSerializer.attribute("", "version", "1"); 86 xmlSerializer.attribute("", "version", "1");
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 xmlSerializer.attribute("", "class", element[0]); 118 xmlSerializer.attribute("", "class", element[0]);
121 xmlSerializer.attribute("", "method", element[1]); 119 xmlSerializer.attribute("", "method", element[1]);
122 xmlSerializer.attribute("", "isnative", element[2]); 120 xmlSerializer.attribute("", "isnative", element[2]);
123 xmlSerializer.attribute("", "file", element[3]); 121 xmlSerializer.attribute("", "file", element[3]);
124 xmlSerializer.attribute("", "line", element[4]); 122 xmlSerializer.attribute("", "line", element[4]);
125 xmlSerializer.endTag("", "frame"); 123 xmlSerializer.endTag("", "frame");
126 i++; 124 i++;
127 } 125 }
128 xmlSerializer.endTag("", "stacktrace"); 126 xmlSerializer.endTag("", "stacktrace");
129 if (hasCause) 127 if (hasCause)
130 {
131 xmlSerializer.endTag("", "cause"); 128 xmlSerializer.endTag("", "cause");
132 }
133 xmlSerializer.endTag("", "error"); 129 xmlSerializer.endTag("", "error");
134 xmlSerializer.startTag("", "comment"); 130 xmlSerializer.startTag("", "comment");
135 xmlSerializer.text(comment); 131 xmlSerializer.text(comment);
136 xmlSerializer.endTag("", "comment"); 132 xmlSerializer.endTag("", "comment");
137 xmlSerializer.endTag("", "crashreport"); 133 xmlSerializer.endTag("", "crashreport");
138 xmlSerializer.endDocument(); 134 xmlSerializer.endDocument();
139 135
140 final String xml = writer.toString(); 136 final String xml = writer.toString();
141 final HttpClient httpclient = new DefaultHttpClient(); 137 final HttpClient httpclient = new DefaultHttpClient();
142 final HttpPost httppost = new HttpPost(this.getString(R.string.crash_repor t_url)); 138 final HttpPost httppost = new HttpPost(getString(R.string.crash_report_url ));
143 httppost.setHeader("Content-Type", "text/xml; charset=UTF-8"); 139 httppost.setHeader("Content-Type", "text/xml; charset=UTF-8");
144 httppost.addHeader("X-Adblock-Plus", "yes"); 140 httppost.addHeader("X-Adblock-Plus", "yes");
145 httppost.setEntity(new StringEntity(xml)); 141 httppost.setEntity(new StringEntity(xml));
146 final HttpResponse httpresponse = httpclient.execute(httppost); 142 final HttpResponse httpresponse = httpclient.execute(httppost);
147 final StatusLine statusLine = httpresponse.getStatusLine(); 143 final StatusLine statusLine = httpresponse.getStatusLine();
148 Log.e(TAG, statusLine.getStatusCode() + " " + statusLine.getReasonPhrase() ); 144 Log.e(TAG, statusLine.getStatusCode() + " " + statusLine.getReasonPhrase() );
149 Log.e(TAG, EntityUtils.toString(httpresponse.getEntity())); 145 Log.e(TAG, EntityUtils.toString(httpresponse.getEntity()));
150 if (statusLine.getStatusCode() != 200) 146 if (statusLine.getStatusCode() != 200)
151 {
152 throw new ClientProtocolException(); 147 throw new ClientProtocolException();
153 }
154 final String response = EntityUtils.toString(httpresponse.getEntity()); 148 final String response = EntityUtils.toString(httpresponse.getEntity());
155 if (!"saved".equals(response)) 149 if (!"saved".equals(response))
156 {
157 throw new ClientProtocolException(); 150 throw new ClientProtocolException();
158 } 151 deleteFile(CrashHandler.REPORT_FILE);
159 this.deleteFile(CrashHandler.REPORT_FILE);
160 } 152 }
161 catch (final ClientProtocolException e) 153 catch (final ClientProtocolException e)
162 { 154 {
163 Log.e(TAG, "Failed to submit a crash", e); 155 Log.e(TAG, "Failed to submit a crash", e);
164 Toast.makeText(this, R.string.msg_crash_submission_failure, Toast.LENGTH_L ONG).show(); 156 Toast.makeText(this, R.string.msg_crash_submission_failure, Toast.LENGTH_L ONG).show();
165 } 157 }
166 catch (final IOException e) 158 catch (final IOException e)
167 { 159 {
168 Log.e(TAG, "Failed to submit a crash", e); 160 Log.e(TAG, "Failed to submit a crash", e);
169 Toast.makeText(this, R.string.msg_crash_submission_failure, Toast.LENGTH_L ONG).show(); 161 Toast.makeText(this, R.string.msg_crash_submission_failure, Toast.LENGTH_L ONG).show();
170 } 162 }
171 catch (final Exception e) 163 catch (final Exception e)
172 { 164 {
173 Log.e(TAG, "Failed to create report", e); 165 Log.e(TAG, "Failed to create report", e);
174 // Assuming corrupted report file, just silently deleting it 166 // Assuming corrupted report file, just silently deleting it
175 this.deleteFile(CrashHandler.REPORT_FILE); 167 deleteFile(CrashHandler.REPORT_FILE);
176 } 168 }
177 this.finish(); 169 finish();
178 } 170 }
179 171
180 public void onCancel(final View v) 172 public void onCancel(final View v)
181 { 173 {
182 this.deleteFile(CrashHandler.REPORT_FILE); 174 deleteFile(CrashHandler.REPORT_FILE);
183 this.finish(); 175 finish();
184 } 176 }
185 } 177 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld