Skip to content

Commit

Permalink
[native] trigger sqlite deletion on wipe state
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wyilio committed Oct 23, 2023
1 parent d163a4c commit 7990a46
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 11 additions & 7 deletions native/data/sqlite-data-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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}`);
},
[],
Expand Down Expand Up @@ -220,4 +224,4 @@ function SQLiteDataHandler(): React.Node {
return null;
}

export { SQLiteDataHandler };
export { SQLiteDataHandler, clearSensitiveData };
2 changes: 2 additions & 0 deletions native/utils/crash-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
Expand Down

0 comments on commit 7990a46

Please sign in to comment.