Cancel alarms & jobs when an app's data is cleared

In the same bit of code, fix a system restore issue:  in the
course of setup + restore, we reestablish permission grants and
notification state up front for the to-be-restored app, and
then bring in its data.  However, a data wipe is part of the
prologue for that data delivery -- so we were inadvertently
unwinding the permission grants and notification state restore
that we'd just performed.  Now, we distinguish the restore flow
from other clear-data operations so we don't unwind that operation.

Finally take the opportunity to elide a lot of copypasta code into
a single predicate-driven implementation.

Bug: 67508896
Bug: 69538432
Test: atest android.app.cts.AlarmManagerTest

Change-Id: I15c912c3c99645599ae9bd6fb7337fa86b4e5757
diff --git a/services/core/java/com/android/server/job/JobSchedulerService.java b/services/core/java/com/android/server/job/JobSchedulerService.java
index 3f014b5..d0ee919 100644
--- a/services/core/java/com/android/server/job/JobSchedulerService.java
+++ b/services/core/java/com/android/server/job/JobSchedulerService.java
@@ -1984,6 +1984,11 @@
         }
 
         @Override
+        public void cancelJobsForUid(int uid, String reason) {
+            JobSchedulerService.this.cancelJobsForUid(uid, reason);
+        }
+
+        @Override
         public void addBackingUpUid(int uid) {
             synchronized (mLock) {
                 // No need to actually do anything here, since for a full backup the