1212import android .os .Handler ;
1313import android .os .Looper ;
1414import android .os .SystemClock ;
15+ import android .text .format .Formatter ;
1516
1617import org .apache .commons .io .FileUtils ;
1718import org .apache .commons .io .IOUtils ;
@@ -196,8 +197,9 @@ private boolean open(boolean allowCopyFromBundle) {
196197 return false ;
197198 }
198199 } else {
199- Logger .d ("Loaded product database revision %d, schema version %d.%d" ,
200- revisionId , schemaVersionMajor , schemaVersionMinor );
200+ Logger .d ("Loaded product database revision %d, schema version %d.%d, %s" ,
201+ revisionId , schemaVersionMajor , schemaVersionMinor ,
202+ Formatter .formatFileSize (application , size ()));
201203 }
202204
203205 parseLastUpdateTimestamp ();
@@ -217,10 +219,12 @@ private void close() {
217219 }
218220
219221 private void putMetaData (String key , String value ) {
220- ContentValues contentValues = new ContentValues ();
221- contentValues .put ("key" , key );
222- contentValues .put ("value" , value );
223- db .replace ("metadata" , null , contentValues );
222+ if (db != null ) {
223+ ContentValues contentValues = new ContentValues ();
224+ contentValues .put ("key" , key );
225+ contentValues .put ("value" , value );
226+ db .replace ("metadata" , null , contentValues );
227+ }
224228 }
225229
226230 private String getMetaData (String key ) {
@@ -478,6 +482,34 @@ protected void onError() {
478482 });
479483 }
480484
485+ /**
486+ * Closes and deletes the locally stored database and falls back to online only mode.
487+ */
488+ public void delete () {
489+ if (db != null ){
490+ close ();
491+ application .deleteDatabase (dbName );
492+ db = null ;
493+ revisionId = -1 ;
494+ schemaVersionMinor = -1 ;
495+ schemaVersionMajor = -1 ;
496+
497+ Logger .d ("Deleted database: " + dbName );
498+ }
499+ }
500+
501+ /**
502+ * @return Size of the database in bytes.
503+ */
504+ public long size () {
505+ if (db == null ){
506+ return 0 ;
507+ }
508+
509+ File dbFile = application .getDatabasePath (dbName );
510+ return dbFile .length ();
511+ }
512+
481513 /**
482514 * Updates the current database in the background by requesting new data from the backend.
483515 * <p>
0 commit comments