diff --git a/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.h b/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.h --- a/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.h +++ b/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.h @@ -17,6 +17,7 @@ static const DatabaseQueryExecutor &getQueryExecutor(); static void clearSensitiveData(); static void initializeQueryExecutor(std::string &databasePath); + static bool checkIfDatabaseNeedsDeletion(); }; } // namespace comm diff --git a/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp b/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp --- a/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp +++ b/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp @@ -65,4 +65,12 @@ commSecureStore.set(DATABASE_MANAGER_STATUS_KEY, DB_MANAGER_WORKABLE); } +bool DatabaseManager::checkIfDatabaseNeedsDeletion() { + comm::CommSecureStore commSecureStore{}; + folly::Optional databaseManagerStatus = + commSecureStore.get(DATABASE_MANAGER_STATUS_KEY); + return databaseManagerStatus.hasValue() && + databaseManagerStatus.value() == DB_MANAGER_SECOND_FAILURE; +} + } // namespace comm diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.h b/native/cpp/CommonCpp/NativeModules/CommCoreModule.h --- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.h +++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.h @@ -60,6 +60,7 @@ setDeviceID(jsi::Runtime &rt, jsi::String deviceType) override; virtual jsi::Value getDeviceID(jsi::Runtime &rt) override; virtual jsi::Value clearSensitiveData(jsi::Runtime &rt) override; + virtual bool checkIfDatabaseNeedsDeletion(jsi::Runtime &rt) override; public: CommCoreModule(std::shared_ptr jsInvoker); diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp --- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp +++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp @@ -1062,4 +1062,8 @@ }); } +bool CommCoreModule::checkIfDatabaseNeedsDeletion(jsi::Runtime &rt) { + return DatabaseManager::checkIfDatabaseNeedsDeletion(); +} + } // namespace comm diff --git a/native/cpp/CommonCpp/_generated/commJSI-generated.cpp b/native/cpp/CommonCpp/_generated/commJSI-generated.cpp --- a/native/cpp/CommonCpp/_generated/commJSI-generated.cpp +++ b/native/cpp/CommonCpp/_generated/commJSI-generated.cpp @@ -83,6 +83,9 @@ static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_clearSensitiveData(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { return static_cast(&turboModule)->clearSensitiveData(rt); } +static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_checkIfDatabaseNeedsDeletion(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + return static_cast(&turboModule)->checkIfDatabaseNeedsDeletion(rt); +} CommCoreModuleSchemaCxxSpecJSI::CommCoreModuleSchemaCxxSpecJSI(std::shared_ptr jsInvoker) : TurboModule("CommTurboModule", jsInvoker) { @@ -109,6 +112,7 @@ methodMap_["setDeviceID"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setDeviceID}; methodMap_["getDeviceID"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getDeviceID}; methodMap_["clearSensitiveData"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_clearSensitiveData}; + methodMap_["checkIfDatabaseNeedsDeletion"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_checkIfDatabaseNeedsDeletion}; } diff --git a/native/cpp/CommonCpp/_generated/commJSI.h b/native/cpp/CommonCpp/_generated/commJSI.h --- a/native/cpp/CommonCpp/_generated/commJSI.h +++ b/native/cpp/CommonCpp/_generated/commJSI.h @@ -43,6 +43,7 @@ virtual jsi::Value setDeviceID(jsi::Runtime &rt, jsi::String deviceType) = 0; virtual jsi::Value getDeviceID(jsi::Runtime &rt) = 0; virtual jsi::Value clearSensitiveData(jsi::Runtime &rt) = 0; + virtual bool checkIfDatabaseNeedsDeletion(jsi::Runtime &rt) = 0; }; @@ -248,6 +249,14 @@ return bridging::callFromJs( rt, &T::clearSensitiveData, jsInvoker_, instance_); } + bool checkIfDatabaseNeedsDeletion(jsi::Runtime &rt) override { + static_assert( + bridging::getParameterCount(&T::checkIfDatabaseNeedsDeletion) == 1, + "Expected checkIfDatabaseNeedsDeletion(...) to have 1 parameters"); + + return bridging::callFromJs( + rt, &T::checkIfDatabaseNeedsDeletion, jsInvoker_, instance_); + } private: T *instance_; diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js --- a/native/schema/CommCoreModuleSchema.js +++ b/native/schema/CommCoreModuleSchema.js @@ -63,6 +63,7 @@ +setDeviceID: (deviceType: string) => Promise; +getDeviceID: () => Promise; +clearSensitiveData: () => Promise; + +checkIfDatabaseNeedsDeletion: () => boolean; } export default (TurboModuleRegistry.getEnforcing(