Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 544759af authored by Fred Quintana's avatar Fred Quintana Committed by The Android Automerger
Browse files

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.

Change-Id: I7658465ca0956dfd9bb341de03126869e6217d31
parent 09acc015
Loading
Loading
Loading
Loading
+5 −5
Original line number Original line Diff line number Diff line
@@ -924,7 +924,7 @@ public class SyncManager implements OnAccountsUpdateListener {
            mStartTime = SystemClock.elapsedRealtime();
            mStartTime = SystemClock.elapsedRealtime();
            mTimeoutStartTime = mStartTime;
            mTimeoutStartTime = mStartTime;
            mSyncWakeLock = mSyncHandler.getSyncWakeLock(
            mSyncWakeLock = mSyncHandler.getSyncWakeLock(
                    mSyncOperation.account.type, mSyncOperation.authority);
                    mSyncOperation.account, mSyncOperation.authority);
            mSyncWakeLock.setWorkSource(new WorkSource(syncAdapterUid));
            mSyncWakeLock.setWorkSource(new WorkSource(syncAdapterUid));
            mSyncWakeLock.acquire();
            mSyncWakeLock.acquire();
        }
        }
@@ -1365,7 +1365,7 @@ public class SyncManager implements OnAccountsUpdateListener {
        public final SyncNotificationInfo mSyncNotificationInfo = new SyncNotificationInfo();
        public final SyncNotificationInfo mSyncNotificationInfo = new SyncNotificationInfo();
        private Long mAlarmScheduleTime = null;
        private Long mAlarmScheduleTime = null;
        public final SyncTimeTracker mSyncTimeTracker = new SyncTimeTracker();
        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();
                Maps.newHashMap();


        private volatile CountDownLatch mReadyToRunLatch = new CountDownLatch(1);
        private volatile CountDownLatch mReadyToRunLatch = new CountDownLatch(1);
@@ -1377,11 +1377,11 @@ public class SyncManager implements OnAccountsUpdateListener {
            }
            }
        }
        }


        private PowerManager.WakeLock getSyncWakeLock(String accountType, String authority) {
        private PowerManager.WakeLock getSyncWakeLock(Account account, String authority) {
            final Pair<String, String> wakeLockKey = Pair.create(accountType, authority);
            final Pair<Account, String> wakeLockKey = Pair.create(account, authority);
            PowerManager.WakeLock wakeLock = mWakeLocks.get(wakeLockKey);
            PowerManager.WakeLock wakeLock = mWakeLocks.get(wakeLockKey);
            if (wakeLock == null) {
            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 = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, name);
                wakeLock.setReferenceCounted(false);
                wakeLock.setReferenceCounted(false);
                mWakeLocks.put(wakeLockKey, wakeLock);
                mWakeLocks.put(wakeLockKey, wakeLock);