Merge "Make the SyncManager have wakelocks per account, not per account type, otherwise the parallel sync behavior of gmail can cause the first account to finish to release the wakelock that is used for the other account, which will result in the device going to sleep before the sync is complete."
diff --git a/core/java/android/content/SyncManager.java b/core/java/android/content/SyncManager.java
index d4ed4b9..9678d48 100644
--- a/core/java/android/content/SyncManager.java
+++ b/core/java/android/content/SyncManager.java
@@ -924,7 +924,7 @@
             mStartTime = SystemClock.elapsedRealtime();
             mTimeoutStartTime = mStartTime;
             mSyncWakeLock = mSyncHandler.getSyncWakeLock(
-                    mSyncOperation.account.type, mSyncOperation.authority);
+                    mSyncOperation.account, mSyncOperation.authority);
             mSyncWakeLock.setWorkSource(new WorkSource(syncAdapterUid));
             mSyncWakeLock.acquire();
         }
@@ -1365,7 +1365,7 @@
         public final SyncNotificationInfo mSyncNotificationInfo = new SyncNotificationInfo();
         private Long mAlarmScheduleTime = null;
         public final SyncTimeTracker mSyncTimeTracker = new SyncTimeTracker();
-        private final HashMap<Pair<String, String>, PowerManager.WakeLock> mWakeLocks =
+        private final HashMap<Pair<Account, String>, PowerManager.WakeLock> mWakeLocks =
                 Maps.newHashMap();
 
         private volatile CountDownLatch mReadyToRunLatch = new CountDownLatch(1);
@@ -1377,11 +1377,11 @@
             }
         }
 
-        private PowerManager.WakeLock getSyncWakeLock(String accountType, String authority) {
-            final Pair<String, String> wakeLockKey = Pair.create(accountType, authority);
+        private PowerManager.WakeLock getSyncWakeLock(Account account, String authority) {
+            final Pair<Account, String> wakeLockKey = Pair.create(account, authority);
             PowerManager.WakeLock wakeLock = mWakeLocks.get(wakeLockKey);
             if (wakeLock == null) {
-                final String name = SYNC_WAKE_LOCK_PREFIX + "_" + authority + "_" + accountType;
+                final String name = SYNC_WAKE_LOCK_PREFIX + "_" + authority + "_" + account;
                 wakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, name);
                 wakeLock.setReferenceCounted(false);
                 mWakeLocks.put(wakeLockKey, wakeLock);