MCPcopy Create free account
hub / github.com/M66B/FairEmail / run

Method run

app/src/main/java/eu/faircode/email/SimpleTask.java:169–363  ·  view source on GitHub ↗
(final Context context, final LifecycleOwner owner, final Bundle args, final String name)

Source from the content-addressed store, hash-verified

167 }
168
169 private void run(final Context context, final LifecycleOwner owner, final Bundle args, final String name) {
170 this.name = name;
171 this.started = new Date().getTime();
172
173 if (Log.isTestRelease())
174 Log.breadcrumb("SimpleTask", args);
175
176 for (String key : args.keySet()) {
177 Object value = args.get(key);
178 if (value instanceof Spanned)
179 args.putCharSequence(key, new SpannableStringBuilderEx((Spanned) value));
180 }
181
182 if (owner instanceof TwoStateOwner)
183 Log.e(new Throwable("SimpleTask/TwoStateOwner"));
184
185 // prevent garbage collection
186 synchronized (tasks) {
187 if (id != null)
188 for (SimpleTask task : new ArrayList<>(tasks))
189 if (id.equals(task.id))
190 task.cancel(context);
191 tasks.add(this);
192 }
193
194 try {
195 onPreExecute(args);
196 } catch (Throwable ex) {
197 Log.e(ex);
198 try {
199 onException(args, ex);
200 } catch (Throwable exex) {
201 Log.e(exex);
202 }
203 }
204
205 LifecycleObserver watcher = new LifecycleObserver() {
206 @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
207 public void onDestroy() {
208 EntityLog.log(context, EntityLog.Type.Debug1, "Owner gone task=" + name);
209 destroyed = true;
210 onDestroyed(args);
211 owner.getLifecycle().removeObserver(this);
212 }
213 };
214
215 Context tcontext;
216 if (context instanceof ActivityBase) {
217 int themeId = ((ActivityBase) context).getThemeId();
218 if (themeId == 0)
219 themeId = context.getApplicationInfo().theme;
220 tcontext = ApplicationEx.getThemedContext(context, themeId);
221 } else
222 tcontext = context.getApplicationContext();
223
224 future = getExecutor(context).submit(new Runnable() {
225 private Object data;
226 private long elapsed;

Callers 1

executeMethod · 0.95

Calls 15

isTestReleaseMethod · 0.95
breadcrumbMethod · 0.95
eMethod · 0.95
onPreExecuteMethod · 0.95
onExceptionMethod · 0.95
getThemedContextMethod · 0.95
getExecutorMethod · 0.95
iMethod · 0.95
onExecuteMethod · 0.95
getMainHandlerMethod · 0.95
cleanupMethod · 0.95

Tested by

no test coverage detected