Skip to content

Commit

Permalink
@mczernek/app loader migration (#8438)
Browse files Browse the repository at this point in the history
* Fix overloading of AppLoaders condition.

* Add information about AppLoader to AndroidManifest's meta-data and consume it in AppLoaderProvider.

* Handle reinstalling of an application in task manager, even when ejecting in the meantime.

* Update CHANGELOG.md

* Move changelog entry to Bug Fixes. Fix typo.

* Add some comments.

* Resatrt alarm after reinstallation not only for startOnBoot option.

* Remove waiting for debugger.

* Fix CHANGELOGs.

* Apply suggestions from code review

Co-authored-by: Tomasz Sapeta <1714764+tsapeta@users.noreply.github.com>

Co-authored-by: Tomasz Sapeta <1714764+tsapeta@users.noreply.github.com>
  • Loading branch information
mczernek and tsapeta committed May 28, 2020
1 parent 7427045 commit fdd4c59
Show file tree
Hide file tree
Showing 16 changed files with 567 additions and 229 deletions.
5 changes: 5 additions & 0 deletions android/expoview/src/main/AndroidManifest.xml
Expand Up @@ -106,6 +106,11 @@
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>

<meta-data
tools:replace="android:value"
android:name="org.unimodules.core.AppLoader#react-native-headless"
android:value="host.exp.exponent.taskManager.ExpoHeadlessAppLoader"/>
</application>

</manifest>
Expand Up @@ -53,16 +53,14 @@ public void onCreate() {
if (!Constants.isStandaloneApp()) {
KernelConstants.MAIN_ACTIVITY_CLASS = LauncherActivity.class;
}

AppLoaderProvider.registerLoader(this, "react-native-headless", ExpoHeadlessAppLoader.class);
KernelProvider.setFactory(new KernelProvider.KernelFactory() {
@Override
public KernelInterface create() {
return new Kernel();
}
});

ExponentKernelModuleProvider.setFactory(reactContext -> new ExponentKernelModule(reactContext));
ExponentKernelModuleProvider.setFactory(ExponentKernelModule::new);

Exponent.initialize(this, this);
NativeModuleDepsProvider.getInstance().add(Kernel.class, KernelProvider.getInstance());
Expand Down
Expand Up @@ -26,7 +26,6 @@ public class ReactAdapterPackage extends BasePackage {

@Override
public List<InternalModule> createInternalModules(Context context) {
AppLoaderProvider.registerLoader(context, "react-native-headless", RNHeadlessAppLoader.class);
// We can force-cast here, because this package will only be used in React Native context.
ReactContext reactContext = (ReactContext) context;
return Arrays.asList(
Expand Down
@@ -1,5 +1,11 @@
<manifest package="org.unimodules.adapters.react"
xmlns:android="http://schemas.android.com/apk/res/android">

<manifest package="org.unimodules.adapters.react">
<application>
<meta-data
android:name="org.unimodules.core.AppLoader#react-native-headless"
android:value="org.unimodules.adapters.react.apploader.RNHeadlessAppLoader"/>
</application>

</manifest>

Expand Up @@ -26,7 +26,6 @@ public class ReactAdapterPackage extends BasePackage {

@Override
public List<InternalModule> createInternalModules(Context context) {
AppLoaderProvider.registerLoader(context, "react-native-headless", RNHeadlessAppLoader.class);
// We can force-cast here, because this package will only be used in React Native context.
ReactContext reactContext = (ReactContext) context;
return Arrays.asList(
Expand Down
4 changes: 1 addition & 3 deletions packages/expo-background-fetch/CHANGELOG.md
Expand Up @@ -8,6 +8,4 @@

### 🐛 Bug fixes

## 8.2.0 — 2020-05-27

*This version does not introduce any user-facing changes.*
- Upgrading an application does not cause `BackgroundFetch` tasks to unregister. ([#8348](https://github.com/expo/expo/pull/8438) by [@mczernek](https://github.com/mczernek))
Expand Up @@ -39,8 +39,8 @@ public String taskType() {
@Override
public boolean canReceiveCustomBroadcast(String action) {
// Let the TaskService know that we want to receive custom broadcasts
// having "android.intent.action.BOOT_COMPLETED" action.
return Intent.ACTION_BOOT_COMPLETED.equals(action);
// having "android.intent.action.BOOT_COMPLETED" or "Intent.ACTION_MY_PACKAGE_REPLACED" action.
return Intent.ACTION_BOOT_COMPLETED.equals(action) || Intent.ACTION_MY_PACKAGE_REPLACED.equals(action);
}

@Override
Expand All @@ -65,13 +65,16 @@ public void didReceiveBroadcast(Intent intent) {
String action = intent.getAction();

if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
// Device has just been booted up - restore an alarm if "startOnBoot" option is enabled.
// Device has just been booted up, so we need restore an alarm if "startOnBoot" option is enabled.
Map<String, Object> options = mTask.getOptions();
boolean startOnBoot = options.containsKey("startOnBoot") && (boolean) options.get("startOnBoot");

if (startOnBoot) {
startAlarm();
}
} else if(Intent.ACTION_MY_PACKAGE_REPLACED.equals(action)) {
// App has just been reinstalled, so we need restore an alarm.
startAlarm();
} else {
Context context = getContext();
TaskManagerUtilsInterface taskManagerUtils = getTaskManagerUtils();
Expand Down
4 changes: 1 addition & 3 deletions packages/expo-task-manager/CHANGELOG.md
Expand Up @@ -8,6 +8,4 @@

### 🐛 Bug fixes

## 8.2.0 — 2020-05-27

*This version does not introduce any user-facing changes.*
- Upgrading an application does not cause `BackgroundFetch` tasks to unregister. ([#8348](https://github.com/expo/expo/pull/8438) by [@mczernek](https://github.com/mczernek))
Expand Up @@ -8,12 +8,15 @@
<intent-filter>
<action android:name="expo.modules.taskManager.TaskBroadcastReceiver.INTENT_ACTION" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
</receiver>
<service
android:name=".TaskJobService"
android:enabled="true"
android:exported="false"
android:permission="android.permission.BIND_JOB_SERVICE" />

<meta-data android:name="expo.modules.taskManager.oneAppId" android:value="true"/>
</application>
</manifest>

0 comments on commit fdd4c59

Please sign in to comment.