Skip to content

Commit

Permalink
Temporary changes for staff release
Browse files Browse the repository at this point in the history
1. `expo-media-library`: don't include videos
2. `mediaConfig`: don't treat animated GIFs as videos
3. D3296: Move `SQLiteQueryExecutor` initialization to common place and implement it in a thread-safe way
4. D3297: Enable database initialization without starting JS on iOS
5. D3370: Enable Common Cpp sources compilation and usage in `NotificationService`
  • Loading branch information
atulsmadhugiri committed May 9, 2022
1 parent eea1833 commit 48fd78a
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 82 deletions.
2 changes: 1 addition & 1 deletion lib/media/file-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const mediaConfig: { [mime: string]: MediaConfig } = Object.freeze({
serverTranscodesImage: true,
},
'image/gif': {
mediaType: 'photo_or_video',
mediaType: 'photo',
extension: 'gif',
serverCanHandle: true,
serverTranscodesImage: true,
Expand Down
17 changes: 2 additions & 15 deletions native/android/app/src/cpp/jsiInstaller.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "CommCoreModule.h"
#include "CommSecureStore.h"
#include "GlobalNetworkSingletonJNIHelper.h"
#include "SQLiteQueryExecutor.h"
#include "jniHelpers.h"
Expand Down Expand Up @@ -34,21 +33,9 @@ class CommHybrid : public jni::HybridClass<CommHybrid> {

jni::local_ref<jni::JObject> sqliteFilePathObj =
additionalParameters.get("sqliteFilePath");
comm::SQLiteQueryExecutor::sqliteFilePath = sqliteFilePathObj->toString();
std::string sqliteFilePath = sqliteFilePathObj->toString();

comm::CommSecureStore commSecureStore;
folly::Optional<std::string> maybeEncryptionKey =
commSecureStore.get("comm.encryptionKey");

if (maybeEncryptionKey) {
comm::SQLiteQueryExecutor::encryptionKey = maybeEncryptionKey.value();
} else {
int sqlcipherEncryptionKeySize = 64;
std::string encryptionKey = comm::crypto::Tools::generateRandomHexString(
sqlcipherEncryptionKeySize);
commSecureStore.set("comm.encryptionKey", encryptionKey);
comm::SQLiteQueryExecutor::encryptionKey = encryptionKey;
}
comm::SQLiteQueryExecutor::initialize(sqliteFilePath);
}

static void registerNatives() {
Expand Down
25 changes: 25 additions & 0 deletions native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "SQLiteQueryExecutor.h"
#include "CommSecureStore.h"
#include "Logger.h"
#include "sqlite_orm.h"

Expand All @@ -14,6 +15,7 @@
#include <sstream>
#include <string>
#include <system_error>
#include <thread>

#define ACCOUNT_ID 1

Expand All @@ -23,6 +25,10 @@ using namespace sqlite_orm;

std::string SQLiteQueryExecutor::sqliteFilePath;
std::string SQLiteQueryExecutor::encryptionKey;
std::once_flag SQLiteQueryExecutor::initialized;
int SQLiteQueryExecutor::sqlcipherEncryptionKeySize = 64;
std::string SQLiteQueryExecutor::secureStoreEncryptionKeyID =
"comm.encryptionKey";

bool create_table(sqlite3 *db, std::string query, std::string tableName) {
char *error;
Expand Down Expand Up @@ -511,6 +517,25 @@ auto &SQLiteQueryExecutor::getStorage() {
return storage;
}

void SQLiteQueryExecutor::initialize(std::string &databasePath) {
std::call_once(SQLiteQueryExecutor::initialized, [&databasePath]() {
SQLiteQueryExecutor::sqliteFilePath = databasePath;
CommSecureStore commSecureStore;
folly::Optional<std::string> maybeEncryptionKey =
commSecureStore.get(SQLiteQueryExecutor::secureStoreEncryptionKeyID);

if (maybeEncryptionKey) {
SQLiteQueryExecutor::encryptionKey = maybeEncryptionKey.value();
return;
}
std::string encryptionKey = comm::crypto::Tools::generateRandomHexString(
SQLiteQueryExecutor::sqlcipherEncryptionKeySize);
commSecureStore.set(
SQLiteQueryExecutor::secureStoreEncryptionKeyID, encryptionKey);
SQLiteQueryExecutor::encryptionKey = encryptionKey;
});
}

SQLiteQueryExecutor::SQLiteQueryExecutor() {
this->migrate();
}
Expand Down
6 changes: 6 additions & 0 deletions native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "DatabaseQueryExecutor.h"
#include "entities/Draft.h"

#include <mutex>
#include <string>

namespace comm {
Expand All @@ -12,11 +13,16 @@ class SQLiteQueryExecutor : public DatabaseQueryExecutor {
void migrate();
static auto &getStorage();

static std::once_flag initialized;
static int sqlcipherEncryptionKeySize;
static std::string secureStoreEncryptionKeyID;

public:
static std::string sqliteFilePath;
static std::string encryptionKey;

SQLiteQueryExecutor();
static void initialize(std::string &databasePath);
std::string getDraft(std::string key) const override;
void updateDraft(std::string key, std::string text) const override;
bool moveDraft(std::string oldKey, std::string newKey) const override;
Expand Down
138 changes: 134 additions & 4 deletions native/ios/Comm.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

50 changes: 12 additions & 38 deletions native/ios/Comm/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@
#import <React/RCTConvert.h>
#import <React/RCTRootView.h>

#import <ExpoModulesCore/EXModuleRegistryProvider.h>
#import <React/RCTBridge+Private.h>
#import <React/RCTCxxBridgeDelegate.h>
#import <React/RCTJSIExecutorRuntimeInstaller.h>
#import <cxxreact/JSExecutor.h>
#import <jsireact/JSIExecutor.h>
#import <reacthermes/HermesExecutorFactory.h>

#import <EXSecureStore/EXSecureStore.h>

#import "CommCoreModule.h"
#import "CommSecureStore.h"
#import "CommSecureStoreIOSWrapper.h"
#import "GlobalNetworkSingleton.h"
#import "NetworkModule.h"
#import "SQLiteQueryExecutor.h"
Expand Down Expand Up @@ -62,12 +57,14 @@ @interface AppDelegate () <
}
@end

@interface CommSecureStoreIOSWrapper ()
- (void)init:(EXSecureStore *)secureStore;
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self attemptDatabaseInitialization];
return YES;
}

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
#ifdef FB_SONARKIT_ENABLED
Expand Down Expand Up @@ -103,35 +100,6 @@ - (BOOL)application:(UIApplication *)application
rootView.loadingViewFadeDelay = 0;
rootView.loadingViewFadeDuration = 0.001;

EXModuleRegistryProvider *moduleRegistryProvider =
[[EXModuleRegistryProvider alloc] init];
EXSecureStore *secureStore =
(EXSecureStore *)[[moduleRegistryProvider moduleRegistry]
getExportedModuleOfClass:EXSecureStore.class];
[[CommSecureStoreIOSWrapper sharedInstance] init:secureStore];

// set sqlite file path
comm::SQLiteQueryExecutor::sqliteFilePath =
std::string([[Tools getSQLiteFilePath] UTF8String]);

// set sqlcipher encryption key
comm::CommSecureStore commSecureStore;
folly::Optional<std::string> maybeEncryptionKey;
try {
maybeEncryptionKey = commSecureStore.get("comm.encryptionKey");
} catch (NSException *exception) {
maybeEncryptionKey = folly::none;
}

if (maybeEncryptionKey) {
comm::SQLiteQueryExecutor::encryptionKey = maybeEncryptionKey.value();
} else {
int sqlcipherEncryptionKeySize = 64;
std::string encryptionKey = comm::crypto::Tools::generateRandomHexString(
sqlcipherEncryptionKeySize);
commSecureStore.set("comm.encryptionKey", encryptionKey);
comm::SQLiteQueryExecutor::encryptionKey = encryptionKey;
}
return YES;
}

Expand Down Expand Up @@ -261,6 +229,12 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
makeRuntimeConfig(3072));
}

- (void)attemptDatabaseInitialization {
std::string sqliteFilePath =
std::string([[Tools getSQLiteFilePath] UTF8String]);
comm::SQLiteQueryExecutor::initialize(sqliteFilePath);
}

// Copied from
// ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/OnLoad.cpp
static ::hermes::vm::RuntimeConfig
Expand Down
13 changes: 8 additions & 5 deletions native/ios/Comm/CommSecureStoreIOSWrapper.mm
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#import "CommSecureStoreIOSWrapper.h"

#import "CommSecureStoreIOSWrapper.h"
#import <ExpoModulesCore/EXModuleRegistryProvider.h>

@interface CommSecureStoreIOSWrapper ()
@property(nonatomic, assign) EXSecureStore *secureStore;
@property(nonatomic, strong) EXSecureStore *secureStore;
@property(nonatomic, strong) NSDictionary *options;
@end

Expand All @@ -26,14 +27,16 @@ + (id)sharedInstance {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
shared = [[self alloc] init];
EXModuleRegistryProvider *moduleRegistryProvider =
[[EXModuleRegistryProvider alloc] init];
EXSecureStore *secureStore =
(EXSecureStore *)[[moduleRegistryProvider moduleRegistry]
getExportedModuleOfClass:EXSecureStore.class];
shared.secureStore = secureStore;
});
return shared;
}

- (void)init:(EXSecureStore *)secureStore {
_secureStore = secureStore;
}

- (void)set:(NSString *)key value:(NSString *)value {
if ([self secureStore] == nil) {
[NSException raise:@"secure store error"
Expand Down
10 changes: 10 additions & 0 deletions native/ios/NotificationService/NotificationService.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)app.comm</string>
</array>
</dict>
</plist>
63 changes: 46 additions & 17 deletions native/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@ require File.join(File.dirname(`node --print "require.resolve('@react-native-com
platform :ios, '12.0'

require 'json'
podfile_properties = JSON.parse(File.read('./Podfile.properties.json')) rescue {}

target 'Comm' do
pod 'ReactNativeKeyboardTrackingView', :path => '../../node_modules/react-native-keyboard-tracking-view'
pod 'ReactNativeKeyboardInput', :path => '../../node_modules/react-native-keyboard-input'
pod 'react-native-ffmpeg/min-lts', :podspec => '../../node_modules/react-native-ffmpeg/react-native-ffmpeg.podspec'
pod 'react-native-video/VideoCaching', :podspec => '../../node_modules/react-native-video/react-native-video.podspec'
def common_comm_target_pods
pod 'SQLCipher-Amalgamation', :path => '../../node_modules/@commapp/sqlcipher-amalgamation'

pod 'gRPC-C++', :podspec => './pod-patch/.patched/gRPC-C++/1.40.0/gRPC-C++.podspec.json'
pod 'gRPC-C++/Protobuf', :podspec => './pod-patch/.patched/gRPC-C++/1.40.0/gRPC-C++.podspec.json'
pod 'gRPC-Core', :podspec => './pod-patch/.patched/gRPC-Core/1.40.0/gRPC-Core.podspec.json'
pod 'Protobuf-C++', '3.15.8'
end

target 'Comm' do
pod 'ReactNativeKeyboardTrackingView', :path => '../../node_modules/react-native-keyboard-tracking-view'
pod 'ReactNativeKeyboardInput', :path => '../../node_modules/react-native-keyboard-input'
pod 'react-native-video/VideoCaching', :podspec => '../../node_modules/react-native-video/react-native-video.podspec'
pod 'react-native-ffmpeg/min-lts', :podspec => '../../node_modules/react-native-ffmpeg/react-native-ffmpeg.podspec'
common_comm_target_pods

use_expo_modules!
config = use_native_modules!
podfile_properties = JSON.parse(File.read('./Podfile.properties.json')) rescue {}
use_react_native!(
:path => config[:reactNativePath],
# to enable hermes on iOS, change `false` to `true` and then install pods
Expand All @@ -32,15 +35,41 @@ target 'Comm' do
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable these next few lines.
use_flipper!({ "Flipper-DoubleConversion" => "1.1.7" })
post_install do |installer|
react_native_post_install(installer)
__apply_Xcode_12_5_M1_post_install_workaround(installer)

# Excluding arm64 because M1 simulator isn't supported yet
# Excluding 32-bit x86 because nobody uses it and it causes compilation issues
installer.pods_project.build_configurations.each do |config|
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64 i386"
config.build_settings['OTHER_CPLUSPLUSFLAGS'] = '-DDONT_AUTOINSTALL_REANIMATED'
end
end

target 'NotificationService' do
common_comm_target_pods
pod 'OLMKit', :path => "../../node_modules/olm"
pod 'RCT-Folly', :podspec => "../../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec"

# Lines below are only needed to compile and use Expo Secure Store in Notification Service.
# If Apple disapproves 'APPLICATION_EXTENSION_API_ONLY' flag then we can safely delete them and use
# customized Expo Secure Store that does not depend on ExpoModulesCore
podfile_properties = JSON.parse(File.read('./Podfile.properties.json')) rescue {}
use_expo_modules!
use_react_native!(
:path => "../../node_modules/react-native",
:hermes_enabled => podfile_properties['expo.jsEngine'] == 'hermes'
)
end

post_install do |installer|
react_native_post_install(installer)
__apply_Xcode_12_5_M1_post_install_workaround(installer)

# Excluding arm64 because M1 simulator isn't supported yet
# Excluding 32-bit x86 because nobody uses it and it causes compilation issues
installer.pods_project.build_configurations.each do |config|
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64 i386"
config.build_settings['OTHER_CPLUSPLUSFLAGS'] = '-DDONT_AUTOINSTALL_REANIMATED'
end

# Lines below are only needed to compile and use Expo Secure Store in Notification Service.
# If Apple disapproves 'APPLICATION_EXTENSION_API_ONLY' flag then we can safely delete them and use
# customized Expo Secure Store that does not depend on ExpoModulesCore
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
end
end
end
2 changes: 1 addition & 1 deletion native/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,6 @@ SPEC CHECKSUMS:
Yoga: e7dc4e71caba6472ff48ad7d234389b91dadc280
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

PODFILE CHECKSUM: 29d35525f36d9b1828f8c1a0d1bb4d88f9715f02
PODFILE CHECKSUM: 5a3e516358e937e7de243dd6978029bc679d7081

COCOAPODS: 1.11.3
2 changes: 1 addition & 1 deletion native/media/media-gallery-keyboard.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class MediaGalleryKeyboard extends React.PureComponent<Props, State> {
} = await MediaLibrary.getAssetsAsync({
first: 20,
after,
mediaType: [MediaLibrary.MediaType.photo, MediaLibrary.MediaType.video],
mediaType: [MediaLibrary.MediaType.photo],
sortBy: [MediaLibrary.SortBy.modificationTime],
});

Expand Down

1 comment on commit 48fd78a

@atulsmadhugiri
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually a General Release, please disregard commit title.

Please sign in to comment.