Skip to content

Commit

Permalink
[ios][android][sdk][ncl] background tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
tsapeta committed Oct 24, 2018
1 parent a3ee8cb commit c750f7e
Show file tree
Hide file tree
Showing 224 changed files with 49,838 additions and 39,134 deletions.
52 changes: 25 additions & 27 deletions android/ReactAndroid/build.gradle
Expand Up @@ -296,33 +296,31 @@ android {
}

dependencies {
api 'com.facebook.infer.annotation:infer-annotation:0.11.2'
api 'javax.inject:javax.inject:1'
api 'com.android.support:appcompat-v7:27.1.1'
api "com.facebook.fresco:fresco:${FRESCO_VERSION}"
api "com.facebook.fresco:imagepipeline-okhttp3:${FRESCO_VERSION}"
api 'com.facebook.soloader:soloader:0.5.1'
api 'com.google.code.findbugs:jsr305:3.0.2'
api "com.squareup.okhttp3:okhttp:${OKHTTP_VERSION}"
api "com.squareup.okhttp3:okhttp-urlconnection:${OKHTTP_VERSION}"
api 'com.squareup.okio:okio:1.14.0'
compile 'org.webkit:android-jsc:r174650'
implementation 'expolib_v1.com.squareup.okhttp3:okhttp:3.6.0'
implementation 'expolib_v1.com.squareup.okio:okio:1.13.0'
implementation 'expolib_v1.com.squareup.okhttp3:okhttp-urlconnection:3.6.0'
implementation 'expolib_v1.com.facebook.fresco:expolib_v1-imagepipeline-okhttp3:1.0.1'

testImplementation "junit:junit:${JUNIT_VERSION}"
testImplementation "org.powermock:powermock-api-mockito:${POWERMOCK_VERSION}"
testImplementation "org.powermock:powermock-module-junit4-rule:${POWERMOCK_VERSION}"
testImplementation "org.powermock:powermock-classloading-xstream:${POWERMOCK_VERSION}"
testImplementation "org.mockito:mockito-core:${MOCKITO_CORE_VERSION}"
testImplementation "org.easytesting:fest-assert-core:${FEST_ASSERT_CORE_VERSION}"
testImplementation "org.robolectric:robolectric:${ROBOLECTRIC_VERSION}"

androidTestImplementation fileTree(dir: 'src/main/third-party/java/buck-android-support/', include: ['*.jar'])
androidTestImplementation 'com.android.support.test:runner:0.3'
androidTestImplementation "org.mockito:mockito-core:${MOCKITO_CORE_VERSION}"
api 'com.facebook.infer.annotation:infer-annotation:0.11.2'
api 'javax.inject:javax.inject:1'
api 'com.android.support:appcompat-v7:27.1.1'
api "com.facebook.fresco:fresco:${FRESCO_VERSION}"
api "com.facebook.fresco:imagepipeline-okhttp3:${FRESCO_VERSION}"
api 'com.facebook.soloader:soloader:0.5.1'
api 'com.google.code.findbugs:jsr305:3.0.2'
api "com.squareup.okhttp3:okhttp:${OKHTTP_VERSION}"
api "com.squareup.okhttp3:okhttp-urlconnection:${OKHTTP_VERSION}"
api 'com.squareup.okio:okio:1.14.0'
compile 'org.webkit:android-jsc:r174650'
implementation 'expolib_v1.com.squareup.okhttp3:okhttp:3.6.0'
implementation 'expolib_v1.com.squareup.okio:okio:1.13.0'
implementation 'expolib_v1.com.squareup.okhttp3:okhttp-urlconnection:3.6.0'
implementation 'expolib_v1.com.facebook.fresco:expolib_v1-imagepipeline-okhttp3:1.0.1'
testImplementation "junit:junit:${JUNIT_VERSION}"
testImplementation "org.powermock:powermock-api-mockito:${POWERMOCK_VERSION}"
testImplementation "org.powermock:powermock-module-junit4-rule:${POWERMOCK_VERSION}"
testImplementation "org.powermock:powermock-classloading-xstream:${POWERMOCK_VERSION}"
testImplementation "org.mockito:mockito-core:${MOCKITO_CORE_VERSION}"
testImplementation "org.easytesting:fest-assert-core:${FEST_ASSERT_CORE_VERSION}"
testImplementation "org.robolectric:robolectric:${ROBOLECTRIC_VERSION}"
androidTestImplementation fileTree(include: ['*.jar'], dir: 'src/main/third-party/java/buck-android-support/')
androidTestImplementation 'com.android.support.test:runner:0.3'
androidTestImplementation "org.mockito:mockito-core:${MOCKITO_CORE_VERSION}"
}

apply from: 'release.gradle'
Expand Down
Expand Up @@ -849,7 +849,7 @@ private void onReloadWithJSDebugger(JavaJSExecutor.Factory jsExecutorFactory) {

@ThreadConfined(UI)
private void onJSBundleLoadedFromServer(@Nullable NativeDeltaClient nativeDeltaClient) {
Log.d(ReactConstants.TAG, "ReactInstanceManager.onJSBundleLoadedFromServer()");
Log.d(ReactConstants.TAG, "ReactInstanceManager.onJSBundleLoadedFromServer():" + (nativeDeltaClient == null));

JSBundleLoader bundleLoader = nativeDeltaClient == null
? JSBundleLoader.createCachedBundleFromNetworkLoader(
Expand Down Expand Up @@ -906,7 +906,7 @@ public void run() {
}
// As destroy() may have run and set this to false, ensure that it is true before we create
mHasStartedCreatingInitialContext = true;

Log.i(TAG, "hasStartedCreatingInitialContext");
try {
Process.setThreadPriority(Process.THREAD_PRIORITY_DISPLAY);
final ReactApplicationContext reactApplicationContext =
Expand Down Expand Up @@ -937,7 +937,7 @@ public void run() {
}
}
};

Log.i(TAG, "before runOnNativeModulesQueueThread");
reactApplicationContext.runOnNativeModulesQueueThread(setupReactContextRunnable);
UiThreadUtil.runOnUiThread(maybeRecreateReactContextRunnable);
} catch (Exception e) {
Expand All @@ -947,6 +947,7 @@ public void run() {
});
ReactMarker.logMarker(REACT_CONTEXT_THREAD_START);
mCreateReactContextThread.start();
Log.i(TAG, "react context thread started!");
}

private void setupReactContext(final ReactApplicationContext reactContext) {
Expand Down Expand Up @@ -1111,6 +1112,7 @@ private ReactApplicationContext createReactContext(
catalystInstance.setGlobalVariable("__RCTProfileIsProfiling", "true");
}
ReactMarker.logMarker(ReactMarkerConstants.PRE_RUN_JS_BUNDLE_START);
Log.i(TAG, "will run JS bundle");
catalystInstance.runJSBundle();
reactContext.initializeWithInstance(catalystInstance);

Expand Down
Expand Up @@ -218,7 +218,6 @@ public void registerSegment(int segmentId, String path) {

/* package */ void loadScriptFromFile(String fileName, String sourceURL, boolean loadSynchronously) {
mSourceURL = sourceURL;

try {
final String contents = (String) Class.forName("host.exp.exponent.ReactNativeStaticHelpers")
.getMethod("getBundleSourceForPath", String.class)
Expand Down
Expand Up @@ -8,6 +8,8 @@
package com.facebook.react.bridge;

import android.content.Context;
import android.util.Log;

import com.facebook.react.bridge.NativeDeltaClient;
import com.facebook.react.common.DebugServerException;

Expand Down
9 changes: 9 additions & 0 deletions android/expoview/build.gradle
Expand Up @@ -147,6 +147,10 @@ dependencies {
api 'host.exp.exponent:expo-ads-admob:1.0.0'
api 'host.exp.exponent:expo-local-authentication:1.0.0'
api 'host.exp.exponent:expo-localization:1.0.0'
api 'host.exp.exponent:expo-task-manager:1.0.0'
api 'host.exp.exponent:expo-task-manager-interface:1.0.0'
api 'host.exp.exponent:expo-background-fetch:1.0.0'
api 'host.exp.exponent:expo-app-loader-provider:1.0.0'
END UNCOMMENT WHEN DISTRIBUTING */

// WHEN_DISTRIBUTING_REMOVE_FROM_HERE
Expand Down Expand Up @@ -182,6 +186,11 @@ dependencies {
api project(':expo-ads-admob')
api project(':expo-local-authentication')
api project(':expo-localization')
api project(':expo-task-manager')
api project(':expo-task-manager-interface')
api project(':expo-background-fetch')
api project(':expo-app-loader-provider')
// WHEN_DISTRIBUTING_REMOVE_TO_HERE

// Versioned react native
// WHEN_PREPARING_SHELL_REMOVE_FROM_HERE
Expand Down
Expand Up @@ -4,6 +4,7 @@

import android.os.Debug;
import android.support.multidex.MultiDexApplication;
import android.util.Log;

import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.core.CrashlyticsCore;
Expand All @@ -13,6 +14,7 @@

import javax.inject.Inject;

import expo.loaders.provider.AppLoaderProvider;
import host.exp.exponent.analytics.Analytics;
import host.exp.exponent.analytics.EXL;
import host.exp.exponent.branch.BranchManager;
Expand All @@ -23,6 +25,7 @@
import host.exp.exponent.kernel.KernelConstants;
import host.exp.exponent.kernel.KernelInterface;
import host.exp.exponent.kernel.KernelProvider;
import host.exp.exponent.headless.HeadlessAppLoader;
import host.exp.exponent.modules.ExponentKernelModule;
import host.exp.exponent.storage.ExponentSharedPreferences;
import host.exp.expoview.Exponent;
Expand Down Expand Up @@ -57,6 +60,7 @@ public void onCreate() {
KernelConstants.MAIN_ACTIVITY_CLASS = LauncherActivity.class;
}

AppLoaderProvider.registerLoader("react-native-experience", HeadlessAppLoader.class);
KernelProvider.setFactory(new KernelProvider.KernelFactory() {
@Override
public KernelInterface create() {
Expand Down
25 changes: 6 additions & 19 deletions android/expoview/src/main/java/host/exp/exponent/RNObject.java
Expand Up @@ -103,14 +103,9 @@ public static String versionForClassname(final String classname) {
public RNObject construct(Object... args) {
try {
mInstance = getConstructorWithTypes(mClazz, objectsToClasses(args)).newInstance(args);
} catch (NoSuchMethodException e) {
EXL.e(TAG, e);
} catch (InvocationTargetException e) {
EXL.e(TAG, e);
} catch (InstantiationException e) {
EXL.e(TAG, e);
} catch (IllegalAccessException e) {
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
EXL.e(TAG, e);
e.printStackTrace();
}

return this;
Expand Down Expand Up @@ -167,14 +162,9 @@ private Class[] objectsToClasses(Object... objects) {
public Object callWithReceiver(Object receiver, String name, Object... args) {
try {
return getMethodWithTypes(mClazz, name, objectsToClasses(args)).invoke(receiver, args);
} catch (IllegalAccessException e) {
EXL.e(TAG, e);
} catch (InvocationTargetException e) {
EXL.e(TAG, e);
} catch (NoSuchMethodException e) {
EXL.e(TAG, e);
} catch (NoSuchMethodError e) {
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | NoSuchMethodError e) {
EXL.e(TAG, e);
e.printStackTrace();
} catch (Throwable e) {
EXL.e(TAG, "Runtime exception in RNObject when calling method " + name + ": " + e.toString());
}
Expand All @@ -185,12 +175,9 @@ public Object callWithReceiver(Object receiver, String name, Object... args) {
public void setFieldWithReceiver(Object receiver, String name, Object value) {
try {
getFieldWithType(mClazz, name, value.getClass()).set(receiver, value);
} catch (IllegalAccessException e) {
EXL.e(TAG, e);
} catch (NoSuchFieldException e) {
EXL.e(TAG, e);
} catch (NoSuchMethodError e) {
} catch (IllegalAccessException | NoSuchFieldException | NoSuchMethodError e) {
EXL.e(TAG, e);
e.printStackTrace();
} catch (Throwable e) {
EXL.e(TAG, "Runtime exception in RNObject when setting field " + name + ": " + e.toString());
}
Expand Down
Expand Up @@ -15,12 +15,14 @@

import expo.adapters.react.ReactModuleRegistryProvider;
import expo.core.interfaces.Package;
import expo.core.interfaces.SingletonModule;
import host.exp.exponent.AppLoader;
import host.exp.exponent.Constants;
import host.exp.exponent.kernel.ExponentUrls;
import host.exp.exponent.kernel.KernelConstants;
import host.exp.expoview.ExpoViewBuildConfig;
import host.exp.expoview.Exponent;
import versioned.host.exp.exponent.ExponentPackage;
import versioned.host.exp.exponent.ExponentPackageDelegate;
import versioned.host.exp.exponent.modules.universal.ExpoModuleRegistryAdapter;

Expand Down Expand Up @@ -129,7 +131,7 @@ public ExponentPackageDelegate getExponentPackageDelegate() {
}

@Override
public ExpoModuleRegistryAdapter getScopedModuleRegistryAdapterForPackages(List<Package> packages) {
return new DetachedModuleRegistryAdapter(new ReactModuleRegistryProvider(packages));
public ExpoModuleRegistryAdapter getScopedModuleRegistryAdapterForPackages(List<Package> packages, List<SingletonModule> singletonModules) {
return new DetachedModuleRegistryAdapter(new ReactModuleRegistryProvider(packages, singletonModules));
}
}
Expand Up @@ -98,7 +98,6 @@ public boolean forceUnversioned() {
private static final int NOTIFICATION_ID = 10101;
private static String READY_FOR_BUNDLE = "readyForBundle";

private RNObject mLinkingPackage = null;
private ReactUnthemedRootView mNuxOverlayView;
private ExponentNotification mNotification;
private ExponentNotification mTempNotification;
Expand Down Expand Up @@ -464,13 +463,6 @@ public void setManifest(String manifestUrl, final JSONObject manifest, final Str

final ExponentNotification finalNotificationObject = notificationObject;

// TODO: deprecated
// LinkingPackage was removed after ABI 5.0.0
if (ABIVersion.toNumber(mDetachSdkVersion) <= ABIVersion.toNumber("5.0.0")) {
mLinkingPackage = new RNObject("host.exp.exponent.modules.external.linking.LinkingPackage");
mLinkingPackage.loadVersion(mDetachSdkVersion).construct(this, mIntentUri);
}

BranchManager.handleLink(this, mIntentUri, mDetachSdkVersion);

runOnUiThread(new Runnable() {
Expand Down Expand Up @@ -607,10 +599,6 @@ public void handleOptions(KernelConstants.ExperienceOptions options) {
}

private void handleUri(String uri) {
if (mLinkingPackage != null && mLinkingPackage.isNotNull()) {
mLinkingPackage.call("onNewUri", uri);
}

// Emits a "url" event to the Linking event emitter
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
super.onNewIntent(intent);
Expand All @@ -630,7 +618,7 @@ protected void startReactInstance() {
Exponent.getInstance().testPackagerStatus(isDebugModeEnabled(), mManifest, new Exponent.PackagerStatusCallback() {
@Override
public void onSuccess() {
mReactInstanceManager = startReactInstance(ExperienceActivity.this, mIntentUri, mLinkingPackage, mDetachSdkVersion, mNotification, mIsShellApp, reactPackages(), expoPackages(), mDevBundleDownloadProgressListener);
mReactInstanceManager = startReactInstance(ExperienceActivity.this, mIntentUri, null, mDetachSdkVersion, mNotification, mIsShellApp, reactPackages(), expoPackages(), mDevBundleDownloadProgressListener);
}

@Override
Expand Down
Expand Up @@ -55,8 +55,10 @@
import host.exp.exponent.utils.JSONBundleConverter;
import host.exp.expoview.Exponent;
import host.exp.expoview.R;
import versioned.host.exp.exponent.ExponentPackage;

import static host.exp.exponent.kernel.KernelConstants.INTENT_URI_KEY;
import static host.exp.exponent.kernel.KernelConstants.IS_HEADLESS_KEY;
import static host.exp.exponent.kernel.KernelConstants.LINKING_URI_KEY;
import static host.exp.exponent.kernel.KernelConstants.MANIFEST_URL_KEY;

Expand Down Expand Up @@ -405,7 +407,8 @@ public RNObject startReactInstance(final Exponent.StartReactInstanceDelegate del
Map<String, Object> experienceProperties = MapBuilder.<String, Object>of(
MANIFEST_URL_KEY, mManifestUrl,
LINKING_URI_KEY, linkingUri,
INTENT_URI_KEY, mIntentUri
INTENT_URI_KEY, mIntentUri,
IS_HEADLESS_KEY, false
);

Exponent.InstanceManagerBuilderProperties instanceManagerBuilderProperties = new Exponent.InstanceManagerBuilderProperties();
Expand All @@ -416,6 +419,7 @@ public RNObject startReactInstance(final Exponent.StartReactInstanceDelegate del
instanceManagerBuilderProperties.expoPackages = extraExpoPackages;
instanceManagerBuilderProperties.exponentPackageDelegate = delegate.getExponentPackageDelegate();
instanceManagerBuilderProperties.manifest = mManifest;
instanceManagerBuilderProperties.singletonModules = ExponentPackage.createSingletonModules(getApplicationContext());

RNObject versionedUtils = new RNObject("host.exp.exponent.VersionedUtils").loadVersion(mSDKVersion);
RNObject builder = versionedUtils.callRecursive("getReactInstanceManagerBuilder", instanceManagerBuilderProperties);
Expand Down

0 comments on commit c750f7e

Please sign in to comment.