Merge "Revert "Revert "AOSP/Email - Changes for code to work with UnifiedEmail's version bump to the targetSdkVersion to 28 (maximum version). Used JobIntentservice API calls to replace context.startService for EmailBroadcastProcessorService."""
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 71648e8..9dd32c2 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -486,7 +486,9 @@
             </intent-filter>
         </receiver>
         <service
-            android:name=".service.EmailBroadcastProcessorService" />
+            android:name=".service.EmailBroadcastProcessorService"
+            android:permission="android.permission.BIND_JOB_SERVICE"
+            android:exported="true" />
 
         <!-- Support for DeviceAdmin / DevicePolicyManager.  See SecurityPolicy class for impl. -->
         <receiver
@@ -725,6 +727,7 @@
         </service>
 
         <service android:name="com.android.email.EmailIntentService"
+                 android:permission="android.permission.BIND_JOB_SERVICE"
                  android:exported="false">
             <intent-filter>
                 <action android:name="com.android.mail.action.RESEND_NOTIFICATIONS" />
diff --git a/provider_src/com/android/email/EmailIntentService.java b/provider_src/com/android/email/EmailIntentService.java
index 0c6d761..5924c90 100644
--- a/provider_src/com/android/email/EmailIntentService.java
+++ b/provider_src/com/android/email/EmailIntentService.java
@@ -29,12 +29,12 @@
     private static final String LOG_TAG = LogTag.getLogTag();
 
     public EmailIntentService() {
-        super("EmailIntentService");
+        super();
     }
 
     @Override
-    protected void onHandleIntent(final Intent intent) {
-        super.onHandleIntent(intent);
+    protected void onHandleWork(final Intent intent) {
+        super.onHandleWork(intent);
 
         if (UIProvider.ACTION_UPDATE_NOTIFICATION.equals(intent.getAction())) {
             final NotificationController nc =
diff --git a/provider_src/com/android/email/service/EmailBroadcastProcessorService.java b/provider_src/com/android/email/service/EmailBroadcastProcessorService.java
index 7aa5467..5d264f0 100644
--- a/provider_src/com/android/email/service/EmailBroadcastProcessorService.java
+++ b/provider_src/com/android/email/service/EmailBroadcastProcessorService.java
@@ -17,7 +17,6 @@
 package com.android.email.service;
 
 import android.accounts.AccountManager;
-import android.app.IntentService;
 import android.content.ComponentName;
 import android.content.ContentResolver;
 import android.content.ContentUris;
@@ -34,6 +33,8 @@
 import android.text.TextUtils;
 import android.text.format.DateUtils;
 
+import androidx.core.app.JobIntentService;
+
 import com.android.email.EmailIntentService;
 import com.android.email.Preferences;
 import com.android.email.R;
@@ -69,7 +70,9 @@
  * This also handles the DeviceAdminReceiver in SecurityPolicy, because it is also
  * a BroadcastReceiver and requires the same processing semantics.
  */
-public class EmailBroadcastProcessorService extends IntentService {
+public class EmailBroadcastProcessorService extends JobIntentService {
+    public static final int JOB_ID = 200;
+
     // Action used for BroadcastReceiver entry point
     private static final String ACTION_BROADCAST = "broadcast_receiver";
 
@@ -81,11 +84,11 @@
     private static final String ACTION_UPGRADE_BROADCAST = "upgrade_broadcast_receiver";
 
     public EmailBroadcastProcessorService() {
-        // Class name will be the thread name.
-        super(EmailBroadcastProcessorService.class.getName());
+        super();
+    }
 
-        // Intent should be redelivered if the process gets killed before completing the job.
-        setIntentRedelivery(true);
+    public static void enqueueWork(Context context, Intent work) {
+        enqueueWork(context, EmailBroadcastProcessorService.class, JOB_ID, work);
     }
 
     /**
@@ -95,13 +98,13 @@
         Intent i = new Intent(context, EmailBroadcastProcessorService.class);
         i.setAction(ACTION_BROADCAST);
         i.putExtra(Intent.EXTRA_INTENT, broadcastIntent);
-        context.startService(i);
+        EmailBroadcastProcessorService.enqueueWork(context, i);
     }
 
     public static void processUpgradeBroadcastIntent(final Context context) {
         final Intent i = new Intent(context, EmailBroadcastProcessorService.class);
         i.setAction(ACTION_UPGRADE_BROADCAST);
-        context.startService(i);
+        EmailBroadcastProcessorService.enqueueWork(context, i);
     }
 
     /**
@@ -113,11 +116,11 @@
         Intent i = new Intent(context, EmailBroadcastProcessorService.class);
         i.setAction(ACTION_DEVICE_POLICY_ADMIN);
         i.putExtra(EXTRA_DEVICE_POLICY_ADMIN, message);
-        context.startService(i);
+        EmailBroadcastProcessorService.enqueueWork(context, i);
     }
 
     @Override
-    protected void onHandleIntent(Intent intent) {
+    protected void onHandleWork(Intent intent) {
         // This method is called on a worker thread.
 
         // Dispatch from entry point