bug 704307 - strictmode Disk read Violation when loading awesomebar r=dougt

This commit is contained in:
Brad Lassey 2011-11-29 22:54:07 -05:00
parent f3e0f2f6bb
commit caaa7ad208
4 changed files with 46 additions and 41 deletions

View File

@ -86,7 +86,6 @@ import android.database.sqlite.*;
import android.provider.*;
import android.content.pm.*;
import android.content.pm.PackageManager.*;
import android.content.SharedPreferences.*;
import dalvik.system.*;
abstract public class GeckoApp
@ -94,11 +93,14 @@ abstract public class GeckoApp
{
private static final String LOGTAG = "GeckoApp";
public static final String ACTION_ALERT_CLICK = "org.mozilla.gecko.ACTION_ALERT_CLICK";
public static final String ACTION_ALERT_CLEAR = "org.mozilla.gecko.ACTION_ALERT_CLEAR";
public static final String ACTION_WEBAPP = "org.mozilla.gecko.WEBAPP";
public static final String ACTION_DEBUG = "org.mozilla.gecko.DEBUG";
public static final String ACTION_BOOKMARK = "org.mozilla.gecko.BOOKMARK";
public static final String ACTION_ALERT_CLICK = "org.mozilla.gecko.ACTION_ALERT_CLICK";
public static final String ACTION_ALERT_CLEAR = "org.mozilla.gecko.ACTION_ALERT_CLEAR";
public static final String ACTION_WEBAPP = "org.mozilla.gecko.WEBAPP";
public static final String ACTION_DEBUG = "org.mozilla.gecko.DEBUG";
public static final String ACTION_BOOKMARK = "org.mozilla.gecko.BOOKMARK";
public static final String SAVED_STATE_URI = "uri";
public static final String SAVED_STATE_TITLE = "title";
public static final String SAVED_STATE_VIEWPORT = "viewport";
private LinearLayout mMainLayout;
private AbsoluteLayout mGeckoLayout;
@ -128,6 +130,10 @@ abstract public class GeckoApp
AboutHomeContent mAboutHomeContent;
boolean mUserDefinedProfile = false;
public String mLastUri;
public String mLastTitle;
public String mLastViewport;
private Vector<View> mPluginViews = new Vector<View>();
public interface OnTabsChangedListener {
@ -385,7 +391,7 @@ abstract public class GeckoApp
intent = getIntent();
prefetchDNS(intent.getData());
new GeckoThread(intent).start();
new GeckoThread(intent, mLastUri, mLastTitle).start();
return true;
}
@ -549,10 +555,20 @@ abstract public class GeckoApp
return file.toString();
}
public SharedPreferences getPlaceholderPrefs() {
return getSharedPreferences("GeckoApp", MODE_PRIVATE);
public String getLastViewport() {
return mLastViewport;
}
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (outState == null)
outState = new Bundle();
outState.putString(SAVED_STATE_URI, mLastUri);
outState.putString(SAVED_STATE_TITLE, mLastTitle);
outState.putString(SAVED_STATE_VIEWPORT, mLastViewport);
}
private void rememberLastScreen(boolean sync) {
if (mUserDefinedProfile)
return;
@ -568,28 +584,10 @@ abstract public class GeckoApp
if (getLayerController().getLayerClient() != mSoftwareLayerClient)
return;
ViewportMetrics viewport = mSoftwareLayerClient.getGeckoViewportMetrics();
String uri = lastHistoryEntry.mUri;
String title = lastHistoryEntry.mTitle;
mLastViewport = mSoftwareLayerClient.getGeckoViewportMetrics().toJSON();
mLastUri = lastHistoryEntry.mUri;
mLastTitle = lastHistoryEntry.mTitle;
SharedPreferences prefs = getPlaceholderPrefs();
Editor editor = prefs.edit();
editor.putString("last-uri", uri);
editor.putString("last-title", title);
if (viewport != null) {
/* XXX Saving this viewport means there may be a slight
* discrepancy between what the user sees when shutting down
* and what they see when starting up, but it oughtn't be much.
*
* The alternative is to do a transformation between the two.
*/
editor.putString("viewport", viewport.toJSON());
}
Log.i(LOGTAG, "Saving:: " + uri + " " + title);
editor.commit();
GeckoEvent event = new GeckoEvent();
event.mType = GeckoEvent.SAVE_STATE;
@ -1238,7 +1236,11 @@ abstract public class GeckoApp
public void onCreate(Bundle savedInstanceState)
{
Log.w(LOGTAG, "zerdatime " + new Date().getTime() + " - onCreate");
if (savedInstanceState != null) {
mLastUri = savedInstanceState.getString(SAVED_STATE_URI);
mLastTitle = savedInstanceState.getString(SAVED_STATE_TITLE);
mLastViewport = savedInstanceState.getString(SAVED_STATE_VIEWPORT);
}
if (Build.VERSION.SDK_INT >= 9) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads().detectDiskWrites().detectNetwork()

View File

@ -1026,10 +1026,12 @@ public class GeckoAppShell
}
public static void setSelectedLocale(String localeCode) {
SharedPreferences settings =
/* We're not using this, not need to save it (see bug 635342)
SharedPreferences settings =
GeckoApp.mAppContext.getPreferences(Activity.MODE_PRIVATE);
settings.edit().putString(GeckoApp.mAppContext.getPackageName() + ".locale",
localeCode).commit();
*/
Locale locale;
int index;
if ((index = localeCode.indexOf('-')) != -1 ||

View File

@ -38,7 +38,6 @@
package org.mozilla.gecko;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.content.res.Configuration;
import android.util.Log;
@ -54,9 +53,13 @@ public class GeckoThread extends Thread {
private static final String LOGTAG = "GeckoThread";
Intent mIntent;
String mUri;
String mTitle;
GeckoThread (Intent intent) {
GeckoThread (Intent intent, String uri, String title) {
mIntent = intent;
mUri = uri;
mTitle = title;
}
public void run() {
@ -65,9 +68,8 @@ public class GeckoThread extends Thread {
String uri = intent.getDataString();
String title = uri;
if (!app.mUserDefinedProfile && (uri == null || uri.length() == 0)) {
SharedPreferences prefs = app.getSharedPreferences("GeckoApp", app.MODE_PRIVATE);
uri = prefs.getString("last-uri", "");
title = prefs.getString("last-title", uri);
uri = mUri;
title = mTitle;
}
if (uri == null || uri.equals("") || uri.equals("about:home")) {
app.showAboutHome();

View File

@ -45,7 +45,6 @@ import org.mozilla.gecko.gfx.PointUtils;
import org.mozilla.gecko.gfx.SingleTileLayer;
import org.mozilla.gecko.GeckoApp;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PointF;
@ -74,11 +73,11 @@ public class PlaceholderLayerClient extends LayerClient {
private PlaceholderLayerClient(Context context) {
mContext = context;
SharedPreferences prefs = GeckoApp.mAppContext.getPlaceholderPrefs();
String viewport = GeckoApp.mAppContext.getLastViewport();
mViewportUnknown = true;
if (prefs.contains("viewport")) {
if (viewport != null) {
try {
JSONObject viewportObject = new JSONObject(prefs.getString("viewport", null));
JSONObject viewportObject = new JSONObject(viewport);
mViewport = new ViewportMetrics(viewportObject);
mViewportUnknown = false;
} catch (JSONException e) {