incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bcur...@apache.org
Subject [6/6] git commit: Proved generating sqlite database path to open database without permission error
Date Thu, 05 Jan 2012 21:18:36 GMT
Proved generating sqlite database path to open database without permission error


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/b106d2ca
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/b106d2ca
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/b106d2ca

Branch: refs/heads/master
Commit: b106d2cae8419d4a82d1c37499ef19422a4f59de
Parents: c66142d
Author: macdonst <simon.macdonald@gmail.com>
Authored: Thu Jan 5 01:49:48 2012 +0800
Committer: macdonst <simon.macdonald@gmail.com>
Committed: Thu Jan 5 01:50:56 2012 +0800

----------------------------------------------------------------------
 framework/src/com/phonegap/Storage.java |   40 +++++++------------------
 1 files changed, 11 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/b106d2ca/framework/src/com/phonegap/Storage.java
----------------------------------------------------------------------
diff --git a/framework/src/com/phonegap/Storage.java b/framework/src/com/phonegap/Storage.java
index fc74dc1..516f6b4 100755
--- a/framework/src/com/phonegap/Storage.java
+++ b/framework/src/com/phonegap/Storage.java
@@ -18,17 +18,22 @@
 */
 package com.phonegap;
 
+import java.io.File;
+
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 import com.phonegap.api.Plugin;
 import com.phonegap.api.PluginResult;
+
+import android.content.Context;
 import android.database.Cursor;
 import android.database.sqlite.*;
 
 /**
- * This class implements the HTML5 database support for Android 1.X devices. It
- * is not used for Android 2.X, since HTML5 database is built in to the browser.
+ * This class implements the HTML5 database support to work around a bug for 
+ * Android 3.0 devices. It is not used for other versions of Android, since 
+ * HTML5 database is built in to the browser.
  */
 public class Storage extends Plugin {
 
@@ -64,11 +69,7 @@ public class Storage extends Plugin {
 		String result = "";
 
 		try {
-			// TODO: Do we want to allow a user to do this, since they could get
-			// to other app databases?
-			if (action.equals("setStorage")) {
-				this.setStorage(args.getString(0));
-			} else if (action.equals("openDatabase")) {
+			if (action.equals("openDatabase")) {
 				this.openDatabase(args.getString(0), args.getString(1),
 						args.getString(2), args.getLong(3));
 			} else if (action.equals("executeSql")) {
@@ -119,21 +120,6 @@ public class Storage extends Plugin {
 	// --------------------------------------------------------------------------
 
 	/**
-	 * Set the application package for the database. Each application saves its
-	 * database files in a directory with the application package as part of the
-	 * file name.
-	 * 
-	 * For example, application "com.phonegap.demo.Demo" would save its database
-	 * files in "/data/data/com.phonegap.demo/databases/" directory.
-	 * 
-	 * @param appPackage
-	 *            The application package.
-	 */
-	public void setStorage(String appPackage) {
-		this.path = "/data/data/" + appPackage + "/databases/";
-	}
-
-	/**
 	 * Open database.
 	 * 
 	 * @param db
@@ -155,12 +141,10 @@ public class Storage extends Plugin {
 
 		// If no database path, generate from application package
 		if (this.path == null) {
-			Package pack = this.ctx.getClass().getPackage();
-			String appPackage = pack.getName();
-			this.setStorage(appPackage);
+			this.path = this.ctx.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
 		}
 
-		this.dbName = this.path + db + ".db";
+		this.dbName = this.path + File.pathSeparator + db + ".db";
 		this.myDb = SQLiteDatabase.openOrCreateDatabase(this.dbName, null);
 	}
 
@@ -249,9 +233,7 @@ public class Storage extends Plugin {
 		}
 
 		// Let JavaScript know that there are no more rows
-		this.sendJavascript("droiddb.completeQuery('" + tx_id + "', " + result
-				+ ");");
-
+		this.sendJavascript("droiddb.completeQuery('" + tx_id + "', " + result + ");");
 	}
 
 }


Mime
View raw message