Merge remote branch 'korg/froyo' into manualmerge
diff --git a/development/ide/eclipse/.classpath b/development/ide/eclipse/.classpath
index 01fa303..d700593 100644
--- a/development/ide/eclipse/.classpath
+++ b/development/ide/eclipse/.classpath
@@ -11,6 +11,7 @@
<classpathentry kind="src" path="cts/tests/SignatureTest/tests/src"/>
<classpathentry kind="src" path="cts/tests/accessibilityservice/src"/>
<classpathentry kind="src" path="cts/tests/appsecurity-tests/src"/>
+ <classpathentry kind="src" path="cts/tests/appsecurity-tests/test-apps/AppWithData/src"/>
<classpathentry kind="src" path="cts/tests/core/runner/src"/>
<classpathentry kind="src" path="cts/tests/deviceadmin/src"/>
<classpathentry kind="src" path="cts/tests/src"/>
diff --git a/tests/appsecurity-tests/test-apps/AppWithData/src/com/android/cts/appwithdata/CreatePrivateDataTest.java b/tests/appsecurity-tests/test-apps/AppWithData/src/com/android/cts/appwithdata/CreatePrivateDataTest.java
index d77a872..1de6464 100644
--- a/tests/appsecurity-tests/test-apps/AppWithData/src/com/android/cts/appwithdata/CreatePrivateDataTest.java
+++ b/tests/appsecurity-tests/test-apps/AppWithData/src/com/android/cts/appwithdata/CreatePrivateDataTest.java
@@ -16,12 +16,17 @@
package com.android.cts.appwithdata;
+import android.content.ContentValues;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteOpenHelper;
+import android.test.AndroidTestCase;
+
import java.io.FileOutputStream;
import java.io.IOException;
-import android.content.Context;
-import android.test.AndroidTestCase;
-
/**
* Test that will create private app data.
*
@@ -35,6 +40,14 @@
*/
private static final String PRIVATE_FILE_NAME = "private_file.txt";
+ private static final String PREFERENCES_FILE_NAME = "preferences";
+ private static final String PREFERENCE_KEY = "preference_key";
+ private static final String PREFERENCE_VALUE = "preference_value";
+
+ static final String DB_TABLE_NAME = "test_table";
+ static final String DB_COLUMN = "test_column";
+ static final String DB_VALUE = "test_value";
+
/**
* Creates a file private to this app
* @throws IOException if any error occurred when creating the file
@@ -45,6 +58,39 @@
outputStream.write("file contents".getBytes());
outputStream.close();
assertTrue(getContext().getFileStreamPath(PRIVATE_FILE_NAME).exists());
+
+ writeToPreferences();
+ writeToDatabase();
+ }
+
+ private void writeToPreferences() {
+ SharedPreferences prefs = mContext.getSharedPreferences(PREFERENCES_FILE_NAME, 0);
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putString(PREFERENCE_KEY, PREFERENCE_VALUE);
+ editor.commit();
+ assertEquals(PREFERENCE_VALUE, prefs.getString(PREFERENCE_KEY, null));
+ }
+
+ private void writeToDatabase() {
+ SQLiteDatabase db = null;
+ Cursor cursor = null;
+ try {
+ db = new TestDatabaseOpenHelper(mContext).getWritableDatabase();
+ ContentValues values = new ContentValues(1);
+ values.put(DB_COLUMN, DB_VALUE);
+ assertTrue(db.insert(DB_TABLE_NAME, null, values) != -1);
+
+ cursor = db.query(DB_TABLE_NAME, new String[] {DB_COLUMN},
+ null, null, null, null, null);
+ assertEquals(1, cursor.getCount());
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
+ if (db != null) {
+ db.close();
+ }
+ }
}
/**
@@ -53,5 +99,53 @@
*/
public void testEnsurePrivateDataNotExist() throws IOException {
assertFalse(getContext().getFileStreamPath(PRIVATE_FILE_NAME).exists());
+
+ assertPreferencesDataDoesNotExist();
+ assertDatabaseDataDoesNotExist();
+ }
+
+ private void assertPreferencesDataDoesNotExist() {
+ SharedPreferences prefs = mContext.getSharedPreferences(PREFERENCES_FILE_NAME, 0);
+ assertNull(prefs.getString(PREFERENCE_KEY, null));
+ }
+
+ private void assertDatabaseDataDoesNotExist() {
+ SQLiteDatabase db = null;
+ Cursor cursor = null;
+ try {
+ db = new TestDatabaseOpenHelper(mContext).getWritableDatabase();
+ cursor = db.query(DB_TABLE_NAME, new String[] {DB_COLUMN},
+ null, null, null, null, null);
+ assertEquals(0, cursor.getCount());
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
+ if (db != null) {
+ db.close();
+ }
+ }
+ }
+
+ static class TestDatabaseOpenHelper extends SQLiteOpenHelper {
+
+ static final String _ID = "_id";
+
+ public TestDatabaseOpenHelper(Context context) {
+ super(context, "test.db", null, 1337);
+ }
+
+ @Override
+ public void onCreate(SQLiteDatabase db) {
+ db.execSQL("CREATE TABLE " + DB_TABLE_NAME + " ("
+ + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ + DB_COLUMN + " TEXT);");
+ }
+
+ @Override
+ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+ db.execSQL("DROP TABLE IF EXISTS " + DB_TABLE_NAME);
+ onCreate(db);
+ }
}
}