1 package expo.modules.interfaces.taskManager;
2 
3 import android.app.job.JobParameters;
4 import android.app.job.JobService;
5 import android.content.Intent;
6 import android.os.Bundle;
7 
8 import java.util.List;
9 import java.util.Map;
10 
11 import expo.modules.core.interfaces.SingletonModule;
12 
13 public interface TaskServiceInterface extends SingletonModule {
14 
15   /**
16    *  Returns boolean value whether the task with given name is already registered for given appScopeKey.
17    */
hasRegisteredTask(String taskName, String appScopeKey)18   boolean hasRegisteredTask(String taskName, String appScopeKey);
19 
20   /**
21    *  Registers task in any kind of persistent storage, so it could be restored in future sessions.
22    */
registerTask(String taskName, String appScopeKey, String appUrl, Class consumerClass, Map<String, Object> options)23   void registerTask(String taskName, String appScopeKey, String appUrl, Class consumerClass, Map<String, Object> options) throws Exception;
24 
25   /**
26    *  Unregisters task with given name and for given appScopeKey. If consumer class is provided,
27    *  it can throw an exception if task's consumer is not a member of that class.
28    */
unregisterTask(String taskName, String appScopeKey, Class consumerClass)29   void unregisterTask(String taskName, String appScopeKey, Class consumerClass) throws Exception;
30 
31   /**
32    *  Unregisters all tasks registered for the app with given appScopeKey.
33    */
unregisterAllTasksForAppScopeKey(String appScopeKey)34   void unregisterAllTasksForAppScopeKey(String appScopeKey);
35 
36   /**
37    *  Returns boolean value whether or not the task's consumer is a member of given class.
38    */
taskHasConsumerOfClass(String taskName, String appScopeKey, Class consumerClass)39   boolean taskHasConsumerOfClass(String taskName, String appScopeKey, Class consumerClass);
40 
41   /**
42    *  Returns options associated with the task with given name and appScopeKey or nil if task not found.
43    */
getTaskOptions(String taskName, String appScopeKey)44   Bundle getTaskOptions(String taskName, String appScopeKey);
45 
46   /**
47    *  Returns a list of task bundles for given appScopeKey.
48    */
getTasksForAppScopeKey(String appScopeKey)49   List<Bundle> getTasksForAppScopeKey(String appScopeKey);
50 
51   /**
52    *  Returns a list of task consumer for given appScopeKey.
53    */
getTaskConsumers(String appScopeKey)54   List<TaskConsumerInterface> getTaskConsumers(String appScopeKey);
55 
56   /**
57    *  Notifies the service that a task has just finished.
58    */
notifyTaskFinished(String taskName, String appScopeKey, Map<String, Object> response)59   void notifyTaskFinished(String taskName, String appScopeKey, Map<String, Object> response);
60 
61   /**
62    *  Passes a reference of task manager for given appScopeKey and appUrl to the service.
63    */
setTaskManager(TaskManagerInterface taskManager, String appScopeKey, String appUrl)64   void setTaskManager(TaskManagerInterface taskManager, String appScopeKey, String appUrl);
65 
66   /**
67    *  Handles intent that just woke up.
68    */
handleIntent(Intent intent)69   void handleIntent(Intent intent);
70 
71   /**
72    *  Executed when the scheduled job is about to start.
73    */
handleJob(JobService jobService, JobParameters jobParameters)74   boolean handleJob(JobService jobService, JobParameters jobParameters);
75 
76   /**
77    *  Called when the job has been cancelled by the system.
78    */
cancelJob(JobService jobService, JobParameters jobParameters)79   boolean cancelJob(JobService jobService, JobParameters jobParameters);
80 
81   /**
82    *  Executes the task with given data bundle and given error.
83    */
executeTask(TaskInterface task, Bundle data, Error error, TaskExecutionCallback callback)84   void executeTask(TaskInterface task, Bundle data, Error error, TaskExecutionCallback callback);
85 
86   /**
87    *  Checks whether the app with given appScopeKey is currently being run in headless mode.
88    */
isStartedByHeadlessLoader(String appScopeKey)89   boolean isStartedByHeadlessLoader(String appScopeKey);
90 
91 }
92