[android] Changed JobScheduler Identifiers - fixed review notes

This commit is contained in:
Dmitry Donskoy 2018-10-05 15:52:09 +03:00 committed by Daria Volvenkova
parent 8b9d5a77ab
commit ca0b55dfc4
6 changed files with 51 additions and 8 deletions

View file

@ -9,6 +9,7 @@ import android.support.v4.app.JobIntentService;
import com.mapswithme.maps.LightFramework;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.routing.RoutingController;
import com.mapswithme.maps.scheduling.JobIdMap;
import com.mapswithme.util.NetworkPolicy;
import com.mapswithme.util.PermissionsUtils;
import com.mapswithme.util.log.Logger;
@ -37,8 +38,8 @@ public class NotificationService extends JobIntentService
final Intent intent = new Intent(context, NotificationService.class)
.setAction(CONNECTIVITY_ACTION);
final int jobId = NotificationService.class.hashCode();
JobIntentService.enqueueWork(context, NotificationService.class, jobId, intent);
int id = JobIdMap.getId(NotificationService.class);
JobIntentService.enqueueWork(context, NotificationService.class, id, intent);
}
private boolean notifyIsNotAuthenticated()

View file

@ -9,6 +9,7 @@ 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;
@ -32,7 +33,7 @@ public class WorkerService extends JobIntentService
final Intent intent = new Intent(context, WorkerService.class);
intent.setAction(WorkerService.ACTION_UPLOAD_OSM_CHANGES);
JobIntentService.enqueueWork(context.getApplicationContext(), WorkerService.class,
WorkerService.class.hashCode(), intent);
JobIdMap.getId(WorkerService.class), intent);
}
/**
@ -42,7 +43,7 @@ public class WorkerService extends JobIntentService
{
final Intent intent = new Intent(context, WorkerService.class);
intent.setAction(WorkerService.ACTION_UPLOAD_UGC);
final int jobId = WorkerService.class.hashCode();
final int jobId = JobIdMap.getId(WorkerService.class);
JobIntentService.enqueueWork(context, WorkerService.class, jobId, intent);
}

View file

@ -7,6 +7,7 @@ import android.support.annotation.NonNull;
import android.support.v4.app.JobIntentService;
import com.mapswithme.maps.background.AbstractLogBroadcastReceiver;
import com.mapswithme.maps.scheduling.JobIdMap;
public class SystemDownloadCompletedReceiver extends AbstractLogBroadcastReceiver
{
@ -24,7 +25,7 @@ public class SystemDownloadCompletedReceiver extends AbstractLogBroadcastReceive
if (manager == null)
return;
intent.setClass(context, SystemDownloadCompletedService.class);
int jobId = SystemDownloadCompletedService.class.hashCode();
int jobId = JobIdMap.getId(SystemDownloadCompletedService.class);
JobIntentService.enqueueWork(context, SystemDownloadCompletedService.class, jobId, intent);
}
}

View file

@ -9,6 +9,7 @@ import android.support.v4.app.JobIntentService;
import android.util.Log;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.scheduling.JobIdMap;
import com.mapswithme.util.CrashlyticsUtils;
import com.mapswithme.util.Utils;
import com.mapswithme.util.log.Logger;
@ -67,7 +68,7 @@ public class TrackRecorderWakeService extends JobIntentService
Context app = context.getApplicationContext();
Intent intent = new Intent(app, TrackRecorderWakeService.class);
final int jobId = TrackRecorderWakeService.class.hashCode();
final int jobId = JobIdMap.getId(TrackRecorderWakeService.class);
if (Utils.isLollipopOrLater())
{
JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);

View file

@ -84,7 +84,7 @@ public class ConnectivityJobScheduler implements ConnectivityListener
public void listen()
{
ComponentName component = new ComponentName(mContext, NativeJobService.class);
int jobId = NativeJobService.class.hashCode();
int jobId = JobIdMap.getId(NativeJobService.class);
JobInfo jobInfo = new JobInfo
.Builder(jobId, component)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
@ -108,7 +108,7 @@ public class ConnectivityJobScheduler implements ConnectivityListener
@Override
public void listen()
{
String tag = String.valueOf(FirebaseJobService.class.hashCode());
String tag = String.valueOf(JobIdMap.getId(FirebaseJobService.class));
int executionWindowStart = (int) TimeUnit.HOURS.toSeconds(SCHEDULE_PERIOD_IN_HOURS);
Job job = mJobDispatcher.newJobBuilder()
.setTag(tag)

View file

@ -0,0 +1,39 @@
package com.mapswithme.maps.scheduling;
import com.mapswithme.maps.background.NotificationService;
import com.mapswithme.maps.background.WorkerService;
import com.mapswithme.maps.bookmarks.SystemDownloadCompletedService;
import com.mapswithme.maps.location.TrackRecorderWakeService;
import com.mapswithme.util.Utils;
import java.util.HashMap;
import java.util.Map;
public class JobIdMap
{
private static final Map<Class<?>, Integer> MAP = new HashMap<>();
static {
MAP.put(Utils.isLollipopOrLater() ? NativeJobService.class : FirebaseJobService.class, calcIdentifier(MAP.size()));
MAP.put(NotificationService.class, calcIdentifier(MAP.size()));
MAP.put(TrackRecorderWakeService.class, calcIdentifier(MAP.size()));
MAP.put(SystemDownloadCompletedService.class, calcIdentifier(MAP.size()));
MAP.put(WorkerService.class, calcIdentifier(MAP.size()));
}
private static final int ID_BASIC = 1070;
private static final int JOB_TYPE_SHIFTS = 12;
private static int calcIdentifier(int count)
{
return (count + 1 << JOB_TYPE_SHIFTS) + ID_BASIC;
}
public static int getId(Class<?> clazz)
{
Integer integer = MAP.get(clazz);
if (integer == null)
throw new IllegalArgumentException("Value not found for args : " + clazz);
return integer;
}
}