OSDN Git Service

Restrict range of sync job ids
authorShreyas Basarge <snb@google.com>
Wed, 9 Mar 2016 16:52:48 +0000 (16:52 +0000)
committerShreyas Basarge <snb@google.com>
Wed, 9 Mar 2016 23:19:55 +0000 (23:19 +0000)
Sync jobs now get an id greater than 100000.
This is done to avoid conflicts with other
jobs scheduled by the System process.

Change-Id: Ifcfa218e2ac5f81231c9e25aa25dbaecaf646603

services/core/java/com/android/server/content/SyncManager.java

index 95a9875..e1d208e 100644 (file)
@@ -192,6 +192,13 @@ public class SyncManager {
      */
     private static final long SYNC_DELAY_ON_CONFLICT = 10*1000; // 10 seconds
 
+    /**
+     * Generate job ids in the range [MIN_SYNC_JOB_ID, MAX_SYNC_JOB_ID) to avoid conflicts with
+     * other jobs scheduled by the system process.
+     */
+    private static final int MIN_SYNC_JOB_ID = 100000;
+    private static final int MAX_SYNC_JOB_ID = 110000;
+
     private static final String SYNC_WAKE_LOCK_PREFIX = "*sync*/";
     private static final String HANDLE_SYNC_ALARM_WAKE_LOCK = "SyncManagerHandleSyncAlarm";
     private static final String SYNC_LOOP_WAKE_LOCK = "SyncLoopWakeLock";
@@ -249,7 +256,7 @@ public class SyncManager {
         synchronized (mScheduledSyncs) {
             int newJobId;
             do {
-                newJobId = mRand.nextInt(Integer.MAX_VALUE);
+                newJobId = MIN_SYNC_JOB_ID + mRand.nextInt(MAX_SYNC_JOB_ID - MIN_SYNC_JOB_ID);
             } while (isJobIdInUseLockedH(newJobId));
             return newJobId;
         }