From 7990a466609ef3b33c9a7546a5579a6502373613 Mon Sep 17 00:00:00 2001 From: wyilio Date: Fri, 13 Oct 2023 12:33:56 -0400 Subject: [PATCH] [native] trigger sqlite deletion on wipe state Summary: We allow developer to wipe state and exit the app. We're deleting the store and async storage, but don't do it for SQLite. Test Plan: Verified clearSensitiveData() is called Reviewers: varun, tomek Reviewed By: tomek Subscribers: ashoat, tomek Differential Revision: https://phab.comm.dev/D9487 --- native/data/sqlite-data-handler.js | 18 +++++++++++------- native/utils/crash-utils.js | 2 ++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/native/data/sqlite-data-handler.js b/native/data/sqlite-data-handler.js index 5698bf9670..66179419a4 100644 --- a/native/data/sqlite-data-handler.js +++ b/native/data/sqlite-data-handler.js @@ -30,6 +30,15 @@ import { useInitialNotificationsEncryptedMessage } from '../utils/crypto-utils.j import { isTaskCancelledError } from '../utils/error-handling.js'; import { useStaffCanSee } from '../utils/staff-utils.js'; +async function clearSensitiveData() { + await commCoreModule.clearSensitiveData(); + try { + await filesystemMediaCache.clearCache(); + } catch { + throw new Error('clear_media_cache_failed'); + } +} + function SQLiteDataHandler(): React.Node { const storeLoaded = useSelector(state => state.storeLoaded); @@ -85,12 +94,7 @@ function SQLiteDataHandler(): React.Node { const callClearSensitiveData = React.useCallback( async (triggeredBy: string) => { - await commCoreModule.clearSensitiveData(); - try { - await filesystemMediaCache.clearCache(); - } catch { - throw new Error('clear_media_cache_failed'); - } + await clearSensitiveData(); console.log(`SQLite database deletion was triggered by ${triggeredBy}`); }, [], @@ -220,4 +224,4 @@ function SQLiteDataHandler(): React.Node { return null; } -export { SQLiteDataHandler }; +export { SQLiteDataHandler, clearSensitiveData }; diff --git a/native/utils/crash-utils.js b/native/utils/crash-utils.js index b774b09813..6f2600ed08 100644 --- a/native/utils/crash-utils.js +++ b/native/utils/crash-utils.js @@ -5,6 +5,7 @@ import AsyncStorage from '@react-native-async-storage/async-storage'; import sleep from 'lib/utils/sleep.js'; import { featureFlagsStorageKey } from '../components/feature-flags-provider.react.js'; +import { clearSensitiveData } from '../data/sqlite-data-handler.js'; import { commCoreModule } from '../native-modules.js'; import { navStateAsyncStorageKey } from '../navigation/persistance.js'; import { getPersistor } from '../redux/persist.js'; @@ -15,6 +16,7 @@ async function wipeAndExit() { __DEV__ ? AsyncStorage.removeItem(navStateAsyncStorageKey) : null, AsyncStorage.removeItem('ANDROID_REFERRER'), AsyncStorage.removeItem(featureFlagsStorageKey), + clearSensitiveData(), ]); await sleep(50); commCoreModule.terminate();