From 19a2f24e5f290441e3ef0264b4a6052a917dcce6 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Wed, 24 Jan 2018 16:43:33 -0800 Subject: Deal gracefully with cancel of nonexistent jobs In particular, fix an implicit assumption that jobs existing under a given "caller" uid implies that the the same jobs must therefore be known under their source uids as well. This isn't true when the jobs in question are sync jobs (caller uid = system) in secondary users that have been torn down. Bug: 72459151 Test: manual; automated multiuser sync testing tbd Change-Id: I9bb6aabfabdaaee04c39236bc8e1bca696898a83 --- services/core/java/com/android/server/job/JobStore.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/job/JobStore.java b/services/core/java/com/android/server/job/JobStore.java index 6da783ce110b..a24a4ac3823b 100644 --- a/services/core/java/com/android/server/job/JobStore.java +++ b/services/core/java/com/android/server/job/JobStore.java @@ -1052,13 +1052,18 @@ public final class JobStore { final ArraySet jobs = mJobs.get(uid); final int sourceUid = job.getSourceUid(); final ArraySet jobsForSourceUid = mJobsPerSourceUid.get(sourceUid); - boolean didRemove = jobs != null && jobs.remove(job) && jobsForSourceUid.remove(job); - if (didRemove) { - if (jobs.size() == 0) { - // no more jobs for this uid; let the now-empty set object be GC'd. + final boolean didRemove = jobs != null && jobs.remove(job); + final boolean sourceRemove = jobsForSourceUid != null && jobsForSourceUid.remove(job); + if (didRemove != sourceRemove) { + Slog.wtf(TAG, "Job presence mismatch; caller=" + didRemove + + " source=" + sourceRemove); + } + if (didRemove || sourceRemove) { + // no more jobs for this uid? let the now-empty set objects be GC'd. + if (jobs != null && jobs.size() == 0) { mJobs.remove(uid); } - if (jobsForSourceUid.size() == 0) { + if (jobsForSourceUid != null && jobsForSourceUid.size() == 0) { mJobsPerSourceUid.remove(sourceUid); } return true; -- cgit v1.2.3-59-g8ed1b