Welcome to mirror list, hosted at ThFree Co, Russian Federation.

WorkerService.java « background « maps « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f4c96e77299809c117646fd9409b125e48d1a54a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.mapswithme.maps.background;

import android.content.Context;
import android.content.Intent;
import androidx.annotation.NonNull;
import androidx.core.app.JobIntentService;
import android.text.TextUtils;
import android.util.Log;

import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.editor.Editor;
import com.mapswithme.maps.scheduling.JobIdMap;
import com.mapswithme.maps.ugc.UGC;
import com.mapswithme.util.CrashlyticsUtils;
import com.mapswithme.util.log.Logger;
import com.mapswithme.util.log.LoggerFactory;

public class WorkerService extends JobIntentService
{
  private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC);
  private static final String TAG = WorkerService.class.getSimpleName();
  private static final String ACTION_UPLOAD_OSM_CHANGES = "com.mapswithme.maps.action.upload_osm_changes";
  private static final String ACTION_UPLOAD_UGC = "com.mapswithme.maps.action.upload_ugc";

  private final boolean mArePlatformAndCoreInitialized =
      MwmApplication.get().arePlatformAndCoreInitialized();

  /**
   * Starts this service to upload map edits to osm servers.
   */
  public static void startActionUploadOsmChanges(@NonNull Context context)
  {
    final Intent intent = new Intent(context, WorkerService.class);
    intent.setAction(WorkerService.ACTION_UPLOAD_OSM_CHANGES);
    JobIntentService.enqueueWork(context.getApplicationContext(), WorkerService.class,
                                 JobIdMap.getId(WorkerService.class), intent);
  }

  /**
   * Starts this service to upload UGC to our servers.
   */
  public static void startActionUploadUGC(@NonNull Context context)
  {
    final Intent intent = new Intent(context, WorkerService.class);
    intent.setAction(WorkerService.ACTION_UPLOAD_UGC);
    final int jobId = JobIdMap.getId(WorkerService.class);
    JobIntentService.enqueueWork(context, WorkerService.class, jobId, intent);
  }

  @Override
  protected void onHandleWork(@NonNull Intent intent)
  {
    String msg = "onHandleIntent: " + intent + " app in background = "
                 + !MwmApplication.backgroundTracker().isForeground();
    LOGGER.i(TAG, msg);
    CrashlyticsUtils.log(Log.INFO, TAG, msg);
    final String action = intent.getAction();

    if (TextUtils.isEmpty(action))
      return;

    if (!mArePlatformAndCoreInitialized)
      return;

    switch (action)
    {
      case ACTION_UPLOAD_OSM_CHANGES:
        handleActionUploadOsmChanges();
        break;

      case ACTION_UPLOAD_UGC:
        handleUploadUGC();
        break;
    }
  }

  private static void handleActionUploadOsmChanges()
  {
    Editor.uploadChanges();
  }

  private static void handleUploadUGC()
  {
    UGC.nativeUploadUGC();
  }
}