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

Commit bbf6d8cf authored by Makoto Onuki's avatar Makoto Onuki
Browse files

WTF when device has no persistent periodic syncs...

... when it most likely has some.

Bug: 64536115
Test: manual
Change-Id: I24c4c950b0266ef22918156c29384bc452f523af
parent b6ba151a
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -97,6 +97,13 @@ public class SyncLogger {
    public void dumpAll(PrintWriter pw) {
    }

    /**
     * @return whether log is enabled or not.
     */
    public boolean enabled() {
        return false;
    }

    /**
     * Actual implementation which is only used on userdebug/eng builds (by default).
     */
@@ -134,6 +141,11 @@ public class SyncLogger {
            mLogPath = new File(Environment.getDataSystemDirectory(), "syncmanager-log");
        }

        @Override
        public boolean enabled() {
            return true;
        }

        private void handleException(String message, Exception e) {
            if (!mErrorShown) {
                Slog.e(TAG, message, e);
+59 −17
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.TrafficStats;
import android.os.BatteryStats;
import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
@@ -461,6 +462,7 @@ public class SyncManager {
                            continue;
                        }
                        if (opx.key.equals(opy.key)) {
                            mLogger.log("Removing duplicate sync: ", opy);
                            mJobScheduler.cancel(opy.jobId);
                        }
                    }
@@ -473,6 +475,8 @@ public class SyncManager {
        if (mJobScheduler != null) {
            return;
        }
        final long token = Binder.clearCallingIdentity();
        try {
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.d(TAG, "initializing JobScheduler object.");
            }
@@ -481,17 +485,47 @@ public class SyncManager {
            mJobSchedulerInternal = LocalServices.getService(JobSchedulerInternal.class);
            // Get all persisted syncs from JobScheduler
            List<JobInfo> pendingJobs = mJobScheduler.getAllPendingJobs();

            int numPersistedPeriodicSyncs = 0;
            int numPersistedOneshotSyncs = 0;
            for (JobInfo job : pendingJobs) {
                SyncOperation op = SyncOperation.maybeCreateFromJobExtras(job.getExtras());
                if (op != null) {
                if (!op.isPeriodic) {
                    if (op.isPeriodic) {
                        numPersistedPeriodicSyncs++;
                    } else {
                        numPersistedOneshotSyncs++;
                        // Set the pending status of this EndPoint to true. Pending icon is
                        // shown on the settings activity.
                        mSyncStorageEngine.markPending(op.target, true);
                    }
                }
            }
            if (mLogger.enabled()) {
                mLogger.log("Connected to JobScheduler: "
                        + numPersistedPeriodicSyncs + " periodic syncs "
                        + numPersistedOneshotSyncs + " oneshot syncs.");
            }
            cleanupJobs();

            if ((numPersistedPeriodicSyncs == 0) && likelyHasPeriodicSyncs()) {
                Slog.wtf(TAG, "Device booted with no persisted periodic syncs.");
            }
        } finally {
            Binder.restoreCallingIdentity(token);
        }
    }

    /**
     * @return whether the device most likely has some periodic syncs.
     */
    private boolean likelyHasPeriodicSyncs() {
        try {
            return AccountManager.get(mContext).getAccountsByType("com.google").length > 0;
        } catch (Throwable th) {
            // Just in case.
        }
        return false;
    }

    private JobScheduler getJobScheduler() {
@@ -1085,10 +1119,12 @@ public class SyncManager {
    }

    private void removeSyncsForAuthority(EndPoint info) {
        mLogger.log("removeSyncsForAuthority: ", info);
        verifyJobScheduler();
        List<SyncOperation> ops = getAllPendingSyncs();
        for (SyncOperation op: ops) {
            if (op.target.matchesSpec(info)) {
                mLogger.log("canceling: ", op);
                getJobScheduler().cancel(op.jobId);
            }
        }
@@ -1634,6 +1670,7 @@ public class SyncManager {
    }

    private void onUserRemoved(int userId) {
        mLogger.log("onUserRemoved: u", userId);
        updateRunningAccounts(null /* Don't sync any target */);

        // Clean up the storage engine database
@@ -2926,6 +2963,9 @@ public class SyncManager {
                    Slog.v(TAG, acc.toString());
                }
            }
            if (mLogger.enabled()) {
                mLogger.log("updateRunningAccountsH: ", Arrays.toString(mRunningAccounts));
            }
            if (mBootCompleted) {
                doDatabaseCleanup();
            }
@@ -2957,6 +2997,7 @@ public class SyncManager {
            List<SyncOperation> ops = getAllPendingSyncs();
            for (SyncOperation op: ops) {
                if (!containsAccountAndUser(allAccounts, op.target.account, op.target.userId)) {
                    mLogger.log("canceling: ", op);
                    getJobScheduler().cancel(op.jobId);
                }
            }
@@ -3075,6 +3116,7 @@ public class SyncManager {
                                "removePeriodicSyncInternalH");
                        runSyncFinishedOrCanceledH(null, asc);
                    }
                    mLogger.log("removePeriodicSyncInternalH-canceling: ", op);
                    getJobScheduler().cancel(op.jobId);
                }
            }