Merge "WTF when device has no persistent periodic syncs..." into oc-dr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
7b0dec4142
@@ -97,6 +97,13 @@ public class SyncLogger {
|
|||||||
public void dumpAll(PrintWriter pw) {
|
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).
|
* 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");
|
mLogPath = new File(Environment.getDataSystemDirectory(), "syncmanager-log");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean enabled() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private void handleException(String message, Exception e) {
|
private void handleException(String message, Exception e) {
|
||||||
if (!mErrorShown) {
|
if (!mErrorShown) {
|
||||||
Slog.e(TAG, message, e);
|
Slog.e(TAG, message, e);
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ import android.net.ConnectivityManager;
|
|||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.net.TrafficStats;
|
import android.net.TrafficStats;
|
||||||
import android.os.BatteryStats;
|
import android.os.BatteryStats;
|
||||||
|
import android.os.Binder;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
@@ -461,6 +462,7 @@ public class SyncManager {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (opx.key.equals(opy.key)) {
|
if (opx.key.equals(opy.key)) {
|
||||||
|
mLogger.log("Removing duplicate sync: ", opy);
|
||||||
mJobScheduler.cancel(opy.jobId);
|
mJobScheduler.cancel(opy.jobId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -473,25 +475,57 @@ public class SyncManager {
|
|||||||
if (mJobScheduler != null) {
|
if (mJobScheduler != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
final long token = Binder.clearCallingIdentity();
|
||||||
Log.d(TAG, "initializing JobScheduler object.");
|
try {
|
||||||
}
|
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
||||||
mJobScheduler = (JobScheduler) mContext.getSystemService(
|
Log.d(TAG, "initializing JobScheduler object.");
|
||||||
Context.JOB_SCHEDULER_SERVICE);
|
}
|
||||||
mJobSchedulerInternal = LocalServices.getService(JobSchedulerInternal.class);
|
mJobScheduler = (JobScheduler) mContext.getSystemService(
|
||||||
// Get all persisted syncs from JobScheduler
|
Context.JOB_SCHEDULER_SERVICE);
|
||||||
List<JobInfo> pendingJobs = mJobScheduler.getAllPendingJobs();
|
mJobSchedulerInternal = LocalServices.getService(JobSchedulerInternal.class);
|
||||||
for (JobInfo job : pendingJobs) {
|
// Get all persisted syncs from JobScheduler
|
||||||
SyncOperation op = SyncOperation.maybeCreateFromJobExtras(job.getExtras());
|
List<JobInfo> pendingJobs = mJobScheduler.getAllPendingJobs();
|
||||||
if (op != null) {
|
|
||||||
if (!op.isPeriodic) {
|
int numPersistedPeriodicSyncs = 0;
|
||||||
// Set the pending status of this EndPoint to true. Pending icon is
|
int numPersistedOneshotSyncs = 0;
|
||||||
// shown on the settings activity.
|
for (JobInfo job : pendingJobs) {
|
||||||
mSyncStorageEngine.markPending(op.target, true);
|
SyncOperation op = SyncOperation.maybeCreateFromJobExtras(job.getExtras());
|
||||||
|
if (op != null) {
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
cleanupJobs();
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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() {
|
private JobScheduler getJobScheduler() {
|
||||||
@@ -1085,11 +1119,13 @@ public class SyncManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void removeSyncsForAuthority(EndPoint info) {
|
private void removeSyncsForAuthority(EndPoint info) {
|
||||||
|
mLogger.log("removeSyncsForAuthority: ", info);
|
||||||
verifyJobScheduler();
|
verifyJobScheduler();
|
||||||
List<SyncOperation> ops = getAllPendingSyncs();
|
List<SyncOperation> ops = getAllPendingSyncs();
|
||||||
for (SyncOperation op: ops) {
|
for (SyncOperation op: ops) {
|
||||||
if (op.target.matchesSpec(info)) {
|
if (op.target.matchesSpec(info)) {
|
||||||
getJobScheduler().cancel(op.jobId);
|
mLogger.log("canceling: ", op);
|
||||||
|
getJobScheduler().cancel(op.jobId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1634,6 +1670,7 @@ public class SyncManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onUserRemoved(int userId) {
|
private void onUserRemoved(int userId) {
|
||||||
|
mLogger.log("onUserRemoved: u", userId);
|
||||||
updateRunningAccounts(null /* Don't sync any target */);
|
updateRunningAccounts(null /* Don't sync any target */);
|
||||||
|
|
||||||
// Clean up the storage engine database
|
// Clean up the storage engine database
|
||||||
@@ -2926,6 +2963,9 @@ public class SyncManager {
|
|||||||
Slog.v(TAG, acc.toString());
|
Slog.v(TAG, acc.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (mLogger.enabled()) {
|
||||||
|
mLogger.log("updateRunningAccountsH: ", Arrays.toString(mRunningAccounts));
|
||||||
|
}
|
||||||
if (mBootCompleted) {
|
if (mBootCompleted) {
|
||||||
doDatabaseCleanup();
|
doDatabaseCleanup();
|
||||||
}
|
}
|
||||||
@@ -2957,6 +2997,7 @@ public class SyncManager {
|
|||||||
List<SyncOperation> ops = getAllPendingSyncs();
|
List<SyncOperation> ops = getAllPendingSyncs();
|
||||||
for (SyncOperation op: ops) {
|
for (SyncOperation op: ops) {
|
||||||
if (!containsAccountAndUser(allAccounts, op.target.account, op.target.userId)) {
|
if (!containsAccountAndUser(allAccounts, op.target.account, op.target.userId)) {
|
||||||
|
mLogger.log("canceling: ", op);
|
||||||
getJobScheduler().cancel(op.jobId);
|
getJobScheduler().cancel(op.jobId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3075,6 +3116,7 @@ public class SyncManager {
|
|||||||
"removePeriodicSyncInternalH");
|
"removePeriodicSyncInternalH");
|
||||||
runSyncFinishedOrCanceledH(null, asc);
|
runSyncFinishedOrCanceledH(null, asc);
|
||||||
}
|
}
|
||||||
|
mLogger.log("removePeriodicSyncInternalH-canceling: ", op);
|
||||||
getJobScheduler().cancel(op.jobId);
|
getJobScheduler().cancel(op.jobId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user