Skip to content

Commit 5bd587c

Browse files
Merge branch 'feature/corruption-details' of https://github.com/greyson-signal/sqlcipher-android into greyson-signal-feature/corruption-details
2 parents 44338e9 + 7052792 commit 5bd587c

File tree

8 files changed

+25
-21
lines changed

8 files changed

+25
-21
lines changed

sqlcipher/src/androidTest/java/net/zetetic/database/sqlcipher_android/DatabaseGeneralTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ public void testDefaultDatabaseErrorHandler() {
960960
assertFalse(mDatabase.isOpen());
961961
assertTrue(dbfile.exists());
962962
try {
963-
errorHandler.onCorruption(mDatabase);
963+
errorHandler.onCorruption(mDatabase, new SQLiteException());
964964
if(SQLiteDatabase.hasCodec()){
965965
assertTrue(dbfile.exists());
966966
} else {
@@ -976,7 +976,7 @@ public void testDefaultDatabaseErrorHandler() {
976976
memoryDb.close();
977977
assertFalse(memoryDb.isOpen());
978978
try {
979-
errorHandler.onCorruption(memoryDb);
979+
errorHandler.onCorruption(memoryDb, new SQLiteException());
980980
} catch (Exception e) {
981981
fail("unexpected");
982982
}
@@ -987,7 +987,7 @@ public void testDefaultDatabaseErrorHandler() {
987987
assertNotNull(dbObj);
988988
assertTrue(dbObj.isOpen());
989989
try {
990-
errorHandler.onCorruption(dbObj);
990+
errorHandler.onCorruption(dbObj, new SQLiteException());
991991
if(SQLiteDatabase.hasCodec()){
992992
assertTrue(dbfile.exists());
993993
} else{
@@ -1012,7 +1012,7 @@ public void testDefaultDatabaseErrorHandler() {
10121012
assertTrue(dbObj.isOpen());
10131013
List<Pair<String, String>> attachedDbs = dbObj.getAttachedDbs();
10141014
try {
1015-
errorHandler.onCorruption(dbObj);
1015+
errorHandler.onCorruption(dbObj, new SQLiteException());
10161016
if(SQLiteDatabase.hasCodec()){
10171017
assertTrue(dbfile.exists());
10181018
} else {
@@ -1047,7 +1047,7 @@ public void testDefaultDatabaseErrorHandler() {
10471047
assertTrue(dbObj.isOpen());
10481048
attachedDbs = dbObj.getAttachedDbs();
10491049
try {
1050-
errorHandler.onCorruption(dbObj);
1050+
errorHandler.onCorruption(dbObj, new SQLiteException());
10511051
if(SQLiteDatabase.hasCodec()){
10521052
assertTrue(dbfile.exists());
10531053
} else {

sqlcipher/src/androidTest/java/net/zetetic/database/sqlcipher_cts/SQLCipherOpenHelperTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private class SqlCipherOpenHelper extends SQLiteOpenHelper {
7272
private final String TAG = getClass().getSimpleName();
7373

7474
public SqlCipherOpenHelper(Context context) {
75-
super(context, "test.db", "test", null, 1, 1, sqLiteDatabase -> Log.e(SQLCipherOpenHelperTest.this.TAG, "onCorruption()"), new SQLiteDatabaseHook() {
75+
super(context, "test.db", "test", null, 1, 1, (sqLiteDatabase, ex) -> Log.e(SQLCipherOpenHelperTest.this.TAG, "onCorruption()"), new SQLiteDatabaseHook() {
7676
@Override
7777
public void preKey(SQLiteConnection sqLiteConnection) {
7878
Log.d(SQLCipherOpenHelperTest.this.TAG, "preKey()");

sqlcipher/src/main/java/net/zetetic/database/DatabaseErrorHandler.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
package net.zetetic.database;
2323

24+
import android.database.sqlite.SQLiteException;
25+
2426
import net.zetetic.database.sqlcipher.SQLiteDatabase;
2527

2628
/**
@@ -32,6 +34,7 @@ public interface DatabaseErrorHandler {
3234
* The method invoked when database corruption is detected.
3335
* @param dbObj the {@link SQLiteDatabase} object representing the database on which corruption
3436
* is detected.
37+
* @param exception the exception reported by sqlite that indicated the database was corrupted.
3538
*/
36-
void onCorruption(SQLiteDatabase dbObj);
39+
void onCorruption(SQLiteDatabase dbObj, SQLiteException exception);
3740
}

sqlcipher/src/main/java/net/zetetic/database/DefaultDatabaseErrorHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public final class DefaultDatabaseErrorHandler implements DatabaseErrorHandler {
5656
* @param dbObj the {@link SQLiteDatabase} object representing the database on which corruption
5757
* is detected.
5858
*/
59-
public void onCorruption(SQLiteDatabase dbObj) {
59+
public void onCorruption(SQLiteDatabase dbObj, SQLiteException exception) {
6060
Log.e(TAG, "Corruption reported by sqlite on database: " + dbObj.getPath());
6161

6262
// If this is a SEE build, do not delete any database files.

sqlcipher/src/main/java/net/zetetic/database/sqlcipher/SQLiteDatabase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,9 @@ String getLabel() {
343343
/**
344344
* Sends a corruption message to the database error handler.
345345
*/
346-
void onCorruption() {
346+
void onCorruption(SQLiteException exception) {
347347
EventLog.writeEvent(EVENT_DB_CORRUPT, getLabel());
348-
mErrorHandler.onCorruption(this);
348+
mErrorHandler.onCorruption(this, exception);
349349
}
350350

351351
/**
@@ -1012,7 +1012,7 @@ private void open() {
10121012
try {
10131013
openInner();
10141014
} catch (SQLiteDatabaseCorruptException ex) {
1015-
onCorruption();
1015+
onCorruption(ex);
10161016
openInner();
10171017
}
10181018
} catch (SQLiteException ex) {

sqlcipher/src/main/java/net/zetetic/database/sqlcipher/SQLiteProgram.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package net.zetetic.database.sqlcipher;
2222

2323
import android.database.DatabaseUtils;
24+
import android.database.sqlite.SQLiteException;
2425
import android.os.CancellationSignal;
2526

2627
import androidx.sqlite.db.SupportSQLiteProgram;
@@ -113,8 +114,8 @@ protected final int getConnectionFlags() {
113114
}
114115

115116
/** @hide */
116-
protected final void onCorruption() {
117-
mDatabase.onCorruption();
117+
protected final void onCorruption(SQLiteException exception) {
118+
mDatabase.onCorruption(exception);
118119
}
119120

120121
/**

sqlcipher/src/main/java/net/zetetic/database/sqlcipher/SQLiteQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ window, startPos, requiredPos, countAllRows, getConnectionFlags(),
7070
mCancellationSignal);
7171
return numRows;
7272
} catch (SQLiteDatabaseCorruptException ex) {
73-
onCorruption();
73+
onCorruption(ex);
7474
throw ex;
7575
} catch (SQLiteException ex) {
7676
Log.e(TAG, "exception: " + ex.getMessage() + "; query: " + getSql());

sqlcipher/src/main/java/net/zetetic/database/sqlcipher/SQLiteStatement.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void executeRaw() {
5050
try {
5151
getSession().executeRaw(getSql(), getBindArgs(), getConnectionFlags(), null);
5252
} catch (SQLiteDatabaseCorruptException ex) {
53-
onCorruption();
53+
onCorruption(ex);
5454
throw ex;
5555
} finally {
5656
releaseReference();
@@ -69,7 +69,7 @@ public void execute() {
6969
try {
7070
getSession().execute(getSql(), getBindArgs(), getConnectionFlags(), null);
7171
} catch (SQLiteDatabaseCorruptException ex) {
72-
onCorruption();
72+
onCorruption(ex);
7373
throw ex;
7474
} finally {
7575
releaseReference();
@@ -90,7 +90,7 @@ public int executeUpdateDelete() {
9090
return getSession().executeForChangedRowCount(
9191
getSql(), getBindArgs(), getConnectionFlags(), null);
9292
} catch (SQLiteDatabaseCorruptException ex) {
93-
onCorruption();
93+
onCorruption(ex);
9494
throw ex;
9595
} finally {
9696
releaseReference();
@@ -112,7 +112,7 @@ public long executeInsert() {
112112
return getSession().executeForLastInsertedRowId(
113113
getSql(), getBindArgs(), getConnectionFlags(), null);
114114
} catch (SQLiteDatabaseCorruptException ex) {
115-
onCorruption();
115+
onCorruption(ex);
116116
throw ex;
117117
} finally {
118118
releaseReference();
@@ -133,7 +133,7 @@ public long simpleQueryForLong() {
133133
return getSession().executeForLong(
134134
getSql(), getBindArgs(), getConnectionFlags(), null);
135135
} catch (SQLiteDatabaseCorruptException ex) {
136-
onCorruption();
136+
onCorruption(ex);
137137
throw ex;
138138
} finally {
139139
releaseReference();
@@ -154,7 +154,7 @@ public String simpleQueryForString() {
154154
return getSession().executeForString(
155155
getSql(), getBindArgs(), getConnectionFlags(), null);
156156
} catch (SQLiteDatabaseCorruptException ex) {
157-
onCorruption();
157+
onCorruption(ex);
158158
throw ex;
159159
} finally {
160160
releaseReference();
@@ -175,7 +175,7 @@ public ParcelFileDescriptor simpleQueryForBlobFileDescriptor() {
175175
return getSession().executeForBlobFileDescriptor(
176176
getSql(), getBindArgs(), getConnectionFlags(), null);
177177
} catch (SQLiteDatabaseCorruptException ex) {
178-
onCorruption();
178+
onCorruption(ex);
179179
throw ex;
180180
} finally {
181181
releaseReference();

0 commit comments

Comments
 (0)