This commit is contained in:
Yamozha
2021-04-02 02:24:13 +03:00
parent c23950b545
commit 7256d79e2c
31493 changed files with 3036630 additions and 0 deletions

View File

@ -0,0 +1,27 @@
# Changelog
## Unpublished
### 🛠 Breaking changes
### 🎉 New features
### 🐛 Bug fixes
## 5.4.0 — 2020-11-17
### 🐛 Bug fixes
- Fix import error when importing from JavaScript. ([#10753](https://github.com/expo/expo/pull/10753) by [@IjzerenHein](https://github.com/IjzerenHein))
## 5.3.0 — 2020-08-18
_This version does not introduce any user-facing changes._
## 5.2.1 — 2020-05-29
*This version does not introduce any user-facing changes.*
## 5.2.0 — 2020-05-27
*This version does not introduce any user-facing changes.*

View File

@ -0,0 +1,5 @@
# unimodules-task-manager-interface
`unimodules-task-manager-interface` is an interface for [unimodules-task-manager](https://www.npmjs.com/package/unimodules-task-manager).
Read [unimodules-core docs](https://github.com/expo/expo/tree/master/packages/unimodules-core) for more details about module interfaces.

View File

@ -0,0 +1,61 @@
apply plugin: 'com.android.library'
apply plugin: 'maven'
group = 'org.unimodules'
version = '5.4.0'
// Simple helper that allows the root project to override versions declared by this library.
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
// Upload android library to maven with javadoc and android sources
configurations {
deployerJars
}
// Creating sources with comments
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
// Put the androidSources and javadoc to the artifacts
artifacts {
archives androidSourcesJar
}
uploadArchives {
repositories {
mavenDeployer {
configuration = configurations.deployerJars
repository(url: mavenLocal().url)
}
}
}
android {
compileSdkVersion safeExtGet("compileSdkVersion", 29)
defaultConfig {
minSdkVersion safeExtGet("minSdkVersion", 21)
targetSdkVersion safeExtGet("targetSdkVersion", 29)
versionCode 18
versionName "5.4.0"
}
lintOptions {
abortOnError false
}
}
if (new File(rootProject.projectDir.parentFile, 'package.json').exists()) {
apply from: project(":unimodules-core").file("../unimodules-core.gradle")
} else {
throw new GradleException(
"'unimodules-core.gradle' was not found in the usual React Native dependency location. " +
"This package can only be used in such projects. Are you sure you've installed the dependencies properly?")
}
dependencies {
unimodule "unimodules-core"
}

View File

@ -0,0 +1,5 @@
<manifest package="org.unimodules.interfaces.taskManager">
</manifest>

View File

@ -0,0 +1,61 @@
package org.unimodules.interfaces.taskManager;
import android.app.job.JobParameters;
import android.app.job.JobService;
import android.content.Context;
import android.content.Intent;
import java.lang.ref.WeakReference;
import java.util.Map;
import org.unimodules.core.interfaces.DoNotStrip;
public abstract class TaskConsumer implements TaskConsumerInterface {
/**
* Version of the consumer. Increase this number in case of any breaking changes made to the task consumer,
* so the existing tasks will be automatically unregistered when the native code gets upgraded.
*/
@DoNotStrip
public static int VERSION = 0;
private WeakReference<Context> mContextRef;
private TaskManagerUtilsInterface mTaskManagerUtils;
public TaskConsumer(Context context, TaskManagerUtilsInterface taskManagerUtils) {
mContextRef = new WeakReference<>(context);
mTaskManagerUtils = taskManagerUtils;
}
protected Context getContext() {
return mContextRef != null ? mContextRef.get() : null;
}
protected TaskManagerUtilsInterface getTaskManagerUtils() {
return mTaskManagerUtils;
}
//region TaskConsumerInterface
public void didReceiveBroadcast(Intent intent) {
// nothing
}
public boolean didExecuteJob(JobService jobService, JobParameters params) {
return false;
}
public boolean didCancelJob(JobService jobService, JobParameters params) {
return false;
}
public void setOptions(Map<String, Object> options) {
// nothing
}
public boolean canReceiveCustomBroadcast(String action) {
// Override it if you want your task consumer to receive custom broadcast like `Intent.ACTION_BOOT_COMPLETED`.
return false;
}
//endregion
}

View File

@ -0,0 +1,49 @@
package org.unimodules.interfaces.taskManager;
import android.app.job.JobParameters;
import android.app.job.JobService;
import android.content.Intent;
import java.util.Map;
public interface TaskConsumerInterface {
/**
* Returns the type of the task, eg. "location" or "geofencing".
*/
String taskType();
/**
* Called once the task has been registered by the task service.
*/
void didRegister(TaskInterface task);
/**
* Executed once the task associated with the consumer has been unregistered by the task service.
*/
void didUnregister();
/**
* Called when the task service has received a notification from the broadcast.
*/
void didReceiveBroadcast(Intent intent);
/**
* Called when the scheduled job started its execution.
*/
boolean didExecuteJob(JobService jobService, JobParameters params);
/**
* Invoked when the scheduled job has been cancelled by the system.
*/
boolean didCancelJob(JobService jobService, JobParameters params);
/**
* Called when registering already registered task with different options.
*/
void setOptions(Map<String, Object> options);
/**
* Should return a boolean value whether the consumer can receive custom broadcast with given action.
*/
boolean canReceiveCustomBroadcast(String action);
}

View File

@ -0,0 +1,8 @@
package org.unimodules.interfaces.taskManager;
import java.util.Map;
// Interface for receiving task execution callbacks.
public interface TaskExecutionCallback {
void onFinished(Map<String, Object> response);
}

View File

@ -0,0 +1,24 @@
package org.unimodules.interfaces.taskManager;
import android.os.Bundle;
import java.util.Map;
public interface TaskInterface {
String getName();
String getAppId();
String getAppUrl();
TaskConsumerInterface getConsumer();
Map<String, Object> getOptions();
Bundle getOptionsBundle();
// Executes the task with given data and error.
void execute(Bundle data, Error error);
// Same as above but also provides a callback that is invoked
// when the JavaScript app has finished executing the task.
void execute(Bundle data, Error error, TaskExecutionCallback callback);
// Sets options for the task.
void setOptions(Map<String, Object> options);
}

View File

@ -0,0 +1,24 @@
package org.unimodules.interfaces.taskManager;
import android.os.Bundle;
import java.util.Map;
public interface TaskManagerInterface {
String EVENT_NAME = "TaskManager.executeTask";
String ERR_TASK_SERVICE_NOT_FOUND = "ERR_TASK_SERVICE_NOT_FOUND";
void registerTask(String taskName, Class consumerClass, Map<String, Object> options) throws Exception;
void unregisterTask(String taskName, Class consumerClass) throws Exception;
void executeTaskWithBody(Bundle body);
boolean taskHasConsumerOfClass(String taskName, Class consumerClass);
void flushQueuedEvents();
String getAppId();
}

View File

@ -0,0 +1,35 @@
package org.unimodules.interfaces.taskManager;
import android.app.PendingIntent;
import android.app.job.JobParameters;
import android.content.Context;
import android.os.PersistableBundle;
import java.util.List;
public interface TaskManagerUtilsInterface {
/**
* Creates pending intent that represents the task containing all its params.
*/
PendingIntent createTaskIntent(Context context, TaskInterface task);
/**
* Cancels pending intent for given task.
*/
void cancelTaskIntent(Context context, String appId, String taskName);
/**
* Schedules a job for given task and with given list of extra data.
*/
void scheduleJob(Context context, TaskInterface task, List<PersistableBundle> data);
/**
* Cancels scheduled job with given identifier.
*/
void cancelScheduledJob(Context context, int jobId);
/**
* Extracts data list from job parameters.
*/
List<PersistableBundle> extractDataFromJobParams(JobParameters params);
}

View File

@ -0,0 +1,91 @@
package org.unimodules.interfaces.taskManager;
import android.app.job.JobParameters;
import android.app.job.JobService;
import android.content.Intent;
import android.os.Bundle;
import java.util.List;
import java.util.Map;
import org.unimodules.core.interfaces.SingletonModule;
public interface TaskServiceInterface extends SingletonModule {
/**
* Returns boolean value whether the task with given name is already registered for given appId.
*/
boolean hasRegisteredTask(String taskName, String appId);
/**
* Registers task in any kind of persistent storage, so it could be restored in future sessions.
*/
void registerTask(String taskName, String appId, String appUrl, Class consumerClass, Map<String, Object> options) throws Exception;
/**
* Unregisters task with given name and for given appId. If consumer class is provided,
* it can throw an exception if task's consumer is not a member of that class.
*/
void unregisterTask(String taskName, String appId, Class consumerClass) throws Exception;
/**
* Unregisters all tasks registered for the app with given appId.
*/
void unregisterAllTasksForAppId(String appId);
/**
* Returns boolean value whether or not the task's consumer is a member of given class.
*/
boolean taskHasConsumerOfClass(String taskName, String appId, Class consumerClass);
/**
* Returns options associated with the task with given name and appId or nil if task not found.
*/
Bundle getTaskOptions(String taskName, String appId);
/**
* Returns a list of task bundles for given appId.
*/
List<Bundle> getTasksForAppId(String appId);
/**
* Returns a list of task consumer for given appId.
*/
List<TaskConsumerInterface> getTaskConsumers(String appId);
/**
* Notifies the service that a task has just finished.
*/
void notifyTaskFinished(String taskName, String appId, Map<String, Object> response);
/**
* Passes a reference of task manager for given appId and appUrl to the service.
*/
void setTaskManager(TaskManagerInterface taskManager, String appId, String appUrl);
/**
* Handles intent that just woke up.
*/
void handleIntent(Intent intent);
/**
* Executed when the scheduled job is about to start.
*/
boolean handleJob(JobService jobService, JobParameters jobParameters);
/**
* Called when the job has been cancelled by the system.
*/
boolean cancelJob(JobService jobService, JobParameters jobParameters);
/**
* Executes the task with given data bundle and given error.
*/
void executeTask(TaskInterface task, Bundle data, Error error, TaskExecutionCallback callback);
/**
* Checks whether the app with given appId is currently being run in headless mode.
*/
boolean isStartedByHeadlessLoader(String appId);
}

View File

@ -0,0 +1 @@
module.exports = null;

View File

@ -0,0 +1,18 @@
require 'json'
package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
Pod::Spec.new do |s|
s.name = 'UMTaskManagerInterface'
s.version = package['version']
s.summary = package['description']
s.description = package['description']
s.license = package['license']
s.author = package['author']
s.homepage = package['homepage']
s.platform = :ios, '10.0'
s.source = { git: 'https://github.com/expo/expo.git' }
s.source_files = 'UMTaskManagerInterface/**/*.{h,m}'
s.preserve_paths = 'UMTaskManagerInterface/**/*.{h,m}'
s.requires_arc = true
end

View File

@ -0,0 +1,63 @@
// Copyright 2015-present 650 Industries. All rights reserved.
#import <UMTaskManagerInterface/UMTaskInterface.h>
#import <UMTaskManagerInterface/UMTaskLaunchReason.h>
// Interface for task consumers. Task consumers are the objects that are responsible for handling tasks.
// Consumers are getting signals from TaskManager (and service) about a few events that are happening during task's lifecycle.
@protocol UMTaskConsumerInterface <NSObject>
@property (nonatomic, strong) id<UMTaskInterface> __nullable task;
@required
/**
* The type of the task, like "location" or "geofencing".
*/
- (nonnull NSString *)taskType;
/**
* Called by UMTaskService when the task is created and associated with the consumer.
*/
- (void)didRegisterTask:(nonnull id<UMTaskInterface>)task;
@optional
/**
* Static method returning boolean value whether the consumer supports launch reason.
*/
+ (BOOL)supportsLaunchReason:(UMTaskLaunchReason)launchReason;
/**
* Version of the consumer. Increase returned number in case of any breaking changes made to the task consumer,
* so the existing tasks will be automatically unregistered when the native code gets upgraded.
*/
+ (NSUInteger)taskConsumerVersion;
/**
* Sets options for the task.
*/
- (void)setOptions:(nonnull NSDictionary *)options;
/**
* Called by UMTaskService to inform the consumer that the associated task is ready to be executed.
*/
- (void)didBecomeReadyToExecute;
/**
* Called right after the task has been unregistered.
*/
- (void)didUnregister;
/**
* Called by UMTaskManager when the task has been completed and we received a result from JS app.
*/
- (void)didFinish;
/**
* Method used to normalize task result that comes from JS app.
*/
- (NSUInteger)normalizeTaskResult:(nullable id)result;
@end

View File

@ -0,0 +1,38 @@
// Copyright 2015-present 650 Industries. All rights reserved.
// forward declaration for consumer interface
@protocol UMTaskConsumerInterface;
@protocol UMTaskInterface
/**
* Name of the task.
*/
@property (nonatomic, strong, readonly) NSString *__nonnull name;
/**
* Identifier of the application for which the task was created.
*/
@property (nonatomic, strong, readonly) NSString *__nonnull appId;
/**
* The URL to the application for which the task was created.
*/
@property (nonatomic, strong, readonly) NSString *__nonnull appUrl;
/**
* Task consumer instance that is responsible for handling (consuming) this task.
*/
@property (nonatomic, strong, readonly) id<UMTaskConsumerInterface> __nonnull consumer;
/**
* Options passed to the task.
*/
@property (nonatomic, strong) NSDictionary *__nullable options;
/**
* Executes the task with given dictionary data and given error.
*/
- (void)executeWithData:(nullable NSDictionary *)data withError:(nullable NSError *)error;
@end

View File

@ -0,0 +1,12 @@
// Copyright 2018-present 650 Industries. All rights reserved.
typedef enum {
UMTaskLaunchReasonUnrecognized,
UMTaskLaunchReasonUser,
UMTaskLaunchReasonBluetoothCentrals,
UMTaskLaunchReasonBluetoothPeripherals,
UMTaskLaunchReasonBackgroundFetch,
UMTaskLaunchReasonLocation,
UMTaskLaunchReasonNewsstandDownloads,
UMTaskLaunchReasonRemoteNotification,
} UMTaskLaunchReason;

View File

@ -0,0 +1,55 @@
// Copyright 2018-present 650 Industries. All rights reserved.
#import <UMTaskManagerInterface/UMTaskInterface.h>
NS_ASSUME_NONNULL_BEGIN
// Interface for UMTaskManager module.
@protocol UMTaskManagerInterface
/**
* Returns boolean value whether task with given taskName has been registered by the app.
*/
- (BOOL)hasRegisteredTaskWithName:(NSString *)taskName;
/**
* Returns boolean value whether or not the task's consumer is a member of given class.
*/
- (BOOL)taskWithName:(NSString *)taskName hasConsumerOfClass:(Class)consumerClass;
/**
* Registers task with given name, task consumer class and options.
* Can throw an exception if task with given name is already registered
* or given consumer class doesn't conform to UMTaskConsumerInterface protocol.
*/
- (void)registerTaskWithName:(NSString *)taskName
consumer:(Class)consumerClass
options:(NSDictionary *)options;
/**
* Unregisters task with given name and consumer class.
* Can throw an exception if the consumer class mismatches.
*/
- (void)unregisterTaskWithName:(NSString *)taskName
consumerClass:(nullable Class)consumerClass;
/**
* Returns boolean value whether the application contains
* given backgroundMode in UIBackgroundModes field in Info.plist file.
*/
- (BOOL)hasBackgroundModeEnabled:(NSString *)backgroundMode;
/**
* Called by task manager service to send an event with given body.
*/
- (void)executeWithBody:(NSDictionary *)body;
/**
* Whether or not the module was initialized for headless (background) JS app.
*/
- (BOOL)isRunningInHeadlessMode;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,67 @@
// Copyright 2015-present 650 Industries. All rights reserved.
#import <UMTaskManagerInterface/UMTaskInterface.h>
@protocol UMTaskServiceInterface
/**
* Returns boolean value whether the task with given name is already registered for given appId.
*/
- (BOOL)hasRegisteredTaskWithName:(nonnull NSString *)taskName
forAppId:(nonnull NSString *)appId;
/**
* Registers task in any kind of persistent storage, so it could be restored in future sessions.
*/
- (void)registerTaskWithName:(nonnull NSString *)taskName
appId:(nonnull NSString *)appId
appUrl:(nonnull NSString *)appUrl
consumerClass:(nonnull Class)consumerClass
options:(nullable NSDictionary *)options;
/**
* Unregisters task with given name and for given appId. If consumer class is provided,
* it can throw an exception if task's consumer is not a member of that class.
*/
- (void)unregisterTaskWithName:(nonnull NSString *)taskName
forAppId:(nonnull NSString *)appId
consumerClass:(nullable Class)consumerClass;
/**
* Unregisters all tasks registered for the app with given appId.
*/
- (void)unregisterAllTasksForAppId:(nonnull NSString *)appId;
/**
* Returns boolean value whether or not the task's consumer is a member of given class.
*/
- (BOOL)taskWithName:(nonnull NSString *)taskName
forAppId:(nonnull NSString *)appId
hasConsumerOfClass:(nonnull Class)consumerClass;
/**
* Returns options associated with the task with given name and appId or nil if task not found.
*/
- (nullable NSDictionary *)getOptionsForTaskName:(nonnull NSString *)taskName
forAppId:(nonnull NSString *)appId;
/**
* Returns an array of registered tasks for given appId.
*/
- (nonnull NSArray *)getRegisteredTasksForAppId:(nullable NSString *)appId;
/**
* Notifies the service that a task has just finished.
*/
- (void)notifyTaskWithName:(nonnull NSString *)taskName
forAppId:(nonnull NSString *)appId
didFinishWithResponse:(nonnull NSDictionary *)response;
/**
* Passes a reference of task manager for given appId to the service.
*/
- (void)setTaskManager:(nonnull id<UMTaskManagerInterface>)taskManager
forAppId:(nonnull NSString *)appId
withUrl:(nonnull NSString *)appUrl;
@end

View File

@ -0,0 +1,27 @@
{
"name": "unimodules-task-manager-interface",
"version": "5.4.0",
"description": "Universal module interface package for TaskManager",
"main": "index.js",
"keywords": [
"unimodules",
"task-manager",
"task",
"background"
],
"repository": {
"type": "git",
"url": "https://github.com/expo/expo.git",
"directory": "packages/unimodules-task-manager-interface"
},
"bugs": {
"url": "https://github.com/expo/expo/issues"
},
"author": "650 Industries, Inc.",
"license": "MIT",
"homepage": "https://github.com/expo/expo/tree/master/packages/unimodules-task-manager-interface",
"unimodulePeerDependencies": {
"@unimodules/core": "*"
},
"gitHead": "bc6b4b3bc3cb5e44e477f145c72c07ed09588651"
}

View File

@ -0,0 +1,4 @@
{
"name": "unimodules-task-manager-interface",
"platforms": ["ios", "android"]
}