OSDN Git Service

Taskbar 3.6.2 (release 2)
authorBraden Farmer <farmerbb@gmail.com>
Mon, 31 Jul 2017 07:53:11 +0000 (01:53 -0600)
committerBraden Farmer <farmerbb@gmail.com>
Mon, 31 Jul 2017 07:53:11 +0000 (01:53 -0600)
Update broadcast receivers to work around background execution limits in Android O

app/build.gradle
app/src/main/java/com/farmerbb/taskbar/receiver/BootReceiver.java
app/src/main/java/com/farmerbb/taskbar/receiver/PackageUpgradeReceiver.java
app/src/main/java/com/farmerbb/taskbar/receiver/ShowHideTaskbarReceiver.java
app/src/main/java/com/farmerbb/taskbar/receiver/StartReceiver.java
app/src/main/java/com/farmerbb/taskbar/receiver/ToggleFreeformModeReceiver.java

index 20d419f..599fa3a 100644 (file)
@@ -34,7 +34,7 @@ android {
         minSdkVersion 21
         targetSdkVersion 26
 
-        versionCode 159
+        versionCode 160
         versionName "3.6.2"
 
         resConfigs "en", "ja", "ru", "de"
index 3eac703..633ec1c 100644 (file)
@@ -20,6 +20,7 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.os.Build;
+import android.os.Handler;
 
 import com.farmerbb.taskbar.activity.DummyActivity;
 import com.farmerbb.taskbar.service.DashboardService;
@@ -53,12 +54,17 @@ public class BootReceiver extends BroadcastReceiver {
                         context.startActivity(intent2);
                     }
 
-                    context.startService(new Intent(context, TaskbarService.class));
-                    context.startService(new Intent(context, StartMenuService.class));
-                    context.startService(new Intent(context, DashboardService.class));
+                    new Handler().postDelayed(() -> {
+                        context.startService(new Intent(context, TaskbarService.class));
+                        context.startService(new Intent(context, StartMenuService.class));
+                        context.startService(new Intent(context, DashboardService.class));
+                    }, Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? 0 : 100);
                 }
 
-                context.startService(new Intent(context, NotificationService.class));
+                if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+                    context.startForegroundService(new Intent(context, NotificationService.class));
+                else
+                    context.startService(new Intent(context, NotificationService.class));
             } else {
                 editor.putBoolean("taskbar_active", U.isServiceRunning(context, NotificationService.class));
                 editor.apply();
index 5034781..21fd034 100644 (file)
@@ -20,6 +20,7 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.os.Build;
+import android.os.Handler;
 
 import com.farmerbb.taskbar.activity.DummyActivity;
 import com.farmerbb.taskbar.service.DashboardService;
@@ -42,13 +43,19 @@ public class PackageUpgradeReceiver extends BroadcastReceiver {
                     context.startActivity(intent2);
                 }
 
-                context.startService(new Intent(context, TaskbarService.class));
-                context.startService(new Intent(context, StartMenuService.class));
-                context.startService(new Intent(context, DashboardService.class));
+                new Handler().postDelayed(() -> {
+                    context.startService(new Intent(context, TaskbarService.class));
+                    context.startService(new Intent(context, StartMenuService.class));
+                    context.startService(new Intent(context, DashboardService.class));
+                }, Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? 0 : 100);
             }
 
-            if(pref.getBoolean("taskbar_active", false))
-                context.startService(new Intent(context, NotificationService.class));
+            if(pref.getBoolean("taskbar_active", false)) {
+                if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+                    context.startForegroundService(new Intent(context, NotificationService.class));
+                else
+                    context.startService(new Intent(context, NotificationService.class));
+            }
         }
     }
 }
index 4255bb4..2ffe0fa 100644 (file)
@@ -20,6 +20,7 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.os.Build;
+import android.os.Handler;
 import android.support.v4.content.LocalBroadcastManager;
 
 import com.farmerbb.taskbar.activity.DummyActivity;
@@ -53,10 +54,16 @@ public class ShowHideTaskbarReceiver extends BroadcastReceiver {
                 context.startActivity(intent2);
             }
 
-            context.startService(taskbarIntent);
-            context.startService(startMenuIntent);
-            context.startService(dashboardIntent);
-            context.startService(notificationIntent);
+            new Handler().postDelayed(() -> {
+                context.startService(taskbarIntent);
+                context.startService(startMenuIntent);
+                context.startService(dashboardIntent);
+            }, Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? 0 : 100);
+
+            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+                context.startForegroundService(notificationIntent);
+            else
+                context.startService(notificationIntent);
 
         } else {
             pref.edit().putBoolean("is_hidden", true).apply();
@@ -73,7 +80,11 @@ public class ShowHideTaskbarReceiver extends BroadcastReceiver {
                 LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.START_MENU_DISAPPEARING"));
             }
 
-            context.startService(notificationIntent);
+            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+                context.startForegroundService(notificationIntent);
+            else
+                context.startService(notificationIntent);
+
         }
     }
 }
index ccc6db8..5689ed8 100644 (file)
@@ -20,6 +20,7 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.os.Build;
+import android.os.Handler;
 
 import com.farmerbb.taskbar.activity.DummyActivity;
 import com.farmerbb.taskbar.service.DashboardService;
@@ -63,10 +64,16 @@ public class StartReceiver extends BroadcastReceiver {
                 context.startActivity(intent2);
             }
 
-            context.startService(new Intent(context, TaskbarService.class));
-            context.startService(new Intent(context, StartMenuService.class));
-            context.startService(new Intent(context, DashboardService.class));
-            context.startService(new Intent(context, NotificationService.class));
+            new Handler().postDelayed(() -> {
+                context.startService(new Intent(context, TaskbarService.class));
+                context.startService(new Intent(context, StartMenuService.class));
+                context.startService(new Intent(context, DashboardService.class));
+            }, Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? 0 : 100);
+
+            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+                context.startForegroundService(new Intent(context, NotificationService.class));
+            else
+                context.startService(new Intent(context, NotificationService.class));
         }
     }
 }
index 2997bb9..e4a91a5 100644 (file)
@@ -19,6 +19,7 @@ import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
+import android.os.Build;
 import android.support.v4.content.LocalBroadcastManager;
 
 import com.farmerbb.taskbar.R;
@@ -36,7 +37,11 @@ public class ToggleFreeformModeReceiver extends BroadcastReceiver {
             pref.edit().putBoolean("freeform_hack", false).apply();
 
             context.stopService(notificationIntent);
-            context.startService(notificationIntent);
+
+            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+                context.startForegroundService(notificationIntent);
+            else
+                context.startService(notificationIntent);
 
             LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.FINISH_FREEFORM_ACTIVITY"));
             LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.UPDATE_FREEFORM_CHECKBOX"));
@@ -50,7 +55,11 @@ public class ToggleFreeformModeReceiver extends BroadcastReceiver {
             intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 
             context.startActivity(intent2);
-            context.startService(notificationIntent);
+
+            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+                context.startForegroundService(notificationIntent);
+            else
+                context.startService(notificationIntent);
 
             LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.UPDATE_FREEFORM_CHECKBOX"));
         } else