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

Side by Side Diff: src/org/adblockplus/android/CrashReportDialog.java

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

Powered by Google App Engine
This is Rietveld