Merge "app/Gallery2/Gallery2.apk app - update the version to target P (28) or higher. Use JobIntentService to start the AsyncService."
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 0263e6d..43439f9 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -7,7 +7,7 @@
 
     <original-package android:name="com.android.gallery3d" />
 
-    <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="24" />
+    <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="28" />
 
     <permission android:name="com.android.gallery3d.permission.GALLERY_PROVIDER"
             android:protectionLevel="signatureOrSystem" />
@@ -324,7 +324,9 @@
                 <data android:scheme="package"/>
             </intent-filter>
         </receiver>
-        <service android:name="com.android.gallery3d.app.PackagesMonitor$AsyncService"/>
+        <service android:name="com.android.gallery3d.app.PackagesMonitor$AsyncService"
+                 android:permission="android.permission.BIND_JOB_SERVICE"
+                 android:exported="true"/>
         <service android:name="com.android.gallery3d.gadget.WidgetService"
                 android:permission="android.permission.BIND_REMOTEVIEWS"/>
         <activity android:name="com.android.gallery3d.gadget.WidgetConfigure"
diff --git a/proguard.flags b/proguard.flags
index 72cba51..5fde2d3 100644
--- a/proguard.flags
+++ b/proguard.flags
@@ -47,6 +47,9 @@
 -keep interface com.actionbarsherlock.** { *; }
 -keepattributes *Annotation*
 
+# Required for JobIntentService
+-keep class androidx.core.app.CoreComponentFactory { *; }
+
 # Required for mp4parser
 -keep public class * implements com.coremedia.iso.boxes.Box
 
diff --git a/src/com/android/gallery3d/app/PackagesMonitor.java b/src/com/android/gallery3d/app/PackagesMonitor.java
index 9b2412f..be262fd 100644
--- a/src/com/android/gallery3d/app/PackagesMonitor.java
+++ b/src/com/android/gallery3d/app/PackagesMonitor.java
@@ -22,6 +22,7 @@
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.preference.PreferenceManager;
+import androidx.core.app.JobIntentService;
 
 import com.android.gallery3d.picasasource.PicasaSource;
 import com.android.gallery3d.util.LightCycleHelper;
@@ -37,16 +38,18 @@
     @Override
     public void onReceive(final Context context, final Intent intent) {
         intent.setClass(context, AsyncService.class);
-        context.startService(intent);
+        AsyncService.enqueueWork(context, intent);
     }
 
-    public static class AsyncService extends IntentService {
-        public AsyncService() {
-            super("GalleryPackagesMonitorAsync");
+    public static class AsyncService extends JobIntentService {
+        public static final int JOB_ID = 1;
+
+        public static void enqueueWork(Context context, Intent work) {
+            enqueueWork(context, AsyncService.class, JOB_ID, work);
         }
 
         @Override
-        protected void onHandleIntent(Intent intent) {
+        protected void onHandleWork(Intent intent) {
             onReceiveAsync(this, intent);
         }
     }