зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset 8b672583d57c (bug 1356693
)
--HG-- extra : rebase_source : 94d92549f1dfdaf81de6612e54d1aab9889ade53
This commit is contained in:
Родитель
d7e4098cb8
Коммит
3cc309c314
|
@ -22,7 +22,6 @@ import java.util.regex.Pattern;
|
|||
import org.json.JSONObject;
|
||||
import org.mozilla.gecko.annotation.WrapForJNI;
|
||||
import org.mozilla.gecko.AppConstants.Versions;
|
||||
import org.mozilla.gecko.util.IOUtils;
|
||||
import org.mozilla.gecko.util.StringUtils;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
|
||||
|
@ -155,10 +154,8 @@ public final class ANRReporter extends BroadcastReceiver
|
|||
.command("/system/bin/getprop", "dalvik.vm.stack-trace-file")
|
||||
.redirectErrorStream(true)
|
||||
.start();
|
||||
|
||||
BufferedReader buf = null;
|
||||
try {
|
||||
buf = new BufferedReader(
|
||||
BufferedReader buf = new BufferedReader(
|
||||
new InputStreamReader(
|
||||
propProc.getInputStream(), StringUtils.UTF_8), TRACES_LINE_SIZE);
|
||||
String propVal = buf.readLine();
|
||||
|
@ -179,8 +176,6 @@ public final class ANRReporter extends BroadcastReceiver
|
|||
}
|
||||
} finally {
|
||||
propProc.destroy();
|
||||
|
||||
IOUtils.safeStreamClose(buf);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.w(LOGTAG, e);
|
||||
|
|
|
@ -41,9 +41,7 @@ import org.mozilla.gecko.Locales;
|
|||
import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.distribution.Distribution;
|
||||
import org.mozilla.gecko.restrictions.Restrictions;
|
||||
import org.mozilla.gecko.util.IOUtils;
|
||||
import org.mozilla.gecko.util.RawResource;
|
||||
import org.mozilla.gecko.util.StringUtils;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
import org.mozilla.gecko.preferences.GeckoPreferences;
|
||||
|
||||
|
@ -270,7 +268,7 @@ public class SuggestedSites {
|
|||
return;
|
||||
}
|
||||
|
||||
OutputStreamWriter outputStreamWriter = null;
|
||||
OutputStreamWriter osw = null;
|
||||
|
||||
try {
|
||||
final JSONArray jsonSites = new JSONArray();
|
||||
|
@ -278,14 +276,20 @@ public class SuggestedSites {
|
|||
jsonSites.put(site.toJSON());
|
||||
}
|
||||
|
||||
outputStreamWriter = new OutputStreamWriter(new FileOutputStream(f), StringUtils.UTF_8);
|
||||
osw = new OutputStreamWriter(new FileOutputStream(f), "UTF-8");
|
||||
|
||||
final String jsonString = jsonSites.toString();
|
||||
outputStreamWriter.write(jsonString, 0, jsonString.length());
|
||||
osw.write(jsonString, 0, jsonString.length());
|
||||
} catch (Exception e) {
|
||||
Log.e(LOGTAG, "Failed to save suggested sites", e);
|
||||
} finally {
|
||||
IOUtils.safeStreamClose(outputStreamWriter);
|
||||
if (osw != null) {
|
||||
try {
|
||||
osw.close();
|
||||
} catch (IOException e) {
|
||||
// Ignore.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -649,16 +649,7 @@ public class Distribution {
|
|||
return null;
|
||||
}
|
||||
|
||||
final BufferedInputStream bufferedInputStream = new BufferedInputStream(connection.getInputStream());
|
||||
try {
|
||||
return new JarInputStream(bufferedInputStream, true);
|
||||
} catch (IOException e) {
|
||||
// Thrown e.g. if JarInputStream can't parse the input as a valid Zip.
|
||||
// In that case we need to ensure the bufferedInputStream gets closed since it won't
|
||||
// be used anywhere (while still passing the Exception up the stack).
|
||||
bufferedInputStream.close();
|
||||
throw e;
|
||||
}
|
||||
return new JarInputStream(new BufferedInputStream(connection.getInputStream()), true);
|
||||
}
|
||||
|
||||
private static void recordFetchTelemetry(final Exception exception) {
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.json.JSONObject;
|
|||
import org.json.JSONArray;
|
||||
import org.mozilla.gecko.AppConstants;
|
||||
import org.mozilla.gecko.util.HardwareUtils;
|
||||
import org.mozilla.gecko.util.IOUtils;
|
||||
import org.mozilla.gecko.util.ProxySelector;
|
||||
|
||||
import android.content.Context;
|
||||
|
@ -379,36 +378,27 @@ public class SwitchBoard {
|
|||
* @return Returns String from server or null when failed.
|
||||
*/
|
||||
@Nullable private static String readFromUrlGET(URL url) {
|
||||
HttpURLConnection connection = null;
|
||||
InputStreamReader inputStreamReader = null;
|
||||
BufferedReader bufferReader = null;
|
||||
try {
|
||||
connection = (HttpURLConnection) ProxySelector.openConnectionWithProxy(url.toURI());
|
||||
HttpURLConnection connection = (HttpURLConnection) ProxySelector.openConnectionWithProxy(url.toURI());
|
||||
connection.setRequestProperty("User-Agent", HardwareUtils.isTablet() ?
|
||||
AppConstants.USER_AGENT_FENNEC_TABLET :
|
||||
AppConstants.USER_AGENT_FENNEC_MOBILE);
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setUseCaches(false);
|
||||
|
||||
// BufferedReader(Reader, int) can throw, hence we need to keep a separate reference
|
||||
// to the InputStreamReader in order to always be able to close it:
|
||||
inputStreamReader = new InputStreamReader(connection.getInputStream());
|
||||
bufferReader = new BufferedReader(inputStreamReader, 8192);
|
||||
InputStream is = connection.getInputStream();
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(is);
|
||||
BufferedReader bufferReader = new BufferedReader(inputStreamReader, 8192);
|
||||
String line;
|
||||
StringBuilder resultContent = new StringBuilder();
|
||||
while ((line = bufferReader.readLine()) != null) {
|
||||
resultContent.append(line);
|
||||
}
|
||||
bufferReader.close();
|
||||
|
||||
return resultContent.toString();
|
||||
} catch (IOException | URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
IOUtils.safeStreamClose(bufferReader);
|
||||
IOUtils.safeStreamClose(inputStreamReader);
|
||||
if (connection != null) {
|
||||
connection.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -12,7 +12,6 @@ import org.mozilla.gecko.R;
|
|||
import org.mozilla.apache.commons.codec.binary.Hex;
|
||||
|
||||
import org.mozilla.gecko.permissions.Permissions;
|
||||
import org.mozilla.gecko.util.IOUtils;
|
||||
import org.mozilla.gecko.util.ProxySelector;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
|
@ -49,7 +48,6 @@ import java.io.FileInputStream;
|
|||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
@ -375,7 +373,6 @@ public class UpdateService extends IntentService {
|
|||
}
|
||||
|
||||
private UpdateInfo findUpdate(boolean force) {
|
||||
URLConnection conn = null;
|
||||
try {
|
||||
URI uri = getUpdateURI(force);
|
||||
|
||||
|
@ -385,8 +382,7 @@ public class UpdateService extends IntentService {
|
|||
}
|
||||
|
||||
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
conn = ProxySelector.openConnectionWithProxy(uri);
|
||||
Document dom = builder.parse(conn.getInputStream());
|
||||
Document dom = builder.parse(ProxySelector.openConnectionWithProxy(uri).getInputStream());
|
||||
|
||||
NodeList nodes = dom.getElementsByTagName("update");
|
||||
if (nodes == null || nodes.getLength() == 0)
|
||||
|
@ -436,14 +432,6 @@ public class UpdateService extends IntentService {
|
|||
} catch (Exception e) {
|
||||
Log.e(LOGTAG, "failed to check for update: ", e);
|
||||
return null;
|
||||
} finally {
|
||||
// conn isn't guaranteed to be an HttpURLConnection, hence we don't want to cast earlier
|
||||
// in this method. However in our current implementation it usually is, so we need to
|
||||
// make sure we close it in that case:
|
||||
final HttpURLConnection httpConn = (HttpURLConnection) conn;
|
||||
if (httpConn != null) {
|
||||
httpConn.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -563,7 +551,6 @@ public class UpdateService extends IntentService {
|
|||
|
||||
OutputStream output = null;
|
||||
InputStream input = null;
|
||||
URLConnection conn = null;
|
||||
|
||||
mDownloading = true;
|
||||
mCancelDownload = false;
|
||||
|
@ -576,7 +563,7 @@ public class UpdateService extends IntentService {
|
|||
mWifiLock.acquire();
|
||||
}
|
||||
|
||||
conn = ProxySelector.openConnectionWithProxy(info.uri);
|
||||
URLConnection conn = ProxySelector.openConnectionWithProxy(info.uri);
|
||||
int length = conn.getContentLength();
|
||||
|
||||
output = new BufferedOutputStream(new FileOutputStream(downloadFile));
|
||||
|
@ -619,22 +606,21 @@ public class UpdateService extends IntentService {
|
|||
Log.e(LOGTAG, "failed to download update: ", e);
|
||||
return null;
|
||||
} finally {
|
||||
IOUtils.safeStreamClose(input);
|
||||
IOUtils.safeStreamClose(output);
|
||||
try {
|
||||
if (input != null)
|
||||
input.close();
|
||||
} catch (java.io.IOException e) { }
|
||||
|
||||
try {
|
||||
if (output != null)
|
||||
output.close();
|
||||
} catch (java.io.IOException e) { }
|
||||
|
||||
mDownloading = false;
|
||||
|
||||
if (mWifiLock.isHeld()) {
|
||||
mWifiLock.release();
|
||||
}
|
||||
|
||||
// conn isn't guaranteed to be an HttpURLConnection, hence we don't want to cast earlier
|
||||
// in this method. However in our current implementation it usually is, so we need to
|
||||
// make sure we close it in that case:
|
||||
final HttpURLConnection httpConn = (HttpURLConnection) conn;
|
||||
if (httpConn != null) {
|
||||
httpConn.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче