From c8b9dd949b9bf2046f3991b50fa953660feb18bd Mon Sep 17 00:00:00 2001 From: Chun-Ho Ng Date: Tue, 21 Jan 2020 15:55:00 -0800 Subject: [PATCH] Fix Opening FB4A Database Plugin Summary: The FB4A SQLite database plugin has to be opened 4-5 times before it shows a list of databases. This is because some databases are encrypted and can't be opened. In this case the code throws and exception and we do not catch that, causing the whole load process to crash. Now catching the exception and returning an empty list. Reviewed By: jknoxville Differential Revision: D19463876 fbshipit-source-id: af8c9a70dc2761e62088d90ce89f8d16057e8745 --- .../databases/impl/SqliteDatabaseDriver.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/android/src/main/java/com/facebook/flipper/plugins/databases/impl/SqliteDatabaseDriver.java b/android/src/main/java/com/facebook/flipper/plugins/databases/impl/SqliteDatabaseDriver.java index a3f8e6278..dc83737f0 100644 --- a/android/src/main/java/com/facebook/flipper/plugins/databases/impl/SqliteDatabaseDriver.java +++ b/android/src/main/java/com/facebook/flipper/plugins/databases/impl/SqliteDatabaseDriver.java @@ -89,24 +89,28 @@ public class SqliteDatabaseDriver extends DatabaseDriver getTableNames(SqliteDatabaseDescriptor databaseDescriptor) { - SQLiteDatabase database = - sqliteDatabaseConnectionProvider.openDatabase(databaseDescriptor.file); try { - Cursor cursor = - database.rawQuery( - "SELECT name FROM " + SCHEMA_TABLE + " WHERE type IN (?, ?)", - new String[] {"table", "view"}); + SQLiteDatabase database = + sqliteDatabaseConnectionProvider.openDatabase(databaseDescriptor.file); try { - List tableNames = new ArrayList<>(); - while (cursor.moveToNext()) { - tableNames.add(cursor.getString(0)); + Cursor cursor = + database.rawQuery( + "SELECT name FROM " + SCHEMA_TABLE + " WHERE type IN (?, ?)", + new String[] {"table", "view"}); + try { + List tableNames = new ArrayList<>(); + while (cursor.moveToNext()) { + tableNames.add(cursor.getString(0)); + } + return tableNames; + } finally { + cursor.close(); } - return tableNames; } finally { - cursor.close(); + database.close(); } - } finally { - database.close(); + } catch (SQLiteException ex) { + return Collections.emptyList(); } }