Skip to content

Commit 241c3aa

Browse files
Merge branch 'karanpopali' into prerelease
2 parents 6f3ecb6 + 3d36f7e commit 241c3aa

File tree

5 files changed

+134
-0
lines changed

5 files changed

+134
-0
lines changed

AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
</intent-filter>
1111
</activity>
1212
<provider android:name=".ZeteticContentProvider" android:authorities="net.zetetic.sqlcipher.zeteticprovider" />
13+
14+
<provider android:name=".ZeteticContentProvider2" android:authorities="net.zetetic.sqlcipher.zeteticprovider2"
15+
android:process=":provider" />
1316
</application>
1417
<uses-permission android:name="android.permission.READ_CONTACTS" />
1518
</manifest>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package net.zetetic;
2+
3+
import java.io.File;
4+
5+
import android.content.ContentProvider;
6+
import android.content.ContentValues;
7+
import android.database.Cursor;
8+
import android.net.Uri;
9+
10+
import net.sqlcipher.database.SQLiteDatabase;
11+
import net.sqlcipher.database.SQLiteQueryBuilder;
12+
13+
public class ZeteticContentProvider2 extends ContentProvider {
14+
15+
public static String DATABASE_NAME = "interprocess_test.db";
16+
public static final Uri CONTENT_URI =
17+
Uri.parse("content://net.zetetic.sqlcipher.zeteticprovider2");
18+
19+
private SQLiteDatabase database;
20+
21+
public ZeteticContentProvider2() {
22+
23+
}
24+
25+
@Override
26+
public boolean onCreate() {
27+
return true;
28+
}
29+
30+
@Override
31+
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
32+
33+
SQLiteDatabase.loadLibs(ZeteticApplication.getInstance());
34+
File databasePath = ZeteticApplication.getInstance().getDatabasePath(DATABASE_NAME);
35+
database = ZeteticApplication.getInstance().createDatabase(databasePath);
36+
37+
createDatabaseWithData(database);
38+
SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
39+
builder.setTables("t1");
40+
return builder.query(database, new String[]{"a", "b"}, null, null, null, null, null);
41+
}
42+
43+
@Override
44+
public String getType(Uri uri) {
45+
return null;
46+
}
47+
48+
@Override
49+
public Uri insert(Uri uri, ContentValues contentValues) {
50+
return null;
51+
}
52+
53+
@Override
54+
public int delete(Uri uri, String s, String[] strings) {
55+
return 0;
56+
}
57+
58+
@Override
59+
public int update(Uri uri, ContentValues contentValues, String s, String[] strings) {
60+
return 0;
61+
}
62+
63+
private void createDatabaseWithData(SQLiteDatabase database) {
64+
database.execSQL("create table if not exists t1(a varchar, b blob);");
65+
ContentValues values = new ContentValues();
66+
values.put("a", "one for the money");
67+
values.put("b", "two for the show".getBytes());
68+
database.insert("t1", null, values);
69+
}
70+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package net.zetetic.tests;
2+
3+
import android.app.Activity;
4+
import android.net.Uri;
5+
6+
import net.sqlcipher.database.SQLiteDatabase;
7+
import net.zetetic.ZeteticApplication;
8+
import net.zetetic.ZeteticContentProvider2;
9+
10+
public class InterprocessBlobQueryTest extends SQLCipherTest {
11+
12+
@Override
13+
public boolean execute(SQLiteDatabase database) {
14+
15+
Activity activity = ZeteticApplication.getInstance().getCurrentActivity();
16+
Uri providerUri = ZeteticContentProvider2.CONTENT_URI;
17+
android.database.Cursor cursor = activity.managedQuery(providerUri, null, null, null, null);
18+
StringBuilder buffer = new StringBuilder();
19+
while (cursor.moveToNext()) {
20+
buffer.append(cursor.getString(0));
21+
buffer.append(new String(cursor.getBlob(1)));
22+
}
23+
cursor.close();
24+
return buffer.toString().length() > 0;
25+
}
26+
27+
28+
29+
@Override
30+
public String getName() {
31+
return "Custom Inter-Process Blob Test";
32+
}
33+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package net.zetetic.tests;
2+
3+
import net.sqlcipher.database.SQLiteDatabase;
4+
import net.zetetic.ZeteticApplication;
5+
6+
import java.io.File;
7+
8+
public class RawRekeyTest extends SQLCipherTest {
9+
10+
String password = "x\'2DD29CA851E7B56E4697B0E1F08507293D761A05CE4D1B628663F411A8086D99\'";
11+
String rekeyCommand = String.format("PRAGMA rekey = \"%s\";", password);
12+
File databaseFile = ZeteticApplication.getInstance().getDatabasePath(ZeteticApplication.DATABASE_NAME);
13+
14+
@Override
15+
public boolean execute(SQLiteDatabase database) {
16+
database.rawExecSQL(rekeyCommand);
17+
database.close();
18+
database = SQLiteDatabase.openOrCreateDatabase(databaseFile, password, null);
19+
return database != null;
20+
}
21+
22+
@Override
23+
public String getName() {
24+
return "Raw Rekey Test";
25+
}
26+
}

src/main/java/net/zetetic/tests/TestSuiteRunner.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ private List<SQLCipherTest> getTestsToRun(){
4444
tests.add(new InvalidPasswordTest());
4545
tests.add(new NullQueryResultTest());
4646
tests.add(new CrossProcessCursorQueryTest());
47+
tests.add(new InterprocessBlobQueryTest());
4748
tests.add(new LoopingQueryTest());
4849
tests.add(new LoopingCountQueryTest());
4950
tests.add(new AttachNewDatabaseTest());
@@ -68,6 +69,7 @@ private List<SQLCipherTest> getTestsToRun(){
6869
tests.add(new QueryNonEncryptedDatabaseTest());
6970
tests.add(new EnableForeignKeySupportTest());
7071
tests.add(new AverageOpenTimeTest());
72+
tests.add(new RawRekeyTest());
7173
return tests;
7274
}
7375
}

0 commit comments

Comments
 (0)